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: Class calling
Type: behavior Stage: resolved
Components: Documentation Versions: Python 3.10, Python 3.9, Python 3.8
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: docs@python Nosy List: adelfino, georg.brandl, icordasc, miss-islington, onlyme, r.david.murray, vstinner
Priority: normal Keywords: patch

Created on 2009-08-22 17:13 by onlyme, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 7987 merged adelfino, 2018-06-28 15:07
PR 23004 merged miss-islington, 2020-10-27 16:19
PR 23005 merged miss-islington, 2020-10-27 16:19
Messages (8)
msg91864 - (view) Author: Stephen Fairchild (onlyme) Date: 2009-08-22 17:13
From:
http://docs.python.org/reference/datamodel.html#the-standard-type-hierarchy

"Class instances
    Class instances are described below. Class instances are callable
only when the class has a __call__() method; x(arguments) is a shorthand
for x.__call__(arguments)."

The following program demonstrates otherwise regarding that last statement. 

def call(self):
    print "inserted __call__ in object of class A"

class A(object):
    def __call__(self):
        print "__call__ method in class A"
        
x = A()               # Equates: x = type(A).__call__(A)
x.__call__ = call

x()                   # Calls the method of class A.
x.__call__(x)         # Calls function "call".
type(x).__call__(x)   # The correct longhand of x() IMHO


If I were to rephrase the documentation:
"Class instances
    Class instances are described below. Class instances are callable
only when the class has a __call__() method; x(arguments) is a shorthand
for type(x).__call__(x, arguments)."
msg91920 - (view) Author: Stephen Fairchild (onlyme) Date: 2009-08-24 13:58
On further reading it seems my objections only apply to new style classes.
msg91921 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2009-08-24 14:55
FYI, all special methods are (now) looked up on the type for new style
classes.  Your suggested rewrite makes things more confusing, IMO
(partly because to make it accurate it would need to be something like
type(x).__call__(x, *args, **kw), which doesn't really make the sentence
clearer).

So far I haven't thought of a rewording I like.  The best I've come up
with is "x(arguments) invokes the __call__ method, passing it the
arguments."  This leaves it to other parts of the language spec to
explain how __call__ gets resolved.

Whatever we decide to do, section 3.4.4 will need a similar update.
msg91922 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2009-08-24 15:03
For some reason the 3.2 docs don't contain the sentence you reference,
but they do have the same mistake in section 3.4.4.  Which is even more
of a mistake in 3.x, since there are only new style classes there.
msg320670 - (view) Author: Andrés Delfino (adelfino) * (Python triager) Date: 2018-06-28 15:09
The PR uses a slight rewording of David's phrasing.
msg379770 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2020-10-27 16:19
New changeset 95f710c55714153f0c8cce48f8215bb3d866ac1d by Andre Delfino in branch 'master':
bpo-6761: Enhance __call__ documentation (GH-7987)
https://github.com/python/cpython/commit/95f710c55714153f0c8cce48f8215bb3d866ac1d
msg379772 - (view) Author: miss-islington (miss-islington) Date: 2020-10-27 16:28
New changeset b1ce0440bfe87e092ca5e2e57875fb7fc1129137 by Miss Skeleton (bot) in branch '3.8':
bpo-6761: Enhance __call__ documentation (GH-7987)
https://github.com/python/cpython/commit/b1ce0440bfe87e092ca5e2e57875fb7fc1129137
msg379774 - (view) Author: miss-islington (miss-islington) Date: 2020-10-27 16:42
New changeset 2cb259fcf3cde56f359c2f393280689784dcc834 by Miss Skeleton (bot) in branch '3.9':
bpo-6761: Enhance __call__ documentation (GH-7987)
https://github.com/python/cpython/commit/2cb259fcf3cde56f359c2f393280689784dcc834
History
Date User Action Args
2022-04-11 14:56:52adminsetgithub: 51010
2020-10-27 18:56:34eric.araujosetstatus: open -> closed
stage: patch review -> resolved
resolution: fixed
versions: + Python 3.9, Python 3.10, - Python 2.6, Python 3.1, Python 2.7, Python 3.2, Python 3.6, Python 3.7
2020-10-27 16:42:46miss-islingtonsetmessages: + msg379774
2020-10-27 16:28:09miss-islingtonsetmessages: + msg379772
2020-10-27 16:19:22miss-islingtonsetpull_requests: + pull_request21920
2020-10-27 16:19:14miss-islingtonsetnosy: + miss-islington
pull_requests: + pull_request21919
2020-10-27 16:19:05vstinnersetnosy: + vstinner
messages: + msg379770
2018-06-28 15:09:09adelfinosetnosy: + adelfino

messages: + msg320670
versions: + Python 3.6, Python 3.7, Python 3.8
2018-06-28 15:07:33adelfinosetkeywords: + patch
stage: needs patch -> patch review
pull_requests: + pull_request7598
2013-02-04 16:10:10icordascsetnosy: + icordasc
2010-10-29 10:07:21adminsetassignee: georg.brandl -> docs@python
2009-08-24 15:03:37r.david.murraysetmessages: + msg91922
versions: + Python 3.1, Python 2.7, Python 3.2
2009-08-24 14:55:42r.david.murraysetpriority: normal

nosy: + r.david.murray
messages: + msg91921

stage: needs patch
2009-08-24 13:58:52onlymesetmessages: + msg91920
2009-08-22 17:13:57onlymecreate