Skip to content

[1.16 regression] Relative order of property methods changes mypy output #19224

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

Closed
gpauloski opened this issue Jun 4, 2025 · 2 comments · Fixed by #19248
Closed

[1.16 regression] Relative order of property methods changes mypy output #19224

gpauloski opened this issue Jun 4, 2025 · 2 comments · Fixed by #19248
Labels
bug mypy got something wrong topic-descriptors Properties, class vs. instance attributes

Comments

@gpauloski
Copy link

Bug Report

In mypy 1.16, the relative ordering of property methods (i.e., getter/setter/deleter) can produce an "Invalid property setter signature" error.

To Reproduce

mypy playground with the same example

Having an @deleter or @getter before a @setter property method produces an error:

class C:
    _value: int = 0

    @property
    def value(self) -> int:
        return self._value

    @value.deleter
    def value(self) -> None: ...  # error: Invalid property setter signature  [misc]

    @value.setter
    def value(self, v: int) -> None: ...
$ mypy t.py
main.py:9: error: Invalid property setter signature  [misc]
Found 1 error in 1 file (checked 1 source file)

Move the @value.deleter method to after @value.setter and the error is fixed.

class C:
    _value: int = 0

    @property
    def value(self) -> int:
        return self._value

    @value.setter
    def value(self, v: int) -> None: ...

    @value.deleter
    def value(self) -> None: ...
$ mypy t.py
Success: no issues found in 1 source file

Expected Behavior

The relative ordering should not alter the output of mypy. I'm not aware of any reason why the ordering should matter and all orderings pass mypy in 1.15.

Your Environment

  • Mypy version used: 1.16
  • Mypy command-line flags: None
  • Mypy configuration options from mypy.ini (and other config files): None
  • Python version used: 3.13
@gpauloski gpauloski added the bug mypy got something wrong label Jun 4, 2025
@sterliakov
Copy link
Collaborator

Introduced in #18510, TODO added in #18774

mypy/mypy/checker.py

Lines 677 to 683 in 4fe7d9f

self.visit_decorator(defn.items[0])
if defn.items[0].var.is_settable_property:
# TODO: here and elsewhere we assume setter immediately follows getter.
assert isinstance(defn.items[1], Decorator)
# Perform a reduced visit just to infer the actual setter type.
self.visit_decorator_inner(defn.items[1], skip_first_item=True)
setter_type = defn.items[1].var.type

This is a known limitation for now; cc @ilevkivskyi

@sterliakov sterliakov added the topic-descriptors Properties, class vs. instance attributes label Jun 4, 2025
@ilevkivskyi
Copy link
Member

Yeah, I was too tired to handle that, and TBH still tired. This looks lower priority than other things (unless this causes dozens of errors for you).

ilevkivskyi added a commit that referenced this issue Jun 7, 2025
Fixes #19224

Note we must add an additional attribute on `OverloadedFuncDef` since
decorator expressions are not serialized.
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

Successfully merging a pull request may close this issue.

3 participants