Python: Add type attribution tests, use moduleName for module-qualified FQNs, and fix RemoveImport shadowing#6798
Merged
knutwannheden merged 8 commits intomainfrom Feb 23, 2026
Merged
Conversation
- 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
- Add param_type_info() to PythonTypeMapping for function parameter Identifier nodes to get JavaType.Variable field_type - Update __convert_name() and map_arg() to flow field_type through to J.Identifier and NamedVariable - Use call signature returnTypeId for call-site-specific return types (e.g. int for identity(42) instead of generic T) - Populate _declared_formal_type_names on method invocation types from function descriptor type parameters - Bump ty-types to 0.0.19.dev20260223102528 for callSignature typeArguments/returnTypeId support
classLiteral types now use moduleName to build proper FQNs (e.g. mymodule.MyClass instead of bare MyClass), and bare function calls get a declaring type from their module. Bumps ty-types to 0.0.19.dev20260223122104.
204705e to
d311477
Compare
- Extract _ty_types_has_module_name() into shared _markers.py module to eliminate duplication and reduce subprocess overhead - Fix temp file leak by adding os.unlink() in finally block - Fix test_class_instance_type_attribution to accept module-qualified FQNs (endsWith 'Foo' instead of exact match) - Gate from-import tests with @requires_module_name since bare function calls need moduleName for declaring type resolution - Accept both posixpath and ntpath in os.path test for Windows compat
Since ty-types minimum version is pinned in pyproject.toml, the @requires_ty_cli and @requires_module_name skip markers are unnecessary. Remove them and the shared _markers.py module. Also prefix UUID-based temp filenames with underscore to ensure they are valid Python module names — ty-types omits moduleName when the filename starts with a digit, causing non-deterministic test behavior.
RemoveImport._is_referenced now skips identifiers inside function scopes that have field_type set, as these are local variables shadowing the imported name rather than actual uses of the import. This prevents keeping unused imports when a local variable happens to share the same name. Also fix test_type_attribution assertions to accept module-qualified FQNs (e.g. 'test.Greeter' instead of bare 'Greeter') since the moduleName improvements now produce module-prefixed names.
knutwannheden
added a commit
that referenced
this pull request
Feb 24, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
classLiteraltypes now usemoduleNamefrom ty-types to build proper FQNs (e.g.mymodule.MyClassinstead of bareMyClass)join("a", "b")imported viafrom os.path import join) now get a declaring type frommoduleNameRemoveImportnow uses type attribution to detect shadowed locals —from os.path import joinis correctly removed whenjoinis only used as a local variable name in a function scope_to ensure valid Python module names (ty-types omitsmoduleNamewhen filenames start with a digit)@requires_ty_cliand@requires_module_nameskip markers since ty-types minimum version is pinned in pyproject.toml0.0.19.dev20260223122104which provides themoduleNamefieldfield_typeattribution on function/method parameter identifiers and call-site type arguments for generic functionsTest plan
ChangeImportshadowing test)RemoveImporttests pass (3 new shadowing tests)