-
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? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
In mypy, the type of new_plan: Literal["free", "premium"] = "free" if account["server_booster"] is False else "premium" |
Beta Was this translation helpful? Give feedback.
In mypy, the type of
new_plan
isstr
. (You can see it if you addreveal_type(new_plan)
to your code and run mypy.) Here's how to work around that: