Skip to content

Remove irrelevant detail from example code. #123587

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 10 additions & 19 deletions Doc/howto/descriptor.rst
Original file line number Diff line number Diff line change
Expand Up @@ -990,7 +990,7 @@ The documentation shows a typical use to define a managed attribute ``x``:
AttributeError: 'C' object has no attribute '_C__x'

To see how :func:`property` is implemented in terms of the descriptor protocol,
here is a mostly pure Python equivalent:
here is a pure Python equivalent that implements most of the core functionality:

.. testcode::

Expand All @@ -1013,26 +1013,17 @@ here is a mostly pure Python equivalent:
if obj is None:
return self
if self.fget is None:
raise AttributeError(
f'property {self.__name__!r} of {type(obj).__name__!r} '
'object has no getter'
)
raise AttributeError
return self.fget(obj)

def __set__(self, obj, value):
if self.fset is None:
raise AttributeError(
f'property {self.__name__!r} of {type(obj).__name__!r} '
'object has no setter'
)
raise AttributeError
self.fset(obj, value)

def __delete__(self, obj):
if self.fdel is None:
raise AttributeError(
f'property {self.__name__!r} of {type(obj).__name__!r} '
'object has no deleter'
)
raise AttributeError
self.fdel(obj)

def getter(self, fget):
Expand Down Expand Up @@ -1105,23 +1096,23 @@ here is a mostly pure Python equivalent:
>>> try:
... cc.no_getter
... except AttributeError as e:
... e.args[0]
... type(e).__name__
...
"property 'no_getter' of 'CC' object has no getter"
'AttributeError'

>>> try:
... cc.no_setter = 33
... except AttributeError as e:
... e.args[0]
... type(e).__name__
...
"property 'no_setter' of 'CC' object has no setter"
'AttributeError'

>>> try:
... del cc.no_deleter
... except AttributeError as e:
... e.args[0]
... type(e).__name__
...
"property 'no_deleter' of 'CC' object has no deleter"
'AttributeError'

>>> CC.no_doc.__doc__ is None
True
Expand Down
Loading