-
Notifications
You must be signed in to change notification settings - Fork 234
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
Bug in __subclasscheck__ causes isinstance() to fail #155
Comments
Wow, thanks for finding that one! It's pretty terrible. But I don't think your fix is right -- wouldn't it bump the invalidation counter each time |
Yes you're right, I've taken another look at the code in order to better determine where the fix should be. I assume this issue cropped up when The call graph for
The next pass through, the first call is I see two issues and potential paths to a fix:
|
Thanks so much for the detailed analysis! I'm focusing on this today, to get it in before Larry tags rc3. Alas, none of the alternatives look attractive. I believe that reordering the checks simply postpones the problem (the tests don't have enough coverage for this). |
I decided that overriding |
From the discussions in #135 and #136 it looks as though
__instancecheck__
and__subclasscheck__
are here to stay for the collections.abc subclasses.There is a bug in the implementation of
__subclasscheck__
forGenericMeta
. The following sample code exposes the bug:The second call of
isinstance([], Iterable)
returnsFalse
when it should returnTrue
.The reason for this appears to be the an incorrect implementation of
__subclasscheck__()
forGenericMeta
.super().__subclasscheck__(cls)
on line 1024 of typing.py results in thelist
type being placed in the negative cache oftyping.Iterable
, afterwardsissubclass(cls, self.__extra__)
evaluates toTrue
, but the negative cache is not invalidated. On the next check ofisinstance([], Iterable)
the negative cache is consulted and returnsFalse
.One possible fix is to invalidate
typing.Iterable
's negative cache ifissubclass(cls, self.__extra__)
evaluates toTrue
, as in the following diff:If you think my proposed change is good, I'll submit a PR with the change.
The text was updated successfully, but these errors were encountered: