python-typing-koans icon indicating copy to clipboard operation
python-typing-koans copied to clipboard

110-easy-class-variable discussion

Open J0 opened this issue 4 years ago • 1 comments

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

J0 avatar May 24 '21 14:05 J0

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")

kracekumar avatar May 24 '21 17:05 kracekumar