[issue6761] Class calling
Stephen Fairchild
report at bugs.python.org
Sat Aug 22 19:13:59 CEST 2009
New submission from Stephen Fairchild <signupaddress at bethere.co.uk>:
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)."
----------
assignee: georg.brandl
components: Documentation
messages: 91864
nosy: georg.brandl, onlyme
severity: normal
status: open
title: Class calling
type: behavior
versions: Python 2.6
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue6761>
_______________________________________
More information about the Python-bugs-list
mailing list