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

Property setter and getter types can't differ #8084

Closed
JukkaL opened this issue Dec 5, 2019 · 1 comment
Closed

Property setter and getter types can't differ #8084

JukkaL opened this issue Dec 5, 2019 · 1 comment

Comments

@JukkaL
Copy link
Collaborator

JukkaL commented Dec 5, 2019

This was reported by @srittau in #220 (comment):

It also seems that the getter and setter need to have the same type at the moment:

class Foo:
    @property
    def bar(self) -> str: ...
    @bar.setter
    def bar(self, v: int) -> None: ...

Foo().bar = 3

This will cause mypy 0.550 to complain:

foo.py:7: error: Incompatible types in assignment (expression has type "int", variable has type "str")

While this example is a bit silly, I have a real-world example involving setting arbitrary Mappings and getting a custom Mapping subtype.

@ilevkivskyi
Copy link
Member

Closing as duplicate of #3004 that has more discussion and typical use cases (non-optional getters and container normalization).

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

No branches or pull requests

2 participants