Skip to content

Commit e3f76e5

Browse files
authored
Remove irrelevant detail from example code. (gh-123587)
1 parent cb6d250 commit e3f76e5

File tree

1 file changed

+10
-19
lines changed

1 file changed

+10
-19
lines changed

Doc/howto/descriptor.rst

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -990,7 +990,7 @@ The documentation shows a typical use to define a managed attribute ``x``:
990990
AttributeError: 'C' object has no attribute '_C__x'
991991

992992
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:
994994

995995
.. testcode::
996996

@@ -1013,26 +1013,17 @@ here is a mostly pure Python equivalent:
10131013
if obj is None:
10141014
return self
10151015
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
10201017
return self.fget(obj)
10211018

10221019
def __set__(self, obj, value):
10231020
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
10281022
self.fset(obj, value)
10291023

10301024
def __delete__(self, obj):
10311025
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
10361027
self.fdel(obj)
10371028

10381029
def getter(self, fget):
@@ -1105,23 +1096,23 @@ here is a mostly pure Python equivalent:
11051096
>>> try:
11061097
... cc.no_getter
11071098
... except AttributeError as e:
1108-
... e.args[0]
1099+
... type(e).__name__
11091100
...
1110-
"property 'no_getter' of 'CC' object has no getter"
1101+
'AttributeError'
11111102

11121103
>>> try:
11131104
... cc.no_setter = 33
11141105
... except AttributeError as e:
1115-
... e.args[0]
1106+
... type(e).__name__
11161107
...
1117-
"property 'no_setter' of 'CC' object has no setter"
1108+
'AttributeError'
11181109

11191110
>>> try:
11201111
... del cc.no_deleter
11211112
... except AttributeError as e:
1122-
... e.args[0]
1113+
... type(e).__name__
11231114
...
1124-
"property 'no_deleter' of 'CC' object has no deleter"
1115+
'AttributeError'
11251116

11261117
>>> CC.no_doc.__doc__ is None
11271118
True

0 commit comments

Comments
 (0)