Merged
Conversation
sharkdp
commented
Apr 7, 2025
| declare_lint! { | ||
| /// ## What it does | ||
| /// Checks for `assert_type()` calls where the actual type | ||
| /// Checks for `assert_type()` and `assert_never()` calls where the actual type |
Contributor
Author
There was a problem hiding this comment.
I did consider making more changes in the lint description here. I also considered a dedicated new diagnostic. But eventually thought that this might be enough? Let me know if you have a different opinion.
Contributor
|
433494f to
9ce9a1d
Compare
MichaReiser
reviewed
Apr 7, 2025
crates/red_knot_python_semantic/resources/mdtest/directives/assert_never.md
Outdated
Show resolved
Hide resolved
9ce9a1d to
4dc402e
Compare
carljm
approved these changes
Apr 7, 2025
dcreager
added a commit
that referenced
this pull request
Apr 9, 2025
* origin/main: [red-knot] Default `python-platform` to current platform (#17183) [red-knot] Add new 'unreachable code' test case (#17306) [red-knot] mypy_primer: Run on `async-utils` (#17303) [red-knot] Add custom `__setattr__` support (#16748) [red-knot] Add `__init__` arguments check when doing `try_call` on a class literal (#16512) [`flake8-pie`] Avoid false positive for multiple assignment with `auto()` (`PIE796`) (#17274) [syntax-errors] Async comprehension in sync comprehension (#17177) [`airflow`] Expand module path check to individual symbols (`AIR302`) (#17278) [syntax-errors] Check annotations in annotated assignments (#17283) [syntax-errors] Extend annotation checks to `await` (#17282) [red-knot] Add support for `assert_never` (#17287) [`flake8-pytest-style`] Avoid false positive for legacy form of `pytest.raises` (`PT011`) (#17231) [red-knot] Do not show types for literal expressions on hover (#17290) [red-knot] Fix dead-code clippy warning (#17291) [red-knot] Reachability analysis (#17199) [red-knot] Don't use latency-sensitive for handlers (#17227)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
We already have partial "support" for
assert_never, because it is annotated asin typeshed. So we already emit a
invalid-argument-typediagnostic if the argument type toassert_neveris not assignable toNever.That is not enough, however. Gradual types like
Any,Unknown,@Todo(…)orAny & intcan be assignable toNever. Which means that we didn't issue any diagnostic in those cases.Also, it seems like
assert_neverdeserves a dedicated diagnostic message, not just a generic "invalid argument type" error.Test Plan
New Markdown tests.