-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
PEP 8: update example of backslash usage for with statements #2244
Conversation
multiple ``with``-statements cannot use implicit continuation, so | ||
backslashes are acceptable:: | ||
multiple ``with``-statements could not use implicit continuation | ||
before Python 3.10, so backslashes were acceptable for that case:: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually it works in CPython 3.9 too -- it was an easter egg of the PEG parser project.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, another dict-keys-are-sorted situation where it’s an implementation detail in one version and an official documented feature in the next. Not sure if I should weigh the text down with technical correctness here!
I’ll wait to see if someone proposes to replace the whole example with something else that still requires or looks better with backslashes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel like we should give an example with parenthesized with instead. The PEP should reflect the current preferred style, not the past style.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The context is a section about backslashes, not context managers! This is saying that backslashes are generally discouraged, with some exceptions like multiple context managers, which now does not apply.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From the perspective of a "regular" Python user, I suggest just picking whichever makes the more sense to tell users and go with that here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this section is about backslashes, what about just saying:
Backslashes may still be appropriate for cases where implicit continuation within parentheses.
the remove the with
statement example. If you can't find another example that doesn't rely on with
-statements, then enough said!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I understand correctly, this could potentially happen in any keyword statement with a syntax that incorporated commas to separate arguments that didn't explicitly allow commas:
return
andyield
statements often have commas used within them, but that's because they are used with tuples, not have multiple distinct arguments, so they work fine- Except statements were fixed in Python 3
- As mentioned for
with
statements were formally fixed in Python 3.10, with an undocumented implementation-dependent fix in Python 3.9 import
statements, unlikefrom
statements, don't allow parens for continuation, but that's deliberate to not encourage users to group too many top-level imports into the same import statement, and thus would be very anti-PEP 8 anyway- For assert statements, this is sorta true, at least without some gymnastics, as described in and proposed to be fixed by PEP 679
I think that's everything, though I'm just a regular Pythonista and not a BDFL or FLUFL like you folks, so I could easily have missed something :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I'm just gonna merge it as-is.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wanted to see how it looks like with Adam’s suggestion (show recommended example first, in the paragraph just before that mentions parens, then keep backslash example with amended text), but I didn’t have time to do that immediately and the discussion did not wait until I came back 🙂
Python3.7 and 3.8 do not support this syntax. See: python/peps#2244
Python3.7 and 3.8 do not support this syntax. See: python/peps#2244 Part-of: #150433
Python3.7 and 3.8 do not support this syntax. See: python/peps#2244 Part-of: odoo#150433
Parentheses are allowed in 3.10, so I did the minimal change to be accurate.