Skip to content

Commit 4902af8

Browse files
committed
Revert "Use meets in pre_validate_solutions?"
This reverts commit 2e83a0c.
1 parent cab649d commit 4902af8

File tree

5 files changed

+12
-32
lines changed

5 files changed

+12
-32
lines changed

mypy/solve.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -576,13 +576,16 @@ def pre_validate_solutions(
576576
new_solutions.append(s)
577577
continue
578578
if s is not None and not is_subtype(s, t.upper_bound):
579-
bound = t.upper_bound
579+
bound_satisfies_all = True
580580
for c in constraints:
581-
bound = meet_types(bound, c.target)
582-
if isinstance(bound, UninhabitedType):
581+
if c.op == SUBTYPE_OF and not is_subtype(t.upper_bound, c.target):
582+
bound_satisfies_all = False
583583
break
584-
else:
585-
new_solutions.append(bound)
584+
if c.op == SUPERTYPE_OF and not is_subtype(c.target, t.upper_bound):
585+
bound_satisfies_all = False
586+
break
587+
if bound_satisfies_all:
588+
new_solutions.append(t.upper_bound)
586589
continue
587590
new_solutions.append(s)
588591
return new_solutions

test-data/unit/check-dataclasses.test

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2122,7 +2122,7 @@ TA = TypeVar('TA', bound=A)
21222122
TB = TypeVar('TB', bound=B)
21232123

21242124
def f(b_or_t: Union[TA, TB, int]) -> None:
2125-
a2 = replace(b_or_t) # E: Argument 1 to "replace" has incompatible type "Union[TA, TB, int]"; expected "TA"
2125+
a2 = replace(b_or_t) # E: Value of type variable "_DataclassT" of "replace" cannot be "Union[TA, TB, int]"
21262126

21272127
[builtins fixtures/tuple.pyi]
21282128

@@ -2202,9 +2202,9 @@ replace(None) # E: Value of type variable "_DataclassT" of "replace" cannot be
22022202
from dataclasses import is_dataclass, replace
22032203

22042204
def f(x: object) -> None:
2205-
_ = replace(x) # E: Argument 1 to "replace" has incompatible type "object"; expected "DataclassInstance"
2205+
_ = replace(x) # E: Value of type variable "_DataclassT" of "replace" cannot be "object"
22062206
if is_dataclass(x):
2207-
_ = replace(x) # E: Argument 1 to "replace" has incompatible type "Union[DataclassInstance, type[DataclassInstance]]"; expected "DataclassInstance"
2207+
_ = replace(x) # E: Value of type variable "_DataclassT" of "replace" cannot be "Union[DataclassInstance, type[DataclassInstance]]"
22082208
if not isinstance(x, type):
22092209
_ = replace(x)
22102210

test-data/unit/check-literal.test

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1662,21 +1662,6 @@ reveal_type(func2(b)) # N: Revealed type is "Literal[4]"
16621662
reveal_type(func2(c)) # N: Revealed type is "builtins.int"
16631663
[builtins fixtures/tuple.pyi]
16641664
[out]
1665-
main:13: error: Value of type variable "TLiteral" of "func1" cannot be "TInt"
1666-
main:20: note: Revealed type is "def [TLiteral <: Literal[3]] (x: TLiteral`-1) -> TLiteral`-1"
1667-
main:22: note: Revealed type is "Literal[3]"
1668-
main:23: note: Revealed type is "Literal[3]"
1669-
main:24: error: Value of type variable "TLiteral" of "func1" cannot be "Literal[4]"
1670-
main:24: note: Revealed type is "Literal[4]"
1671-
main:25: error: Value of type variable "TLiteral" of "func1" cannot be "Literal[4]"
1672-
main:25: note: Revealed type is "Literal[4]"
1673-
main:26: note: Revealed type is "Literal[3]"
1674-
main:26: error: Argument 1 to "func1" has incompatible type "int"; expected "Literal[3]"
1675-
main:28: note: Revealed type is "builtins.int"
1676-
main:29: note: Revealed type is "Literal[3]"
1677-
main:30: note: Revealed type is "builtins.int"
1678-
main:31: note: Revealed type is "Literal[4]"
1679-
main:32: note: Revealed type is "builtins.int"
16801665

16811666
[case testLiteralAndGenericsRespectsValueRestriction]
16821667
from typing import Literal, TypeVar

test-data/unit/check-namedtuple.test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1362,7 +1362,7 @@ class NT(NamedTuple, Generic[T]):
13621362
return self._replace()
13631363

13641364
class SNT(NT[int]): ...
1365-
reveal_type(SNT("test", 42).meth()) # N: Revealed type is "tuple[builtins.str, Never, fallback=__main__.SNT]"
1365+
reveal_type(SNT("test", 42).meth()) # N: Revealed type is "tuple[builtins.str, builtins.int, fallback=__main__.SNT]"
13661366
[builtins fixtures/tuple.pyi]
13671367
[typing fixtures/typing-namedtuple.pyi]
13681368

test-data/unit/check-overloading.test

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1335,14 +1335,6 @@ def g(x: U, y: V) -> None:
13351335
f([x, y]) # E: Value of type variable "T" of "f" cannot be "object"
13361336
[builtins fixtures/list.pyi]
13371337
[out]
1338-
tmp/foo.pyi:12: error: "mystr" not callable
1339-
tmp/foo.pyi:13: error: No overload variant of "f" matches argument type "V"
1340-
tmp/foo.pyi:13: note: Possible overload variants:
1341-
tmp/foo.pyi:13: note: def [T: str] f(x: T) -> T
1342-
tmp/foo.pyi:13: note: def [T: str] f(x: list[T]) -> None
1343-
tmp/foo.pyi:15: note: Revealed type is "None"
1344-
tmp/foo.pyi:16: error: Value of type variable "T" of "f" cannot be "V"
1345-
tmp/foo.pyi:17: error: List item 1 has incompatible type "V"; expected "str"
13461338

13471339
[case testOverloadOverlapWithTypeVars]
13481340
from foo import *

0 commit comments

Comments
 (0)