File tree 3 files changed +20
-13
lines changed 3 files changed +20
-13
lines changed Original file line number Diff line number Diff line change @@ -540,23 +540,23 @@ def isabstract(object):
540
540
return False
541
541
542
542
def _getmembers (object , predicate , getter ):
543
+ results = []
544
+ processed = set ()
545
+ names = dir (object )
543
546
if isclass (object ):
544
547
mro = (object ,) + getmro (object )
548
+ # add any DynamicClassAttributes to the list of names if object is a class;
549
+ # this may result in duplicate entries if, for example, a virtual
550
+ # attribute with the same name as a DynamicClassAttribute exists
551
+ try :
552
+ for base in object .__bases__ :
553
+ for k , v in base .__dict__ .items ():
554
+ if isinstance (v , types .DynamicClassAttribute ):
555
+ names .append (k )
556
+ except AttributeError :
557
+ pass
545
558
else :
546
559
mro = ()
547
- results = []
548
- processed = set ()
549
- names = dir (object )
550
- # :dd any DynamicClassAttributes to the list of names if object is a class;
551
- # this may result in duplicate entries if, for example, a virtual
552
- # attribute with the same name as a DynamicClassAttribute exists
553
- try :
554
- for base in object .__bases__ :
555
- for k , v in base .__dict__ .items ():
556
- if isinstance (v , types .DynamicClassAttribute ):
557
- names .append (k )
558
- except AttributeError :
559
- pass
560
560
for key in names :
561
561
# First try to get the value via getattr. Some descriptors don't
562
562
# like calling their __get__ (see bug #1785), so fall back to
Original file line number Diff line number Diff line change @@ -1215,8 +1215,13 @@ class A(metaclass=M):
1215
1215
@types .DynamicClassAttribute
1216
1216
def eggs (self ):
1217
1217
return 'spam'
1218
+ class B :
1219
+ def __getattr__ (self , attribute ):
1220
+ return None
1218
1221
self .assertIn (('eggs' , 'scrambled' ), inspect .getmembers (A ))
1219
1222
self .assertIn (('eggs' , 'spam' ), inspect .getmembers (A ()))
1223
+ b = B ()
1224
+ self .assertIn (('__getattr__' , b .__getattr__ ), inspect .getmembers (b ))
1220
1225
1221
1226
def test_getmembers_static (self ):
1222
1227
class A :
Original file line number Diff line number Diff line change
1
+ Now :func: `inspect.getmembers ` only gets :attr: `__bases__ ` attribute from
2
+ class type. Patch by Weipeng Hong.
You can’t perform that action at this time.
0 commit comments