Skip to content

Literal not supported as type

I know I can use StrEnum. However, I often find Literal to be less cumbersome. Therefore, it would be great if typed_settings supported Literal as an alternative to StrEnum and IntEnum.

Currently this script:

from typing import Literal
import typed_settings as ts

@ts.settings
class Settings:
    marker: Literal['a', 'b'] = ts.option(
        default="a",
        help="You can choose a or b",
    )

@ts.cli(Settings, "example")
def cli(settings: Settings):
    print(settings)

if __name__ == "__main__":
    cli()

produces the following error:

ValueError: Invalid default 'a' for option 'marker' with type typing.Literal['a', 'b']: TypeError('issubclass() arg 1 must be a class')