-
Notifications
You must be signed in to change notification settings - Fork 1.6k
[ty] Infer type of implicit cls parameter in method bodies
#21685
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ibraheemdev
wants to merge
2
commits into
main
Choose a base branch
from
ibraheem/implicit-cls-body
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+167
−154
Conversation
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
Diagnostic diff on typing conformance testsChanges were detected when running ty on typing conformance tests--- old-output.txt 2025-11-28 23:08:44.942458669 +0000
+++ new-output.txt 2025-11-28 23:08:48.482467336 +0000
@@ -516,15 +516,13 @@
generics_self_advanced.py:36:9: error[type-assertion-failure] Type `list[Self@method2]` does not match asserted type `list[typing.Self]`
generics_self_advanced.py:37:9: error[type-assertion-failure] Type `Self@method2` does not match asserted type `typing.Self`
generics_self_advanced.py:38:9: error[type-assertion-failure] Type `Self@method2` does not match asserted type `Unknown`
-generics_self_advanced.py:42:9: error[type-assertion-failure] Type `type[Self@method3]` does not match asserted type `Unknown`
-generics_self_advanced.py:43:9: error[type-assertion-failure] Type `list[Self@method3]` does not match asserted type `Unknown`
-generics_self_advanced.py:44:9: error[type-assertion-failure] Type `Self@method3` does not match asserted type `Unknown`
+generics_self_advanced.py:43:9: error[type-assertion-failure] Type `list[Self@method3]` does not match asserted type `list[typing.Self]`
+generics_self_advanced.py:44:9: error[type-assertion-failure] Type `Self@method3` does not match asserted type `typing.Self`
generics_self_advanced.py:45:9: error[type-assertion-failure] Type `Self@method3` does not match asserted type `Unknown`
generics_self_attributes.py:26:33: error[invalid-argument-type] Argument is incorrect: Expected `typing.Self | None`, found `LinkedList[int]`
generics_self_attributes.py:29:5: error[invalid-assignment] Object of type `OrdinalLinkedList` is not assignable to attribute `next` of type `typing.Self | None`
generics_self_attributes.py:32:5: error[invalid-assignment] Object of type `LinkedList[int]` is not assignable to attribute `next` of type `typing.Self | None`
generics_self_basic.py:20:16: error[invalid-return-type] Return type does not match returned value: expected `Self@method2`, found `Shape`
-generics_self_basic.py:27:9: error[type-assertion-failure] Type `type[Self@from_config]` does not match asserted type `Unknown`
generics_self_basic.py:33:16: error[invalid-return-type] Return type does not match returned value: expected `Self@cls_method2`, found `Shape`
generics_self_basic.py:54:1: error[type-assertion-failure] Type `Shape` does not match asserted type `Unknown`
generics_self_basic.py:55:1: error[type-assertion-failure] Type `Circle` does not match asserted type `Unknown`
@@ -1039,4 +1037,4 @@
typeddicts_usage.py:28:17: error[missing-typed-dict-key] Missing required key 'name' in TypedDict `Movie` constructor
typeddicts_usage.py:28:18: error[invalid-key] Unknown key "title" for TypedDict `Movie`: Unknown key "title"
typeddicts_usage.py:40:24: error[invalid-type-form] The special form `typing.TypedDict` is not allowed in type expressions
-Found 1041 diagnostics
+Found 1039 diagnostics
|
|
CodSpeed Performance ReportMerging #21685 will degrade performances by 11.47%Comparing Summary
Benchmarks breakdown
|
|
| Lint rule | Added | Removed | Changed |
|---|---|---|---|
invalid-argument-type |
70 | 18 | 77 |
unresolved-attribute |
85 | 0 | 0 |
unused-ignore-comment |
0 | 81 | 0 |
possibly-missing-attribute |
48 | 0 | 0 |
invalid-return-type |
34 | 1 | 4 |
unknown-argument |
39 | 0 | 0 |
invalid-assignment |
38 | 0 | 0 |
missing-argument |
10 | 0 | 0 |
parameter-already-assigned |
8 | 0 | 0 |
no-matching-overload |
7 | 0 | 0 |
too-many-positional-arguments |
5 | 0 | 0 |
unsupported-operator |
5 | 0 | 0 |
not-iterable |
3 | 0 | 0 |
unsupported-base |
2 | 0 | 0 |
deprecated |
1 | 0 | 0 |
invalid-context-manager |
1 | 0 | 0 |
invalid-type-form |
1 | 0 | 0 |
redundant-cast |
1 | 0 | 0 |
| Total | 358 | 100 | 81 |
|
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
Extends #20922 to infer unannotated
clsparameters astype[Self]in method bodies.Part of astral-sh/ty#159.