Skip to content

Generic type parsing for type annotations (v0.9.0) - #92

Merged
octo-youcef merged 5 commits into
mainfrom
feature/generic-type-parsing
May 1, 2026
Merged

Generic type parsing for type annotations (v0.9.0)#92
octo-youcef merged 5 commits into
mainfrom
feature/generic-type-parsing

Conversation

@octo-youcef

Copy link
Copy Markdown
Collaborator

Summary

Adds full support for generic type annotations in Python code, eliminating false positive warnings from type inference.

Closes #39

Changes

New functionality:

  • Parse list[T], dict[K, V], set[T], tuple[T, ...] generic types
  • Parse union types: X | None, int | str | None
  • Parse Optional[T] from typing module
  • Parse nested generics: list[dict[str, int]], dict[str, list[int]]
  • Support typing module aliases: List[int], Dict[str, Any]

Implementation:

  • Created type_utils.parse_type_annotation() shared helper function
  • Updated ASTExtractor._get_type_string() to use helper for extracting parameter and return type annotations
  • Updated TypeInferrer._get_type_string() to use helper for type inference validation

Impact:

  • Type annotations now preserve full generic information instead of erasing to base type
    • Before: list[int] → stored as "list"
    • After: list[int] → stored as "list[int]"
  • Type inference validation now correctly compares generic types
  • Eliminates false warnings when actual and annotated types match but have generic parameters

Testing

  • Added 18 comprehensive unit tests for parse_type_annotation() helper
  • Added test for generic type extraction in ASTExtractor
  • Added test for generic type inference in TypeInferrer
  • All 312 unit tests passing (20 new tests)
  • Coverage: 80.63% (above 75% threshold)

Commits

  1. Add type_utils module for parsing generic type annotations
  2. Update ASTExtractor to parse generic type annotations
  3. Update TypeInferrer to parse generic type annotations
  4. Update CHANGELOG for v0.9.0
  5. Bump version: 0.8.4 → 0.9.0

🤖 Generated with Claude Code

- Create parse_type_annotation() helper for parsing AST type nodes
- Handles simple types (str, int, CustomClass)
- Handles generic types (list[int], dict[str, Any])
- Handles union types (str | None, int | str)
- Handles Optional types (Optional[str])
- Handles nested generics (list[dict[str, int]])
- Add 18 comprehensive unit tests covering all type patterns
- All 310 unit tests passing
- Replace _get_type_string() implementation with type_utils helper
- Now extracts list[T], dict[K, V], Optional[T], X | None types
- Add comprehensive test for generic type extraction
- All 311 unit tests passing
- Replace _get_type_string() implementation with type_utils helper
- Now handles list[T], dict[K, V], Optional[T], X | None in annotations
- Add test verifying generic type inference works correctly
- All 312 unit tests passing (20 new tests total)
@octo-youcef
octo-youcef requested a review from ydkadri as a code owner May 1, 2026 07:43
@octo-youcef
octo-youcef merged commit 9f2e2e5 into main May 1, 2026
8 checks passed
@octo-youcef
octo-youcef deleted the feature/generic-type-parsing branch May 1, 2026 07:56
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.

Support generic type annotation parsing (dict[K,V], T | None, etc.)

2 participants