-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
problematic formatting: indentation change in docstring #4276
Comments
This is essentially a duplicate of #2150. We re-indent docstrings because it is sometimes necessary in cases where we re-indent the code itself, and we have previously rejected requests to make this configurable. I proposed a framework towards making this configurable (#3087), but for better or worse it was rejected. |
I would just re-iterate that docstring are data, not code, and as such should never be modified by a code formatter for any reason, whatsoever. This is certainly and by far the biggest mistake |
@bryevdv have you found some other usable formatter? I'm leaning towards autopep8 currently. (made a comparison tool for my own sake: https://github.com/kaddkaka/python-formatting-examples) |
@kaddkaka No, we simply do not use a formatter at this time. |
In case it's useful, it appears Black uses this logic https://peps.python.org/pep-0257/#handling-docstring-indentation when handling docstring whitespace. This means that if you have some other text in your docstring that's at the minimum indentation, Black will not destroy your ASCII art. The easiest way to do this would be to put a new line:
|
Tools are supposed to work for you, not the other way around. 🙂 |
It's good to know, but it's no help since it doesn't magically fix all existing code. |
black might destroy ascii art in dosctring when re-indenting docstring lines.
Example code:
result after 'black`:
as seen, the carets
^
are now misaligned. This can in problematic cases destroy information and be very confusing, misleading and lead to future mistakes.In my mind it would be better to not touch docstrings - but I guess there might be some reason for it?
(original PR on ruff: astral-sh/ruff#10396)
The text was updated successfully, but these errors were encountered: