Skip to content

Commit

Permalink
Fix issue #643: Optimize noqa() with an lru_cache for Python 3.2+. (#644
Browse files Browse the repository at this point in the history
)

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+).
  • Loading branch information
JulienPalard authored and sigmavirus24 committed Jun 4, 2017
1 parent f913dfc commit 454e035
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion pycodestyle.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,16 @@
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

Expand Down Expand Up @@ -1410,7 +1420,7 @@ def stdin_get_value():
"""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):
Expand Down

0 comments on commit 454e035

Please sign in to comment.