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: howto/descriptor.rst incorrectly mentions method.__class__
Type: enhancement Stage: resolved
Components: Documentation Versions: Python 3.10
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: rhettinger Nosy List: Yonatan Goldschmidt, docs@python, miss-islington, rhettinger
Priority: normal Keywords: patch

Created on 2020-07-28 20:47 by Yonatan Goldschmidt, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 21665 merged Yonatan Goldschmidt, 2020-07-28 20:58
PR 21667 merged miss-islington, 2020-07-29 01:38
PR 21668 merged miss-islington, 2020-07-29 01:38
Messages (4)
msg374526 - (view) Author: Yonatan Goldschmidt (Yonatan Goldschmidt) * Date: 2020-07-28 20:47
In Doc/howto/descriptor.rst:

    # Internally, the bound method stores the underlying function,
    # the bound instance, and the class of the bound instance.
    >>> d.f.__func__
    <function D.f at 0x1012e5ae8>
    >>> d.f.__self__
    <__main__.D object at 0x1012e1f98>
    >>> d.f.__class__
    <class 'method'>

The bound method (PyMethodObject) does not store "the class of the bound instance" - it only stores the "function" and "self".
d.f.__class__ is the class of the "method" type itself, not the class of d.f's instance (D from d = D())

I think this mention should be removed from the documentation?
msg374541 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2020-07-28 23:42
Good catch.  Thanks for the report.
msg374543 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2020-07-28 23:48
The origin of the error was an incorrect update from Python 2 semantics where the class was exposed as an attribute:

Python 2.7.17 (v2.7.17:c2f86d86e6, Oct 19 2019, 16:24:34) 
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license()" for more information.
>>> class A:
	def f(self, x):
		return x
	
>>> a = A()
>>> bm = a.f
>>> bm.im_class
<class __main__.A at 0x1002daf30>
>>> bm.im_self
<__main__.A instance at 0x103a204b0>
>>> bm.im_func
<function f at 0x1004ed950>
msg374557 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2020-07-29 03:19
Thanks for the PR.
History
Date User Action Args
2022-04-11 14:59:34adminsetgithub: 85599
2020-07-29 03:19:27rhettingersetstatus: open -> closed
resolution: fixed
messages: + msg374557

stage: patch review -> resolved
2020-07-29 01:38:46miss-islingtonsetpull_requests: + pull_request20818
2020-07-29 01:38:36miss-islingtonsetnosy: + miss-islington
pull_requests: + pull_request20817
2020-07-29 00:11:04rhettingersettitle: howto/descriptor.rst unnecessarily mentions method.__class__ -> howto/descriptor.rst incorrectly mentions method.__class__
2020-07-28 23:48:37rhettingersetmessages: + msg374543
2020-07-28 23:42:49rhettingersetmessages: + msg374541
2020-07-28 23:39:56rhettingersetassignee: docs@python -> rhettinger

nosy: + rhettinger
2020-07-28 20:58:02Yonatan Goldschmidtsetkeywords: + patch
stage: patch review
pull_requests: + pull_request20810
2020-07-28 20:47:00Yonatan Goldschmidtcreate