Skip to content

Commit 454e035

Browse files
JulienPalardsigmavirus24
authored andcommitted
Fix issue #643: Optimize noqa() with an lru_cache for Python 3.2+. (#644)
Had to catch a "No signature found for builtin <built-in method search of _sre.SRE_Pattern object at 0x...>" in 3.4: In python3.4 the search was not detected as a function, now that it's wrapped in an lru_cache it is, yet it still has no signature (it has in 3.5+).
1 parent f913dfc commit 454e035

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

pycodestyle.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,16 @@
5858
import warnings
5959
import bisect
6060

61+
try:
62+
from functools import lru_cache
63+
except ImportError:
64+
def lru_cache(maxsize=128): # noqa as it's a fake implementation.
65+
"""Does not really need a real a lru_cache, it's just optimization, so
66+
let's just do nothing here. Python 3.2+ will just get better
67+
performances, time to upgrade?
68+
"""
69+
return lambda function: function
70+
6171
from fnmatch import fnmatch
6272
from optparse import OptionParser
6373

@@ -1410,7 +1420,7 @@ def stdin_get_value():
14101420
"""Read the value from stdin."""
14111421
return TextIOWrapper(sys.stdin.buffer, errors='ignore').read()
14121422

1413-
noqa = re.compile(r'# no(?:qa|pep8)\b', re.I).search
1423+
noqa = lru_cache(512)(re.compile(r'# no(?:qa|pep8)\b', re.I).search)
14141424

14151425

14161426
def expand_indent(line):

0 commit comments

Comments
 (0)