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

bug: target-version not respected when formatting with statement #14756

Closed
ziadkh0 opened this issue Dec 3, 2024 · 2 comments
Closed

bug: target-version not respected when formatting with statement #14756

ziadkh0 opened this issue Dec 3, 2024 · 2 comments
Labels
formatter Related to the formatter question Asking for support or clarification

Comments

@ziadkh0
Copy link

ziadkh0 commented Dec 3, 2024

Formatting the following code with target-version set to "py39" and line-length set to 10 (just for the example):

with A() as a, B() as b:
    pass

Expected output similar to:

with \
    A() as a, \
    B() as b \
:
    pass

Actual output:

with (
    A() as a,
    B() as b,
):
    pass

Playground

Support for using grouping parentheses to break the with statement in multiple lines was added in version 3.10, see: https://docs.python.org/3/reference/compound_stmts.html#the-with-statement

@AlexWaygood
Copy link
Member

Thanks for opening the issue!

Support for using grouping parentheses to break the with statement in multiple lines was added in version 3.10, see: https://docs.python.org/3/reference/compound_stmts.html#the-with-statement

It was only formally added to the language spec in Python 3.10. However, it was (initially only accidentally) made valid syntax in Python 3.9. This definitely isn't going to be reverted in CPython, so it's entirely safe to assume that with items can be parenthesized on Python 3.9. Black also uses parenthesized with items on Python 3.9, and I think it's good for us to be consistent with Black here. (Actually this was recently discussed again at psf/black#4488, but they decided to keep their current behaviour.)

Is this behaviour causing an issue for you somewhere? :-)

@AlexWaygood AlexWaygood added question Asking for support or clarification formatter Related to the formatter labels Dec 3, 2024
@ziadkh0
Copy link
Author

ziadkh0 commented Dec 3, 2024

Thank you for the quick reply!
I didn't that 😮
I just check it, and I can confirm that it's not causing an issues 😄
I guess this issue can be closed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
formatter Related to the formatter question Asking for support or clarification
Projects
None yet
Development

No branches or pull requests

3 participants