Repository navigation
fix(extract): drop Python Self type annotation from references - #4386
rajatnagda45 wants to merge 1 commit into
Conversation
A `-> Self` / `: Self` / `typing.Self` annotation (PEP 673) names the enclosing class, not a corpus symbol, but the Python type-ref pass treated the bare identifier `Self` as a type reference and ran it through the sourceless-stub path. That fabricated a node with the bare id `self` that every `Self`-annotated method in the corpus collapses onto — a god node, the same keyword-type pitfall Rust's `Self` was fixed for. `Self` now sits with the other typing special forms in the type-container set, so it is skipped the way `None`/`Ellipsis`/`ClassVar` already are; this also covers the `typing.Self` attribute spelling. Dropping it matches how the `-> "ClassName"` self forward-ref is already left unresolved. A genuine user return type is unaffected.
|
Thanks for the pull request, @rajatnagda45. A maintainer will review it soon. Want to talk it through while it is in review? Come join us on our Discord server. For longer-form discussion there is also GitHub Discussions. A couple of things that speed up review: make sure the test suite passes on Python 3.10 and 3.13, and that the change keeps extraction deterministic. |
There was a problem hiding this comment.
Graphify reviewed this change.
No issues found by static checks — no coupling regressions or blocking issues in the code graph. That is not the same as safe to merge: see what was not checked.
Not checked: tests were not run; no formal proof of the changed code.
Graphify review — findings
Stops PEP 673 Self annotations (-> Self, : Self, typing.Self) from emitting type references, so they no longer mint a sourceless self stub that every such method across the corpus collapses onto. Self is now treated like other keyword types in _PYTHON_TYPE_CONTAINERS and left unresolved, the same way the -> "ClassName" forward-ref already is. Genuine user return types still produce references edges.
No blocking issues surfaced. 2 lower-confidence candidates did not survive cross-model review.
Analysis details — impact, health, verification
Impact & health
Graphify review
Impact — 872 functions depend on the 306 functions this change touches.
Health — grade A; 10 existing hotspot(s) in the area this change touches (pre-existing, not introduced here):
_extract_generic()— 19 callers, 38 callees (high)extract_js()— 90 callers, 7 callees (high)extract_xaml()— 19 callers, 17 callees (high)extract_objc()— 25 callers, 10 callees (high)extract_php()— 38 callers, 5 callees (high)extract_cpp()— 37 callers, 5 callees (high)extract_julia()— 22 callers, 8 callees (high)extract_svelte()— 14 callers, 8 callees (high)- …and 2 more
Verification — 872 functions in the blast radius were not formally verified this run (proofs are advisory here).
Gate & verification
graphify gate
PASS — objectively clean (no health regressions, tests not run — proofs not run this pass (advisory)). Grounded, not self-assessed.
Advisory (not blocking):
- verification_scope: 761 function(s) in the blast radius were not formally verified this run
Test selection
Test selection
35 of 391 test file(s) selected (9%) via static blast radius.
tests/test_astro_extraction.py— impacttests/test_build.py— impacttests/test_cjs_module_extension.py— impacttests/test_cpp_nested_and_cli.py— impacttests/test_csharp_partial_classes.py— impacttests/test_dotnet.py— impacttests/test_extract.py— impacttests/test_extract_php_closures.py— impacttests/test_import_extension_resolution.py— impacttests/test_indirect_call_block_scoped_shadow.py— impacttests/test_indirect_dispatch.py— impacttests/test_indirect_dispatch_assign_return.py— impacttests/test_indirect_dispatch_getattr.py— impacttests/test_js_exported_scalar_bindings.py— impacttests/test_languages.py— impacttests/test_multilang.py— impacttests/test_php_unparsed_casts.py— impacttests/test_python_inherited_method_calls.py— impacttests/test_python_property_reads.py— impacttests/test_python_self_type_ref.py— impact, changed-testtests/test_python_underscore_resolution.py— impacttests/test_rationale.py— impacttests/test_ruby_resolution.py— impacttests/test_scala_context_bounds.py— impacttests/test_scala_given_instances.py— impacttests/test_scala_self_type.py— impacttests/test_scala_top_level_binding.py— impacttests/test_scala_type_definition.py— impacttests/test_svelte_extraction.py— impacttests/test_swift_computed_properties.py— impacttests/test_swift_protocol_requirements.py— impacttests/test_trailing_newline_not_a_syntax_error.py— impacttests/test_ts_new_expression_calls.py— impacttests/test_typescript_module_extensions.py— impacttests/test_vue_extraction.py— impact
Selection is safe under the controlled-regression assumption; always-run tests + a periodic full run are the backstops. Advisory — it never changes the check verdict.
Python property-accessor decorators and `Self` (#4385, #4386), Swift `Self` (#4387), Go generic type params (#4388), the Python forward type-hint file-node fix (#4343), PowerShell dot-source paths (#4369), and the C# verbatim-interpolated-string recovery (#3612) all change AST extraction output, so warm caches must re-extract. Co-Authored-By: Claude Opus 4.8 <[email protected]>
|
Shipped in v0.9.88, just released to PyPI as |
Fixes #4381.
Problem
PEP 673
Selfnames the enclosing class, not a corpus symbol, but the Python type-ref pass treats the bare identifierSelf(and thetyping.Selftail) as a type reference and runs it through the sourceless-stub path. That fabricates a node with the bare idselfthat everySelf-annotated method in the corpus collapses onto — a god node, the same keyword-type pitfall Rust'sSelfwas fixed for.Implementation
Selfnow sits with the other typing special forms (None,Ellipsis,ClassVar, …) in the type-container set, so it is skipped the way those already are; the attribute branch covers thetyping.Selfspelling. Dropping it matches how the-> "ClassName"self forward-ref is already left unresolved. A genuine user return/parameter type is unaffected.Verification
New
tests/test_python_self_type_ref.py(return, parameter,typing.Self, cross-file, and a real-type guard). The single-file cases fail on pre-fix v8 and pass with the fix.Commands run:
uv run pytest tests/(7519 passed, 15 skipped; security/wheel excluded as above)uv run ruff check .(clean)uv run pyright graphify/extractors/engine.py(34 errors, 0 added vs v8)Limitations
Follows the existing design of not resolving a self-type annotation to the enclosing class node (as with the string forward-ref); it is dropped, not rebound.