66
77from astroid .brain .helpers import register_module_extender
88from astroid .builder import extract_node , parse
9- from astroid .const import PY39_PLUS
109from astroid .context import InferenceContext
1110from astroid .exceptions import AttributeInferenceError
1211from astroid .manager import AstroidManager
@@ -61,9 +60,7 @@ def __add__(self, other): pass
6160 def __iadd__(self, other): pass
6261 def __mul__(self, other): pass
6362 def __imul__(self, other): pass
64- def __rmul__(self, other): pass"""
65- if PY39_PLUS :
66- base_deque_class += """
63+ def __rmul__(self, other): pass
6764 @classmethod
6865 def __class_getitem__(self, item): return cls"""
6966 return base_deque_class
@@ -73,9 +70,7 @@ def _ordered_dict_mock():
7370 base_ordered_dict_class = """
7471 class OrderedDict(dict):
7572 def __reversed__(self): return self[::-1]
76- def move_to_end(self, key, last=False): pass"""
77- if PY39_PLUS :
78- base_ordered_dict_class += """
73+ def move_to_end(self, key, last=False): pass
7974 @classmethod
8075 def __class_getitem__(cls, item): return cls"""
8176 return base_ordered_dict_class
@@ -116,11 +111,10 @@ def easy_class_getitem_inference(node, context: InferenceContext | None = None):
116111def register (manager : AstroidManager ) -> None :
117112 register_module_extender (manager , "collections" , _collections_transform )
118113
119- if PY39_PLUS :
120- # Starting with Python39 some objects of the collection module are subscriptable
121- # thanks to the __class_getitem__ method but the way it is implemented in
122- # _collection_abc makes it difficult to infer. (We would have to handle AssignName inference in the
123- # getitem method of the ClassDef class) Instead we put here a mock of the __class_getitem__ method
124- manager .register_transform (
125- ClassDef , easy_class_getitem_inference , _looks_like_subscriptable
126- )
114+ # Starting with Python39 some objects of the collection module are subscriptable
115+ # thanks to the __class_getitem__ method but the way it is implemented in
116+ # _collection_abc makes it difficult to infer. (We would have to handle AssignName inference in the
117+ # getitem method of the ClassDef class) Instead we put here a mock of the __class_getitem__ method
118+ manager .register_transform (
119+ ClassDef , easy_class_getitem_inference , _looks_like_subscriptable
120+ )
0 commit comments