@@ -786,7 +786,7 @@ def f(self) -> int:
786
786
787
787
788
788
@pytest .mark .skipif (not PY_3_8_PLUS , reason = "cached_property is 3.8+" )
789
- def test_slots_cached_property_with_empty_getattr_raises_attribute_error_of_requested ():
789
+ def test_slots_cached_property_with_empty_getattribute_raises_attribute_error_of_requested ():
790
790
"""
791
791
Ensures error information is not lost.
792
792
"""
@@ -809,8 +809,8 @@ def f(self):
809
809
@pytest .mark .skipif (not PY_3_8_PLUS , reason = "cached_property is 3.8+" )
810
810
def test_slots_cached_property_raising_attributeerror ():
811
811
"""
812
- Ensures AttributeError raised by a property is preserved by __getattr__()
813
- implementation.
812
+ Ensures AttributeError raised by a property is preserved by
813
+ __getattribute__() implementation.
814
814
815
815
Regression test for issue https://github.com/python-attrs/attrs/issues/1230
816
816
"""
@@ -846,9 +846,9 @@ def q(self):
846
846
847
847
848
848
@pytest .mark .skipif (not PY_3_8_PLUS , reason = "cached_property is 3.8+" )
849
- def test_slots_cached_property_with_getattr_calls_getattr_for_missing_attributes ():
849
+ def test_slots_cached_property_with_getattribute_calls_getattr_for_missing_attributes ():
850
850
"""
851
- Ensure __getattr__ implementation is maintained for non cached_properties.
851
+ Ensure __getattribute__ implementation is maintained for non cached_properties.
852
852
"""
853
853
854
854
@attr .s (slots = True )
@@ -859,7 +859,7 @@ class A:
859
859
def f (self ):
860
860
return self .x
861
861
862
- def __getattr__ (self , item ):
862
+ def __getattribute__ (self , item ):
863
863
return item
864
864
865
865
a = A (1 )
@@ -868,16 +868,16 @@ def __getattr__(self, item):
868
868
869
869
870
870
@pytest .mark .skipif (not PY_3_8_PLUS , reason = "cached_property is 3.8+" )
871
- def test_slots_getattr_in_superclass__is_called_for_missing_attributes_when_cached_property_present ():
871
+ def test_slots_getattribute_in_superclass__is_called_for_missing_attributes_when_cached_property_present ():
872
872
"""
873
- Ensure __getattr__ implementation is maintained in subclass.
873
+ Ensure __getattribute__ implementation is maintained in subclass.
874
874
"""
875
875
876
876
@attr .s (slots = True )
877
877
class A :
878
878
x = attr .ib ()
879
879
880
- def __getattr__ (self , item ):
880
+ def __getattribute__ (self , item ):
881
881
return item
882
882
883
883
@attr .s (slots = True )
@@ -949,9 +949,9 @@ def __getattr__(self, item: str) -> str:
949
949
950
950
951
951
@pytest .mark .skipif (not PY_3_8_PLUS , reason = "cached_property is 3.8+" )
952
- def test_slots_getattr_in_subclass_gets_superclass_cached_property ():
952
+ def test_slots_getattribute_in_subclass_gets_superclass_cached_property ():
953
953
"""
954
- Ensure super() in __getattr__ is not broken through cached_property re-write.
954
+ Ensure super() in __getattribute__ is not broken through cached_property re-write.
955
955
"""
956
956
957
957
@attr .s (slots = True )
@@ -962,7 +962,7 @@ class A:
962
962
def f (self ):
963
963
return self .x
964
964
965
- def __getattr__ (self , item ):
965
+ def __getattribute__ (self , item ):
966
966
return item
967
967
968
968
@attr .s (slots = True )
@@ -971,8 +971,8 @@ class B(A):
971
971
def g (self ):
972
972
return self .x
973
973
974
- def __getattr__ (self , item ):
975
- return super ().__getattr__ (item )
974
+ def __getattribute__ (self , item ):
975
+ return super ().__getattribute__ (item )
976
976
977
977
b = B (1 )
978
978
assert b .f == 1
@@ -1023,10 +1023,11 @@ class B:
1023
1023
def g (self ):
1024
1024
return self .x * 2
1025
1025
1026
- def __getattr__ (self , item ):
1027
- if hasattr (super (), "__getattr__" ):
1028
- return super ().__getattr__ (item )
1029
- return item
1026
+ def __getattribute__ (self , item ):
1027
+ try :
1028
+ return super ().__getattribute__ (item )
1029
+ except AttributeError :
1030
+ return item
1030
1031
1031
1032
@attr .s (slots = True )
1032
1033
class AB (A , B ):
0 commit comments