Skip to content

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

Open
allsmog wants to merge 1 commit intojoernio:masterfrom
allsmog:py/improve-type-recovery
Open

[pysrc2cpg] Improve type hint extraction and type recovery from annotations#5911
allsmog wants to merge 1 commit intojoernio:masterfrom
allsmog:py/improve-type-recovery

Conversation

@allsmog
Copy link
Copy Markdown

@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
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.

1 participant