File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -2659,16 +2659,22 @@ arg-n)``.
26592659Like function objects, bound method objects support getting arbitrary
26602660attributes. However, since method attributes are actually stored on the
26612661underlying function object (``meth.__func__ ``), setting method attributes on
2662- bound methods is disallowed. Attempting to set a method attribute results in a
2663- :exc: `TypeError ` being raised. In order to set a method attribute, you need to
2664- explicitly set it on the underlying function object::
2662+ bound methods is disallowed. Attempting to set an attribute on a method
2663+ results in an :exc: `AttributeError ` being raised. In order to set a method
2664+ attribute, you need to explicitly set it on the underlying function object::
26652665
2666- class C:
2667- def method(self):
2668- pass
2669-
2670- c = C()
2671- c.method.__func__.whoami = 'my name is c'
2666+ >>> class C:
2667+ ... def method(self):
2668+ ... pass
2669+ ...
2670+ >>> c = C()
2671+ >>> c.method.whoami = 'my name is method' # can't set on the method
2672+ Traceback (most recent call last):
2673+ File "<stdin>", line 1, in <module>
2674+ AttributeError: 'method' object has no attribute 'whoami'
2675+ >>> c.method.__func__.whoami = 'my name is method'
2676+ >>> c.method.whoami
2677+ 'my name is method'
26722678
26732679See :ref: `types ` for more information.
26742680
You can’t perform that action at this time.
0 commit comments