summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulien <github@mandark.fr>2017-06-04 02:20:30 +0200
committerIan Cordasco <sigmavirus24@users.noreply.github.com>2017-06-03 19:20:30 -0500
commit454e035fd969ee5d6da76fcc169ee028933f391e (patch)
tree24ab9fc68e07b2a5d6144517c39407b53ef0a1f5
parentf913dfc041bab577cdea34e261153545b98d3e4c (diff)
downloadpep8-454e035fd969ee5d6da76fcc169ee028933f391e.tar.gz
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+).
-rwxr-xr-xpycodestyle.py12
1 files changed, 11 insertions, 1 deletions
diff --git a/pycodestyle.py b/pycodestyle.py
index bb96195..8afa286 100755
--- a/pycodestyle.py
+++ b/pycodestyle.py
@@ -58,6 +58,16 @@ import tokenize
import warnings
import bisect
+try:
+ from functools import lru_cache
+except ImportError:
+ def lru_cache(maxsize=128): # noqa as it's a fake implementation.
+ """Does not really need a real a lru_cache, it's just optimization, so
+ let's just do nothing here. Python 3.2+ will just get better
+ performances, time to upgrade?
+ """
+ return lambda function: function
+
from fnmatch import fnmatch
from optparse import OptionParser
@@ -1410,7 +1420,7 @@ else:
"""Read the value from stdin."""
return TextIOWrapper(sys.stdin.buffer, errors='ignore').read()
-noqa = re.compile(r'# no(?:qa|pep8)\b', re.I).search
+noqa = lru_cache(512)(re.compile(r'# no(?:qa|pep8)\b', re.I).search)
def expand_indent(line):