Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[red-knot] Highlight call-arguments range for reveal_type, static_assert, … #15907

Open
sharkdp opened this issue Feb 3, 2025 · 1 comment
Labels
diagnostics Related to reporting of diagnostics. red-knot Multi-file analysis & type inference

Comments

@sharkdp
Copy link
Contributor

sharkdp commented Feb 3, 2025

Description

We currently highlight the full call expression for reveal_type-diagnostics and static_assert diagnostics:

info: revealed-type
 --> /home/shark/playground/test.py:3:1
  |
1 | from knot_extensions import static_assert
2 |
3 | reveal_type(2 + 3)
  | ------------------ info: Revealed type is `Literal[5]`
4 |
5 | static_assert((2 + 3) < 4)
  |

error: lint:static-assert-error
 --> /home/shark/playground/test.py:5:1
  |
3 | reveal_type(2 + 3)
4 |
5 | static_assert((2 + 3) < 4)
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^ Static assertion error: argument evaluates to `False`
  |

I would like it better if only the argument was highlighted. I wanted to make this change quickly, but it's not completely straightforward and messes with CallOutcome (which @AlexWaygood is working on), so I figured I'd create a ticket instead.

This is also somewhat related to multiple-range diagnostics, because for functions like assert_type(<expr>, <type-expr>), we might want to highlight the first argument ("… has type <actual-type>") and then create a separate (informational?) text range for <type-expr> to highlight it as the expected type. In any case, we can certainly do better than this:

error: lint:type-assertion-failure
 --> /home/shark/playground/test.py:4:1
  |
2 | from typing import assert_type
3 |
4 | assert_type(2 + 3, str)
  | ^^^^^^^^^^^^^^^^^^^^^^^ Actual type `Literal[5]` is not the same as asserted type `str`
  |
@sharkdp sharkdp added the red-knot Multi-file analysis & type inference label Feb 3, 2025
@AlexWaygood AlexWaygood added the diagnostics Related to reporting of diagnostics. label Feb 3, 2025
@MichaReiser
Copy link
Member

CC: @BurntSushi

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
diagnostics Related to reporting of diagnostics. red-knot Multi-file analysis & type inference
Projects
None yet
Development

No branches or pull requests

3 participants