@@ -677,27 +677,29 @@ def prop(self, val):
677
677
class B (A ):
678
678
...
679
679
680
- a = B ()
681
- # When you access a Python method the function is bound
682
- # to the object at access time so you get a new instance
683
- # of MethodType every time.
684
- #
685
- # https://docs.python.org/3/howto/descriptor.html#functions-and-methods
686
- assert a .meth is not a .meth
687
- # normal attribute should give you back the same
688
- # instance every time
689
- assert a .aardvark is a .aardvark
690
- # and our property happens to give the same instance every time
691
- assert a . prop is a . prop
692
-
693
- assert a .cls_level is A .cls_level
694
-
695
- assert a . override == 'override'
680
+ def verify_pre_post_state ( obj ):
681
+ # When you access a Python method the function is bound
682
+ # to the object at access time so you get a new instance
683
+ # of MethodType every time.
684
+ #
685
+ # https://docs.python.org/3/howto/descriptor.html#functions-and-methods
686
+ assert obj .meth is not obj .meth
687
+ # normal attribute should give you back the same
688
+ # instance every time
689
+ assert obj .aardvark is obj .aardvark
690
+ assert a . aardvark == 'aardvark'
691
+ # and our property happens to give the same instance every time
692
+ assert obj . prop is obj . prop
693
+ assert obj .cls_level is A .cls_level
694
+ assert obj . override == 'override'
695
+ assert not hasattr ( obj , 'extra' )
696
696
697
+ a = B ()
698
+ verify_pre_post_state (a )
697
699
with cbook ._setattr_cm (
698
700
a ,
699
- aardvark = 'moose' , meth = lambda : None , prop = 'b' , cls_level = 'bob' ,
700
- override = 'boo'
701
+ aardvark = 'moose' , meth = lambda : None , prop = 'b' ,
702
+ cls_level = 'bob' , override = 'boo' , extra = 'extra '
701
703
):
702
704
# because we have set a lambda, it is normal attribute access
703
705
# and the same every time
@@ -707,11 +709,5 @@ class B(A):
707
709
assert a .prop == 'b'
708
710
assert a .cls_level == 'bob'
709
711
assert a .override == 'boo'
710
-
711
- # check that we get different MethodType instances each time
712
- assert a .meth is not a .meth
713
- assert a .aardvark is a .aardvark
714
- assert a .aardvark == 'aardvark'
715
- assert a .prop is a .prop
716
- assert a .cls_level is A .cls_level
717
- assert a .override == 'override'
712
+ assert a .extra == 'extra'
713
+ verify_pre_post_state (a )
0 commit comments