Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a3ad8a0

Browse files
committed
#16440: merge with 3.2.
2 parents 7cac2d8 + 8b6b176 commit a3ad8a0

1 file changed

Lines changed: 15 additions & 9 deletions

File tree

Doc/library/stdtypes.rst

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3343,16 +3343,22 @@ arg-n)``.
33433343
Like function objects, bound method objects support getting arbitrary
33443344
attributes. However, since method attributes are actually stored on the
33453345
underlying function object (``meth.__func__``), setting method attributes on
3346-
bound methods is disallowed. Attempting to set a method attribute results in a
3347-
:exc:`TypeError` being raised. In order to set a method attribute, you need to
3348-
explicitly set it on the underlying function object::
3346+
bound methods is disallowed. Attempting to set an attribute on a method
3347+
results in an :exc:`AttributeError` being raised. In order to set a method
3348+
attribute, you need to explicitly set it on the underlying function object::
33493349

3350-
class C:
3351-
def method(self):
3352-
pass
3353-
3354-
c = C()
3355-
c.method.__func__.whoami = 'my name is c'
3350+
>>> class C:
3351+
... def method(self):
3352+
... pass
3353+
...
3354+
>>> c = C()
3355+
>>> c.method.whoami = 'my name is method' # can't set on the method
3356+
Traceback (most recent call last):
3357+
File "<stdin>", line 1, in <module>
3358+
AttributeError: 'method' object has no attribute 'whoami'
3359+
>>> c.method.__func__.whoami = 'my name is method'
3360+
>>> c.method.whoami
3361+
'my name is method'
33563362

33573363
See :ref:`types` for more information.
33583364

0 commit comments

Comments
 (0)