File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -3343,16 +3343,22 @@ arg-n)``.
33433343Like function objects, bound method objects support getting arbitrary
33443344attributes. However, since method attributes are actually stored on the
33453345underlying 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
33573363See :ref: `types ` for more information.
33583364
You can’t perform that action at this time.
0 commit comments