-
-
Notifications
You must be signed in to change notification settings - Fork 3k
[match-case] Fix narrowing of class pattern with union-argument. #19517
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
randolf-scholz
wants to merge
8
commits into
python:master
Choose a base branch
from
randolf-scholz:fix_match_callable_2
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Conversation
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
randolf-scholz
commented
Jul 27, 2025
Comment on lines
+8006
to
+8008
if not proposed_type_ranges: | ||
# This is the case for `if isinstance(x, ())` which always returns False. | ||
return UninhabitedType(), default |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test is actually redundant, it works just as well if we comment it out since make_simplified_union([])
returns UninhabitedType()
.
This comment has been minimized.
This comment has been minimized.
Diff from mypy_primer, showing the effect of this PR on open source code: prefect (https://github.com/PrefectHQ/prefect)
- src/prefect/tasks.py:559: error: Incompatible types in assignment (expression has type "Union[int, float, list[float], None]", variable has type "list[float]") [assignment]
+ src/prefect/tasks.py:559: error: Incompatible types in assignment (expression has type "Union[float, int, list[float], None]", variable has type "list[float]") [assignment]
hydra-zen (https://github.com/mit-ll-responsible-ai/hydra-zen)
- src/hydra_zen/wrapper/_implementations.py:932: error: Incompatible return value type (got "type[object]", expected "DataClass_ | type[DataClass_] | ListConfig | DictConfig") [return-value]
spark (https://github.com/apache/spark)
- python/pyspark/pandas/series.py:5116: error: Need type annotation for "cond" [var-annotated]
- python/pyspark/pandas/series.py:5129: error: Incompatible types in assignment (expression has type "Column", variable has type "Never") [assignment]
- python/pyspark/pandas/series.py:5131: error: Incompatible types in assignment (expression has type "Column", variable has type "Never") [assignment]
- python/pyspark/pandas/series.py:5134: error: Incompatible types in assignment (expression has type "Column", variable has type "Never") [assignment]
- python/pyspark/ml/connect/readwrite.py:100: error: Redundant cast to "JavaEstimator[Any]" [redundant-cast]
- python/pyspark/ml/connect/readwrite.py:103: error: Redundant cast to "JavaEvaluator" [redundant-cast]
sympy (https://github.com/sympy/sympy)
- sympy/polys/domains/domain.py:542: error: Cannot infer value of type parameter "Es" of "convert_from" of "Domain" [misc]
- sympy/polys/domains/domain.py:549: error: Cannot infer value of type parameter "Es" of "convert_from" of "Domain" [misc]
- sympy/polys/domains/domain.py:551: error: Cannot infer value of type parameter "Es" of "convert_from" of "Domain" [misc]
- sympy/polys/domains/domain.py:584: error: Incompatible types in assignment (expression has type "Basic", variable has type "Es | Expr | complex") [assignment]
|
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.
Sibling PR to #19473, with some experimental changes.
conditional_types
function.UninhabitedType(), default
when no ranges are given. This corresponds toisinstance(x, ())
, with an empty tuple, which always returnsFalse
at runtime.testIsinstanceWithOverlappingPromotionTypes
restrict_subtype_away
: if the second argument is aTypeVar
, replace it with its upper bound (crucial to get correct result intestNarrowSelfType
)TypeChecker.get_isinstance_type
to return empty list (fixesisinstance(x, ())
behavior).Modified tests
testIsInstanceWithEmtpy2ndArg
now correctly infers unreachable forisinstance(x, ())
.testNarrowingUnionMixins
now predicts the same results as pyright playground, https://mypy-play.net/?mypy=latest&python=3.12&gist=734c95f128705cfb0dc4ce24f1ad8eec