-
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
Docstring formatting does not always respect line length in dynamic
mode
#9126
Comments
Thanks for the feedback! I wonder if this is happening because we only subtract @BurntSushi would you mind taking a look |
That might be it actually. I figured it might be because of edge cases with classes or something, but indeed a simple example like this also exceeds the line length, but only by 4 characters:
|
This fixes a bug where the current indent level was not calculated correctly for doctests. Namely, it didn't account for the extra indent level (in terms of ASCII spaces) used by by the PS1 (`>>> `) and PS2 (`... `) prompts. As a result, lines could extend up to 4 spaces beyond the configured line length limit. We fix that by passing the `CodeExampleKind` to the `format` routine instead of just the code itself. In this way, `format` can query whether there will be any extra indent added _after_ formatting the code and take that into account for its line length setting. Fixes #9126
Nice find! I put up a fix in #9129. @MichaReiser You were exactly correct! At least for this bug, it was indeed that the line length setting on the nested call to the formatter wasn't taking the extra spaces from the doctest prompt into account. |
This fixes a bug where the current indent level was not calculated correctly for doctests. Namely, it didn't account for the extra indent level (in terms of ASCII spaces) used by by the PS1 (`>>> `) and PS2 (`... `) prompts. As a result, lines could extend up to 4 spaces beyond the configured line length limit. We fix that by passing the `CodeExampleKind` to the `format` routine instead of just the code itself. In this way, `format` can query whether there will be any extra indent added _after_ formatting the code and take that into account for its line length setting. We add a few regression tests, taken directly from @stinodego's examples. Fixes #9126
First off, thanks so much for the great work on the docstring formatter! I'm very much looking forward to using it for the Polars code base.
When running the new docstring formatter on our code base, I found a number of examples where dynamic line length mode did not produce the expected result. See the three examples below:
In ruff
0.1.8
, running the ruff docstring formatter on these withline-length = 88
will produce line lengths over 88.I think examples 1 and 2 are clear violations. Example 3 is debatable whether the result is desired or not.
The text was updated successfully, but these errors were encountered: