Skip to content

Commit eec874b

Browse files
committed
equivalence like you've never seen
1 parent 4f1d7e1 commit eec874b

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

crates/ty_python_semantic/resources/mdtest/call/overloads.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1073,6 +1073,11 @@ def f(a: Foo, b: list[str], c: list[LiteralString], e):
10731073
# since both overloads match and they have return types that are not equivalent,
10741074
# step (5) of the overload evaluation algorithm says we must evaluate the result of the
10751075
# call as `Unknown`.
1076+
#
1077+
# Note: although the spec does not state as such (since intersections in general are not
1078+
# specified currently), `(str | LiteralString) & Unknown` might also be a reasonable type
1079+
# here (the union of all overload returns, intersected with `Unknown`) -- here that would
1080+
# simplify to `str & Unknown`.
10761081
reveal_type(a.join(e)) # revealed: Unknown
10771082
```
10781083

crates/ty_python_semantic/resources/mdtest/protocols.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1121,13 +1121,31 @@ from typing import TypeVar
11211121

11221122
S = TypeVar("S")
11231123

1124+
class NonGenericProto1(Protocol):
1125+
x: int
1126+
y: str
1127+
1128+
class NonGenericProto2(Protocol):
1129+
y: str
1130+
x: int
1131+
1132+
class Nominal1: ...
1133+
class Nominal2: ...
1134+
11241135
class GenericProto[T](Protocol):
11251136
x: T
11261137

11271138
class LegacyGenericProto(Protocol[S]):
11281139
x: S
11291140

11301141
static_assert(is_equivalent_to(GenericProto[int], LegacyGenericProto[int]))
1142+
static_assert(is_equivalent_to(GenericProto[NonGenericProto1], LegacyGenericProto[NonGenericProto2]))
1143+
1144+
static_assert(
1145+
is_equivalent_to(
1146+
GenericProto[NonGenericProto1 | Nominal1 | Nominal2], LegacyGenericProto[Nominal2 | Nominal1 | NonGenericProto2]
1147+
)
1148+
)
11311149

11321150
static_assert(not is_equivalent_to(GenericProto[str], GenericProto[int]))
11331151
static_assert(not is_equivalent_to(GenericProto[str], LegacyGenericProto[int]))

0 commit comments

Comments
 (0)