-
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
base: main
Are you sure you want to change the base?
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 11.77%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 <[email protected]>
I ran the walltime benchamarks locally after pulling in #20515 This PR clearly regresses for all projects but they complete in a reasonable time:
|
The mypy primer runs still take significantly longer:
and there are projects that still don't complete, e.g. But it's certainly much better than before where prefect never completed too One of the files that's much slower on this branch than before is src/prefect/_vendor/croniter/croniter.py |
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 <[email protected]>
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 <[email protected]>
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 <[email protected]>
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 <[email protected]>
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 <[email protected]>
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 <[email protected]>
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 |
Summary
Part of astral-sh/ty#159
Add support for adding a synthetic
typing.Self
type forself
arguments in methods.typing.Self
is 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
self
was notAny
anymore:MDtests
self
parameter 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
self
was not unknown anymore.