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

False negative undefined-variable for decorators in multiple scenario #3641

Open
mattwala opened this issue May 21, 2020 · 1 comment
Open
Labels
C: undefined-variable Issues related to 'undefined-variable' check Checkers Related to a checker Enhancement ✨ Improvement to a component False Negative 🦋 No message is emitted but something is wrong with the code Needs PR This issue is accepted, sufficiently specified and now needs an implementation

Comments

@mattwala
Copy link

Steps to reproduce

class A:
    @property
    def x(self):
        raise NotImplementedError

class B(A):
    @x.getter
    def x(self):
        return 42

Current behavior

Pylint output suggests this code has no errors:

$ pylint -E test.py
$ # no errors

Expected behavior

The name x is not in scope (the correct way to override this would be @A.x.getter).

Python output:

$ python test.py 
Traceback (most recent call last):
  File "test.py", line 8, in <module>
    class B(A):
  File "test.py", line 10, in B
    @x.getter
NameError: name 'x' is not defined

pylint --version output

pylint 2.5.2
astroid 2.4.1
Python 3.8.2 | packaged by conda-forge | (default, Mar 23 2020, 17:55:48) 
[Clang 9.0.1 ]
@mattwala
Copy link
Author

This issue is more general than properties. Pylint doesn't report an error for this code:

class C:
    @f
    def f(self):
        pass

@PCManticore PCManticore added Checkers Related to a checker Enhancement ✨ Improvement to a component labels May 28, 2020
@DanielNoord DanielNoord added the C: undefined-variable Issues related to 'undefined-variable' check label Nov 18, 2021
@Pierre-Sassoulas Pierre-Sassoulas changed the title Does not report undefined variable when overriding property descriptor in a subclass False negative undefined-variable for decorator in multiple scenario Jul 5, 2022
@Pierre-Sassoulas Pierre-Sassoulas added False Negative 🦋 No message is emitted but something is wrong with the code Needs PR This issue is accepted, sufficiently specified and now needs an implementation labels Jul 5, 2022
@Pierre-Sassoulas Pierre-Sassoulas changed the title False negative undefined-variable for decorator in multiple scenario False negative undefined-variable for decorators in multiple scenario Jul 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C: undefined-variable Issues related to 'undefined-variable' check Checkers Related to a checker Enhancement ✨ Improvement to a component False Negative 🦋 No message is emitted but something is wrong with the code Needs PR This issue is accepted, sufficiently specified and now needs an implementation
Projects
None yet
Development

No branches or pull requests

4 participants