-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Patch check_op_reversible
to support tuple
subclasses.
#19046
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
base: master
Are you sure you want to change the base?
Patch check_op_reversible
to support tuple
subclasses.
#19046
Conversation
check_op_reversible
to support tuple
subclasses.
This comment has been minimized.
This comment has been minimized.
Likely typeshed definition of
Your new version looks reasonable: we want to exclude some kinds of Instances that shouldn't be treated that way, but for any other combination runtime coverage is sufficient. This sounds good, though perhaps more tests are needed (typevar in LHS/RHS? TypeVarTuple? TypedDict/dict?) to make sure we don't actually add more than necessary. |
@sterliakov I added a |
Diff from mypy_primer, showing the effect of this PR on open source code: xarray (https://github.com/pydata/xarray)
+ xarray/computation/computation.py: note: In function "_cov_corr":
+ xarray/computation/computation.py:304: error: Redundant cast to "T_DataArray" [redundant-cast]
|
# Note: use `covers_at_runtime` instead of `is_subtype` (#19006) | ||
covers_at_runtime(right_type, left_type) | ||
and ( | ||
# Checking (A implies B) using the logically equivalent (not A or B), where |
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.
formally called "modus ponens" (https://wikipedia.org/wiki/Modus_ponens), and the binary operator itself is called the "material conditional" (https://wikipedia.org/wiki/Material_conditional) 🤓
Fixes #19006
TypeCheckSuite::check-expressions.test::testReverseBinaryOperator4
tuple-typeshed.pyi
that duplicates the tuple definition from typeshed.This patch drops the
is_subtype(right_type, left_type)
check in favor of the weakercovers_at_runtime(right_type, left_type)
.Open Issues
Some tests were still failing because
isinstance(left_type, Instance)
fails whenleft_type
istuple[()]
. As a workaround, I changed the unconditional checkinto the conditional check
But I am not sure this is the correct thing to do.
(FIXED) I get different results when running tests versus checking a file manually:
versus