Skip to content

Fix Callable[..., ...] false negative (#3912)#3929

Open
ibraheemshaikh5 wants to merge 5 commits into
facebook:mainfrom
ibraheemshaikh5:fix-callable-ellipsis-false-neg
Open

Fix Callable[..., ...] false negative (#3912)#3929
ibraheemshaikh5 wants to merge 5 commits into
facebook:mainfrom
ibraheemshaikh5:fix-callable-ellipsis-false-neg

Conversation

@ibraheemshaikh5

@ibraheemshaikh5 ibraheemshaikh5 commented Jun 24, 2026

Copy link
Copy Markdown

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.

@meta-cla meta-cla Bot added the cla signed label Jun 24, 2026
@kinto0 kinto0 self-assigned this Jun 24, 2026
@meta-codesync

meta-codesync Bot commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

@kinto0 has imported this pull request. If you are a Meta employee, you can view this in D109604289.

@github-actions

This comment has been minimized.

Comment thread pyrefly/lib/alt/specials.rs Outdated
errors,
arguments[1].range(),
ErrorKind::BadSpecialization,
"`...` is not a valid return type for `Callable`".to_owned(),

@jorenham jorenham Jun 24, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@ibraheemshaikh5 ibraheemshaikh5 Jun 24, 2026

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, good catch. I just pushed a commit to tighten up the wording. TAL at what you mentioned in the issue thread now.

@github-actions github-actions Bot added size/s and removed size/s labels Jun 24, 2026
Comment thread pyrefly/lib/alt/specials.rs Outdated
self.error(
errors,
arguments[1].range(),
ErrorKind::BadSpecialization,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For f() -> ... pyrefly currently uses invalid-annotation as error code, so maybe we should also use that one (InvalidAnnotation) here?

@github-actions

Copy link
Copy Markdown

According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅

@github-actions github-actions Bot added size/s and removed size/s labels Jun 25, 2026
@ibraheemshaikh5

Copy link
Copy Markdown
Author

I extended the fix beyond the Callable return slot. Now the following cases are covered:

  • list[...] / dict[int, ...] (type-argument positions) now report ... cannot be used for type parameter with invalid-annotation, replacing the ParamSpec message
  • class C[T: ...], type[...], and TypeVar(bound=...) report Ellipsis is not allowed in this context (invalid-annotation).
  • The Callable return type error now uses InvalidAnnotation for consistency and accuracy

For testing:
Added test_ellipsis_invalid_type_form in simple.rs covering the full list (including tuple[...]), and confirmed valid uses still pass: Callable[..., int], tuple[int, ...], ParamSpec(default=...), and ParamSpec specialization.

@ibraheemshaikh5 ibraheemshaikh5 requested a review from jorenham June 25, 2026 21:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

false negative: Callable[..., ...]

3 participants