Skip to content

[pysrc2cpg] Improve type hint extraction and type recovery from annotations#5911

Open
allsmog wants to merge 2 commits into
joernio:masterfrom
allsmog:py/improve-type-recovery
Open

[pysrc2cpg] Improve type hint extraction and type recovery from annotations#5911
allsmog wants to merge 2 commits into
joernio:masterfrom
allsmog:py/improve-type-recovery

Conversation

@allsmog
Copy link
Copy Markdown
Contributor

@allsmog allsmog commented Mar 30, 2026

Improves Python type recovery precision by leveraging existing type annotations.

  • Improve extractTypesFromHint for generics: Optional[str] -> str|None, List[int] -> list, Union[A,B] -> A|B, Dict -> dict, Tuple -> tuple
  • Add Python 3.10+ pipe union syntax support (int | str)
  • Seed type recovery symbol table from parameter, local, and return type annotations
  • Add type stubs for ~45 stdlib builtins (len, str, sorted, etc.) and common stdlib functions (os.path.join, json.loads, etc.)

Test plan

  • New type hint propagation tests in TypeRecoveryPassTests
  • Updated FunctionDefCpgTests for improved generic resolution
  • All existing pysrc2cpg tests pass

…ations

- Improve extractTypesFromHint for Optional, Union, List, Dict, Tuple generics
- Add Python 3.10+ pipe union syntax (int | str) support
- Seed type recovery symbol table from parameter/local/return type annotations
- Add type stubs for ~45 stdlib builtins and common stdlib functions
@fabsx00 fabsx00 self-requested a review April 8, 2026 14:48
@fabsx00
Copy link
Copy Markdown
Contributor

fabsx00 commented Apr 8, 2026

@allsmog could you run sbt scalafmt test:scalafmt on both of your PRs? Thank you!

@allsmog
Copy link
Copy Markdown
Contributor Author

allsmog commented Apr 8, 2026

Done on both! #5910 was already clean and #5911 needed a couple of reformats — pushed now.

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.

2 participants