Skip to content

issubclass raising error when argument 1 is a typing._GenericAlias #96871

@nickeldan

Description

@nickeldan

This seems related to issue #89489 but I'm not sure if it's the same problem.

I have a metaclass that examines the __annotations__ of its instances. At one point, I check whether the type of an annotated field is a subclass of int (e.g., an enum.IntEnum subclass) by issubclass(field_type, int). It works fine unless the type is a typing._GenericAlias such as typing.Optional[bytes] in which case it raises an error:

TypeError: issubclass() arg 1 must be a class

Could issubclass just return False in this case?

This is on Python 3.8.10.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions