Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: mypy is confusing the type of the getter with that of the setter #7211

Closed
AbdulRahmanAlHamali opened this issue Jul 14, 2019 · 1 comment

Comments

@AbdulRahmanAlHamali
Copy link

Hello, starting v0.720, the following code:

from typing import Union


class Test:
    def __init__(self, something: Union[int, str]):
        self.something = something

    @property
    def something(self) -> str:
        return self._something

    @something.setter
    def something(self, val: Union[int, str]) -> None:
        if isinstance(val, int):
            self._something = str(val)
        else:
            self._something = val

fails with the following error:

error: Incompatible types in assignment (expression has type "Union[int, str]", variable has type "str")

It seems that mypy is confusing the type of the getter with the type of the setter. Any idea what might be causing this?

Thanks!

@AbdulRahmanAlHamali AbdulRahmanAlHamali changed the title Bug: Type of getter is getting used instead of the setter Bug: mypy is confusing the type of the getter with that of the setter Jul 14, 2019
@ilevkivskyi
Copy link
Member

Properties with different getter and setter types were never supported see #3004. It was not caught before because there was a bug that all properties defined after they use in __init__() were silently turned into Any.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants