summaryrefslogtreecommitdiffstats
path: root/Doc
diff options
context:
space:
mode:
authorEzio Melotti <ezio.melotti@gmail.com>2012-11-08 23:03:44 (GMT)
committerEzio Melotti <ezio.melotti@gmail.com>2012-11-08 23:03:44 (GMT)
commit090177676a0449bc5625fc4fdc870b7c9a9f913a (patch)
tree104d9c7a69080979bb2b5278fd30651290651e84 /Doc
parent3eb0e1da80727a124507232355d23384c9a496a1 (diff)
downloadcpython-090177676a0449bc5625fc4fdc870b7c9a9f913a.zip
cpython-090177676a0449bc5625fc4fdc870b7c9a9f913a.tar.gz
cpython-090177676a0449bc5625fc4fdc870b7c9a9f913a.tar.bz2
#16440: fix exception type and clarify example.
Diffstat (limited to 'Doc')
-rw-r--r--Doc/library/stdtypes.rst25
1 files changed, 16 insertions, 9 deletions
diff --git a/Doc/library/stdtypes.rst b/Doc/library/stdtypes.rst
index e42791f..b51110e 100644
--- a/Doc/library/stdtypes.rst
+++ b/Doc/library/stdtypes.rst
@@ -2878,16 +2878,23 @@ that class), otherwise a :exc:`TypeError` is raised.
Like function objects, methods objects support getting arbitrary attributes.
However, since method attributes are actually stored on the underlying function
object (``meth.im_func``), setting method attributes on either bound or unbound
-methods is disallowed. Attempting to set a method attribute results in a
-:exc:`TypeError` being raised. In order to set a method attribute, you need to
-explicitly set it on the underlying function object::
+methods is disallowed. Attempting to set an attribute on a method results in
+an :exc:`AttributeError` being raised. In order to set a method attribute, you
+need to explicitly set it on the underlying function object::
+
+ >>> class C:
+ ... def method(self):
+ ... pass
+ ...
+ >>> c = C()
+ >>> c.method.whoami = 'my name is method' # can't set on the method
+ Traceback (most recent call last):
+ File "<stdin>", line 1, in <module>
+ AttributeError: 'instancemethod' object has no attribute 'whoami'
+ >>> c.method.im_func.whoami = 'my name is method'
+ >>> c.method.whoami
+ 'my name is method'
- class C:
- def method(self):
- pass
-
- c = C()
- c.method.im_func.whoami = 'my name is c'
See :ref:`types` for more information.