You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Here's a curious problem. issubclass() check of a type against an ABC-derived class raises TypeError claiming that type is not a class, however inspect.isclass() says it's a class, and issubclass() check against a simple class works fine:
from abc import ABC
class C1:
pass
issubclass(dict[str, str], C1) # False
class C2(ABC):
pass
issubclass(dict[str, str], C2) # TypeError: issubclass() arg 1 must be a class
I've ran into this problem while using inspect module to look for subclasses of a specific ABC in a module which may also contain type aliases, and after converting a type alias from Dict[str, str] to modern dict[str, str] I've got an unexpected crash in this code:
I encountered a slight variation of this issue. I am using python 3.10.12:
importinspectfromabcimportABCMetaclassC1(ABCMeta):
passclassC2(metaclass=C1):
passDictAlias=dict[str,str]
print(inspect.isclass(DictAlias)) # Trueprint(issubclass(DictAlias, C1)) # Falseprint(issubclass(DictAlias, C2)) # TypeError: issubclass() arg 1 must be a class
Note that the original example by AMDmi3 also fails
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: