New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
isinstance(anything, MetaclassThatDefinesInstancecheck) raises instead of returning False #46578
Comments
>>> class Meta(type):
... def __instancecheck__(self, other):
... return False
>>> isinstance(3, Meta) In 2.6, this results in: Traceback (most recent call last):
File "<stdin>", line 1, in <module>
RuntimeError: maximum recursion depth exceeded while calling a Python object
(That's a recursion in C, through PyObject_IsInstance and
instancemethod_call) In 3.0, I get: Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: __instancecheck__() takes exactly 2 positional arguments (1
given) |
In 3.0 it happens with any class. Just the cls argument missing on the |
Seems like that's the wrong usage and the PEP-3119 notices that it's |
This is not a bug. Function __instancecheck__ should be a classmethod. >>> class Meta(type):
... @classmethod
... def __instancecheck__(self, other):
... return False
...
>>> isinstance(3, Meta)
False |
So..., could this issue be closed ? |
Yes, it should be. I don't have permissions to. |
I don't think so. It wouldn't be a bug if I wrote: >>> class Meta(type):
... def __instancecheck__(self, other):
... return True
>>> isinstance(3, Meta)
... False but it is a bug that the isinstance call raises an exception. If recent You guys also seem to have missed that the examples in PEP-3119 in fact |
I think the best is to ignore __instancecheck__ when Here is a patch along this idea. I don't know if this is applicable to 3.0: unbound methods don't exist |
This now works correctly (returns False) in release26-maint, trunk and py3k. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: