Fix Callable[..., ...] false negative (#3912)#3929
Conversation
|
@kinto0 has imported this pull request. If you are a Meta employee, you can view this in D109604289. |
This comment has been minimized.
This comment has been minimized.
| errors, | ||
| arguments[1].range(), | ||
| ErrorKind::BadSpecialization, | ||
| "`...` is not a valid return type for `Callable`".to_owned(), |
There was a problem hiding this comment.
The way this is worded (the "for Callable" bit mostly) could be interpreted to mean that ... can be used as return type in other places. But's it's not valid as a (return) type in general.
There was a problem hiding this comment.
Thank you, good catch. I just pushed a commit to tighten up the wording. TAL at what you mentioned in the issue thread now.
| self.error( | ||
| errors, | ||
| arguments[1].range(), | ||
| ErrorKind::BadSpecialization, |
There was a problem hiding this comment.
For f() -> ... pyrefly currently uses invalid-annotation as error code, so maybe we should also use that one (InvalidAnnotation) here?
|
According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅ |
|
I extended the fix beyond the Callable return slot. Now the following cases are covered:
For testing: |
Summary
When Callable[..., ...] is annotated, the second ellipsis sits in the return slot where ... is not a valid type, but pyrefly accepted it silently and revealed (...) -> Ellipsis. The return type was flowing through expr_untype as Type::Ellipsis, which nothing rejected.
This resolves that by checking for a literal ... in the Callable return argument inside specials.rs, emitting an error, and recovering as Unknown. The change is intentionally small and scoped to that slot only, with a regression test in callable.rs.
Fixes #3912
Test Plan
Added test_callable_ellipsis_return for the Callable[..., ...] case. Ran the callable and paramspec test suites plus test.py locally all green, no conformance changes.