David Peter
aac79e453a
[red-knot] Better diagnostics for method calls (#16362)
## Summary
Add better error messages and additional spans for method calls. Can be
reviewed commit-by-commit.
before:
```
error: lint:invalid-argument-type
--> /home/shark/playground/test.py:6:10
|
5 | c = C()
6 | c.square("hello") # error: [invalid-argument-type]
| ^^^^^^^ Object of type `Literal["hello"]` cannot be assigned to parameter 2 (`x`); expected type `int`
7 |
8 | # import inspect
|
```
after:
```
error: lint:invalid-argument-type
--> /home/shark/playground/test.py:6:10
|
5 | c = C()
6 | c.square("hello") # error: [invalid-argument-type]
| ^^^^^^^ Object of type `Literal["hello"]` cannot be assigned to parameter 2 (`x`) of bound method `square`; expected type `int`
7 |
8 | # import inspect
|
::: /home/shark/playground/test.py:2:22
|
1 | class C:
2 | def square(self, x: int) -> int:
| ------ info: parameter declared in function definition here
3 | return x * x
|
```
## Test Plan
New snapshot test
2025-02-25 09:58:08 +01:00
..
2025-02-24 15:17:16 +01:00
2025-02-18 13:34:39 +01:00
2025-02-24 09:55:34 +01:00
2024-12-21 11:33:10 +01:00
2025-02-04 08:27:17 +01:00
2025-02-25 09:58:08 +01:00
2025-02-21 19:26:05 +01:00
2025-02-19 10:22:30 -05:00
2025-02-21 19:26:05 +01:00
2024-12-17 09:49:39 +05:30
2025-02-25 09:58:08 +01:00
2025-02-03 09:27:29 +00:00
2025-02-12 08:52:11 +01:00
2025-02-20 12:25:55 +00:00
2025-02-24 15:17:16 +01:00
2024-12-06 12:55:56 -08:00
2025-02-14 15:17:51 +05:30
2025-01-16 11:21:56 -08:00
2025-02-21 19:26:05 +01:00
2025-02-21 21:05:48 +00:00
2025-02-04 08:27:17 +01:00
2025-02-24 15:17:16 +01:00
2025-02-05 22:26:15 +01:00
2025-02-25 09:58:08 +01:00
2025-02-04 08:27:17 +01:00
2025-02-24 09:55:34 +01:00
2025-02-05 22:26:15 +01:00
2025-02-20 23:22:26 +01:00
2025-02-21 20:46:36 +00:00
2025-02-03 09:27:29 +00:00
2025-02-21 19:26:05 +01:00
2025-02-18 13:34:39 +01:00
2024-10-31 21:00:51 +00:00
2025-02-24 15:17:16 +01:00
2025-02-25 09:58:08 +01:00
2024-12-19 21:02:14 +00:00
2025-02-04 08:27:17 +01:00
2025-02-03 09:27:29 +00:00
2024-12-06 02:41:33 +00:00
2025-02-04 08:27:17 +01:00
2025-02-03 09:27:29 +00:00
2025-02-04 08:27:17 +01:00
2025-02-04 08:27:17 +01:00
2025-02-04 08:27:17 +01:00
2025-01-20 09:55:54 +01:00
2025-02-20 23:22:26 +01:00
2025-02-24 09:55:34 +01:00
2025-02-06 07:15:26 +00:00
2025-02-20 23:22:26 +01:00
2025-02-05 22:26:15 +01:00
2025-02-05 17:47:49 -05:00
2025-02-21 19:26:05 +01:00
2025-02-14 12:24:10 -08:00
2025-02-03 09:27:29 +00:00