Skip to content

Commit 537c55d

Browse files
committed
Reimplement flake8 bypass as a decorator.
1 parent 1f46354 commit 537c55d

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

importlib_metadata/__init__.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,14 @@
55
import sys
66
import zipp
77
import email
8+
import inspect
89
import pathlib
910
import operator
1011
import warnings
1112
import functools
1213
import itertools
1314
import posixpath
15+
import contextlib
1416
import collections.abc
1517

1618
from ._compat import (
@@ -227,6 +229,13 @@ def select(self, **params):
227229
return self._all.select(**params)
228230

229231

232+
class Flake8Bypass(warnings.catch_warnings, contextlib.ContextDecorator):
233+
def __enter__(self):
234+
super().__enter__()
235+
is_flake8 = any('flake8' in str(frame) for frame in inspect.stack())
236+
is_flake8 and warnings.simplefilter('ignore', DeprecationWarning)
237+
238+
230239
class DeprecatedDict(dict):
231240
"""
232241
Compatibility wrapper around dict to indicate that
@@ -252,6 +261,7 @@ def __getitem__(self, name):
252261
self._warn()
253262
return super().__getitem__(name)
254263

264+
@Flake8Bypass()
255265
def get(self, name, default=None):
256266
self._warn()
257267
return super().get(name, default)

0 commit comments

Comments
 (0)