Fix typing-related issued on Python < 3.9.

This commit is contained in:
Andrey Rakhmatullin 2023-05-10 14:21:18 +04:00
parent e03c6bb70a
commit 6998e1c905
2 changed files with 4 additions and 7 deletions

View File

@ -5,10 +5,9 @@ Python Standard Library.
This module must not depend on any module outside the Standard Library.
"""
import collections
import weakref
from collections.abc import Mapping
from typing import Any, Optional, Sequence, TypeVar
from typing import Any, Optional, OrderedDict, Sequence, TypeVar
_KT = TypeVar("_KT")
_VT = TypeVar("_VT")
@ -68,7 +67,7 @@ class CaselessDict(dict):
return dict.pop(self, self.normkey(key), *args)
class LocalCache(collections.OrderedDict[_KT, _VT]):
class LocalCache(OrderedDict[_KT, _VT]):
"""Dictionary with a finite number of keys.
Older items expires first.
@ -85,7 +84,7 @@ class LocalCache(collections.OrderedDict[_KT, _VT]):
super().__setitem__(key, value)
class LocalWeakReferencedCache(weakref.WeakKeyDictionary[_KT, _VT]):
class LocalWeakReferencedCache(weakref.WeakKeyDictionary):
"""
A weakref.WeakKeyDictionary implementation that uses LocalCache as its
underlying data structure, making it ordered and capable of being size-limited.

View File

@ -232,9 +232,7 @@ def walk_callable(node: ast.AST) -> Generator[ast.AST, Any, None]:
yield node
_generator_callbacks_cache: LocalWeakReferencedCache[
Callable, bool
] = LocalWeakReferencedCache(limit=128)
_generator_callbacks_cache = LocalWeakReferencedCache(limit=128)
def is_generator_with_return_value(callable: Callable) -> bool: