Open
Description
Bug description
- In the three examples hereafter, the variable is assigned in a one line if-condition-assignment, and it is used when condition is true, i.e. visually before the assignment, but after the condition is evaluated at run time.
- Only the two first examples generates a report. They both uses a text concatenation with '+' operator .
print('d' + (f'{s1}' if (s1 := 'x') else '')) # Using variable 's1' before assignment pylint(used-before-assignment)
print((f'{s2}' if (s2 := 'x') else '') + 'd') # Using variable 's2' before assignment pylint(used-before-assignment)
print(f'{s3}' if (s3 := 'x') else '') # No report
Configuration
No response
Command used
pylint launched by the "python" extension of VSCode.
Pylint output
# Using variable 's1' before assignment - pylint(used-before-assignment)
# Using variable 's2' before assignment - pylint(used-before-assignment)
Expected behavior
No reported error.
Pylint version
- pylint 2.15.3
- Python extension for VSCode: v2022.14.0
- Visual studio (VSCode): 1.71.2
- Python version(3.10.7 (tags/v3.10.7:6cc6b13, Sep 5 2022, 14:08:36) installed from python.org
OS / Environment
Windows-10-10.0.22000-SP0
Additional dependencies
I searched for similar open issues but didn't find one.
Thank you for your great job!
Patrick Bourdon - PARIS.
Metadata
Metadata
Assignees
Labels
Related to the walrus operator / assignment expressionIssues related to 'used-before-assignment' checkA message is emitted but nothing is wrong with the codeThis issue is accepted, sufficiently specified and now needs an implementationA bug or crash where it's not immediately obvious what is happenning