kracekumar / python-typing-koans

Python typing koans to learn type-hints in Python3 using Mypy
119 stars 10 forks source link

110-easy-class-variable discussion #9

Open J0 opened 3 years ago

J0 commented 3 years ago

For task 110 I had to rename the last variable from user to new_user as I'd previously received an error stating that we can't assign a type to a variable which already has a type. Would just like to check if there's an alternative solution which doesn't involve renaming the variable.

Here's the relevant line: https://github.com/J0/python-typing-koans/blob/main/koans/py/110-easy-class-variable.py#L66

kracekumar commented 3 years ago

I guess the indentation is causing the issue(in the original file). The mypy is in strict mode which uses user as variable User and the line new_user: Optional[User] = User.get_user(name="Guido") use variable as Optional[User]. This causes the mypy to raise error.

There is no issue with the your code, can you align the code like this and try?

def main() -> None:
 . ..

# Same level as main
user: Optional[User] = User.get_user(name="Guido")