-
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
Fix crash with f-string docstrings #4019
Conversation
Python does not consider f-strings to be docstrings, so we probably shouldn't be formatting them as such Fixes psf#4018 Despite its name, I think docstring_preview.py might be testing stable style, which this unfortunately does change
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
Thanks, it does look like this changes the stable style. The case it changes is rather odd, but we should still follow our policy and make the change only in the stable style. Some options:
|
Option 2 would also change the stable style right? I would also like to avoid Option 3. Note afaict that the AST safety check special cases all strings, not just docstrings, which makes me even more loathe to take Option 3. So Option 1 it is? |
I thought Option 2 was safe because any change we make to f-strings with placeholders would cause an AST safety crash. Though I guess it would change the stable style under |
Oh, it's not any f-string with placeholders. It's f-strings with leading or trailing space with placeholders adjacent to that space. I guess we could detect that specific situation and not format, but I'd prefer to have the behaviour be consistent and predictable, especially since Python does not consider f-strings to be docstrings. |
Actually wait, there is no stability concern. The stability guarantee is just that code that was previously formatted with Black will not change, not that formatting unformatted code will lead to the same results. |
Fixes #4018
Python does not consider f-strings to be docstrings, so we probably shouldn't be formatting them as such. This is the easiest way to fix the issue with the AST check.
Despite its name, I think docstring_preview.py might be testing stable style, which this unfortunately does change