Skip to content

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

@mykola-mokhnach

Description

@mykola-mokhnach

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

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