File tree 1 file changed +6
-3
lines changed
1 file changed +6
-3
lines changed Original file line number Diff line number Diff line change @@ -344,20 +344,23 @@ def _flatten_literal_params(parameters):
344
344
345
345
346
346
_cleanups = []
347
+ _caches = { }
347
348
348
349
349
350
def _tp_cache (func = None , / , * , typed = False ):
350
351
"""Internal wrapper caching __getitem__ of generic types with a fallback to
351
352
original function for non-hashable arguments.
352
353
"""
353
354
def decorator (func ):
354
- cached = functools .lru_cache (typed = typed )(func )
355
- _cleanups .append (cached .cache_clear )
355
+ cache = functools .lru_cache (typed = typed )(func )
356
+ _caches [func ] = cache
357
+ _cleanups .append (cache .cache_clear )
358
+ del cache
356
359
357
360
@functools .wraps (func )
358
361
def inner (* args , ** kwds ):
359
362
try :
360
- return cached (* args , ** kwds )
363
+ return _caches [ func ] (* args , ** kwds )
361
364
except TypeError :
362
365
pass # All real errors (not unhashable args) are raised below.
363
366
return func (* args , ** kwds )
You can’t perform that action at this time.
0 commit comments