Skip to content

Pylint not catching undefined variable. #1905

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

Closed
asincero opened this issue Feb 27, 2018 · 1 comment
Closed

Pylint not catching undefined variable. #1905

asincero opened this issue Feb 27, 2018 · 1 comment

Comments

@asincero
Copy link

Steps to reproduce

Lint the following:

a = 37337
if a == 37337:
    some_value = 'fee'
    print(some_value)
else:
    print(some_value)

Current behavior

pylint doesn't catch that "some_value" is not defined in the "else" block.

Expected behavior

I'm thinking pylint should be able to catch that "some_value" is not defined in the "else" block.

pylint --version output

Using config file /home/tech/.pylintrc
pylint 1.8.2,
astroid 1.6.1
Python 3.6.4 (default, Jan 30 2018, 17:36:50)
[GCC 6.3.0 20170516]

@brycepg
Copy link
Contributor

brycepg commented Feb 27, 2018

This really can't happen properly without constructing a control-flow graph of nodes for lookup, which pylint currently doesn't have the ability to do unfortunately. Currently we only do lookups by 'scope' (if statement blocks do not have scope).

Don't expect this to be fixed for a long while yet :(

Closing as duplicate of #85
Also reported as #12, #1376

@brycepg brycepg closed this as completed Feb 27, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants