Skip to content

Commit ed33213

Browse files
committed
Wrap function rather than decorating method. Avoids varying stack depths.
1 parent 7e7fc8c commit ed33213

File tree

1 file changed

+5
-11
lines changed

1 file changed

+5
-11
lines changed

importlib_metadata/__init__.py

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
import functools
1313
import itertools
1414
import posixpath
15-
import contextlib
1615
import collections.abc
1716

1817
from ._compat import (
@@ -193,13 +192,9 @@ def _from_text_for(cls, text, dist):
193192
return cls(ep._for(dist) for ep in EntryPoint._from_text(text))
194193

195194

196-
class Flake8Bypass(warnings.catch_warnings, contextlib.ContextDecorator):
197-
def __enter__(self):
198-
super().__enter__()
199-
is_flake8 = any(
200-
'flake8' in str(frame.filename) for frame in inspect.stack()[:5]
201-
)
202-
is_flake8 and warnings.simplefilter('ignore', DeprecationWarning)
195+
def flake8_bypass(func):
196+
is_flake8 = any('flake8' in str(frame.filename) for frame in inspect.stack()[:5])
197+
return func if not is_flake8 else lambda: None
203198

204199

205200
class DeprecatedDict(dict):
@@ -221,7 +216,7 @@ class DeprecatedDict(dict):
221216
>>> list(dd.values())
222217
['bar']
223218
>>> len(recwarn)
224-
2
219+
1
225220
"""
226221

227222
_warn = functools.partial(
@@ -235,9 +230,8 @@ def __getitem__(self, name):
235230
self._warn()
236231
return super().__getitem__(name)
237232

238-
@Flake8Bypass()
239233
def get(self, name, default=None):
240-
self._warn()
234+
flake8_bypass(self._warn)()
241235
return super().get(name, default)
242236

243237
def __iter__(self):

0 commit comments

Comments
 (0)