Skip to content

Commit

Permalink
Importing inspect is expensive. Defer it unless needed.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaraco committed Mar 14, 2021
1 parent bf777ae commit 60f2791
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion importlib_metadata/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import sys
import zipp
import email
import inspect
import pathlib
import operator
import warnings
Expand Down Expand Up @@ -206,6 +205,9 @@ def _from_text_for(cls, text, dist):


def flake8_bypass(func):
# defer inspect import as performance optimization.
import inspect

is_flake8 = any('flake8' in str(frame.filename) for frame in inspect.stack()[:5])
return func if not is_flake8 else lambda: None

Expand Down

0 comments on commit 60f2791

Please sign in to comment.