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

Improve detecting statement inclusion #2027

Open
ostr00000 opened this issue Feb 12, 2023 · 0 comments
Open

Improve detecting statement inclusion #2027

ostr00000 opened this issue Feb 12, 2023 · 0 comments

Comments

@ostr00000
Copy link
Contributor

Steps to reproduce

  1. Consider following code in include_error.py:
    """Undefined variable reproduce test"""
    
    if (val := True) or (val_2 := True):
        print(val)
        print(val_2)
    else:
        print(val)
        print(val_2)
    
  2. Run pylint ./include_error.py

Current behavior

No error in Pylint, but there is a runtime error.

Expected behavior

Pylint should show warning (ex. undefined-variable), because there is a possible execution path where val_2 is not defined.

python -c "from astroid import __pkginfo__; print(__pkginfo__.version)" output

  • 2.15.0-dev0

Additional information

astroid incorrectly assumes statement inclusion based on statement exclusion (currently there exist only function are_exclusive).
A new function determining statement inclusion should be added. All places where function are_exclusive is used should be reviewed, and if required, a new function should be used.
Detailed information in #2023 (comment)

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

1 participant