@@ -2354,26 +2354,24 @@ def getattr(
2354
2354
2355
2355
if name in self .special_attributes and class_context and not values :
2356
2356
result = [self .special_attributes .lookup (name )]
2357
- if name == "__bases__" :
2358
- # Need special treatment, since they are mutable
2359
- # and we need to return all the values.
2360
- result += values
2361
2357
return result
2362
2358
2363
2359
if class_context :
2364
2360
values += self ._metaclass_lookup_attribute (name , context )
2365
2361
2366
- # Remove AnnAssigns without value, which are not attributes in the purest sense.
2367
- for value in values . copy () :
2362
+ result : list [ InferenceResult ] = []
2363
+ for value in values :
2368
2364
if isinstance (value , node_classes .AssignName ):
2369
2365
stmt = value .statement ()
2366
+ # Ignore AnnAssigns without value, which are not attributes in the purest sense.
2370
2367
if isinstance (stmt , node_classes .AnnAssign ) and stmt .value is None :
2371
- values .pop (values .index (value ))
2368
+ continue
2369
+ result .append (value )
2372
2370
2373
- if not values :
2371
+ if not result :
2374
2372
raise AttributeInferenceError (target = self , attribute = name , context = context )
2375
2373
2376
- return values
2374
+ return result
2377
2375
2378
2376
@lru_cache (maxsize = 1024 ) # noqa
2379
2377
def _metaclass_lookup_attribute (self , name , context ):
@@ -2385,7 +2383,7 @@ def _metaclass_lookup_attribute(self, name, context):
2385
2383
for cls in (implicit_meta , metaclass ):
2386
2384
if cls and cls != self and isinstance (cls , ClassDef ):
2387
2385
cls_attributes = self ._get_attribute_from_metaclass (cls , name , context )
2388
- attrs .update (set ( cls_attributes ) )
2386
+ attrs .update (cls_attributes )
2389
2387
return attrs
2390
2388
2391
2389
def _get_attribute_from_metaclass (self , cls , name , context ):
0 commit comments