Skip to content

Python: Fix self-assigned fields and or-expression type propagation#2602

Merged
lshala merged 8 commits into
mainfrom
ls/fix-self-assigned-fields
Mar 10, 2026
Merged

Python: Fix self-assigned fields and or-expression type propagation#2602
lshala merged 8 commits into
mainfrom
ls/fix-self-assigned-fields

Conversation

@lshala

@lshala lshala commented Feb 23, 2026

Copy link
Copy Markdown
Contributor

Two related fixes:

  • Instance/self-assigned fields (e.g. self.foo = Foo()) were not being declared because self has an UnknownType. This prevented calls on those fields from being resolved.
  • There are also cases where the type can either be passed via a parameter or it will be declared with the default constructor (e.g. self.foo = foo or Foo())

Partially fixes #2575

@codecov

codecov Bot commented Feb 23, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 91.66667% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 74.19%. Comparing base (fedc70a) to head (e3055ff).
⚠️ Report is 2 commits behind head on main.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
...ofer/aisec/cpg/passes/PythonAddDeclarationsPass.kt 60.00% 0 Missing and 2 partials ⚠️
Additional details and impacted files
Files with missing lines Coverage Δ
...tlin/de/fraunhofer/aisec/cpg/frontends/Language.kt 85.87% <100.00%> (+0.93%) ⬆️
...cpg/graph/statements/expressions/BinaryOperator.kt 76.36% <100.00%> (+0.43%) ⬆️
...hofer/aisec/cpg/frontends/python/PythonLanguage.kt 94.54% <100.00%> (+0.24%) ⬆️
...ofer/aisec/cpg/passes/PythonAddDeclarationsPass.kt 88.28% <60.00%> (+3.88%) ⬆️

... and 4 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@lshala
lshala marked this pull request as ready for review February 24, 2026 12:31
@lshala
lshala marked this pull request as draft February 24, 2026 14:05

@maximiliankaul maximiliankaul left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM. Maybe double check with someone more familiar with our assignedTypes functionality.

@lshala
lshala marked this pull request as ready for review March 4, 2026 16:32
@lshala
lshala added this pull request to the merge queue Mar 10, 2026
Merged via the queue into main with commit bc0925b Mar 10, 2026
4 checks passed
@lshala
lshala deleted the ls/fix-self-assigned-fields branch March 10, 2026 14:34
KuechA pushed a commit that referenced this pull request Mar 20, 2026
…2602)

* Add second test

* Fix failing test and adjust binary operator handling

* Add assert

* Handle or and and operators via assignedTypes

* Refactor default implementation of propagateAssignedTypes
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

Successfully merging this pull request may close these issues.

3 participants