PEP 8: update example of backslash usage for with statements by merwok · Pull Request #2244 · python/peps (original) (raw)

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 andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Conversation15 Commits1 Checks0 Files changed

Conversation

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters

[ Show hidden characters]({{ revealButtonHref }})

merwok

Parentheses are allowed in 3.10, so I did the minimal change to be accurate.

@merwok

gvanrossum

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::

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.

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.

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.

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.

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.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good!

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!

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:

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 :)

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.

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 🙂

aj-fuentes added a commit to odoo-dev/odoo that referenced this pull request

Jan 22, 2024

@aj-fuentes

robodoo pushed a commit to odoo/odoo that referenced this pull request

Jan 22, 2024

@aj-fuentes

This was referenced

Jan 22, 2024

luanjubica pushed a commit to luanjubica/odoo-code that referenced this pull request

Feb 14, 2024

@aj-fuentes @luanjubica