]> granicus.if.org Git - python/commitdiff
#16440: fix exception type and clarify example.
authorEzio Melotti <ezio.melotti@gmail.com>
Thu, 8 Nov 2012 23:08:25 +0000 (01:08 +0200)
committerEzio Melotti <ezio.melotti@gmail.com>
Thu, 8 Nov 2012 23:08:25 +0000 (01:08 +0200)
Doc/library/stdtypes.rst

index 1d7467d2b5a6c5dca897a3e24d4ac52f94a3ce60..f6eca5682b5fc694e8eefdcfd920d66a426d43dd 100644 (file)
@@ -2659,16 +2659,22 @@ arg-n)``.
 Like function objects, bound method objects support getting arbitrary
 attributes.  However, since method attributes are actually stored on the
 underlying function object (``meth.__func__``), setting method attributes on
-bound 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::
+bound 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.__func__.whoami = 'my name is c'
+   >>> 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: 'method' object has no attribute 'whoami'
+   >>> c.method.__func__.whoami = 'my name is method'
+   >>> c.method.whoami
+   'my name is method'
 
 See :ref:`types` for more information.