Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue #643: Optimize noqa() with an lru_cache for Python 3.2+. #644

Merged
merged 1 commit into from
Jun 4, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Fix issue #643: Optimize noqa() with an lru_cache for Python 3.2+.
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 committed May 14, 2017
commit c4d0625027f89346a79dbe0612d21596df50df9b
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