This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: How does the __self__ attribute of method become a class rather a instance?
Type: behavior Stage: resolved
Components: Documentation Versions: Python 3.6, Python 3.5
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: docs@python Nosy List: docs@python, serhiy.storchaka, woo yoo
Priority: normal Keywords:

Created on 2016-12-21 09:08 by woo yoo, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Messages (5)
msg283724 - (view) Author: woo yoo (woo yoo) Date: 2016-12-21 09:08
The documentation of instance methods confused me, it classifies methods into two types:the one is retrieved by an instance of a class, the other is created by retrieving a method from a class or instance.

According to the description,

>When an instance method object is created by retrieving a class method >object from a class or instance, its __self__ attribute is the class >itself, and its __func__ attribute is the function object underlying the >class method.

the  __self__ attribute of the more complex methods is a class. How does this happen? Is this description incorrect?
msg283725 - (view) Author: woo yoo (woo yoo) Date: 2016-12-21 09:12
The quotation section :

When an instance method object is created by retrieving a class method object from a class or instance, its __self__ attribute is the class itself, and its __func__ attribute is the function object underlying the class method.

The associated link is https://docs.python.org/3.6/reference/datamodel.html#the-standard-type-hierarchy ,which lies in the 'instance mthods' section.
msg283727 - (view) Author: woo yoo (woo yoo) Date: 2016-12-21 09:17
Not a bug,sorry to bother
msg283728 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2016-12-21 09:23
The description looks correct to me. Note that it says about class methods.

>>> class A:
...     @classmethod
...     def f(cls): pass
... 
>>> a = A()
>>> A.f
<bound method A.f of <class '__main__.A'>>
>>> A.f.__self__
<class '__main__.A'>
>>> a.f
<bound method A.f of <class '__main__.A'>>
>>> a.f.__self__
<class '__main__.A'>
msg283729 - (view) Author: woo yoo (woo yoo) Date: 2016-12-21 09:36
Thanks for your reply.
History
Date User Action Args
2022-04-11 14:58:40adminsetgithub: 73218
2016-12-21 09:36:01woo yoosetmessages: + msg283729
2016-12-21 09:23:16serhiy.storchakasetnosy: + serhiy.storchaka
messages: + msg283728

resolution: not a bug
stage: resolved
2016-12-21 09:17:36woo yoosetstatus: open -> closed

messages: + msg283727
2016-12-21 09:12:09woo yoosetmessages: + msg283725
2016-12-21 09:08:52woo yoocreate