Issue 7624: isinstance(... ,collections.Callable) fails with oldstyle class instances (original) (raw)

Created on 2010-01-03 19:13 by rgammans, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
issue7624_abc.diff flox,2010-01-29 18:53 Patch, apply to trunk
Messages (7)
msg97175 - (view) Author: Roger Gammans (rgammans) Date: 2010-01-03 19:13
The following sequence causes isinstance to raise an exception rather than to return False. >>> class foo: ... pass ... >>> import collections >>> isinstance(foo,collections.Callable) True >>> isinstance(foo(),collections.Callable) Traceback (most recent call last): File "", line 1, in File "/usr/lib/python2.6/abc.py", line 131, in __instancecheck__ return (cls.__subclasscheck__(subclass) or File "/usr/lib/python2.6/abc.py", line 147, in __subclasscheck__ ok = cls.__subclasshook__(subclass) File "/usr/lib/python2.6/_abcoll.py", line 117, in __subclasshook__ if any("__call__" in B.__dict__ for B in C.__mro__): AttributeError: class foo has no attribute '__mro__' >>>
msg98516 - (view) Author: Florent Xicluna (flox) * (Python committer) Date: 2010-01-29 16:26
Confirmed with all others "isinstance(..., collections.Hashable)" and similar. According to the documentation, we might expect the same behavior as for new-style class.
msg98517 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2010-01-29 17:19
Well the fix is easy for old-style classes, since we just have to use hasattr(obj, '__call__') in that case.
msg98522 - (view) Author: Florent Xicluna (flox) * (Python committer) Date: 2010-01-29 18:38
Wow, critical issue, are you sure? Here is the patch, with tests. IMO, the tests may be ported to 3.x.
msg98524 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2010-01-29 18:46
"subtype == _InstanceType" can probably be replaced with "subtype is _InstanceType". Otherwise, the patch looks good to me.
msg98525 - (view) Author: Florent Xicluna (flox) * (Python committer) Date: 2010-01-29 18:53
fixed
msg100652 - (view) Author: Florent Xicluna (flox) * (Python committer) Date: 2010-03-08 15:35
Fixed in r78800. Additional tests backported to 3.x.
History
Date User Action Args
2022-04-11 14:56:56 admin set github: 51873
2010-03-08 15:35:44 flox set status: open -> closedtitle: isinstance(... ,collections.Callable) fails with oldstyle class i nstances -> isinstance(... ,collections.Callable) fails with oldstyle class instancesmessages: + resolution: accepted -> fixedstage: commit review -> resolved
2010-02-27 16:57:11 flox set assignee: floxresolution: acceptedstage: patch review -> commit review
2010-01-29 18:53:32 flox set files: + issue7624_abc.diffmessages: +
2010-01-29 18:53:01 flox set files: - issue7624_abc.diff
2010-01-29 18:46:36 pitrou set nosy: + benjamin.petersonmessages: +
2010-01-29 18:38:07 flox set files: + issue7624_abc.diffkeywords: + patchmessages: + stage: needs patch -> patch review
2010-01-29 17:19:06 pitrou set priority: normal -> criticalnosy: + pitroumessages: + keywords: + easy
2010-01-29 16:26:10 flox set priority: normalversions: + Python 2.7messages: + type: behaviorstage: needs patch
2010-01-29 14:05:47 flox set nosy: + flox
2010-01-07 21:53:33 ezio.melotti set nosy: + ezio.melotti
2010-01-03 19:13:31 rgammans create