|
Hey everyone, I’m having an issue with a from typing import Literal
class Account(
id: str,
email: str,
username: str,
pterodactyl_id: int,
hosting_plan: Literal['free', 'premium', 'sponsor'] = 'free'
)Somewhere else in my code, I define the variable new_plan = "free" if account["server_booster"] is False else "premium"Since However, when I pass I’m really confused about why this happens. Is this a bug in Mypy, or am I missing something? |
Answered by
Akuli
Feb 21, 2025
Replies: 1 comment 1 reply
|
In mypy, the type of new_plan: Literal["free", "premium"] = "free" if account["server_booster"] is False else "premium" |
1 reply
Answer selected by
Revox179
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment

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