Repository navigation
Conversation
…has retained parameters Per the typing spec, an input signature with both *args and **kwargs typed as Any is equivalent to '...' in Callable, even when other parameters are declared between them. The star parameters are gradual and impose no constraints on the assignable callable, while retained parameters are still checked. Fixes python#22460
Contributor
|
Diff from mypy_primer, showing the effect of this PR on open source code: prefect (https://github.com/PrefectHQ/prefect)
+ src/prefect/flows.py:1824: error: Overloaded function signatures 4 and 5 overlap with incompatible return types [overload-overlap]
+ src/prefect/flows.py:1824: note: Flipping the order of overloads will fix this error
+ src/prefect/flows.py:2477: error: Overloaded function signatures 4 and 5 overlap with incompatible return types [overload-overlap]
+ src/prefect/flows.py:2477: note: Flipping the order of overloads will fix this error
pandas-stubs (https://github.com/pandas-dev/pandas-stubs)
+ pandas-stubs/core/series.pyi:1345: error: Overloaded function signatures 1 and 3 overlap with incompatible return types [overload-overlap]
+ pandas-stubs/core/series.pyi:1353: error: Overloaded function signatures 2 and 3 overlap with incompatible return types [overload-overlap]
+ pandas-stubs/core/series.pyi:1370: error: Overloaded function signatures 1 and 2 overlap with incompatible return types [overload-overlap]
+ pandas-stubs/core/groupby/generic.pyi:243: error: Overloaded function signatures 1 and 2 overlap with incompatible return types [overload-overlap]
pytensor (https://github.com/pymc-devs/pytensor)
- pytensor/tensor/random/basic.py:632: error: Signature of "__call__" incompatible with supertype "pytensor.tensor.random.op.RandomVariable" [override]
- pytensor/tensor/random/basic.py:632: note: Superclass:
- pytensor/tensor/random/basic.py:632: note: def __call__(self, *args: Any, size: Any = ..., name: Any = ..., rng: Any = ..., dtype: Any = ..., return_next_rng: bool = ..., **kwargs: Any) -> Any
- pytensor/tensor/random/basic.py:632: note: Subclass:
- pytensor/tensor/random/basic.py:632: note: def __call__(self, loc: ndarray[tuple[Any, ...], dtype[Any]] | float, scale: ndarray[tuple[Any, ...], dtype[Any]] | float = ..., size: list[int] | int | None = ..., **kwargs: Any) -> RandomVariable
poetry (https://github.com/python-poetry/poetry)
+ src/poetry/utils/env/site_packages.py:188: error: Overloaded function signatures 1 and 2 overlap with incompatible return types [overload-overlap]
scipy-stubs (https://github.com/scipy/scipy-stubs)
+ scipy-stubs/integrate/_tanhsinh.pyi:79: error: Overloaded function signatures 1 and 5 overlap with incompatible return types [overload-overlap]
+ scipy-stubs/integrate/_tanhsinh.pyi:95: error: Overloaded function signatures 2 and 6 overlap with incompatible return types [overload-overlap]
+ scipy-stubs/integrate/_tanhsinh.pyi:95: error: Overloaded function signatures 2 and 7 overlap with incompatible return types [overload-overlap]
+ scipy-stubs/integrate/_tanhsinh.pyi:111: error: Overloaded function signatures 3 and 6 overlap with incompatible return types [overload-overlap]
+ scipy-stubs/integrate/_tanhsinh.pyi:111: error: Overloaded function signatures 3 and 7 overlap with incompatible return types [overload-overlap]
+ scipy-stubs/integrate/_tanhsinh.pyi:127: error: Overloaded function signatures 4 and 5 overlap with incompatible return types [overload-overlap]
+ scipy-stubs/integrate/_tanhsinh.pyi:127: note: Flipping the order of overloads will fix this error
+ scipy-stubs/integrate/_tanhsinh.pyi:127: error: Overloaded function signatures 4 and 6 overlap with incompatible return types [overload-overlap]
+ scipy-stubs/integrate/_tanhsinh.pyi:127: error: Overloaded function signatures 4 and 7 overlap with incompatible return types [overload-overlap]
|
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.
Fixes #22460
What changed
Per the typing spec:
mypy already treats a signature that consists exactly of
(*args: Any, **kwargs: Any)asCallable[..., X](are_trivial_parameters), but when a retained parameter is declared between them (e.g.def __call__(self, *args: Any, formatter: int, **kwargs: Any) -> None), the fast path does not apply and the star parameters are then checked strictly, rejecting every callable that does not itself declare*args/**kwargs.This PR adds the
trivial_star_paramscase toare_parameters_compatible:m: strthat the base signature never passes is fine.Out of scope: signatures where only one of the two star parameters is
Anyare unaffected (still checked strictly), and proper-subtype checks are unchanged (mirroring the existing trivial-parameter fast paths).Reproducer (from the issue, now passing)
Before this PR:
Tests
Three data-driven cases added to
check-protocols.test:testTrivialStarParamsInCallbackProtocol— accepted callables (the issue's case, plus positional/**kwargsvariants).testTrivialStarParamsRetainedParamsChecked— retained parameters are still enforced (missing param, wrong param type are still rejected).testNonTrivialStarParamsStillChecked— no regression when a star parameter is notAny.Validation
pytest mypy/test/testcheck.py: 8364 passed, 16 skipped, 7 xfailed (base: 8361 passed, 16 skipped, 7 xfailed — no failures either side).mypy --config-file mypy_self_check.ini mypy/subtypes.py: clean.AI assistance
This PR was prepared with the help of an AI coding agent. The spec interpretation, the fix, and the red/green validation above were verified locally against mypy master (0952029).