Skip to content

False positives when redefining property in subclass #5936

Open
@mthuurne

Description

@mthuurne

I'm running mypy on the following code: (no additional arguments)

class Base:
	def __init__(self, value):
		self._value = value

	@property
	def value(self):
		return self._value

class Sub(Base):
	@Base.value.setter
	def value(self, value):
		self._value = value

And it reports:

inherited_property.py:10: error: "Callable[[Any], Any]" has no attribute "setter"

Line 10 is @Base.value.setter, so it seems to have a problem with referring to a property defined in a different class. Python itself has no problem with this though.

If the property has a setter in the base class, a slightly different error is reported:

class Base:
	def __init__(self, value):
		self._value = value

	@property
	def value(self):
		return self._value

	@value.setter
	def value(self, value):
		self._value = value

class Sub(Base):
	@Base.value.setter
	def value(self, value):
		self._value = value

This results in mypy reporting:

inherited_property.py:14: error: overloaded function has no attribute "setter"

Again the error is reported on the @Base.value.setter line.

I'm using a mypy dev snapshot (0.650+) on Python 3.6.5.

I found the existing issue #220, but that is so generic that I figured it would make sense to open a new separate issue for tracking this specific use case.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions