Skip to content

Commit 03a4d56

Browse files
authored
[ty] Change range of revealed-type diagnostic to be the range of the argument passed in, not the whole call (#17980)
1 parent 642eac4 commit 03a4d56

File tree

25 files changed

+167
-165
lines changed

25 files changed

+167
-165
lines changed

crates/ty/tests/cli.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -197,12 +197,12 @@ fn config_override_python_platform() -> anyhow::Result<()> {
197197
exit_code: 0
198198
----- stdout -----
199199
info: revealed-type: Revealed type
200-
--> test.py:5:1
200+
--> test.py:5:13
201201
|
202202
3 | from typing_extensions import reveal_type
203203
4 |
204204
5 | reveal_type(sys.platform)
205-
| ^^^^^^^^^^^^^^^^^^^^^^^^^ `Literal["linux"]`
205+
| ^^^^^^^^^^^^ `Literal["linux"]`
206206
|
207207
208208
Found 1 diagnostic
@@ -215,12 +215,12 @@ fn config_override_python_platform() -> anyhow::Result<()> {
215215
exit_code: 0
216216
----- stdout -----
217217
info: revealed-type: Revealed type
218-
--> test.py:5:1
218+
--> test.py:5:13
219219
|
220220
3 | from typing_extensions import reveal_type
221221
4 |
222222
5 | reveal_type(sys.platform)
223-
| ^^^^^^^^^^^^^^^^^^^^^^^^^ `LiteralString`
223+
| ^^^^^^^^^^^^ `LiteralString`
224224
|
225225
226226
Found 1 diagnostic
@@ -711,11 +711,11 @@ fn exit_code_only_info() -> anyhow::Result<()> {
711711
exit_code: 0
712712
----- stdout -----
713713
info: revealed-type: Revealed type
714-
--> test.py:3:1
714+
--> test.py:3:13
715715
|
716716
2 | from typing_extensions import reveal_type
717717
3 | reveal_type(1)
718-
| ^^^^^^^^^^^^^^ `Literal[1]`
718+
| ^ `Literal[1]`
719719
|
720720
721721
Found 1 diagnostic
@@ -741,11 +741,11 @@ fn exit_code_only_info_and_error_on_warning_is_true() -> anyhow::Result<()> {
741741
exit_code: 0
742742
----- stdout -----
743743
info: revealed-type: Revealed type
744-
--> test.py:3:1
744+
--> test.py:3:13
745745
|
746746
2 | from typing_extensions import reveal_type
747747
3 | reveal_type(1)
748-
| ^^^^^^^^^^^^^^ `Literal[1]`
748+
| ^ `Literal[1]`
749749
|
750750
751751
Found 1 diagnostic
@@ -1219,7 +1219,7 @@ fn concise_revealed_type() -> anyhow::Result<()> {
12191219
success: true
12201220
exit_code: 0
12211221
----- stdout -----
1222-
info[revealed-type] test.py:5:1: Revealed type: `Literal["hello"]`
1222+
info[revealed-type] test.py:5:13: Revealed type: `Literal["hello"]`
12231223
Found 1 diagnostic
12241224
12251225
----- stderr -----
@@ -1248,12 +1248,12 @@ fn can_handle_large_binop_expressions() -> anyhow::Result<()> {
12481248
exit_code: 0
12491249
----- stdout -----
12501250
info: revealed-type: Revealed type
1251-
--> test.py:4:1
1251+
--> test.py:4:13
12521252
|
12531253
2 | from typing_extensions import reveal_type
12541254
3 | total = 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1...
12551255
4 | reveal_type(total)
1256-
| ^^^^^^^^^^^^^^^^^^ `Literal[2000]`
1256+
| ^^^^^ `Literal[2000]`
12571257
|
12581258
12591259
Found 1 diagnostic

crates/ty_python_semantic/resources/mdtest/expression/len.md

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -11,30 +11,28 @@ reveal_type(len(r"conca\t" "ena\tion")) # revealed: Literal[14]
1111
reveal_type(len(b"ytes lite" rb"al")) # revealed: Literal[11]
1212
reveal_type(len("𝒰𝕹🄸©🕲𝕕ℇ")) # revealed: Literal[7]
1313

14-
reveal_type( # revealed: Literal[7]
15-
len(
14+
# fmt: off
15+
16+
reveal_type(len( # revealed: Literal[7]
1617
"""foo
1718
bar"""
18-
)
19-
)
20-
reveal_type( # revealed: Literal[9]
21-
len(
19+
))
20+
21+
reveal_type(len( # revealed: Literal[9]
2222
r"""foo\r
2323
bar"""
24-
)
25-
)
26-
reveal_type( # revealed: Literal[7]
27-
len(
24+
))
25+
26+
reveal_type(len( # revealed: Literal[7]
2827
b"""foo
2928
bar"""
30-
)
31-
)
32-
reveal_type( # revealed: Literal[9]
33-
len(
29+
))
30+
reveal_type(len( # revealed: Literal[9]
3431
rb"""foo\r
3532
bar"""
36-
)
37-
)
33+
))
34+
35+
# fmt: on
3836
```
3937

4038
### Tuples
@@ -50,15 +48,17 @@ reveal_type(len(tuple())) # revealed: int
5048
# TODO: Handle star unpacks; Should be: Literal[0]
5149
reveal_type(len((*[],))) # revealed: Literal[1]
5250

51+
# fmt: off
52+
5353
# TODO: Handle star unpacks; Should be: Literal[1]
54-
reveal_type( # revealed: Literal[2]
55-
len(
56-
(
57-
*[],
58-
1,
59-
)
54+
reveal_type(len( # revealed: Literal[2]
55+
(
56+
*[],
57+
1,
6058
)
61-
)
59+
))
60+
61+
# fmt: on
6262

6363
# TODO: Handle star unpacks; Should be: Literal[2]
6464
reveal_type(len((*[], 1, 2))) # revealed: Literal[3]

crates/ty_python_semantic/resources/mdtest/snapshots/for.md_-_For_loops_-_Bad_`__getitem__`_method.snap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,12 @@ info: `lint:not-iterable` is enabled by default
4444

4545
```
4646
info: revealed-type: Revealed type
47-
--> src/mdtest_snippet.py:11:5
47+
--> src/mdtest_snippet.py:11:17
4848
|
4949
9 | # error: [not-iterable]
5050
10 | for x in Iterable():
5151
11 | reveal_type(x) # revealed: int
52-
| ^^^^^^^^^^^^^^ `int`
52+
| ^ `int`
5353
|
5454
5555
```

crates/ty_python_semantic/resources/mdtest/snapshots/for.md_-_For_loops_-_No_`__iter__`_method_and_`__getitem__`_is_not_callable.snap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,12 @@ info: `lint:not-iterable` is enabled by default
4040

4141
```
4242
info: revealed-type: Revealed type
43-
--> src/mdtest_snippet.py:8:5
43+
--> src/mdtest_snippet.py:8:17
4444
|
4545
6 | # error: [not-iterable]
4646
7 | for x in Bad():
4747
8 | reveal_type(x) # revealed: Unknown
48-
| ^^^^^^^^^^^^^^ `Unknown`
48+
| ^ `Unknown`
4949
|
5050
5151
```

crates/ty_python_semantic/resources/mdtest/snapshots/for.md_-_For_loops_-_Possibly-not-callable_`__getitem__`_method.snap

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,12 @@ info: `lint:not-iterable` is enabled by default
6363

6464
```
6565
info: revealed-type: Revealed type
66-
--> src/mdtest_snippet.py:24:9
66+
--> src/mdtest_snippet.py:24:21
6767
|
6868
22 | for x in Iterable1():
6969
23 | # TODO... `int` might be ideal here?
7070
24 | reveal_type(x) # revealed: int | Unknown
71-
| ^^^^^^^^^^^^^^ `int | Unknown`
71+
| ^ `int | Unknown`
7272
25 |
7373
26 | # error: [not-iterable]
7474
|
@@ -93,12 +93,12 @@ info: `lint:not-iterable` is enabled by default
9393

9494
```
9595
info: revealed-type: Revealed type
96-
--> src/mdtest_snippet.py:29:9
96+
--> src/mdtest_snippet.py:29:21
9797
|
9898
27 | for y in Iterable2():
9999
28 | # TODO... `int` might be ideal here?
100100
29 | reveal_type(y) # revealed: int | Unknown
101-
| ^^^^^^^^^^^^^^ `int | Unknown`
101+
| ^ `int | Unknown`
102102
|
103103
104104
```

crates/ty_python_semantic/resources/mdtest/snapshots/for.md_-_For_loops_-_Possibly_invalid_`__getitem__`_methods.snap

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,12 @@ info: `lint:not-iterable` is enabled by default
6060

6161
```
6262
info: revealed-type: Revealed type
63-
--> src/mdtest_snippet.py:22:9
63+
--> src/mdtest_snippet.py:22:21
6464
|
6565
20 | for x in Iterable1():
6666
21 | # TODO: `str` might be better
6767
22 | reveal_type(x) # revealed: str | Unknown
68-
| ^^^^^^^^^^^^^^ `str | Unknown`
68+
| ^ `str | Unknown`
6969
23 |
7070
24 | # error: [not-iterable]
7171
|
@@ -89,12 +89,12 @@ info: `lint:not-iterable` is enabled by default
8989

9090
```
9191
info: revealed-type: Revealed type
92-
--> src/mdtest_snippet.py:26:9
92+
--> src/mdtest_snippet.py:26:21
9393
|
9494
24 | # error: [not-iterable]
9595
25 | for y in Iterable2():
9696
26 | reveal_type(y) # revealed: str | int
97-
| ^^^^^^^^^^^^^^ `str | int`
97+
| ^ `str | int`
9898
|
9999
100100
```

crates/ty_python_semantic/resources/mdtest/snapshots/for.md_-_For_loops_-_Possibly_invalid_`__iter__`_methods.snap

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,12 @@ info: `lint:not-iterable` is enabled by default
6464

6565
```
6666
info: revealed-type: Revealed type
67-
--> src/mdtest_snippet.py:18:9
67+
--> src/mdtest_snippet.py:18:21
6868
|
6969
16 | # error: [not-iterable]
7070
17 | for x in Iterable1():
7171
18 | reveal_type(x) # revealed: int
72-
| ^^^^^^^^^^^^^^ `int`
72+
| ^ `int`
7373
19 |
7474
20 | class Iterable2:
7575
|
@@ -93,12 +93,12 @@ info: `lint:not-iterable` is enabled by default
9393

9494
```
9595
info: revealed-type: Revealed type
96-
--> src/mdtest_snippet.py:30:9
96+
--> src/mdtest_snippet.py:30:21
9797
|
9898
28 | for x in Iterable2():
9999
29 | # TODO: `int` would probably be better here:
100100
30 | reveal_type(x) # revealed: int | Unknown
101-
| ^^^^^^^^^^^^^^ `int | Unknown`
101+
| ^ `int | Unknown`
102102
|
103103
104104
```

crates/ty_python_semantic/resources/mdtest/snapshots/for.md_-_For_loops_-_Possibly_invalid_`__next__`_method.snap

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,12 @@ info: `lint:not-iterable` is enabled by default
6767

6868
```
6969
info: revealed-type: Revealed type
70-
--> src/mdtest_snippet.py:29:9
70+
--> src/mdtest_snippet.py:29:21
7171
|
7272
27 | # error: [not-iterable]
7373
28 | for x in Iterable1():
7474
29 | reveal_type(x) # revealed: int | str
75-
| ^^^^^^^^^^^^^^ `int | str`
75+
| ^ `int | str`
7676
30 |
7777
31 | # error: [not-iterable]
7878
|
@@ -96,12 +96,12 @@ info: `lint:not-iterable` is enabled by default
9696

9797
```
9898
info: revealed-type: Revealed type
99-
--> src/mdtest_snippet.py:34:9
99+
--> src/mdtest_snippet.py:34:21
100100
|
101101
32 | for y in Iterable2():
102102
33 | # TODO: `int` would probably be better here:
103103
34 | reveal_type(y) # revealed: int | Unknown
104-
| ^^^^^^^^^^^^^^ `int | Unknown`
104+
| ^ `int | Unknown`
105105
|
106106
107107
```

crates/ty_python_semantic/resources/mdtest/snapshots/for.md_-_For_loops_-_Possibly_unbound_`__iter__`_and_bad_`__getitem__`_method.snap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,12 @@ info: `lint:not-iterable` is enabled by default
5252

5353
```
5454
info: revealed-type: Revealed type
55-
--> src/mdtest_snippet.py:19:9
55+
--> src/mdtest_snippet.py:19:21
5656
|
5757
17 | # error: [not-iterable]
5858
18 | for x in Iterable():
5959
19 | reveal_type(x) # revealed: int | bytes
60-
| ^^^^^^^^^^^^^^ `int | bytes`
60+
| ^ `int | bytes`
6161
|
6262
6363
```

crates/ty_python_semantic/resources/mdtest/snapshots/for.md_-_For_loops_-_Possibly_unbound_`__iter__`_and_possibly_invalid_`__getitem__`.snap

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,12 @@ info: `lint:not-iterable` is enabled by default
7070

7171
```
7272
info: revealed-type: Revealed type
73-
--> src/mdtest_snippet.py:33:9
73+
--> src/mdtest_snippet.py:33:21
7474
|
7575
31 | for x in Iterable1():
7676
32 | # TODO: `bytes | str` might be better
7777
33 | reveal_type(x) # revealed: bytes | str | Unknown
78-
| ^^^^^^^^^^^^^^ `bytes | str | Unknown`
78+
| ^ `bytes | str | Unknown`
7979
34 |
8080
35 | # error: [not-iterable]
8181
|
@@ -99,12 +99,12 @@ info: `lint:not-iterable` is enabled by default
9999

100100
```
101101
info: revealed-type: Revealed type
102-
--> src/mdtest_snippet.py:37:9
102+
--> src/mdtest_snippet.py:37:21
103103
|
104104
35 | # error: [not-iterable]
105105
36 | for y in Iterable2():
106106
37 | reveal_type(y) # revealed: bytes | str | int
107-
| ^^^^^^^^^^^^^^ `bytes | str | int`
107+
| ^ `bytes | str | int`
108108
|
109109
110110
```

crates/ty_python_semantic/resources/mdtest/snapshots/for.md_-_For_loops_-_Possibly_unbound_`__iter__`_and_possibly_unbound_`__getitem__`.snap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,12 @@ info: `lint:not-iterable` is enabled by default
5050

5151
```
5252
info: revealed-type: Revealed type
53-
--> src/mdtest_snippet.py:18:9
53+
--> src/mdtest_snippet.py:18:21
5454
|
5555
16 | # error: [not-iterable]
5656
17 | for x in Iterable():
5757
18 | reveal_type(x) # revealed: int | bytes
58-
| ^^^^^^^^^^^^^^ `int | bytes`
58+
| ^ `int | bytes`
5959
|
6060
6161
```

crates/ty_python_semantic/resources/mdtest/snapshots/for.md_-_For_loops_-_Union_type_as_iterable_where_one_union_element_has_invalid_`__iter__`_method.snap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,12 @@ info: `lint:not-iterable` is enabled by default
5252

5353
```
5454
info: revealed-type: Revealed type
55-
--> src/mdtest_snippet.py:19:9
55+
--> src/mdtest_snippet.py:19:21
5656
|
5757
17 | # error: [not-iterable]
5858
18 | for x in Test() if flag else Test2():
5959
19 | reveal_type(x) # revealed: int
60-
| ^^^^^^^^^^^^^^ `int`
60+
| ^ `int`
6161
|
6262

6363
```

crates/ty_python_semantic/resources/mdtest/snapshots/for.md_-_For_loops_-_Union_type_as_iterable_where_one_union_element_has_no_`__iter__`_method.snap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,12 @@ info: `lint:not-iterable` is enabled by default
4747

4848
```
4949
info: revealed-type: Revealed type
50-
--> src/mdtest_snippet.py:14:9
50+
--> src/mdtest_snippet.py:14:21
5151
|
5252
12 | # error: [not-iterable]
5353
13 | for x in Test() if flag else 42:
5454
14 | reveal_type(x) # revealed: int
55-
| ^^^^^^^^^^^^^^ `int`
55+
| ^ `int`
5656
|
5757

5858
```

0 commit comments

Comments
 (0)