clean up lru_cache in compat

This commit is contained in:
Anthony Sottile 2021-03-29 18:09:37 -07:00
parent 358ae85120
commit 5b9edd04ee
3 changed files with 6 additions and 7 deletions

View file

@ -1,10 +1,9 @@
"""Expose backports in a single place.""" """Expose backports in a single place."""
import sys import sys
from functools import lru_cache
if sys.version_info >= (3, 8): # pragma: no cover (PY38+) if sys.version_info >= (3, 8): # pragma: no cover (PY38+)
import importlib.metadata as importlib_metadata import importlib.metadata as importlib_metadata
else: # pragma: no cover (<PY38) else: # pragma: no cover (<PY38)
import importlib_metadata import importlib_metadata
__all__ = ("lru_cache", "importlib_metadata") __all__ = ("importlib_metadata",)

View file

@ -4,6 +4,7 @@ import collections
import contextlib import contextlib
import copy import copy
import enum import enum
import functools
import itertools import itertools
import linecache import linecache
import logging import logging
@ -20,7 +21,6 @@ from typing import Union
from flake8 import defaults from flake8 import defaults
from flake8 import statistics from flake8 import statistics
from flake8 import utils from flake8 import utils
from flake8._compat import lru_cache
from flake8.formatting import base as base_formatter from flake8.formatting import base as base_formatter
__all__ = ("StyleGuide",) __all__ = ("StyleGuide",)
@ -49,7 +49,7 @@ class Decision(enum.Enum):
Selected = "selected error" Selected = "selected error"
@lru_cache(maxsize=512) @functools.lru_cache(maxsize=512)
def find_noqa(physical_line): # type: (str) -> Optional[Match[str]] def find_noqa(physical_line): # type: (str) -> Optional[Match[str]]
return defaults.NOQA_INLINE_REGEXP.search(physical_line) return defaults.NOQA_INLINE_REGEXP.search(physical_line)
@ -374,7 +374,7 @@ class StyleGuideManager:
filename=filename, extend_ignore_with=violations filename=filename, extend_ignore_with=violations
) )
@lru_cache(maxsize=None) @functools.lru_cache(maxsize=None)
def style_guide_for(self, filename): # type: (str) -> StyleGuide def style_guide_for(self, filename): # type: (str) -> StyleGuide
"""Find the StyleGuide for the filename in particular.""" """Find the StyleGuide for the filename in particular."""
guides = sorted( guides = sorted(

View file

@ -1,6 +1,7 @@
"""Utility methods for flake8.""" """Utility methods for flake8."""
import collections import collections
import fnmatch as _fnmatch import fnmatch as _fnmatch
import functools
import inspect import inspect
import io import io
import logging import logging
@ -21,7 +22,6 @@ from typing import Tuple
from typing import Union from typing import Union
from flake8 import exceptions from flake8 import exceptions
from flake8._compat import lru_cache
if False: # `typing.TYPE_CHECKING` was introduced in 3.5.2 if False: # `typing.TYPE_CHECKING` was introduced in 3.5.2
from flake8.plugins.manager import Plugin from flake8.plugins.manager import Plugin
@ -209,7 +209,7 @@ def _stdin_get_value_py3(): # type: () -> str
return stdin_value.decode("utf-8") return stdin_value.decode("utf-8")
@lru_cache(maxsize=1) @functools.lru_cache(maxsize=1)
def stdin_get_value(): # type: () -> str def stdin_get_value(): # type: () -> str
"""Get and cache it so plugins can use it.""" """Get and cache it so plugins can use it."""
return _stdin_get_value_py3() return _stdin_get_value_py3()