-
Notifications
You must be signed in to change notification settings - Fork 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
Ruff makes triple sure the user is aware an error code has been remapped when it has explictly been ignored #3431
Comments
I think we used to show this once, but a refactor made it more difficult to enforce that it appears "exactly once". |
IMO it would be better at the end of cli output rather than the beginning |
It seems that this warning is coming from https://github.com/charliermarsh/ruff/blob/bb3bb24b59d8f0da5c42972b177cd29db9390d6f/crates/ruff/src/settings/mod.rs#L362-L369 |
I think it's that we may call |
Yeah I looked into that macro but realized that it wouldn't fix it. I think that it could be adapted for dynamic warnings like these by using a static hashmap with the appropriate locks, but I'm not sure if the overhead from that is worth it. |
I think it's probably worth it, since this isn't a high-performance codepath. Are you interested in giving that a try? |
I started on a kind of ridiculous change to use macros in /// Returns the redirect target for the given code.
pub(crate) fn get_redirect_target(code: &str) -> Option<&'static str> {
redirect(code).map(|(_, target)| target)
}
/// Returns the code and the redirect target if the given code is a redirect.
/// (The same code is returned to obtain it with a static lifetime).
pub(crate) fn get_redirect(code: &str) -> Option<(&'static str, &'static str)> {
redirect(code)
}
fn redirect(code: &str) -> Option<(&'static str, &'static str)> {
macro_rules! redirect {
($src:expr, $dst:expr) => {{
if code == $src {
crate::warn_user_once!("`{}` has been remapped to `{}`.", $src, $dst);
return Some(($src, $dst));
}
}};
}
redirect!("SIM111", "SIM110");
return None;
} That actually does work, but the issue is that the redirect itself is done before we set up the logger (e.g., if the codes are provided as command-line arguments), so the warning doesn't show up in all cases because it's "too soon". |
I can give it a shot, but I should say I'm not too familiar with atomics (might be a good opportunity to learn, though). Since this function is not async, things like |
If a refactor is necessary than I also think it might be better to show warnings like this near the end of the output. |
We could make the redirects |
I can help with this one. |
Summary
When ignoring a remapped error code, ruff is very insistent in error logs that the error code has been remapped.
Steps to reproduce
pyproject.toml:
command:
ruff .
There does not need to be any python files in the current directory.
Screenshots
The text was updated successfully, but these errors were encountered: