Skip to content

Commit

Permalink
Merge pull request #228 from asottile/perf-boost
Browse files Browse the repository at this point in the history
improve tokenize performance on python<3.10
  • Loading branch information
asottile authored Mar 13, 2022
2 parents a6f604f + e0176a4 commit 48861a6
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions reorder_python_imports.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@
from aspy.refactor_imports.import_obj import ImportImport
from aspy.refactor_imports.sort import sort

# this is a performance hack. see https://bugs.python.org/issue43014
if ( # pragma: no branch
sys.version_info < (3, 10) and
callable(getattr(tokenize, '_compile', None))
): # pragma: <3.10 cover
from functools import lru_cache
tokenize._compile = lru_cache()(tokenize._compile) # type: ignore

CodeType = enum.Enum('CodeType', 'PRE_IMPORT_CODE IMPORT NON_CODE CODE')


Expand Down

0 comments on commit 48861a6

Please sign in to comment.