Repository navigation
Fix spurious error on optional dict of generic callable union - #22520
Closed
zhengdaodeguL wants to merge 1 commit into
Closed
zhengdaodeguL wants to merge 1 commit into
zhengdaodeguL wants to merge 1 commit into
Conversation
Fixes python#22513 In solve_one, an invariant context could set the same union as both a lower and an upper bound. The join of the lower bounds could then add redundant members when compatibility depended on Any, widening the inferred value type and leaving the outer dict with two competing dict alternatives. Keep the original union when it already accepts every lower bound.
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]
|
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
In
solve_one(), an invariant context can use the same union as both the lower and the upper bound. When the join of the lower bounds gains a redundant member throughAnycompatibility, the inferred value type is widened, which produces two competingdictcandidates for an optional dict of callable unions and reports a spuriousdict-itemerror.Fix: when both bounds are unions that differ,
topis itself one of the lower bounds, and every lower bound is already a subtype oftop, keep the original union instead of using the join result.Added
testInferenceContextOptionalDictOfCallableUnion(the exact repro from the issue) tocheck-inference-context.test; it fails before this change and passes after. Related suites pass (1178 passed, 5 skipped, 1 xfailed acrosstestcheck.py -k "InferenceContext or Generic or Union",testsolve.py,testtypes.py).