-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
[RET503] Interaction with mypy
assert_never
#3304
Comments
For the purpose of this error, |
I actually thought we did account for this -- lemme look back at the code today. |
Major apologies, latest version does seem to solve this! The releases are just too fast to keep up :) |
Oh no worries at all! Glad to hear it :) |
FYI, this is present in cibuildwheel using ruff 0.0.261: |
Is it possible that the code (I think here) isn't accounting for the typing module reexport location? |
Ah yeah, you're exactly right. |
This is rather a niche circumstance but thought it's worth mentioning. For exhaustive checking of Enums, there's an idiom to use with Mypy, checking each possible value and ending with
assert_never
. This is not a runtime check but purely a Mypy static type check.Ruff will give a
RET503
here which makes sense without mypy but given mypy is telling us it's safe, it would be nice for Ruff to detect this too. In the example above, using ruff with--fix
will actually insert the linereturn None
after the assert which then further causes linting issues of unreachable code.My naive solution to this is check for
assert_never(.*)
where thereturn
should be and accept that as a valid explicitreturn
statement.Looking into the checker code. It seems like it could be added as a
StmntKind
to the following lines as I'm guessing this code block is where it says to do nothing.https://github.com/charliermarsh/ruff/blob/3ed539d50ed6260358c97d2e00b49bad4abfa37e/crates/ruff/src/rules/flake8_return/rules.rs#L272-L275
However I'm really not a rustacian so just grasping at straws.
The text was updated successfully, but these errors were encountered: