Skip to content

stubtest incorrectly interprets property with deleter as overloaded function in stubs #21254

@jonathandung

Description

@jonathandung

Bug Report

Due to stubtest apparently simplistically assuming any duplicate definitions of a function/method with decorators in .pyi files to be overloads, the following bug emerges when using the property descriptor while annotating deleter.

I know that annotating deleter is not usually necessary, but I am accustomed to putting all my type annotations and docstrings in .pyi files only. For some classes with novel or unconventional property deletion behaviour, I find it useful to annotate the deleter as well and include the docstring there.

To Reproduce

In _mypy/_2.py:

class spam:
    @property
    def eggs(self): return 42
    @eggs.deleter
    def eggs(self): print('eggs')

In _mypy/_2.pyi:

class spam:
    @property
    def eggs(self) -> int: ...
    @eggs.deleter
    def eggs(self) -> None: '''Foo bar baz.'''

Actual Behavior

error: _mypy._2.spam.eggs is read-only at runtime but not in the stub
Stub: in file /_mypy/_2.pyi:2
Overload(def (self: _mypy._2.spam) -> int)
Runtime:
<property object at 0x00000236AC0438D0>

Your Environment

  • Mypy version used: 1.20.0
  • Mypy command-line flags: python -m mypy.stubtest _mypy
  • Python version used: 3.14

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrong

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions