-
Notifications
You must be signed in to change notification settings - Fork 1.6k
[ty] Infer type of self as typing.Self in method body #18473
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
[ty] Infer type of self as typing.Self in method body #18473
Conversation
5b6005e to
23d7a60
Compare
|
Hi @Glyphack, saw that you opened this up! Let me know if you want to find some time to chat through the options. Edit: Tomorrow, that is, it's the end of the day for me 😄 |
3d924df to
c910aa5
Compare
CodSpeed Performance ReportMerging #18473 will degrade performances by 16.08%Comparing Summary
Benchmarks breakdown
Footnotes
|
This comment was marked as resolved.
This comment was marked as resolved.
e0cdb98 to
536b734
Compare
384d96c to
1a31240
Compare
This comment was marked as resolved.
This comment was marked as resolved.
8ecf5cb to
a04183a
Compare
ed21280 to
7d94153
Compare
Part of astral-sh/ty#159 This PR only adjusts the signature of a method so if it has a `self` argument then that argument will have type of `Typing.Self` even if it's not specified. If user provides an explicit annotation then Ty will not override that annotation. - astral-sh/ty#1131 - astral-sh/ty#1157 - astral-sh/ty#1156 - astral-sh/ty#1173 - #20328 - astral-sh/ty#1163 - astral-sh/ty#1196 Added mdtests. Also some tests need #18473 to work completely. So I added a todo for those new cases that I added. --------- Co-authored-by: David Peter <mail@david-peter.de>
Part of astral-sh/ty#159 This PR only adjusts the signature of a method so if it has a `self` argument then that argument will have type of `Typing.Self` even if it's not specified. If user provides an explicit annotation then Ty will not override that annotation. - astral-sh/ty#1131 - astral-sh/ty#1157 - astral-sh/ty#1156 - astral-sh/ty#1173 - #20328 - astral-sh/ty#1163 - astral-sh/ty#1196 Added mdtests. Also some tests need #18473 to work completely. So I added a todo for those new cases that I added. --------- Co-authored-by: David Peter <mail@david-peter.de>
Part of astral-sh/ty#159 This PR only adjusts the signature of a method so if it has a `self` argument then that argument will have type of `Typing.Self` even if it's not specified. If user provides an explicit annotation then Ty will not override that annotation. - astral-sh/ty#1131 - astral-sh/ty#1157 - astral-sh/ty#1156 - astral-sh/ty#1173 - #20328 - astral-sh/ty#1163 - astral-sh/ty#1196 Added mdtests. Also some tests need #18473 to work completely. So I added a todo for those new cases that I added. --------- Co-authored-by: David Peter <mail@david-peter.de>
This reverts commit 32be31d.
|
I "forked" this PR in #20812 and updated the salsa version. There are 4 new projects that now fail with too many iteration errors https://micha-typing-self-function-s.ecosystem-663.pages.dev/timing. I only checked setuptools, and the error looks legit. The type becomes massive! I think this should now be unblocked (once we figure out how to fix the non-convergent cases). The perf impact is still pretty "bad" but I think that's expected given that we now check much more code https://codspeed.io/astral-sh/ruff/branches/micha%2Ftyping-self-function-scope |
|
I will squash-merge this into #20922 for the same reasons that applied for the previous type-of-self PR. I'd like to clean up the looong history a bit (I will transfer comments that are still relevant), and I'd like to iterate faster on the ecosystem results, which are more convenient to use when it's not a contributor PR. @Glyphack thank you! |
c6cfaf7
into
astral-sh:david/type-of-self-in-methods-integration
Part of astral-sh/ty#159 Add support for adding a synthetic `typing.Self` type for `self` arguments in methods. `typing.Self` is assigned as the type if there are no annotations. - Updated md tests. --------- Co-authored-by: David Peter <mail@david-peter.de>
Part of astral-sh/ty#159 Add support for adding a synthetic `typing.Self` type for `self` arguments in methods. `typing.Self` is assigned as the type if there are no annotations. - Updated md tests. --------- Co-authored-by: David Peter <mail@david-peter.de>
Summary
Part of astral-sh/ty#159
Add support for adding a synthetic
typing.Selftype forselfarguments in methods.typing.Selfis assigned as the type if there are no annotations.This PR only adds the functionality when the symbol lookup is happening.
#18007 is handling the case when a call is happening.
Surfaced issues
After running tests and mypy primer some tests started failing because
selfwas notAnyanymore:MDtests
selfparameter type is set ty#697Too many cycle iterations
Too-many fix point iterations in growing union of literals ty#660
too many cycle iterations in cyclic dependent attributes ty#692
incrementing a value inside a tuple: solved by [ty] Infer type of self as typing.Self in method body #18473 (comment)
Test Plan
selfwas not unknown anymore.