python-enforce-typing
python-enforce-typing copied to clipboard
Bug: Literal[x] not supported
Right now, using Literal[x]
where x
is not a type raises an error:
@enforce_types
@dataclass
class Foo:
foo: Literal[True]
Foo(foo=True)
# => TypeError: isinstance() arg 2 must be a type or tuple of types
This is because Literal[x]
passes the typing. _SpecialForm
check, but the code then expects x
to be a type. This means the following (which I don't think makes sense) passes without an error:
@enforce_types
@dataclass
class Bar:
foo: Literal[bool]
Bar(foo=True) # this should fail since `foo` isn't the type `bool`