Skip to content

Fix CodeQL warnings in Python#6230

Merged
StephanTLavavej merged 4 commits intomicrosoft:mainfrom
StephanTLavavej:python-codeql
Apr 17, 2026
Merged

Fix CodeQL warnings in Python#6230
StephanTLavavej merged 4 commits intomicrosoft:mainfrom
StephanTLavavej:python-codeql

Conversation

@StephanTLavavej
Copy link
Copy Markdown
Member

  • Fix CodeQL "Unnecessary lambda".
  • Fix CodeQL "Empty except".
    • Instead of calling index() and ignoring ValueError, we can guard the logic with if VALUE in LIST.
  • Suppress CodeQL "Empty except".
    • The warnings say "Except doesn't do anything and has no comment", so we should be able to add comments to suppress the warnings. Unlike C++ CodeQL suppressions, we don't have an opaque ID with a specific suppression syntax to follow, but prefixing the comment with "CodeQL:" will be a good reminder that these comments serve a purpose.
  • Attempt to fix CodeQL "Mismatch in multiple assignment".
    • For the line cmd, out, err, rc = self.runStep(step, litConfig) this is complaining: "Assigning multiple variables without ensuring that you define a value for each variable causes an exception at runtime." I speculate that this is happening because CodeQL doesn't understand what we're doing with the 3-tuple returned by executeCommand(). I'm hoping that explicitly unpacking it into 3 variables, before composing runStep()'s 4-tuple result, will make it happy.

Instead of calling index() and ignoring ValueError, we can guard the logic with `if VALUE in LIST`.
The warnings say "Except doesn't do anything and has no comment",
so we should be able to add comments to suppress the warnings.

Unlike C++ CodeQL suppressions, we don't have an opaque ID with a specific suppression syntax to follow,
but prefixing the comment with "CodeQL:" will be a good reminder that these comments serve a purpose.
For the line:
```py
cmd, out, err, rc = self.runStep(step, litConfig)
```

this is complaining: "Assigning multiple variables without ensuring that you define a value for each variable causes an exception at runtime."

I speculate that this is happening because CodeQL doesn't understand what we're doing with the 3-tuple returned by executeCommand().

I'm hoping that explicitly unpacking it into 3 variables, before composing runStep()'s 4-tuple result, will make it happy.
@StephanTLavavej StephanTLavavej added the test Related to test code label Apr 6, 2026
@StephanTLavavej StephanTLavavej requested a review from a team as a code owner April 6, 2026 21:39
@github-project-automation github-project-automation bot moved this to Initial Review in STL Code Reviews Apr 6, 2026
@StephanTLavavej StephanTLavavej moved this from Initial Review to Final Review in STL Code Reviews Apr 6, 2026
Comment thread tests/utils/stl/util.py
@StephanTLavavej StephanTLavavej moved this from Final Review to Ready To Merge in STL Code Reviews Apr 10, 2026
@StephanTLavavej StephanTLavavej moved this from Ready To Merge to Merging in STL Code Reviews Apr 15, 2026
@StephanTLavavej
Copy link
Copy Markdown
Member Author

I'm mirroring this to the MSVC-internal repo. Please notify me if any further changes are pushed, otherwise no action is required.

@StephanTLavavej StephanTLavavej merged commit b581a9b into microsoft:main Apr 17, 2026
49 checks passed
@github-project-automation github-project-automation bot moved this from Merging to Done in STL Code Reviews Apr 17, 2026
@StephanTLavavej StephanTLavavej deleted the python-codeql branch April 17, 2026 10:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

test Related to test code

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

4 participants