red_knot_python_semantic: migrate types/infer to new diagnostic model

I gave up trying to do this one lint at a time and just (mostly)
mechanically translated this entire file in one go.

Generally the messages stay the same (with most moving from an
annotation message to the diagnostic's main message). I added a couple
of `info` sub-diagnostics where it seemed to be the obvious intent.
This commit is contained in:
Andrew Gallant 2025-04-16 11:28:18 -04:00 committed by Andrew Gallant
parent b8b624d890
commit 27a377f077
13 changed files with 485 additions and 461 deletions

View file

@ -32,12 +32,12 @@ fn config_override_python_version() -> anyhow::Result<()> {
success: false
exit_code: 1
----- stdout -----
error: lint:unresolved-attribute
error: lint:unresolved-attribute: Type `<module 'sys'>` has no attribute `last_exc`
--> <temp_dir>/test.py:5:7
|
4 | # Access `sys.last_exc` that was only added in Python 3.12
5 | print(sys.last_exc)
| ^^^^^^^^^^^^ Type `<module 'sys'>` has no attribute `last_exc`
| ^^^^^^^^^^^^
|
Found 1 diagnostic
@ -165,11 +165,11 @@ fn cli_arguments_are_relative_to_the_current_directory() -> anyhow::Result<()> {
success: false
exit_code: 1
----- stdout -----
error: lint:unresolved-import
error: lint:unresolved-import: Cannot resolve import `utils`
--> <temp_dir>/child/test.py:2:6
|
2 | from utils import add
| ^^^^^ Cannot resolve import `utils`
| ^^^^^
3 |
4 | stat = add(10, 15)
|
@ -265,11 +265,11 @@ fn configuration_rule_severity() -> anyhow::Result<()> {
success: false
exit_code: 1
----- stdout -----
error: lint:division-by-zero
error: lint:division-by-zero: Cannot divide object of type `Literal[4]` by zero
--> <temp_dir>/test.py:2:5
|
2 | y = 4 / 0
| ^^^^^ Cannot divide object of type `Literal[4]` by zero
| ^^^^^
3 |
4 | for a in range(0, int(y)):
|
@ -301,11 +301,11 @@ fn configuration_rule_severity() -> anyhow::Result<()> {
success: true
exit_code: 0
----- stdout -----
warning: lint:division-by-zero
warning: lint:division-by-zero: Cannot divide object of type `Literal[4]` by zero
--> <temp_dir>/test.py:2:5
|
2 | y = 4 / 0
| ^^^^^ Cannot divide object of type `Literal[4]` by zero
| ^^^^^
3 |
4 | for a in range(0, int(y)):
|
@ -341,22 +341,22 @@ fn cli_rule_severity() -> anyhow::Result<()> {
success: false
exit_code: 1
----- stdout -----
error: lint:unresolved-import
error: lint:unresolved-import: Cannot resolve import `does_not_exit`
--> <temp_dir>/test.py:2:8
|
2 | import does_not_exit
| ^^^^^^^^^^^^^ Cannot resolve import `does_not_exit`
| ^^^^^^^^^^^^^
3 |
4 | y = 4 / 0
|
error: lint:division-by-zero
error: lint:division-by-zero: Cannot divide object of type `Literal[4]` by zero
--> <temp_dir>/test.py:4:5
|
2 | import does_not_exit
3 |
4 | y = 4 / 0
| ^^^^^ Cannot divide object of type `Literal[4]` by zero
| ^^^^^
5 |
6 | for a in range(0, int(y)):
|
@ -388,22 +388,22 @@ fn cli_rule_severity() -> anyhow::Result<()> {
success: true
exit_code: 0
----- stdout -----
warning: lint:unresolved-import
warning: lint:unresolved-import: Cannot resolve import `does_not_exit`
--> <temp_dir>/test.py:2:8
|
2 | import does_not_exit
| ^^^^^^^^^^^^^ Cannot resolve import `does_not_exit`
| ^^^^^^^^^^^^^
3 |
4 | y = 4 / 0
|
warning: lint:division-by-zero
warning: lint:division-by-zero: Cannot divide object of type `Literal[4]` by zero
--> <temp_dir>/test.py:4:5
|
2 | import does_not_exit
3 |
4 | y = 4 / 0
| ^^^^^ Cannot divide object of type `Literal[4]` by zero
| ^^^^^
5 |
6 | for a in range(0, int(y)):
|
@ -439,11 +439,11 @@ fn cli_rule_severity_precedence() -> anyhow::Result<()> {
success: false
exit_code: 1
----- stdout -----
error: lint:division-by-zero
error: lint:division-by-zero: Cannot divide object of type `Literal[4]` by zero
--> <temp_dir>/test.py:2:5
|
2 | y = 4 / 0
| ^^^^^ Cannot divide object of type `Literal[4]` by zero
| ^^^^^
3 |
4 | for a in range(0, int(y)):
|
@ -476,11 +476,11 @@ fn cli_rule_severity_precedence() -> anyhow::Result<()> {
success: true
exit_code: 0
----- stdout -----
warning: lint:division-by-zero
warning: lint:division-by-zero: Cannot divide object of type `Literal[4]` by zero
--> <temp_dir>/test.py:2:5
|
2 | y = 4 / 0
| ^^^^^ Cannot divide object of type `Literal[4]` by zero
| ^^^^^
3 |
4 | for a in range(0, int(y)):
|
@ -835,11 +835,11 @@ fn user_configuration() -> anyhow::Result<()> {
success: true
exit_code: 0
----- stdout -----
warning: lint:division-by-zero
warning: lint:division-by-zero: Cannot divide object of type `Literal[4]` by zero
--> <temp_dir>/project/main.py:2:5
|
2 | y = 4 / 0
| ^^^^^ Cannot divide object of type `Literal[4]` by zero
| ^^^^^
3 |
4 | for a in range(0, int(y)):
|
@ -877,11 +877,11 @@ fn user_configuration() -> anyhow::Result<()> {
success: false
exit_code: 1
----- stdout -----
warning: lint:division-by-zero
warning: lint:division-by-zero: Cannot divide object of type `Literal[4]` by zero
--> <temp_dir>/project/main.py:2:5
|
2 | y = 4 / 0
| ^^^^^ Cannot divide object of type `Literal[4]` by zero
| ^^^^^
3 |
4 | for a in range(0, int(y)):
|
@ -935,25 +935,25 @@ fn check_specific_paths() -> anyhow::Result<()> {
success: false
exit_code: 1
----- stdout -----
error: lint:unresolved-import
error: lint:unresolved-import: Cannot resolve import `does_not_exist`
--> <temp_dir>/project/tests/test_main.py:2:8
|
2 | import does_not_exist # error: unresolved-import
| ^^^^^^^^^^^^^^ Cannot resolve import `does_not_exist`
| ^^^^^^^^^^^^^^
|
error: lint:division-by-zero
error: lint:division-by-zero: Cannot divide object of type `Literal[4]` by zero
--> <temp_dir>/project/main.py:2:5
|
2 | y = 4 / 0 # error: division-by-zero
| ^^^^^ Cannot divide object of type `Literal[4]` by zero
| ^^^^^
|
error: lint:unresolved-import
error: lint:unresolved-import: Cannot resolve import `main2`
--> <temp_dir>/project/other.py:2:6
|
2 | from main2 import z # error: unresolved-import
| ^^^^^ Cannot resolve import `main2`
| ^^^^^
3 |
4 | print(z)
|
@ -972,18 +972,18 @@ fn check_specific_paths() -> anyhow::Result<()> {
success: false
exit_code: 1
----- stdout -----
error: lint:unresolved-import
error: lint:unresolved-import: Cannot resolve import `does_not_exist`
--> <temp_dir>/project/tests/test_main.py:2:8
|
2 | import does_not_exist # error: unresolved-import
| ^^^^^^^^^^^^^^ Cannot resolve import `does_not_exist`
| ^^^^^^^^^^^^^^
|
error: lint:unresolved-import
error: lint:unresolved-import: Cannot resolve import `main2`
--> <temp_dir>/project/other.py:2:6
|
2 | from main2 import z # error: unresolved-import
| ^^^^^ Cannot resolve import `main2`
| ^^^^^
3 |
4 | print(z)
|

View file

@ -40,13 +40,13 @@ error: lint:invalid-assignment: Object of type `Literal["wrong"]` is not assigna
```
```
error: lint:invalid-attribute-access
error: lint:invalid-attribute-access: Cannot assign to instance attribute `attr` from the class object `Literal[C]`
--> /src/mdtest_snippet.py:9:1
|
7 | instance.attr = "wrong" # error: [invalid-assignment]
8 |
9 | C.attr = 1 # error: [invalid-attribute-access]
| ^^^^^^ Cannot assign to instance attribute `attr` from the class object `Literal[C]`
| ^^^^^^
|
```

View file

@ -23,13 +23,13 @@ mdtest path: crates/red_knot_python_semantic/resources/mdtest/diagnostics/attrib
# Diagnostics
```
error: lint:unresolved-attribute
error: lint:unresolved-attribute: Unresolved attribute `non_existent` on type `Literal[C]`.
--> /src/mdtest_snippet.py:3:1
|
1 | class C: ...
2 |
3 | C.non_existent = 1 # error: [unresolved-attribute]
| ^^^^^^^^^^^^^^ Unresolved attribute `non_existent` on type `Literal[C]`.
| ^^^^^^^^^^^^^^
4 |
5 | instance = C()
|
@ -37,12 +37,12 @@ error: lint:unresolved-attribute
```
```
error: lint:unresolved-attribute
error: lint:unresolved-attribute: Unresolved attribute `non_existent` on type `C`.
--> /src/mdtest_snippet.py:6:1
|
5 | instance = C()
6 | instance.non_existent = 1 # error: [unresolved-attribute]
| ^^^^^^^^^^^^^^^^^^^^^ Unresolved attribute `non_existent` on type `C`.
| ^^^^^^^^^^^^^^^^^^^^^
|
```

View file

@ -40,12 +40,12 @@ error: lint:invalid-assignment: Object of type `Literal["wrong"]` is not assigna
```
```
error: lint:invalid-attribute-access
error: lint:invalid-attribute-access: Cannot assign to ClassVar `attr` from an instance of type `C`
--> /src/mdtest_snippet.py:10:1
|
9 | instance = C()
10 | instance.attr = 1 # error: [invalid-attribute-access]
| ^^^^^^^^^^^^^ Cannot assign to ClassVar `attr` from an instance of type `C`
| ^^^^^^^^^^^^^
|
```

View file

@ -18,11 +18,11 @@ mdtest path: crates/red_knot_python_semantic/resources/mdtest/import/basic.md
# Diagnostics
```
error: lint:unresolved-import
error: lint:unresolved-import: Cannot resolve import `zqzqzqzqzqzqzq`
--> /src/mdtest_snippet.py:1:8
|
1 | import zqzqzqzqzqzqzq # error: [unresolved-import] "Cannot resolve import `zqzqzqzqzqzqzq`"
| ^^^^^^^^^^^^^^ Cannot resolve import `zqzqzqzqzqzqzq`
| ^^^^^^^^^^^^^^
|
```

View file

@ -27,12 +27,12 @@ mdtest path: crates/red_knot_python_semantic/resources/mdtest/import/basic.md
# Diagnostics
```
error: lint:unresolved-import
error: lint:unresolved-import: Cannot resolve import `a.foo`
--> /src/mdtest_snippet.py:2:8
|
1 | # Topmost component resolvable, submodule not resolvable:
2 | import a.foo # error: [unresolved-import] "Cannot resolve import `a.foo`"
| ^^^^^ Cannot resolve import `a.foo`
| ^^^^^
3 |
4 | # Topmost component unresolvable:
|
@ -40,12 +40,12 @@ error: lint:unresolved-import
```
```
error: lint:unresolved-import
error: lint:unresolved-import: Cannot resolve import `b.foo`
--> /src/mdtest_snippet.py:5:8
|
4 | # Topmost component unresolvable:
5 | import b.foo # error: [unresolved-import] "Cannot resolve import `b.foo`"
| ^^^^^ Cannot resolve import `b.foo`
| ^^^^^
|
```

View file

@ -20,11 +20,11 @@ mdtest path: crates/red_knot_python_semantic/resources/mdtest/diagnostics/unreso
# Diagnostics
```
error: lint:unresolved-import
error: lint:unresolved-import: Cannot resolve import `does_not_exist`
--> /src/mdtest_snippet.py:1:8
|
1 | import does_not_exist # error: [unresolved-import]
| ^^^^^^^^^^^^^^ Cannot resolve import `does_not_exist`
| ^^^^^^^^^^^^^^
2 |
3 | x = does_not_exist.foo
|

View file

@ -25,11 +25,11 @@ mdtest path: crates/red_knot_python_semantic/resources/mdtest/diagnostics/unreso
# Diagnostics
```
error: lint:unresolved-import
error: lint:unresolved-import: Module `a` has no member `does_not_exist`
--> /src/mdtest_snippet.py:1:28
|
1 | from a import does_exist1, does_not_exist, does_exist2 # error: [unresolved-import]
| ^^^^^^^^^^^^^^ Module `a` has no member `does_not_exist`
| ^^^^^^^^^^^^^^
|
```

View file

@ -20,11 +20,11 @@ mdtest path: crates/red_knot_python_semantic/resources/mdtest/diagnostics/unreso
# Diagnostics
```
error: lint:unresolved-import
error: lint:unresolved-import: Cannot resolve import `.does_not_exist`
--> /src/mdtest_snippet.py:1:7
|
1 | from .does_not_exist import add # error: [unresolved-import]
| ^^^^^^^^^^^^^^ Cannot resolve import `.does_not_exist`
| ^^^^^^^^^^^^^^
2 |
3 | stat = add(10, 15)
|

View file

@ -20,11 +20,11 @@ mdtest path: crates/red_knot_python_semantic/resources/mdtest/diagnostics/unreso
# Diagnostics
```
error: lint:unresolved-import
error: lint:unresolved-import: Cannot resolve import `.does_not_exist.foo.bar`
--> /src/mdtest_snippet.py:1:7
|
1 | from .does_not_exist.foo.bar import add # error: [unresolved-import]
| ^^^^^^^^^^^^^^^^^^^^^^ Cannot resolve import `.does_not_exist.foo.bar`
| ^^^^^^^^^^^^^^^^^^^^^^
2 |
3 | stat = add(10, 15)
|

View file

@ -20,11 +20,11 @@ mdtest path: crates/red_knot_python_semantic/resources/mdtest/diagnostics/unreso
# Diagnostics
```
error: lint:unresolved-import
error: lint:unresolved-import: Cannot resolve import `does_not_exist`
--> /src/mdtest_snippet.py:1:6
|
1 | from does_not_exist import add # error: [unresolved-import]
| ^^^^^^^^^^^^^^ Cannot resolve import `does_not_exist`
| ^^^^^^^^^^^^^^
2 |
3 | stat = add(10, 15)
|

View file

@ -32,11 +32,11 @@ mdtest path: crates/red_knot_python_semantic/resources/mdtest/diagnostics/unreso
# Diagnostics
```
error: lint:unresolved-import
error: lint:unresolved-import: Cannot resolve import `....foo`
--> /src/package/subpackage/subsubpackage/__init__.py:1:10
|
1 | from ....foo import add # error: [unresolved-import]
| ^^^ Cannot resolve import `....foo`
| ^^^
2 |
3 | stat = add(10, 15)
|

File diff suppressed because it is too large Load diff