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

Use before assignment not detected #1807

Closed
Hibou57 opened this issue Dec 31, 2017 · 4 comments
Closed

Use before assignment not detected #1807

Hibou57 opened this issue Dec 31, 2017 · 4 comments
Labels
Control flow Requires control flow understanding Duplicate 🐫 Duplicate of an already existing issue Enhancement ✨ Improvement to a component

Comments

@Hibou57
Copy link

Hibou57 commented Dec 31, 2017

Steps to reproduce

Check this with Pylint:

def test(a):
    if a == 1:
        b = 2
    return 3 if b else 4

Current behavior

Does not warn b is used without (very probably) being assigned (more below).

Expected behavior

Opinions may vary, still here is mine: I know too many false alerts is at the detriment of alerts in the large. I know there use to be a Borland C++ compiler triggering annoying and noisy warnings when an assignment was conditional, which seems to be a case very close to this one. But there is only one condition, so clearly it can’t cover all cases. The probability b is not assigned, is high.

pylint --version output

pylint 1.7.4,
astroid 1.5.3
Python 3.5.2 (default, Nov 23 2017, 16:37:01)
[GCC 5.4.0 20160609]

Note

I’m not telling about it as a bug, rather a an hint.

@PCManticore PCManticore added Control flow Requires control flow understanding Enhancement ✨ Improvement to a component labels Jan 3, 2018
@PCManticore
Copy link
Contributor

This makes sense, but we could only detect it in a sane manner once we land control flow support in pylint.

@Hibou57
Copy link
Author

Hibou57 commented Jan 7, 2018

@PCManticore , don’t worry too much, PyLint is already very clever even without it.

@jacobtylerwalls
Copy link
Member

Duplicate of #1727 and #267.

@Pierre-Sassoulas Pierre-Sassoulas added the Duplicate 🐫 Duplicate of an already existing issue label Dec 4, 2021
@Pierre-Sassoulas
Copy link
Member

Closing as a duplicate of #1727, it's old but the discussion happened elsewhere. (Thank you @jacobtylerwalls for helping us cleanup)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Control flow Requires control flow understanding Duplicate 🐫 Duplicate of an already existing issue Enhancement ✨ Improvement to a component
Projects
None yet
Development

No branches or pull requests

4 participants