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

Error when overriding a property created via decorators #14684

Open
Cleptomania opened this issue Feb 12, 2023 · 2 comments
Open

Error when overriding a property created via decorators #14684

Cleptomania opened this issue Feb 12, 2023 · 2 comments
Labels
bug mypy got something wrong

Comments

@Cleptomania
Copy link

Bug Report

When a parent class has a property, created via decorators with a getter and setter. If you attempt to override the fset of the parent by using decorators in the subclass, mypy throws an error.

To Reproduce

class A:
    def __init__(self, x: int):
        self._x = x

    @property
    def x(self) -> int:
        return self._x

    @x.setter
    def x(self, new_value: int):
        self._x = new_value


class B(A):
    def __init__(self):
        super().__init__(100)

    @A.x.setter
    def x(self, new_value: int):
        A.x.fset(self, new_value)

        print("Do something else ontop of the parent setter")

Expected Behavior

Mypy should produce no errors

Actual Behavior

Mypy produces the errors:

overloaded function has no attribute "setter" [attr-defined] on the decorator line in the subclass.
overloaded function has no attribute "fset" [attr-defined] on the call to fset in the subclass.

If instead of using a decorator, the property is created in the parent class via the property() function like below, then mypy does not produce any errors.

class A:
    def __init__(self, x: int):
        self._x = x

    def _get_x(self) -> int:
        return self._x

    def _set_x(self, new_value: int):
        self._x = new_value

    x = property(_get_x, _set_x)

Your Environment

  • Mypy version used: 1.0.0
  • Mypy command-line flags: None
  • Mypy configuration options from mypy.ini (and other config files): Default configuration
  • Python version used: 3.10.5
@Cleptomania Cleptomania added the bug mypy got something wrong label Feb 12, 2023
@tmke8
Copy link
Contributor

tmke8 commented Feb 13, 2023

Duplicate of #5936?

@Cleptomania
Copy link
Author

It does seem to be the same problem, I couldn't find this exact problem when searching yesterday, if it makes sense feel free to close this in favor of the pre-existing one. I'll not the work-around I found to the problem in the other issue in case it proves helpful to anyone.

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

No branches or pull requests

2 participants