Skip to content

support fields of type typing.Literal#54

Open
abrasive wants to merge 1 commit into
ProtixIT:mainfrom
abrasive:support-Literal
Open

support fields of type typing.Literal#54
abrasive wants to merge 1 commit into
ProtixIT:mainfrom
abrasive:support-Literal

Conversation

@abrasive
Copy link
Copy Markdown

Thanks for releasing this super handy tool!

This PR does what it says on the tin, so you can have, say,

@dataclass(kw_only=True)
class UnitConfig:
    trigger: Literal["edge", "level"]

I made sure it lints clean with poetry run ruff check, was there anything else?

The docs for typing.Literal say it will take any type, but pyright and mypy will only accept bool, int, str, bytes, and enum values, so I've just implemented the first three.

Apparently mypy will also take None as one of the arguments and treat it as equivalent to Optional[Literal[. I haven't implemented this behaviour, as either Optional[] or the approach you take in the docs of using | None both work fine; will that be confusing?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant