From 7e7fc8c8f379df4a3d47258015de8e7ae4cd54c5 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Thu, 4 Mar 2021 05:22:38 -0500 Subject: [PATCH] Just check the filename in the frame. Otherwise, it'll match on the current line. --- importlib_metadata/__init__.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/importlib_metadata/__init__.py b/importlib_metadata/__init__.py index fb30e2cb..5dc51d3e 100644 --- a/importlib_metadata/__init__.py +++ b/importlib_metadata/__init__.py @@ -196,7 +196,9 @@ def _from_text_for(cls, text, dist): class Flake8Bypass(warnings.catch_warnings, contextlib.ContextDecorator): def __enter__(self): super().__enter__() - is_flake8 = any('flake8' in str(frame) for frame in inspect.stack()) + is_flake8 = any( + 'flake8' in str(frame.filename) for frame in inspect.stack()[:5] + ) is_flake8 and warnings.simplefilter('ignore', DeprecationWarning) @@ -219,7 +221,7 @@ class DeprecatedDict(dict): >>> list(dd.values()) ['bar'] >>> len(recwarn) - 1 + 2 """ _warn = functools.partial(