-
-
Notifications
You must be signed in to change notification settings - Fork 31.3k
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
issubclass() is inconsistent with generic aliases #101162
Comments
This happens because >>> list[int].__bases__
(<class 'object'>,)
>>> import typing
>>> typing.List[int].__bases__
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/sobolev/Desktop/cpython/Lib/typing.py", line 1307, in __getattr__
raise AttributeError(attr)
AttributeError: __bases__. Did you mean: '__args__'? But, we can easily change this and forbid As the result, everything is going to work the same as >>> list[int].__bases__
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: __bases__. Did you mean: '__args__'?
>>> issubclass(list[int], object)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: issubclass() arg 1 must be a class Moreover, all typing/types/genericalias tests pass with this change. |
issubclass working on a GenericAlias was a bug that was fixed in python 3.13 (see python/cpython#101162) Fixes #81 Signed-off-by: Paul Mars <paul.mars@canonical.com>
issubclass working on a GenericAlias was a bug that was fixed in python 3.13 (see python/cpython#101162) Fixes #81 Signed-off-by: Paul Mars <paul.mars@canonical.com>
issubclass working on a GenericAlias was a bug that was fixed in python 3.13 (see python/cpython#101162) Fixes #81 Signed-off-by: Paul Mars <paul.mars@canonical.com>
Instances of
types.GenericAlias
are accepted as the first argument ofissubclass()
:while instances of
typing.GenericAlias
are not:Although both are rejected if the second argument is an abstract class:
Usually
issubclass(x, y)
is preceded by the checkisinstance(x, type)
, so the final result will always be false since 3.11, but if that check is omitted, you can see a difference.Linked PRs
issubclass
withGenericAlias
as the 1st arg #103369The text was updated successfully, but these errors were encountered: