Avoid `@lru_cache` on methods
The problem with `@lru_cache` on methods is that it also captures `self` and leaks it until the entry is evicted (if ever).
This commit is contained in:
parent
7720154ca0
commit
614f5394b5
|
@ -554,6 +554,7 @@ def set_location(node, lineno, col_offset):
|
||||||
return node
|
return node
|
||||||
|
|
||||||
|
|
||||||
|
@functools.lru_cache(maxsize=1)
|
||||||
def _get_assertion_exprs(src: bytes) -> Dict[int, str]:
|
def _get_assertion_exprs(src: bytes) -> Dict[int, str]:
|
||||||
"""Return a mapping from {lineno: "assertion test expression"}."""
|
"""Return a mapping from {lineno: "assertion test expression"}."""
|
||||||
ret: Dict[int, str] = {}
|
ret: Dict[int, str] = {}
|
||||||
|
@ -675,10 +676,6 @@ class AssertionRewriter(ast.NodeVisitor):
|
||||||
self.enable_assertion_pass_hook = False
|
self.enable_assertion_pass_hook = False
|
||||||
self.source = source
|
self.source = source
|
||||||
|
|
||||||
@functools.lru_cache(maxsize=1)
|
|
||||||
def _assert_expr_to_lineno(self) -> Dict[int, str]:
|
|
||||||
return _get_assertion_exprs(self.source)
|
|
||||||
|
|
||||||
def run(self, mod: ast.Module) -> None:
|
def run(self, mod: ast.Module) -> None:
|
||||||
"""Find all assert statements in *mod* and rewrite them."""
|
"""Find all assert statements in *mod* and rewrite them."""
|
||||||
if not mod.body:
|
if not mod.body:
|
||||||
|
@ -906,7 +903,7 @@ class AssertionRewriter(ast.NodeVisitor):
|
||||||
|
|
||||||
# Passed
|
# Passed
|
||||||
fmt_pass = self.helper("_format_explanation", msg)
|
fmt_pass = self.helper("_format_explanation", msg)
|
||||||
orig = self._assert_expr_to_lineno()[assert_.lineno]
|
orig = _get_assertion_exprs(self.source)[assert_.lineno]
|
||||||
hook_call_pass = ast.Expr(
|
hook_call_pass = ast.Expr(
|
||||||
self.helper(
|
self.helper(
|
||||||
"_call_assertion_pass",
|
"_call_assertion_pass",
|
||||||
|
|
|
@ -522,7 +522,6 @@ class PytestPluginManager(PluginManager):
|
||||||
if x.is_dir():
|
if x.is_dir():
|
||||||
self._getconftestmodules(x, importmode, rootpath)
|
self._getconftestmodules(x, importmode, rootpath)
|
||||||
|
|
||||||
@lru_cache(maxsize=128)
|
|
||||||
def _getconftestmodules(
|
def _getconftestmodules(
|
||||||
self, path: Path, importmode: Union[str, ImportMode], rootpath: Path
|
self, path: Path, importmode: Union[str, ImportMode], rootpath: Path
|
||||||
) -> List[types.ModuleType]:
|
) -> List[types.ModuleType]:
|
||||||
|
|
Loading…
Reference in New Issue