Skip to content

False negative on setter field of undefined variable #19312

Open
@sterliakov

Description

@sterliakov

Bug Report

Property setter detection is now a bit too greedy. No matter what, a decorator of the shape @something.setter is treated as a setter of the preceding @property - irrespective of what something is.

To Reproduce

class Demo:
    @property
    def foo(self) -> int:
        return 0
    
    @certainly_not_a_foo_what_is_this_at_all.setter
    def foo(self, _: int) -> None:
        ...


d = Demo()
reveal_type(d.foo)  # N: Revealed type is "builtins.int"
d.foo = 0
d.foo = ''  # E: Incompatible types in assignment (expression has type "str", variable has type "int")  [assignment]

https://mypy-play.net/?mypy=master&python=3.12&flags=strict&gist=92b58f4d15da129a921ab39d8c0548cf

Expected Behavior

Say that the long name is not defined.

Actual Behavior

See inline comments - that thing is still treated as foo setter.

Your Environment

  • Mypy version used: master
  • Mypy command-line flags: N/A
  • Mypy configuration options from mypy.ini (and other config files): N/A
  • Python version used: 3.12

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrongtopic-descriptorsProperties, class vs. instance attributes

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions