Skip to content

Issue with Literal Type Hint in Mypy #1929

Answered by Akuli
Revox179 asked this question in Q&A
Discussion options

You must be logged in to vote

In mypy, the type of new_plan is str. (You can see it if you add reveal_type(new_plan) to your code and run mypy.) Here's how to work around that:

new_plan: Literal["free", "premium"] = "free" if account["server_booster"] is False else "premium"

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@Revox179
Comment options

Answer selected by Revox179
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants