Skip to content

Python: Add type attribution tests and fix method declaration/type hint types#6794

Merged
knutwannheden merged 1 commit intomainfrom
add-type-attribution-tests
Feb 23, 2026
Merged

Python: Add type attribution tests and fix method declaration/type hint types#6794
knutwannheden merged 1 commit intomainfrom
add-type-attribution-tests

Conversation

@knutwannheden
Copy link
Copy Markdown
Contributor

Summary

  • Add type attribution tests to 13 existing Python parser test files, covering method invocations, binary ops, type hints, collection literals, imports, field access, class instances, method declarations, async defs, for loops, unary ops, ternaries, and lambdas (24 new tests total)
  • Add method_declaration_type() to type_mapping.py that builds JavaType.Method for function/method declarations — uses structured descriptor data from ty-types when available, falls back to resolving parameter annotations individually
  • Add type attribution to ParameterizedType nodes (e.g., List[int]) in the parser visitor
  • Fix pre-existing assign_test.py bug: method.simple_namemethod.name.simple_name, and FQN assertions to use startswith for types that include type parameters
  • Bump ty-types dependency to >=0.0.19.dev20260223093555 which now populates parameters and returnType on function descriptors

Test plan

  • All 572 tree tests pass (including 24 new type attribution tests)
  • 1 expected failure: from-import declaring_type is None (genuine type mapping gap for direct function imports)
  • Verified with ty-types 0.0.19.dev20260223093555 that function descriptors now include parameters and returnType

- Add type attribution tests to 13 existing parser test files covering
  method invocations, binary ops, type hints, collection literals, imports,
  field access, class instances, method declarations, async defs, for loops,
  unary ops, ternaries, and lambdas
- Add `method_declaration_type()` to type_mapping.py to build JavaType.Method
  for function declarations using ty-types descriptor data with annotation fallback
- Add type attribution to ParameterizedType nodes in type hint expressions
- Fix pre-existing assign_test.py bug (simple_name access, FQN startswith)
- Add typing.Text test to test_type_attribution.py
- Bump ty-types dependency to >=0.0.19.dev20260223093555
@github-project-automation github-project-automation Bot moved this to In Progress in OpenRewrite Feb 23, 2026
@knutwannheden knutwannheden changed the title Add type attribution tests and fix method declaration/type hint types Python: Add type attribution tests and fix method declaration/type hint types Feb 23, 2026
@knutwannheden knutwannheden merged commit ea79af4 into main Feb 23, 2026
1 check passed
@knutwannheden knutwannheden deleted the add-type-attribution-tests branch February 23, 2026 10:27
@github-project-automation github-project-automation Bot moved this from In Progress to Done in OpenRewrite Feb 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

1 participant