-
Notifications
You must be signed in to change notification settings - Fork 282
Pass most conformance tests for Zuban #2139
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
… bound of the class
| ret2 = example4(v2, 1) | ||
| assert_type(ret2, Any) | ||
| assert_type(ret2, Any) # E[example4] | ||
| assert_type(ret2, list[Any]) # E[example4] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn't Step 5 of https://typing.python.org/en/latest/spec/overload.html#step-5 explicitly mandate Any (not list[Any]) here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are right, that it's written that way. My personal opinion is that it should be possible for type checkers to be more precise than what the spec mandates. I personally would also be supportive to allow list[int] | list[str], but I doubt any type checker would do that.
It's of course possible for me to disable this fallback logic, but I'd rather not, because I find it useful. I also don't think that it's necessary to explain in the spec that fallback types can be used. But if people don't think so, then I probably have to start a discussion about this as well (like 2-3 other cases where Zuban is more strict).
In this specific case I also doubt that it will cause interoperability issues, since anybody using the overload will work with a list output.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Our motivation for standardizing the overload algorithm was to ensure that type checkers produce the same result when evaluating overloaded calls. Allowing variations would be run counter to this goal.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do think that it's good that overloads are standardized. I'm just a bit sad that this behavior is being ditched for IMO no good reason. I have changed it regardless, I don't think it's worth discussing. I did not yet create a Zuban release, so you should probably not merge yet.
Are there other issues? Happy to create a release otherwise.
…luation" Reverted because this change was not according to the spec. This reverts commit 593d74d.
ab19cfd to
d66cdb2
Compare
d66cdb2 to
474b63e
Compare
| @@ -1,12 +1,9 @@ | |||
| conformant = "Partial" | |||
| notes = """ | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can remove the empty notes section (possibly in a few more files too)
| return x | ||
| stop() | ||
| ... # E?: This statement can be marked unreachable | ||
| return "whatever works" # No type error |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For what it's worth I wouldn't mind allowing an error here; the type is clearly wrong and I don't think it's wrong for type checkers to detect that even in unreachable code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(No change requested though; fine to leave it as is.)
JelleZijlstra
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me!
This latest update passes most conformance tests for Zuban. I simplified the flags for
zuban checkand it also passes 2 more tests for Pyrefly.I have made several small changes to the tests. These should mostly be uncontroversial:
SelfTypeVar = TypeVar("SelfTypeVar", bound=Foo7[int]); Callable[[SelfTypevar], SelfTypeVar]instead ofCallable[[Foo7[int]], Foo7[int]]. I personally believe this should be how we infer things, since it's more precise but I don't think we have to mandate this.list[Any]instead ofAnyin an overload, if there was no match, because both of the overloads return a list and it is therefore just a slightly more precise type.__init__). There is already an error for the outer attributex, but I feel like this error should be fine.There remain 4 non-passing tests for Zuban, all of which I'm not sure the tests are doing the right thing. I will be discussing these in the typing discourse.