Skip to content

Commit 06359c0

Browse files
committed
Remove caching logic from the cached function
1 parent 3381827 commit 06359c0

File tree

1 file changed

+21
-8
lines changed

1 file changed

+21
-8
lines changed

src/flake8_requirements/checker.py

+21-8
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import re
44
import sys
55
from collections import namedtuple
6+
from functools import wraps
67
from logging import getLogger
78

89
from pkg_resources import parse_requirements
@@ -29,6 +30,19 @@
2930
STDLIB.update(STDLIB_PY3)
3031

3132

33+
def memoize(f):
34+
"""Cache value returned by the function."""
35+
@wraps(f)
36+
def w(*args, **kw):
37+
memoize.mem[f] = v = f(*args, **kw)
38+
return v
39+
return w
40+
41+
42+
# Initialize cache memory block.
43+
memoize.mem = {}
44+
45+
3246
def project2module(project):
3347
"""Convert project name into a module name."""
3448
# Name unification in accordance with PEP 426.
@@ -271,16 +285,15 @@ def parse_options(cls, options):
271285
}
272286

273287
@classmethod
288+
@memoize
274289
def get_setup(cls):
275290
"""Get package setup."""
276-
if not getattr(cls, '_setup', None):
277-
try:
278-
with open("setup.py") as f:
279-
cls._setup = SetupVisitor(ast.parse(f.read()))
280-
except IOError as e:
281-
LOG.warning("Couldn't open setup file: %s", e)
282-
cls._setup = SetupVisitor(ast.parse(""))
283-
return cls._setup
291+
try:
292+
with open("setup.py") as f:
293+
return SetupVisitor(ast.parse(f.read()))
294+
except IOError as e:
295+
LOG.warning("Couldn't open setup file: %s", e)
296+
return SetupVisitor(ast.parse(""))
284297

285298
@property
286299
def processing_setup_py(self):

0 commit comments

Comments
 (0)