Skip to content

Commit d2fbf2a

Browse files
authored
[ty] Remove Type::Tuple (#19669)
1 parent 2abd683 commit d2fbf2a

File tree

27 files changed

+1196
-1232
lines changed

27 files changed

+1196
-1232
lines changed

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

Lines changed: 22 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -183,33 +183,27 @@ def takes_at_least_two_positional_only(x: int, y: int, /, *args) -> None: ...
183183
class SingleElementTuple(tuple[int]): ...
184184

185185
def _(args: SingleElementTuple) -> None:
186-
# TODO: we should emit `[too-many-positional-arguments]` here
187-
takes_zero(*args)
186+
takes_zero(*args) # error: [too-many-positional-arguments]
188187

189188
takes_one(*args)
190189

191-
# TODO: we should emit `[missing-argument]` on both of these
192-
takes_two(*args)
193-
takes_two_positional_only(*args)
190+
takes_two(*args) # error: [missing-argument]
191+
takes_two_positional_only(*args) # error: [missing-argument]
194192

195-
# TODO: these should both be `[missing-argument]`, not `[invalid-argument-type]`
196-
takes_two_different(*args) # error: [invalid-argument-type]
197-
takes_two_different_positional_only(*args) # error: [invalid-argument-type]
193+
takes_two_different(*args) # error: [missing-argument]
194+
takes_two_different_positional_only(*args) # error: [missing-argument]
198195

199196
takes_at_least_zero(*args)
200197
takes_at_least_one(*args)
201198

202-
# TODO: we should emit `[missing-argument]` on both of these
203-
takes_at_least_two(*args)
204-
takes_at_least_two_positional_only(*args)
199+
takes_at_least_two(*args) # error: [missing-argument]
200+
takes_at_least_two_positional_only(*args) # error: [missing-argument]
205201

206202
class TwoElementIntTuple(tuple[int, int]): ...
207203

208204
def _(args: TwoElementIntTuple) -> None:
209-
# TODO: we should emit `[too-many-positional-arguments]` on both of these
210-
takes_zero(*args)
211-
takes_one(*args)
212-
205+
takes_zero(*args) # error: [too-many-positional-arguments]
206+
takes_one(*args) # error: [too-many-positional-arguments]
213207
takes_two(*args)
214208
takes_two_positional_only(*args)
215209
takes_two_different(*args) # error: [invalid-argument-type]
@@ -222,40 +216,23 @@ def _(args: TwoElementIntTuple) -> None:
222216
class IntStrTuple(tuple[int, str]): ...
223217

224218
def _(args: IntStrTuple) -> None:
225-
# TODO: we should emit `[too-many-positional-arguments]` here
226-
takes_zero(*args)
219+
takes_zero(*args) # error: [too-many-positional-arguments]
227220

228-
# TODO: this should be `[too-many-positional-arguments]`, not `[invalid-argument-type]`
229-
takes_one(*args) # error: [invalid-argument-type]
221+
takes_one(*args) # error: [too-many-positional-arguments]
230222

231-
# TODO: we should have one diagnostic for each of these, not two
232-
# error: [invalid-argument-type]
233223
# error: [invalid-argument-type]
234224
takes_two(*args)
235225
# error: [invalid-argument-type]
236-
# error: [invalid-argument-type]
237226
takes_two_positional_only(*args)
238227

239-
# TODO: these are all false positives
240-
# error: [invalid-argument-type]
241-
# error: [invalid-argument-type]
242228
takes_two_different(*args)
243-
# error: [invalid-argument-type]
244-
# error: [invalid-argument-type]
245229
takes_two_different_positional_only(*args)
246-
247230
takes_at_least_zero(*args)
248-
249-
# TODO: false positive
250-
# error: [invalid-argument-type]
251231
takes_at_least_one(*args)
252232

253-
# TODO: we should only emit one diagnostic for each of these, not two
254-
# error: [invalid-argument-type]
255233
# error: [invalid-argument-type]
256234
takes_at_least_two(*args)
257235
# error: [invalid-argument-type]
258-
# error: [invalid-argument-type]
259236
takes_at_least_two_positional_only(*args)
260237
```
261238

@@ -377,9 +354,7 @@ def takes_at_least_two_positional_only(x: int, y: int, /, *args) -> None: ...
377354
class IntStarInt(tuple[int, *tuple[int, ...]]): ...
378355

379356
def _(args: IntStarInt) -> None:
380-
# TODO: we should emit `[too-many-positional-arguments]` here
381-
takes_zero(*args)
382-
357+
takes_zero(*args) # error: [too-many-positional-arguments]
383358
takes_one(*args)
384359
takes_two(*args)
385360
takes_two_positional_only(*args)
@@ -393,50 +368,32 @@ def _(args: IntStarInt) -> None:
393368
class IntStarStr(tuple[int, *tuple[str, ...]]): ...
394369

395370
def _(args: IntStarStr) -> None:
396-
# TODO: we should emit `[too-many-positional-arguments]` here
397-
takes_zero(*args)
371+
takes_zero(*args) # error: [too-many-positional-arguments]
398372

399-
# TODO: false positive
400-
# error: [invalid-argument-type]
401373
takes_one(*args)
402374

403-
# TODO: we should only emit one diagnostic for each of these, not two
404-
# error: [invalid-argument-type]
405375
# error: [invalid-argument-type]
406376
takes_two(*args)
407377
# error: [invalid-argument-type]
408-
# error: [invalid-argument-type]
409378
takes_two_positional_only(*args)
410379

411-
# TODO: false positives
412-
# error: [invalid-argument-type]
413-
# error: [invalid-argument-type]
414380
takes_two_different(*args)
415-
# error: [invalid-argument-type]
416-
# error: [invalid-argument-type]
417381
takes_two_different_positional_only(*args)
418382

419383
takes_at_least_zero(*args)
420384

421-
# TODO: false positive
422-
# error: [invalid-argument-type]
423385
takes_at_least_one(*args)
424386

425-
# TODO: we should only have one diagnostic for each of these, not two
426-
# error: [invalid-argument-type]
427387
# error: [invalid-argument-type]
428388
takes_at_least_two(*args)
429389
# error: [invalid-argument-type]
430-
# error: [invalid-argument-type]
431390
takes_at_least_two_positional_only(*args)
432391

433392
class IntIntStarInt(tuple[int, int, *tuple[int, ...]]): ...
434393

435394
def _(args: IntIntStarInt) -> None:
436-
# TODO: we should emit `[too-many-positional-arguments]` on both of these
437-
takes_zero(*args)
438-
takes_one(*args)
439-
395+
takes_zero(*args) # error: [too-many-positional-arguments]
396+
takes_one(*args) # error: [too-many-positional-arguments]
440397
takes_two(*args)
441398
takes_two_positional_only(*args)
442399
takes_two_different(*args) # error: [invalid-argument-type]
@@ -449,51 +406,31 @@ def _(args: IntIntStarInt) -> None:
449406
class IntIntStarStr(tuple[int, int, *tuple[str, ...]]): ...
450407

451408
def _(args: IntIntStarStr) -> None:
452-
# TODO: we should emit `[too-many-positional-arguments]` here
453-
takes_zero(*args)
409+
takes_zero(*args) # error: [too-many-positional-arguments]
454410

455-
# TODO: this should be `[too-many-positional-arguments]`, not `invalid-argument-type`
456-
takes_one(*args) # error: [invalid-argument-type]
411+
takes_one(*args) # error: [too-many-positional-arguments]
457412

458-
# TODO: these are all false positives
459-
# error: [invalid-argument-type]
460-
# error: [invalid-argument-type]
461413
takes_two(*args)
462-
# error: [invalid-argument-type]
463-
# error: [invalid-argument-type]
464414
takes_two_positional_only(*args)
465415

466-
# TODO: each of these should only have one diagnostic, not two
467-
# error: [invalid-argument-type]
468416
# error: [invalid-argument-type]
469417
takes_two_different(*args)
470418
# error: [invalid-argument-type]
471-
# error: [invalid-argument-type]
472419
takes_two_different_positional_only(*args)
473420

474421
takes_at_least_zero(*args)
475422

476-
# TODO: false positive
477-
# error: [invalid-argument-type]
478423
takes_at_least_one(*args)
479424

480-
# TODO: these are both false positives
481-
# error: [invalid-argument-type]
482-
# error: [invalid-argument-type]
483425
takes_at_least_two(*args)
484426

485-
# TODO: these are both false positives
486-
# error: [invalid-argument-type]
487-
# error: [invalid-argument-type]
488427
takes_at_least_two_positional_only(*args)
489428

490429
class IntStarIntInt(tuple[int, *tuple[int, ...], int]): ...
491430

492431
def _(args: IntStarIntInt) -> None:
493-
# TODO: we should emit `[too-many-positional-arguments]` on both of these
494-
takes_zero(*args)
495-
takes_one(*args)
496-
432+
takes_zero(*args) # error: [too-many-positional-arguments]
433+
takes_one(*args) # error: [too-many-positional-arguments]
497434
takes_two(*args)
498435
takes_two_positional_only(*args)
499436
takes_two_different(*args) # error: [invalid-argument-type]
@@ -506,40 +443,25 @@ def _(args: IntStarIntInt) -> None:
506443
class IntStarStrInt(tuple[int, *tuple[str, ...], int]): ...
507444

508445
def _(args: IntStarStrInt) -> None:
509-
# TODO: we should emit `too-many-positional-arguments` here
510-
takes_zero(*args)
446+
takes_zero(*args) # error: [too-many-positional-arguments]
511447

512-
# TODO: this should be `too-many-positional-arguments`, not `invalid-argument-type`
513-
takes_one(*args) # error: [invalid-argument-type]
448+
takes_one(*args) # error: [too-many-positional-arguments]
514449

515-
# TODO: we should only emit one diagnostic for each of these
516-
# error: [invalid-argument-type]
517450
# error: [invalid-argument-type]
518451
takes_two(*args)
519452
# error: [invalid-argument-type]
520-
# error: [invalid-argument-type]
521453
takes_two_positional_only(*args)
522454

523-
# TODO: we should not emit diagnostics for these
524-
# error: [invalid-argument-type]
525-
# error: [invalid-argument-type]
526455
takes_two_different(*args)
527-
# error: [invalid-argument-type]
528-
# error: [invalid-argument-type]
529456
takes_two_different_positional_only(*args)
530457

531458
takes_at_least_zero(*args)
532459

533-
# TODO: false positive
534-
takes_at_least_one(*args) # error: [invalid-argument-type]
460+
takes_at_least_one(*args)
535461

536-
# TODO: should only have one diagnostic here
537-
# error: [invalid-argument-type]
538462
# error: [invalid-argument-type]
539463
takes_at_least_two(*args)
540464

541-
# TODO: should only have one diagnostic here
542-
# error: [invalid-argument-type]
543465
# error: [invalid-argument-type]
544466
takes_at_least_two_positional_only(*args)
545467
```

crates/ty_python_semantic/resources/mdtest/generics/legacy/classes.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -411,10 +411,9 @@ def test_seq(x: Sequence[T]) -> Sequence[T]:
411411
return x
412412

413413
def func8(t1: tuple[complex, list[int]], t2: tuple[int, *tuple[str, ...]], t3: tuple[()]):
414-
# TODO: should be `Sequence[int | float | complex | list[int]]`
415-
reveal_type(test_seq(t1)) # revealed: Sequence[Unknown]
416-
# TODO: should be `Sequence[int | str]`
417-
reveal_type(test_seq(t2)) # revealed: Sequence[Unknown]
414+
reveal_type(test_seq(t1)) # revealed: Sequence[int | float | complex | list[int]]
415+
reveal_type(test_seq(t2)) # revealed: Sequence[int | str]
416+
418417
# TODO: this should be `Sequence[Never]`
419418
reveal_type(test_seq(t3)) # revealed: Sequence[Unknown]
420419
```

crates/ty_python_semantic/resources/mdtest/generics/pep695/classes.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -367,10 +367,9 @@ def test_seq[T](x: Sequence[T]) -> Sequence[T]:
367367
return x
368368

369369
def func8(t1: tuple[complex, list[int]], t2: tuple[int, *tuple[str, ...]], t3: tuple[()]):
370-
# TODO: should be `Sequence[int | float | complex | list[int]]`
371-
reveal_type(test_seq(t1)) # revealed: Sequence[Unknown]
372-
# TODO: should be `Sequence[int | str]`
373-
reveal_type(test_seq(t2)) # revealed: Sequence[Unknown]
370+
reveal_type(test_seq(t1)) # revealed: Sequence[int | float | complex | list[int]]
371+
reveal_type(test_seq(t2)) # revealed: Sequence[int | str]
372+
374373
# TODO: this should be `Sequence[Never]`
375374
reveal_type(test_seq(t3)) # revealed: Sequence[Unknown]
376375
```

crates/ty_python_semantic/resources/mdtest/mdtest_custom_typeshed.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ We can then place custom stub files in `/typeshed/stdlib`, for example:
2323

2424
```pyi
2525
class object: ...
26+
class tuple: ...
2627
class BuiltinClass: ...
2728

2829
builtin_symbol: BuiltinClass
@@ -97,12 +98,18 @@ simple untyped definition is enough to make `reveal_type` work in tests:
9798
typeshed = "/typeshed"
9899
```
99100

101+
`/typeshed/stdlib/builtins.pyi`:
102+
103+
```pyi
104+
class tuple: ...
105+
```
106+
100107
`/typeshed/stdlib/typing_extensions.pyi`:
101108

102109
```pyi
103110
def reveal_type(obj, /): ...
104111
```
105112

106113
```py
107-
reveal_type(()) # revealed: tuple[()]
114+
reveal_type(()) # revealed: tuple
108115
```

crates/ty_python_semantic/resources/mdtest/scopes/moduletype_attrs.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@ typeshed = "/typeshed"
193193

194194
```pyi
195195
class object: ...
196+
class tuple: ...
196197
class int: ...
197198
class bytes: ...
198199

0 commit comments

Comments
 (0)