Repository navigation
Fix spurious error on optional dict of generic callable union - #22573
Open
Sudhakar7J wants to merge 1 commit into
Open
Sudhakar7J wants to merge 1 commit into
Sudhakar7J wants to merge 1 commit into
Conversation
Contributor
|
Diff from mypy_primer, showing the effect of this PR on open source code: spark (https://github.com/apache/spark)
- python/pyspark/pandas/groupby.py:3544: error: Argument 2 to "zip" has incompatible type "list[Hashable | Any] | Hashable | list[Any | tuple[Any, ...]]"; expected "Iterable[Hashable | Any]" [arg-type]
+ python/pyspark/pandas/groupby.py:3544: error: Argument 2 to "zip" has incompatible type "list[Any | tuple[Any, ...]] | Hashable"; expected "Iterable[Any | tuple[Any, ...]]" [arg-type]
cattrs (https://github.com/python-attrs/cattrs)
- src/cattrs/converters.py:250: error: Argument 1 to "register_func_list" of "MultiStrategyDispatch" has incompatible type "list[tuple[Callable[[Any], bool], Callable[[Any, BaseConverter], Callable[[Any], Any]], str] | tuple[Callable[[Any], bool], Callable[[Any], str]] | tuple[Callable[[Any], Any], Callable[[Any], Any]] | tuple[Callable[[Any], Any], Callable[[Any], dict[str, Any]]] | tuple[Callable[[Any], bool], Callable[[type[Enum], BaseConverter], Callable[[Enum], Any]], str] | <7 more items>]"; expected "list[tuple[Callable[[Any], bool], Any] | tuple[Callable[[Any], bool], Any, bool] | tuple[Callable[[Any], bool], Callable[[Any, BaseConverter], Any], Literal['extended']]]" [arg-type]
- src/cattrs/converters.py:292: error: Argument 1 to "register_func_list" of "MultiStrategyDispatch" has incompatible type "list[tuple[Callable[[Any], Any], Callable[[Mapping[str, Any], type[T]], T]] | tuple[Callable[[Any], bool], Callable[[type[Enum], BaseConverter], Callable[[Any, type[Enum]], Enum]], str] | tuple[Callable[[Any], Any | bool], Callable[[Any], Callable[[Any, type[T]], T]], bool] | tuple[Callable[[Any], bool], Callable[[Any, BaseConverter], Callable[[Any, Any], Any]], str] | tuple[Callable[[Any], bool], Callable[[Any, bool], Callable[[Any, type[T]], type[T] | None]], bool] | <14 more items>]"; expected "list[tuple[Callable[[Any], bool], Any] | tuple[Callable[[Any], bool], Any, bool] | tuple[Callable[[Any], bool], Callable[[Any, BaseConverter], Any], Literal['extended']]]" [arg-type]
- src/cattrs/converters.py:470: error: Argument 1 to "register_func_list" of "MultiStrategyDispatch" has incompatible type "list[tuple[Any, Any, str] | tuple[Callable[[Any], bool], Any] | tuple[Callable[[Any], bool], Any, bool] | tuple[Callable[[Any], bool], Callable[[Any, BaseConverter], Any], Literal['extended']]]"; expected "list[tuple[Callable[[Any], bool], Any] | tuple[Callable[[Any], bool], Any, bool] | tuple[Callable[[Any], bool], Callable[[Any, BaseConverter], Any], Literal['extended']]]" [arg-type]
- src/cattrs/converters.py:611: error: Argument 1 to "register_func_list" of "MultiStrategyDispatch" has incompatible type "list[tuple[Any, Any, str] | tuple[Callable[[Any], bool], Any] | tuple[Callable[[Any], bool], Any, bool] | tuple[Callable[[Any], bool], Callable[[Any, BaseConverter], Any], Literal['extended']]]"; expected "list[tuple[Callable[[Any], bool], Any] | tuple[Callable[[Any], bool], Any, bool] | tuple[Callable[[Any], bool], Callable[[Any, BaseConverter], Any], Literal['extended']]]" [arg-type]
- src/cattrs/preconf/orjson.py:90: error: Argument 1 to "register_func_list" of "MultiStrategyDispatch" has incompatible type "list[tuple[Callable[[Any], bool], partial[Callable[[Any], Any]], str] | tuple[Callable[[Any], bool], Callable[[Any, Any], Any], bool] | tuple[Callable[[Any], bool], Any] | tuple[Callable[[Any], bool], Any, bool] | tuple[Callable[[Any], bool], Callable[[Any, BaseConverter], Any], Literal['extended']]]"; expected "list[tuple[Callable[[Any], bool], Any] | tuple[Callable[[Any], bool], Any, bool] | tuple[Callable[[Any], bool], Callable[[Any, BaseConverter], Any], Literal['extended']]]" [arg-type]
|
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 #22513
When an invariant context uses the same union as both a lower and an upper bound,
joinof lower bounds can add redundant members throughAnycompatibility. Insolve_one(), if the joined bottom is a subtype of top but is a different union, and top already accepts every lower bound (including being one of them), keep top instead of the widened join.This fixes the regression reported in #22513, where a dict value typed as an optional union of generic callables produced a spurious
dict-itemerror.Verification
testInferenceContextOptionalDictOfCallableUnionincheck-inference-context.test(from the issue repro).pytest mypy/test/testcheck.py -n0 -k "testInferenceContextOptionalDictOfCallableUnion": 1 passed.pytest mypy/test/testcheck.py -n0 -k "InferenceContext or Generic or Union": 1147 passed, 4 skipped, 7241 deselected, 1 xfailed.pytest mypy/test/testsolve.py mypy/test/testtypes.py -n0: 144 passed, 2 skipped.ruff check mypy/solve.pyandblack --check mypy/solve.py: clean.AI assistance: this change was prepared with AI assistance; I reviewed the diagnosis, fix, and verification.