Skip to content
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

removal of leading white-space in top-of-file comment #10550

Closed
janwilmans opened this issue Mar 24, 2024 · 4 comments
Closed

removal of leading white-space in top-of-file comment #10550

janwilmans opened this issue Mar 24, 2024 · 4 comments
Labels
docstring Related to docstring linting or formatting formatter Related to the formatter

Comments

@janwilmans
Copy link

janwilmans commented Mar 24, 2024

using ruff vscode plugin, default configuration but with:

[tool.ruff]
line-length = 160
indent-width = 4

Before code format:

#!/usr/bin/env python3
"""Returns with exitcode 1 if /....., otherwise 0 (success)
    description bla bla description
    description bla bla description
"""

after code format:

#!/usr/bin/env python3
"""Returns with exitcode 1 if /....., otherwise 0 (success)
description bla bla description
description bla bla description
"""

All leading whitespace in comments up top seems to be removed, however, in raw-strings that are assigned to a variable, this does not happen.

@AlexWaygood AlexWaygood added docstring Related to docstring linting or formatting formatter Related to the formatter labels Mar 24, 2024
@charliermarsh
Copy link
Member

I believe this is by design. The formatter normalizes docstrings, and a string expression at the top of a file is a docstring.

@janwilmans
Copy link
Author

The docstring can change the behaviour of the program, such as with docopt, so I think there should at least be a way to disable this ?

@zanieb
Copy link
Member

zanieb commented Mar 25, 2024

This looks like a duplicate of #10396

You can disable this with # fmt: skip as discussed there.

@janwilmans
Copy link
Author

You are correct, this is a duplicate, I did not find it because I did not look for 'docstring' as a keyword, silly me, thank you for pointing that out.

However, I think it is not a reasonable solution to annotate all python files with tool-specific annotations, I see there is an issue #4276 for this on the Black repo. They are also of the opinion that modifying user data is allowed by a code formatter.

I'm not sure I follow this logic, any change that have a runtime effect is a bug to me. I will go back to autopep8, feel free to close this issue.

@MichaReiser MichaReiser closed this as not planned Won't fix, can't repro, duplicate, stale Mar 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docstring Related to docstring linting or formatting formatter Related to the formatter
Projects
None yet
Development

No branches or pull requests

5 participants