Issue 29032: How does the self attribute of method become a class rather a instance? (original) (raw)

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:40 admin set github: 73218
2016-12-21 09:36:01 woo yoo set messages: +
2016-12-21 09:23:16 serhiy.storchaka set nosy: + serhiy.storchakamessages: + resolution: not a bugstage: resolved
2016-12-21 09:17:36 woo yoo set status: open -> closedmessages: +
2016-12-21 09:12:09 woo yoo set messages: +
2016-12-21 09:08:52 woo yoo create