This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Unexpected TypeError with type alias+issubclass+ABC
Type: behavior Stage:
Components: Library (Lib) Versions: Python 3.11, Python 3.10, Python 3.9
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: AMDmi3, andrei.avk, burrito, corona10, gvanrossum, kj
Priority: normal Keywords:

Created on 2021-09-29 21:14 by AMDmi3, last changed 2022-04-11 14:59 by admin.

Messages (2)
msg402914 - (view) Author: Dmitry Marakasov (AMDmi3) * Date: 2021-09-29 21:14
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:

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

Not sure which is the culprit, ABC or how dict[]-style type aliases are implemented.
msg414170 - (view) Author: Andrei Kulakov (andrei.avk) * (Python triager) Date: 2022-02-28 01:51
This error was added in https://bugs.python.org/issue33018 . See some discussion on that issue.

Note that first arg needs to be a type (i.e. instance of `type`) to avoid this error:

[ins] In [41]: class C(ABC):0

[ins] In [42]: issubclass(dict, C)
Out[42]: False

[ins] In [43]: issubclass('', C)  # TypeError: issubclass() arg 1 must be a class

[ins] In [44]: issubclass(typing.Dict, C)   # same error as above
History
Date User Action Args
2022-04-11 14:59:50adminsetgithub: 89489
2022-02-28 01:52:34andrei.avksetnosy: + kj
type: behavior
2022-02-28 01:51:26andrei.avksetnosy: + andrei.avk
messages: + msg414170
2022-02-23 13:00:49burritosetnosy: + burrito
2021-09-30 01:09:05corona10setversions: + Python 3.10, Python 3.11
2021-09-30 01:08:56corona10setnosy: + gvanrossum
2021-09-30 00:55:33corona10setnosy: + corona10
2021-09-29 21:14:09AMDmi3create