-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Open
Labels
Assignment expressionRelated to the walrus operator / assignment expressionRelated to the walrus operator / assignment expressionC: used-before-assignmentIssues related to 'used-before-assignment' checkIssues related to 'used-before-assignment' checkFalse Positive 🦟A message is emitted but nothing is wrong with the codeA message is emitted but nothing is wrong with the codeNeeds PRThis issue is accepted, sufficiently specified and now needs an implementationThis issue is accepted, sufficiently specified and now needs an implementationNeeds investigation 🔬A bug or crash where it's not immediately obvious what is happenningA bug or crash where it's not immediately obvious what is happenning
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
Assignment expressionRelated to the walrus operator / assignment expressionRelated to the walrus operator / assignment expressionC: used-before-assignmentIssues related to 'used-before-assignment' checkIssues related to 'used-before-assignment' checkFalse Positive 🦟A message is emitted but nothing is wrong with the codeA message is emitted but nothing is wrong with the codeNeeds PRThis issue is accepted, sufficiently specified and now needs an implementationThis issue is accepted, sufficiently specified and now needs an implementationNeeds investigation 🔬A bug or crash where it's not immediately obvious what is happenningA bug or crash where it's not immediately obvious what is happenning