Skip to content

Python: Port ModificationOfLocals.ql#21602

Open
tausbn wants to merge 2 commits intomainfrom
tausbn/python-port-modification-of-locals
Open

Python: Port ModificationOfLocals.ql#21602
tausbn wants to merge 2 commits intomainfrom
tausbn/python-port-modification-of-locals

Conversation

@tausbn
Copy link
Copy Markdown
Contributor

@tausbn tausbn commented Mar 27, 2026

A simple rewrite using API graphs.

@tausbn tausbn force-pushed the tausbn/python-port-modification-of-locals branch from 32e212d to 7de29fd Compare March 27, 2026 22:29
@tausbn tausbn added the no-change-note-required This PR does not need a change note label Apr 7, 2026
tausbn added 2 commits April 7, 2026 23:46
Changing the `locals()` dictionary actually _does_ change the attributes
of the class being defined, so we shouldn't alert in this case.
@tausbn tausbn force-pushed the tausbn/python-port-modification-of-locals branch from d3ec1c6 to e368844 Compare April 7, 2026 21:46
@tausbn tausbn marked this pull request as ready for review April 7, 2026 21:50
@tausbn tausbn requested a review from a team as a code owner April 7, 2026 21:50
Copilot AI review requested due to automatic review settings April 7, 2026 21:50
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Ports the ModificationOfLocals.ql query to use API graphs instead of legacy points-to, and refines scope handling to avoid false positives in module and class scopes.

Changes:

  • Replace legacy points-to based locals() origin detection with semmle.python.ApiGraphs-based modeling.
  • Exclude both module scope and class scope from reporting (since locals() mutations can be effective there).
  • Add a new query-test case covering class-body locals() mutation.
Show a summary per file
File Description
python/ql/src/Statements/ModificationOfLocals.ql Ports locals() tracking to API graphs and excludes Module/Class scopes to improve correctness.
python/ql/test/query-tests/Statements/general/test.py Adds a regression test ensuring class-scope locals() updates are treated as OK.

Copilot's findings

  • Files reviewed: 2/2 changed files
  • Comments generated: 0

@tausbn
Copy link
Copy Markdown
Contributor Author

tausbn commented Apr 7, 2026

Preliminary DCA alert results look good: 11 new true positives, and 4 new false positives that should be fixed by the second commit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

no-change-note-required This PR does not need a change note Python

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants