Repository navigation
Check the parameters before a gradual *args: Any, **kwargs: Any tail - #5692
Closed
samwgoldman wants to merge 1 commit into
Closed
samwgoldman wants to merge 1 commit into
samwgoldman wants to merge 1 commit into
Conversation
Summary: Fixes #5194. The typing spec treats `*args: Any, **kwargs: Any` in a signature as `...`, but keeps the signature's other parameters. Pyrefly instead treated the whole signature as gradual: when either side of a callable assignability check had such a tail, any parameter mismatch counted as success. So `def f(a: str, /, *args, **kwargs)` was assignable to `Callable[[int], None]`, and an override `def m(self, x: str, *args: Any, **kwargs: Any)` of `def m(self, x: int)` was accepted, also against an overloaded parent. This change models such a signature as its other parameters followed by a gradual tail, and checks those parameters normally: - When the target has the tail, the parameter matcher matches the target's other parameters as usual, and the tail stands for whatever positional and keyword parameters of the source remain. - When the source has the tail, no special case is needed: its `*args: Any` and `**kwargs: Any` already accept the remaining parameters of the target, and its other parameters are checked like any others. - Against a `ParamSpec`, a remainder that is only the tail is `...`. So `Callable[P, R]` accepts it even where `P` is not being solved, and a gradual `*args` can consume the rest of a `Concatenate` prefix. Because no errors are suppressed anymore, failed checks keep their details. `strict-callable-subtyping` still turns the gradual tail off. Overrides use the same relation, so an override that lacks a parameter that precedes the parent's gradual tail (or the reverse) is now reported. Error differential: - mypy_primer: no differences. pytorch and pandas: no changes. - numpy: -1, an `assert_type` in numpy's own typing tests now passes. Differential Revision: D133047779
Contributor
|
@samwgoldman has exported this pull request. If you are a Meta employee, you can view the originating Diff in D133047779. |
|
According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅ |
rchen152
approved these changes
Nov 19, 2026
rchen152
left a comment
Contributor
There was a problem hiding this comment.
Review automatically exported from Phabricator review in Meta.
Contributor
|
This pull request has been merged in 76655fa. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary:
Fixes #5194.
The typing spec treats
*args: Any, **kwargs: Anyin a signature as..., but keeps the signature's other parameters. Pyrefly instead treated the whole signature as gradual: when either side of a callable assignability check had such a tail, any parameter mismatch counted as success. Sodef f(a: str, /, *args, **kwargs)was assignable toCallable[[int], None], and an overridedef m(self, x: str, *args: Any, **kwargs: Any)ofdef m(self, x: int)was accepted, also against an overloaded parent.This change models such a signature as its other parameters followed by a gradual tail, and checks those parameters normally:
*args: Anyand**kwargs: Anyalready accept the remaining parameters of the target, and its other parameters are checked like any others.ParamSpec, a remainder that is only the tail is.... SoCallable[P, R]accepts it even wherePis not being solved, and a gradual*argscan consume the rest of aConcatenateprefix.Because no errors are suppressed anymore, failed checks keep their details.
strict-callable-subtypingstill turns the gradual tail off.Overrides use the same relation, so an override that lacks a parameter that precedes the parent's gradual tail (or the reverse) is now reported.
Error differential:
assert_typein numpy's own typing tests now passes.Differential Revision: D133047779