Jelle Zijlstra <jelle.zijls...@gmail.com> added the comment:

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.

----------
nosy: +Jelle Zijlstra, gvanrossum, kj, levkivskyi

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue44293>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to