@@ -1077,6 +1077,87 @@ x, y = g(z) # E: Argument 1 to "g" has incompatible type "int"; expected "Tuple[
1077
1077
[builtins fixtures/tuple.pyi]
1078
1078
[out]
1079
1079
1080
+ [case testFixedTupleJoinVarTuple]
1081
+ from typing import Tuple
1082
+
1083
+ class A: pass
1084
+ class B(A): pass
1085
+
1086
+ fixtup = None # type: Tuple[B, B]
1087
+
1088
+ vartup_b = None # type: Tuple[B, ...]
1089
+ reveal_type(fixtup if int() else vartup_b) # N: Revealed type is 'builtins.tuple[__main__.B]'
1090
+ reveal_type(vartup_b if int() else fixtup) # N: Revealed type is 'builtins.tuple[__main__.B]'
1091
+
1092
+ vartup_a = None # type: Tuple[A, ...]
1093
+ reveal_type(fixtup if int() else vartup_a) # N: Revealed type is 'builtins.tuple[__main__.A]'
1094
+ reveal_type(vartup_a if int() else fixtup) # N: Revealed type is 'builtins.tuple[__main__.A]'
1095
+
1096
+
1097
+ [builtins fixtures/tuple.pyi]
1098
+ [out]
1099
+
1100
+ [case testFixedTupleJoinList]
1101
+ from typing import Tuple, List
1102
+
1103
+ class A: pass
1104
+ class B(A): pass
1105
+
1106
+ fixtup = None # type: Tuple[B, B]
1107
+
1108
+ lst_b = None # type: List[B]
1109
+ reveal_type(fixtup if int() else lst_b) # N: Revealed type is 'typing.Sequence[__main__.B]'
1110
+ reveal_type(lst_b if int() else fixtup) # N: Revealed type is 'typing.Sequence[__main__.B]'
1111
+
1112
+ lst_a = None # type: List[A]
1113
+ reveal_type(fixtup if int() else lst_a) # N: Revealed type is 'typing.Sequence[__main__.A]'
1114
+ reveal_type(lst_a if int() else fixtup) # N: Revealed type is 'typing.Sequence[__main__.A]'
1115
+
1116
+ [builtins fixtures/tuple.pyi]
1117
+ [out]
1118
+
1119
+ [case testEmptyTupleJoin]
1120
+ from typing import Tuple, List
1121
+
1122
+ class A: pass
1123
+
1124
+ empty = ()
1125
+
1126
+ fixtup = None # type: Tuple[A]
1127
+ reveal_type(fixtup if int() else empty) # N: Revealed type is 'builtins.tuple[__main__.A]'
1128
+ reveal_type(empty if int() else fixtup) # N: Revealed type is 'builtins.tuple[__main__.A]'
1129
+
1130
+ vartup = None # type: Tuple[A, ...]
1131
+ reveal_type(empty if int() else vartup) # N: Revealed type is 'builtins.tuple[__main__.A]'
1132
+ reveal_type(vartup if int() else empty) # N: Revealed type is 'builtins.tuple[__main__.A]'
1133
+
1134
+ lst = None # type: List[A]
1135
+ reveal_type(empty if int() else lst) # N: Revealed type is 'typing.Sequence[__main__.A*]'
1136
+ reveal_type(lst if int() else empty) # N: Revealed type is 'typing.Sequence[__main__.A*]'
1137
+
1138
+ [builtins fixtures/tuple.pyi]
1139
+ [out]
1140
+
1141
+ [case testTupleSubclassJoin]
1142
+ from typing import Tuple, NamedTuple
1143
+
1144
+ class NTup(NamedTuple):
1145
+ a: bool
1146
+ b: bool
1147
+
1148
+ class SubTuple(Tuple[bool]): ...
1149
+ class SubVarTuple(Tuple[int, ...]): ...
1150
+
1151
+ ntup = None # type: NTup
1152
+ subtup = None # type: SubTuple
1153
+ vartup = None # type: SubVarTuple
1154
+
1155
+ reveal_type(ntup if int() else vartup) # N: Revealed type is 'builtins.tuple[builtins.int]'
1156
+ reveal_type(subtup if int() else vartup) # N: Revealed type is 'builtins.tuple[builtins.int]'
1157
+
1158
+ [builtins fixtures/tuple.pyi]
1159
+ [out]
1160
+
1080
1161
[case testTupleWithUndersizedContext]
1081
1162
a = ([1], 'x')
1082
1163
if int():
0 commit comments