Skip to content

False positive E1101 (no-member) on overridden class property setters #3480

@akkeluukkonen

Description

@akkeluukkonen

Steps to reproduce

class Parent: def __init__(self): self._attr = 0 @property def attr(self): return self._attr @attr.setter def attr(self, value): self._attr = value class Child(Parent): @Parent.attr.setter def attr(self, value): # Perform "pre-hook" actions Parent.attr.fset(self, value) # Perform "post-hook" actions

Current behavior

issue.py:14:5: E1101: Method 'attr' has no 'setter' member (no-member)
issue.py:17:8: E1101: Method 'attr' has no 'fset' member (no-member)

Expected behavior

No E1101 errors.

The described code example functions as expected, even though it is a quite niche use case. This is closely related to #2221 where a similar issue is observed with getters. However, with setters the situation is somewhat different. You cannot define @attr.setter if you have not defined the property itself in the Child class. However, you can define it by using the described @Parent.attr.setter.

The actual use case here is that I'm inheriting a class from another library that I wish to extend. It has a quite complex @attr.setter function that I don't want to directly copy in case it receives an update later. However, in my case I need to run additional "post-hook" actions directly after the Parent setter in order to synchronize some data only existing in the Child class.

pylint --version output

pylint 2.4.4 astroid 2.3.3 Python 3.8.2 (default, Mar 7 2020, 19:36:55) [GCC 7.4.0] 

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions