Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

E1101 false positive with overridden properties #2221

Closed
SeanDS opened this issue Jun 24, 2018 · 4 comments
Closed

E1101 false positive with overridden properties #2221

SeanDS opened this issue Jun 24, 2018 · 4 comments

Comments

@SeanDS
Copy link

SeanDS commented Jun 24, 2018

Steps to reproduce

The following example of property overriding results in the pylint warning E1101:Method 'some_property' has no 'getter' member. The problem seems to be that pylint doesn't realise that @property in the parent class is implicitly the getter referenced in the child class.

class Parent(object):
    @property
    def some_property(self):
        return "parent property"

class Child(Parent):
    @Parent.some_property.getter
    def some_property(self):
        return "child property"

if __name__ == "__main__":
    p = Parent()
    print(p.some_property)
    c = Child()
    print(c.some_property)

Current behavior

Pylint warns E1101:Method 'some_property' has no 'getter' member.

Expected behavior

Pylint should realise that @Parent.some_property.getter is equivalent to the parent's some_property property.

pylint --version output

No config file found, using default configuration
pylint 1.8.2, 
astroid 1.6.1
Python 3.6.4 |Anaconda, Inc.| (default, Jan 16 2018, 18:10:19) 
[GCC 7.2.0]
@PCManticore
Copy link
Contributor

This is an incredible unimportant edge case. I don't even understand what this code is supposed to be doing.

@SeanDS
Copy link
Author

SeanDS commented Jun 25, 2018

The property in the subclass overrides the behaviour of the property in the parent class. I'm not sure why you think this is unimportant - isn't this a standard technique in object oriented Python?

@PCManticore
Copy link
Contributor

Why don't you just redefine the property in the child class, what does the "overriding" brings in this case different than doing:

class Parent(object):
    @property
    def some_property(self):
        return "parent property"

class Child(Parent):
   @property
    def some_property(self):
        return "child property"

if __name__ == "__main__":
    p = Parent()
    print(p.some_property)
    c = Child()
    print(c.some_property)

Even if this pattern is useful with regards with setters, it still feels to be an antipattern and might even trip anyone reading this code without context.

@SeanDS
Copy link
Author

SeanDS commented Jun 25, 2018

Hmm, I wasn't aware you could just redefine the property. Since that's the case, I think I agree with you. Thanks :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants