cpython icon indicating copy to clipboard operation
cpython copied to clipboard

gh-99087: Add missing newline for prompts in docs

Open slateny opened this issue 3 years ago • 7 comments

https://github.com/python/cpython/issues/99087

slateny avatar Nov 02 '22 05:11 slateny

This is against the recommendations by the dev guide: https://devguide.python.org/documentation/style-guide/#code-examples

Suggesting to close this PR.

erlend-aasland avatar Nov 02 '22 09:11 erlend-aasland

I would argue that it does aid copy-pasting and is necessary despite impeding some readability: for example, in the enum howto, we have this: image

which (when the >>> is clicked on the top-right of the code box) corresponds to the prompt

class Perm(IntFlag):
    R = 4
    W = 2
    X = 1
    RWX = 7
Perm.RWX

~Perm.RWX

Perm(7)

but this causes a error when pasted:

>>> class Perm(IntFlag):
...     R = 4
...     W = 2
...     X = 1
...     RWX = 7
... Perm.RWX
  File "<stdin>", line 6
    Perm.RWX
    ^^^^
SyntaxError: invalid syntax

This happens if the previous line is a part of something function, class, etc. when there's indentation, so the new line's needed to clear it out. I should have also put my justification in the description instead of leaving it empty - my bad on that.

slateny avatar Nov 02 '22 16:11 slateny

I think the devguide paragraph @erlend-aasland cites isn't exactly on point here. It's about not introducing the secondary prompt to examples that currently don't have it, but this PR adds an extra line of secondary prompt to examples that already have it.

JelleZijlstra avatar Nov 02 '22 16:11 JelleZijlstra

I should have also put my justification in the description instead of leaving it empty - my bad on that.

Yeah, either that, or creating an issue describing the problem. Perhaps an issue would have been appropriate here, since it is clearly not a trivial change.

erlend-aasland avatar Nov 02 '22 16:11 erlend-aasland

The problem here is that the edit looks gross and makes the examples slightly longer, noisier, and less readable without adding anything substantive.

rhettinger avatar Nov 02 '22 19:11 rhettinger

The problem here is that the edit looks gross and makes the examples slightly longer, noisier, and less readable without adding anything substantive.

Preventing errors from copy-pasting prompts, especially from howto pages, would quality as substantive to me, and since the edit is just extending the existing ... it doesn't appear that much visually intrusive. However, if the consensus is that prompts are to be left as-is intentionally, then I have no problem with closing this PR and pointing future PRs with similar changes to this one for justification.

slateny avatar Nov 03 '22 03:11 slateny

I think this change is helpful [...]

I agree, it makes sense to me. I also think we should amend the dev guide.

erlend-aasland avatar Nov 08 '22 08:11 erlend-aasland

FTR; the sqlite3 change is no longer relevant.

erlend-aasland avatar Nov 27 '22 22:11 erlend-aasland

Deploy Preview for python-cpython-preview ready!

Name Link
Latest commit db5bbe32feab90fd723f86a97874f189eef0f840
Latest deploy log https://app.netlify.com/sites/python-cpython-preview/deploys/63926a89e5beed0009ff7d1c
Deploy Preview https://deploy-preview-98993--python-cpython-preview.netlify.app
Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

netlify[bot] avatar Dec 08 '22 22:12 netlify[bot]