summaryrefslogtreecommitdiffstats
path: root/Doc/reference/datamodel.rst
diff options
context:
space:
mode:
authorRaymond Hettinger <rhettinger@users.noreply.github.com>2019-08-29 08:27:42 (GMT)
committerGitHub <noreply@github.com>2019-08-29 08:27:42 (GMT)
commit0dac68f1e593c11612ed54af9edb865d398f3b05 (patch)
tree0697b0f9543d4b65feaf75b3335c2fb85481e4d1 /Doc/reference/datamodel.rst
parent84125fed2a45a9e454d7e870d8bbaf6ece3d41e8 (diff)
downloadcpython-0dac68f1e593c11612ed54af9edb865d398f3b05.zip
cpython-0dac68f1e593c11612ed54af9edb865d398f3b05.tar.gz
cpython-0dac68f1e593c11612ed54af9edb865d398f3b05.tar.bz2
bpo-36743: __get__ is sometimes called without the owner argument (#12992)
Diffstat (limited to 'Doc/reference/datamodel.rst')
-rw-r--r--Doc/reference/datamodel.rst25
1 files changed, 18 insertions, 7 deletions
diff --git a/Doc/reference/datamodel.rst b/Doc/reference/datamodel.rst
index d1702cc..8813f57 100644
--- a/Doc/reference/datamodel.rst
+++ b/Doc/reference/datamodel.rst
@@ -1618,21 +1618,32 @@ refers to the attribute whose name is the key of the property in the owner
class' :attr:`~object.__dict__`.
-.. method:: object.__get__(self, instance, owner)
+.. method:: object.__get__(self, instance, owner=None)
- Called to get the attribute of the owner class (class attribute access) or of an
- instance of that class (instance attribute access). *owner* is always the owner
- class, while *instance* is the instance that the attribute was accessed through,
- or ``None`` when the attribute is accessed through the *owner*. This method
- should return the (computed) attribute value or raise an :exc:`AttributeError`
- exception.
+ Called to get the attribute of the owner class (class attribute access) or
+ of an instance of that class (instance attribute access). The optional
+ *owner* argument is the owner class, while *instance* is the instance that
+ the attribute was accessed through, or ``None`` when the attribute is
+ accessed through the *owner*.
+ This method should return the computed attribute value or raise an
+ :exc:`AttributeError` exception.
+
+ :PEP:`252` specifies that :meth:`__get__` is callable with one or two
+ arguments. Python's own built-in descriptors support this specification;
+ however, it is likely that some third-party tools have descriptors
+ that require both arguments. Python's own :meth:`__getattribute__`
+ implementation always passes in both arguments whether they are required
+ or not.
.. method:: object.__set__(self, instance, value)
Called to set the attribute on an instance *instance* of the owner class to a
new value, *value*.
+ Note, adding :meth:`__set__` or :meth:`__delete__` changes the kind of
+ descriptor to a "data descriptor". See :ref:`descriptor-invocation` for
+ more details.
.. method:: object.__delete__(self, instance)