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 JelleZijlstra
Recipients JelleZijlstra, gvanrossum, joperez, kj, levkivskyi
Date 2021-06-03.00:23:57
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1622679838.3.0.930996818854.issue44293@roundup.psfhosted.org>
In-reply-to
Content
The reason for this is that types.GenericAlias.__getattribute__ delegates to the alias's origin (in the `ga_getattro` function). As a result, `list[int].__class__` calls `list.__class__` and returns `type`. And the implementation of `isinstance(obj, type)` ultimately calls `issubclass(obj.__class__, type)`. (That's in `object_isinstance()` in abstract.c. It's news to me; I didn't know you could customize isinstance() behavior on the object side.)

To fix this, we could make `ga_getattro` not delegate for `__class__`, so that `list[int].__class__` would return `GenericAlias` instead of `type`. The current implementation of GenericAlias has been around for a few releases by now, though, so that change might break some use cases.

> This is not the case for other generic aliases.

This is not true; it is the same for e.g. `set[int]`. Unless you meant something else here.
History
Date User Action Args
2021-06-03 00:23:58JelleZijlstrasetrecipients: + JelleZijlstra, gvanrossum, levkivskyi, joperez, kj
2021-06-03 00:23:58JelleZijlstrasetmessageid: <1622679838.3.0.930996818854.issue44293@roundup.psfhosted.org>
2021-06-03 00:23:58JelleZijlstralinkissue44293 messages
2021-06-03 00:23:57JelleZijlstracreate