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() should respect __class__ #36297
Comments
isinstance(obj, class_or_type_or_tuple) should compare This is important for using weak references and other issubclass may need a similar treatment. |
Logged In: YES -1. That means that you can't use isinstance anymore to If you need a function that unwraps wrappers, write one |
Logged In: YES I give this a +1. To refute Martin's -1: The use case that If you want to know if something is a wrapper, you have to |
Logged In: YES There has been a long-standing guarantee that 'type(o) is X' |
Logged In: YES A new isinstance can maintain and extend the semantic Martin Let's say object wl is a wrapped list: from Zope.ContextWrapper import Wrapper
wl = Wrapper([])
assert isinstance(wl, list) is 1
assert isinstance(wl, Wrapper) is 1 So, your semantics are maintained. With the proposed change, |
Logged In: YES oops... please ignore my unsupported use of "is" to compare I meant: from Zope.ContextWrapper import Wrapper
wl = Wrapper([])
assert isinstance(wl, list) == 1
assert isinstance(wl, Wrapper) == 1 |
Logged In: YES I'm not sure I like SteveA's suggestion of making >>> class C: pass # classic class
...
>>> c = C()
>>> isinstance(c, C)
1
>>> import types
>>> isinstance(c, types.InstanceType)
1
>>> I'm also not sure I agree with Martin's assertion that I guess we'll have to look at actual use cases of |
Logged In: YES OK, checked in. When X is a new-style class, isinstance(x, |
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: