The following code Prints False
:
from enum import Enum
type_ = str
print(issubclass(type_, Enum))
The following code prints True
:
from enum import Enum
type_ = Enum('MyEnum', {'a': 1, 'b': 2})
print(issubclass(type_, Enum))
The following code throws an error:
from enum import Enum
from typing import List
type_ = List[str]
print(issubclass(type_, Enum))
# TypeError: issubclass() arg 1 must be a class
Is there a better way than a try / except to check that an object is a class definition? Something like:
print(isclass(type_) and issubclass(type_, Enum))