FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

gh-135676: Add a summary of source characters by encukou · Pull Request #138194 · python/cpython · GitHub

/ cpython Public

gh-135676: Add a summary of source characters - #138194

Merged
encukou merged 5 commits into
python:mainfrom
encukou:lex-analysis-highlevel
Oct 8, 2025
Merged

gh-135676: Add a summary of source characters#138194
encukou merged 5 commits into
python:mainfrom
encukou:lex-analysis-highlevel

Conversation

encukou commented Aug 27, 2025
edited by github-actions Bot
Loading

Copy link
Copy Markdown
Member

The lexical analysis docs have notes like this at the end:

  • The period can also occur in floating-point and imaginary literals.

  • The following printing ASCII characters have special meaning as part of other tokens or are otherwise significant to the lexical analyzer: ' " # \

  • The following printing ASCII characters are not used in Python. Their occurrence outside string literals and comments is an unconditional error: $ ? `

The intent behind these seems to be providing a "map" of what all the ASCII characters do in Python, but that map is incomplete as it is, and isn't really kept up to date.

This instead provides a summary of source characters -- nominally the ones that start tokens, with notes for other notable cases.
The table can also serve as an alternate "table of contents".

The presentation -- a table of bulleted lists -- is a bit wacky but I think it gets the job done.


📚 Documentation preview 📚: https://cpython-previews--138194.org.readthedocs.build/

Comment thread Doc/reference/lexical_analysis.rst Outdated
Comment thread Doc/reference/lexical_analysis.rst Outdated
encukou marked this pull request as ready for review September 3, 2025 14:28

AA-Turner left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

I think this is a useful addition!

A

Comment thread Doc/reference/lexical_analysis.rst Outdated
Comment on lines +15 to +18
.. note::

A ":dfn:`stream`" is a *sequence*, in the general sense of the word
(not necessarily a Python :term:`sequence object <sequence>`).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

I'm not sure this note is needed?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

I agree with @AA-Turner. Stream and sequence are both overloaded terms that may be better unpacked by the reader in context.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

OK; I've removed it

Comment on lines +32 to +33
.. list-table::
:header-rows: 1

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

In general for list tables it can be useful to alternate list markers, e.g. using - to denote items of the second-level list. Not essential, though.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

All my list-tables will do that from now on :)

* * :ref:`String literal <strings>`

* * * ASCII letter (``a``-``z``, ``A``-``Z``)
* non-ASCII character

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Is 'non-ASCII character' too broad here? Not all characters can form valid identifiers, especially if expanding to the full Unicode space!

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

It is broad, but: if the tokenizer sees a non-ASCII character, the next token can only be a NAME (or error). (Except inside strings/comments, but then it's not deciding what the next token will be.)

If I remember correctly¹, the tokenizer implementation does lump non-ASCII characters with the letters, and only checks validity after it parses an identifier-like token.

¹ Maybe I don't, but it certainly could do that :)

willingc left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

A nice improvement @encukou. I've left a few prose suggestions but fine as is too. Thanks!

Comment thread Doc/reference/lexical_analysis.rst Outdated
Comment on lines +15 to +18
.. note::

A ":dfn:`stream`" is a *sequence*, in the general sense of the word
(not necessarily a Python :term:`sequence object <sequence>`).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

I agree with @AA-Turner. Stream and sequence are both overloaded terms that may be better unpacked by the reader in context.

Comment thread Doc/reference/lexical_analysis.rst Outdated
encukou added the needs backport to 3.14 bugs and security fixes label Oct 8, 2025
encukou merged commit 59a6f9d into python:main Oct 8, 2025
29 checks passed
github-project-automation Bot moved this from Todo to Done in Docs PRs Oct 8, 2025

Copy link
Copy Markdown

Thanks @encukou for the PR 🌮🎉.. I'm working now to backport this PR to: 3.14.
🐍🍒⛏🤖

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Oct 8, 2025
(cherry picked from commit 59a6f9d)

Co-authored-by: Petr Viktorin <encukou@gmail.com>
Co-authored-by: Carol Willing <carolcode@willingconsulting.com>
Co-authored-by: Stan Ulbrych <89152624+StanFromIreland@users.noreply.github.com>
Co-authored-by: Blaise Pabon <blaise@gmail.com>
Co-authored-by: Micha Albert <info@micha.zone>
Co-authored-by: KeithTheEE <kmurrayis@gmail.com>
encukou deleted the lex-analysis-highlevel branch October 8, 2025 14:34

bedevere-app Bot commented Oct 8, 2025

Copy link
Copy Markdown

GH-139781 is a backport of this pull request to the 3.14 branch.

bedevere-app Bot removed the needs backport to 3.14 bugs and security fixes label Oct 8, 2025

encukou commented Oct 8, 2025

Copy link
Copy Markdown
Member Author

Thank you for the reviews!

encukou added a commit that referenced this pull request Oct 8, 2025
…139781)

(cherry picked from commit 59a6f9d)

Co-authored-by: Petr Viktorin <encukou@gmail.com>
Co-authored-by: Carol Willing <carolcode@willingconsulting.com>
Co-authored-by: Stan Ulbrych <89152624+StanFromIreland@users.noreply.github.com>
Co-authored-by: Blaise Pabon <blaise@gmail.com>
Co-authored-by: Micha Albert <info@micha.zone>
Co-authored-by: KeithTheEE <kmurrayis@gmail.com>
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Documentation in the Doc dir skip news

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

5 participants


Back | FazBrowse Home | New Git URL