homepage

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.

Author christian.heimes
Recipients Claudiu.Popa, christian.heimes, ionelmc, llllllllll
Date 2015年04月17日.20:14:45
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1429301685.22.0.874170676642.issue23990@psf.upfronthosting.co.za>
In-reply-to
Content
I have closed the issue because the code behaves according to the language specs and the language design. It is not broken at all. The callable test just checks for the attribute __call__ on the *type* of an object. The check is not performed on the *object* itself.
In your example
 callable(a)
does not do
 hasattr(a, '__call__')
but
 hasattr(type(a), '__call__')
which translates to
 hasattr(A, '__call__')
The behavior is very well consistent. I presume it just doesn't match your expectations. Special methods have a slightly different lookup behavior than ordinary. Due to the highly dynamic nature of Python the __call__ attribute is not validated at all.
For example this is expected behavior:
>>> class Example:
... __call__ = None
... 
>>> callable(Example())
True
>>> class Example:
... __call__ = None
... 
>>> example = Example()
>>> callable(example)
True
>>> example()
Traceback (most recent call last):
 File "<stdin>", line 1, in <module>
TypeError: 'NoneType' object is not callable
History
Date User Action Args
2015年04月17日 20:14:45christian.heimessetrecipients: + christian.heimes, ionelmc, Claudiu.Popa, llllllllll
2015年04月17日 20:14:45christian.heimessetmessageid: <1429301685.22.0.874170676642.issue23990@psf.upfronthosting.co.za>
2015年04月17日 20:14:45christian.heimeslinkissue23990 messages
2015年04月17日 20:14:45christian.heimescreate

AltStyle によって変換されたページ (->オリジナル) /