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."""
import sys
from functools import lru_cache
if sys.version_info >= (3, 8): # pragma: no cover (PY38+)
import importlib.metadata as importlib_metadata
else: # pragma: no cover (<PY38)
import importlib_metadata
__all__ = ("lru_cache", "importlib_metadata")
__all__ = ("importlib_metadata",)

View file

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

View file

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