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

mypy does not properly verify types while overriding property setters #12997

Closed
mykola-mokhnach opened this issue Jun 20, 2022 · 2 comments
Closed
Labels
bug mypy got something wrong topic-descriptors Properties, class vs. instance attributes

Comments

@mykola-mokhnach
Copy link

mykola-mokhnach commented Jun 20, 2022

Bug Report

mypy does not properly verify types while overriding property setters

To Reproduce

Tryto override a property setter in a subclass according to how it is described in https://stackoverflow.com/questions/3336767/overriding-inherited-properties-getters-and-setters-in-python:

class A:
    def __init__(self):
        self._attr: str = ''

    @property
    def attr(self) -> str:
        return self._attr

    @attr.setter
    def attr(self, value: str) -> None:
        self._attr = value


class B(A):
    @A.attr.setter
    def attr(self, value: str) -> None:
        A.attr.fset(self, value)

Expected Behavior

No errors from mypy

Actual Behavior

mypy fails typecheck with the following errors:
error: overloaded function has no attribute "setter"
and
error: overloaded function has no attribute "fset"

on the following lines:
@A.attr.setter and A.attr.fset(self, value)

Your Environment

  • Mypy version used: 0.961
  • Mypy command-line flags:
  • Mypy configuration options from mypy.ini (and other config files):
  • Python version used: 3.9.9
  • Operating system and version: macOS 11.6.5
@mykola-mokhnach mykola-mokhnach added the bug mypy got something wrong label Jun 20, 2022
@AlexWaygood AlexWaygood added the topic-descriptors Properties, class vs. instance attributes label Jun 20, 2022
@AlexWaygood
Copy link
Member

Duplicate of #4644

@AlexWaygood AlexWaygood marked this as a duplicate of #4644 Jun 20, 2022
@AlexWaygood AlexWaygood closed this as not planned Won't fix, can't repro, duplicate, stale Jun 20, 2022
@AlexWaygood
Copy link
Member

Duplicate of #4644

And/or #5936

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong topic-descriptors Properties, class vs. instance attributes
Projects
None yet
Development

No branches or pull requests

2 participants