File tree 1 file changed +10
-19
lines changed 1 file changed +10
-19
lines changed Original file line number Diff line number Diff line change @@ -990,7 +990,7 @@ The documentation shows a typical use to define a managed attribute ``x``:
990
990
AttributeError: 'C' object has no attribute '_C__x'
991
991
992
992
To see how :func: `property ` is implemented in terms of the descriptor protocol,
993
- here is a mostly pure Python equivalent:
993
+ here is a pure Python equivalent that implements most of the core functionality :
994
994
995
995
.. testcode ::
996
996
@@ -1013,26 +1013,17 @@ here is a mostly pure Python equivalent:
1013
1013
if obj is None:
1014
1014
return self
1015
1015
if self.fget is None:
1016
- raise AttributeError(
1017
- f'property {self.__name__!r} of {type(obj).__name__!r} '
1018
- 'object has no getter'
1019
- )
1016
+ raise AttributeError
1020
1017
return self.fget(obj)
1021
1018
1022
1019
def __set__(self, obj, value):
1023
1020
if self.fset is None:
1024
- raise AttributeError(
1025
- f'property {self.__name__!r} of {type(obj).__name__!r} '
1026
- 'object has no setter'
1027
- )
1021
+ raise AttributeError
1028
1022
self.fset(obj, value)
1029
1023
1030
1024
def __delete__(self, obj):
1031
1025
if self.fdel is None:
1032
- raise AttributeError(
1033
- f'property {self.__name__!r} of {type(obj).__name__!r} '
1034
- 'object has no deleter'
1035
- )
1026
+ raise AttributeError
1036
1027
self.fdel(obj)
1037
1028
1038
1029
def getter(self, fget):
@@ -1105,23 +1096,23 @@ here is a mostly pure Python equivalent:
1105
1096
>>> try :
1106
1097
... cc.no_getter
1107
1098
... except AttributeError as e:
1108
- ... e.args[ 0 ]
1099
+ ... type (e). __name__
1109
1100
...
1110
- "property 'no_getter' of 'CC' object has no getter"
1101
+ 'AttributeError'
1111
1102
1112
1103
>>> try :
1113
1104
... cc.no_setter = 33
1114
1105
... except AttributeError as e:
1115
- ... e.args[ 0 ]
1106
+ ... type (e). __name__
1116
1107
...
1117
- "property 'no_setter' of 'CC' object has no setter"
1108
+ 'AttributeError'
1118
1109
1119
1110
>>> try :
1120
1111
... del cc.no_deleter
1121
1112
... except AttributeError as e:
1122
- ... e.args[ 0 ]
1113
+ ... type (e). __name__
1123
1114
...
1124
- "property 'no_deleter' of 'CC' object has no deleter"
1115
+ 'AttributeError'
1125
1116
1126
1117
>>> CC .no_doc.__doc__ is None
1127
1118
True
You can’t perform that action at this time.
0 commit comments