Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
37614227
Commit
37614227
authored
Aug 23, 2007
by
Georg Brandl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Bug #1758696: more info about descriptors.
parent
604c121e
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
10 additions
and
3 deletions
+10
-3
Doc/reference/datamodel.rst
Doc/reference/datamodel.rst
+10
-3
No files found.
Doc/reference/datamodel.rst
View file @
37614227
...
@@ -1546,11 +1546,11 @@ Super Binding
...
@@ -1546,11 +1546,11 @@ Super Binding
``A.__dict__['m'].__get__(obj, A)``.
``A.__dict__['m'].__get__(obj, A)``.
For instance bindings, the precedence of descriptor invocation depends on the
For instance bindings, the precedence of descriptor invocation depends on the
which descriptor methods are defined.
D
ata descriptors define both
which descriptor methods are defined.
Normally, d
ata descriptors define both
:meth:`__get__` and :meth:`__set__`
. N
on-data descriptors have just the
:meth:`__get__` and :meth:`__set__`
, while n
on-data descriptors have just the
:meth:`__get__` method. Data descriptors always override a redefinition in an
:meth:`__get__` method. Data descriptors always override a redefinition in an
instance dictionary. In contrast, non-data descriptors can be overridden by
instance dictionary. In contrast, non-data descriptors can be overridden by
instances.
instances.
[#]_
Python methods (including :func:`staticmethod` and :func:`classmethod`) are
Python methods (including :func:`staticmethod` and :func:`classmethod`) are
implemented as non-data descriptors. Accordingly, instances can redefine and
implemented as non-data descriptors. Accordingly, instances can redefine and
...
@@ -2242,6 +2242,13 @@ For more information on context managers, see :ref:`typecontextmanager`.
...
@@ -2242,6 +2242,13 @@ For more information on context managers, see :ref:`typecontextmanager`.
.. [#] This, and other statements, are only roughly true for instances of new-style
.. [#] This, and other statements, are only roughly true for instances of new-style
classes.
classes.
.. [#] A descriptor can define any combination of :meth:`__get__`,
:meth:`__set__` and :meth:`__delete__`. If it does not define :meth:`__get__`,
then accessing the attribute even on an instance will return the descriptor
object itself. If the descriptor defines :meth:`__set__` and/or
:meth:`__delete__`, it is a data descriptor; if it defines neither, it is a
non-data descriptor.
.. [#] For operands of the same type, it is assumed that if the non-reflected method
.. [#] For operands of the same type, it is assumed that if the non-reflected method
(such as :meth:`__add__`) fails the operation is not supported, which is why the
(such as :meth:`__add__`) fails the operation is not supported, which is why the
reflected method is not called.
reflected method is not called.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment