[New-bugs-announce] [issue45326] Unexpected TypeError with type alias+issubclass+ABC

Dmitry Marakasov report at bugs.python.org
Wed Sep 29 17:14:09 EDT 2021

New submission from Dmitry Marakasov <amdmi3 at amdmi3.ru>:

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:

issubclass(dict[str, str], C1)  # False

class C2(ABC):

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:

    if inspect.isclass(member) and issubclass(member, superclass):

Not sure which is the culprit, ABC or how dict[]-style type aliases are implemented.

components: Library (Lib)
messages: 402914
nosy: AMDmi3
priority: normal
severity: normal
status: open
title: Unexpected TypeError with type alias+issubclass+ABC
versions: Python 3.9

Python tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list