-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Clearer error message when line-length goes beyond threshold
#21072
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
Conversation
|
|
My implementation example doesn't seem quite right. I don't think we should prohibit people from setting |
IMO, there's no need for having artificial constraints about the max size of the line-length, or a need to set a warning, the way that I see it, if a user explicitly set One possible solution would be to remove ruff/crates/ruff_linter/src/line_width.rs Lines 24 to 25 in 64ab79e
And relying on the constrains of ruff/crates/ruff_linter/src/line_width.rs Lines 94 to 103 in 64ab79e
|
|
It seems that the root of the problem lies in crate toml. |
|
although it seems that the TOML specification mentions this
# hexadecimal with prefix `0x`
hex1 = 0xDEADBEEF
hex2 = 0xdeadbeef
hex3 = 0xdead_beef
# octal with prefix `0o`
oct1 = 0o01234567
oct2 = 0o755 # useful for Unix file permissions
# binary with prefix `0b`
bin1 = 0b11010110Arbitrary 64-bit signed integers (from −2^63 to 2^63−1) should be accepted and handled losslessly. If an integer cannot be represented losslessly, an error must be thrown. |
So if I understand you correctly it will be something like: let raw = match i64::deserialize(deserializer) {
Ok(v) => v,
Err(_) => {
let s: &str = Deserializer::deserialize(deserializer)?;
i64::from_str(s).map_err(ParseLineWidthError::ParseError)?
}
}
let value = u16::try_from(raw).map_err(???)The main issue with this approach is that ruff/crates/ruff_linter/src/line_width.rs Lines 90 to 93 in 64ab79e
can only store u16 and in the best case with this approach we'll have i64. It doesn't make much sense to change the type to i64. what does deserlizing to i64 first gives us? why can't we just do what you suggested initially?
|
crates/ruff_linter/src/line_width.rs
Outdated
| let value = NonZeroU16::try_from(value).map_err(|_| { | ||
| serde::de::Error::custom(format!( | ||
| "line-length must be between 1 and {} (got {value})", | ||
| Self::MAX, | ||
| )) | ||
| })?; | ||
|
|
||
| Self::try_from(value.get()).map_err(serde::de::Error::custom) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: Maybe something like this:
| let value = NonZeroU16::try_from(value).map_err(|_| { | |
| serde::de::Error::custom(format!( | |
| "line-length must be between 1 and {} (got {value})", | |
| Self::MAX, | |
| )) | |
| })?; | |
| Self::try_from(value.get()).map_err(serde::de::Error::custom) | |
| let value = Self::try_from(value).map_err(|_| { | |
| serde::de::Error::custom(format!( | |
| "line-length must be between 1 and {} (got {value})", | |
| Self::MAX, | |
| )) | |
| }) |
Co-authored-by: Micha Reiser <micha@reiser.io>
MichaReiser
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you
* origin/main: Respect `--output-format` with `--watch` (#21097) [`pyflakes`] Revert to stable behavior if imports for module lie in alternate branches for `F401` (#20878) Fix finding keyword range for clause header after statement ending with semicolon (#21067) [ty] Fix bug where ty would think all types had an `__mro__` attribute (#20995) Restore `indent.py` (#21094) [`flake8-django`] Apply `DJ001` to annotated fields (#20907) Clearer error message when `line-length` goes beyond threshold (#21072) Update upload and download artifacts github actions (#21083) Update dependency mdformat-mkdocs to v4.4.2 (#21088) Update cargo-bins/cargo-binstall action to v1.15.9 (#21086) Update Rust crate clap to v4.5.50 (#21090) Update Rust crate get-size2 to v0.7.1 (#21091) Update Rust crate bstr to v1.12.1 (#21089) Add missing docstring sections to the numpy list (#20931) [`pydoclint`] Fix false positive on explicit exception re-raising (`DOC501`, `DOC502`) (#21011) [ty] Use constructor parameter types as type context (#21054)
Fixes #20823
Summary
Implemented code from original issue
Test Plan
Added test