Repository navigation
fix(typescript): extract abstract method signatures - #3961
Closed
rajatnagda45 wants to merge 1 commit into
Closed
rajatnagda45 wants to merge 1 commit into
rajatnagda45 wants to merge 1 commit into
Conversation
An abstract class's `abstract area(): number;` parses as
`abstract_method_signature`, which was not a TypeScript function type, so the
abstract method was dropped. An interface's `method_signature` has long been a
function type, so `interface D { draw(): void }` put `draw` in the graph — but
the identical contract on an `abstract class` did not.
The result: the base of an abstract class kept only its concrete methods, a
polymorphic `shape.area()` had no declaration to resolve to, and the overridden
contract had no node to carry it.
An abstract method is the same kind of contract as an interface method: a
subclass must implement it. Add `abstract_method_signature` to the TS function
types (inherited by the TSX config). Its name sits on the same `name` field as
`method_signature`, so no other change is needed. Abstract fields
(`public_field_definition`) are left as-is, matching concrete fields which are
not nodes either.
Added tests/test_ts_abstract_methods.py: the abstract method becomes a node,
a call through the abstract type resolves to it, and it reaches parity with the
interface method it mirrors.
|
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. |
Member
|
Shipped in v0.9.74 (live on PyPI as Closing as shipped. |
1 task done
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.
Problem
An abstract class's method was dropped from the graph, while the identical contract on an
interfacewas kept:So the base of an
abstract classkept only its concrete methods, a polymorphicshape.area()had no declaration to resolve to, and the overridden contract had no node to carry it.Implementation
An abstract method is the same kind of contract as an interface method: a subclass must implement it.
interfacemethods (method_signature) were already a TS function type; abstract methods parse asabstract_method_signature, which was not.Add
abstract_method_signatureto the TypeScript function types (inherited by the TSX config). Its name sits on the samenamefield asmethod_signature, so nothing else is needed.Limitations
Abstract fields (
public_field_definitionwithabstract) are left as-is, matching concrete fields, which are not nodes either. Scope is abstract methods only.Verification
tests/test_ts_abstract_methods.py(new): the abstract method becomes a node; a concrete method and a free function calling it both resolve to it; parity with the interface method it mirrors. All fail onv8, pass with the fix.uv run pytest tests/— full suite green (6175 passed, 15 skipped). Existing TS suites (test_ts_inheritance,test_ts_namespace,test_typescript_enum_members,test_ts_decorators) unchanged.uv run ruff check .clean;uv run pyrightadds zero new errors.