[ty] Fix false-positive unsupported-operator for "symmetric" TypeVars#22756
[ty] Fix false-positive unsupported-operator for "symmetric" TypeVars#22756charliermarsh merged 1 commit intomainfrom
unsupported-operator for "symmetric" TypeVars#22756Conversation
Typing conformance results improved 🎉The percentage of diagnostics emitted that were expected errors increased from 77.33% to 77.41%. The percentage of expected errors that received a diagnostic held steady at 69.23%. Summary
False positives removedDetails
|
|
|
(I think this isn't quite right, revisiting.) |
110df46 to
128df87
Compare
unsupported-operator for symmetric TypeVars
6089cf8 to
ebd3b15
Compare
unsupported-operator for symmetric TypeVarsunsupported-operator for "symmetric" TypeVars
4f3384d to
f011749
Compare
|
I think this fix makes sense, but I'm not certain if there's a more "general" fix or whether this should be happening at a deeper level. |
dcreager
left a comment
There was a problem hiding this comment.
I think this fix makes sense, but I'm not certain if there's a more "general" fix or whether this should be happening at a deeper level.
I think you're right that this is a more pointed fix than what we (at least eventually) want.
For one, this only handles binary operators, not arbitrary method calls:
class A:
def method2(self, x: A) -> A: ...
def method3(self, x: A, y: A) -> A: ...
class B:
def method2(self, x: B) -> B: ...
def method3(self, x: B, y: B) -> B: ...
def f[T: (A, B)](a: T, b: T, c: T):
# both of these should be okay
a.method2(b)
a.method3(b, c)And another case we have to consider is an overloaded function:
class A: ...
class B: ...
@overload
def func(x: A, y: A) -> A: ...
@overload
def func(x: B, y: B) -> B: ...
def f[T: (A, B)](a: T, b: T):
# should be okay
func(a, b)But, I think to solve all of these examples in general, we need the new solver. That would let us create a constraint set that constrains both arguments (and the receiver that we did member lookup on!) simultaneously.
So given that, I'm okay with it landing this version as a stop-gap, since it definitely resolves some real false positives.
8e9e9df to
a34725c
Compare
Union the return types Add more tests Also support unary Limit to symmetric typevar Simplfiy tests
a34725c to
0da8299
Compare
* main: (62 commits) [`refurb`] Do not add `abc.ABC` if already present (`FURB180`) (#22234) [ty] Add a new `assert-type-unspellable-subtype` diagnostic (#22815) [ty] Avoid duplicate syntax errors for `await` outside functions (#22826) [ty] Fix unary operator false-positive for constrained TypeVars (#22783) [ty] Fix binary operator false-positive for constrained TypeVars (#22782) [ty] Fix false-positive `unsupported-operator` for "symmetric" TypeVars (#22756) [`pydocstyle`] Clarify which quote styles are allowed (`D300`) (#22825) [ty] Use distributed versions of AND and OR on constraint sets (#22614) [ty] Add support for dict literals and dict() calls as default values for parameters with TypedDict types (#22161) Document `-` stdin convention in CLI help text (#22817) [ty] Make `infer_subscript_expression_types` a method on `Type` (#22731) [ty] Simplify `OverloadLiteral::spans` and `OverloadLiteral::parameter_span` (#22823) [ty] Require both `*args` and `**kwargs` when calling a `ParamSpec` callable (#22820) [ty] Handle tagged errors in conformance (#22746) Add `--color` cli option to force colored output (#22806) Identify notebooks by LSP didOpen instead of `.ipynb` file extension (#22810) [ty] Fix docstring rendering for literal blocks after doctests (#22676) [ty] Update salsa to fix out-of-order query validation (#22498) [ty] Inline cycle initial and recovery functions (#22814) [ty] Pass the generic context through the decorator (#22544) ...
Summary
When a TypeVar has value constraints (e.g.,
TypeVar("Scalar", int, float)), we were reportingunsupported-operatorbecause the constrained TypeVars were being treated like unions -- we checked every possible combination, rather than understanding that both occurrences of the same TypeVar must have the same type.