Message394963
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. |
|
Date |
User |
Action |
Args |
2021-06-03 00:23:58 | JelleZijlstra | set | recipients:
+ JelleZijlstra, gvanrossum, levkivskyi, joperez, kj |
2021-06-03 00:23:58 | JelleZijlstra | set | messageid: <1622679838.3.0.930996818854.issue44293@roundup.psfhosted.org> |
2021-06-03 00:23:58 | JelleZijlstra | link | issue44293 messages |
2021-06-03 00:23:57 | JelleZijlstra | create | |
|