GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — gh-142411: Change documentation to reflect the new docstring adjustments in 3.13 by decorator-factory · Pull Request #142413 · python/cpython

Conversation

@decorator-factory

@decorator-factory decorator-factory commented Dec 8, 2025 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

See issue #142411 for details.

  1. Document that compile can now raise UnicodeDecodeError

  2. Fix paragraph about docstring indentation in the tutorial. The REPL output was fixed in Docs: Fix indent in controlflow.rst #134008, but the preceding paragraph hasn't been adjusted

I believe this should be backported to 3.13 and 3.14, not sure how that works.

  • Issue: Indicate that surrogate literals are not allowed in docstrings since Python 3.13 #142411

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

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@bedevere-app bedevere-app Bot added docs Documentation in the Doc dir skip news labels Dec 8, 2025
@python-cla-bot

python-cla-bot Bot commented Dec 8, 2025 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

All commit authors signed the Contributor License Agreement.

CLA signed

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@github-project-automation github-project-automation Bot added this to Docs PRs Dec 8, 2025
@github-project-automation github-project-automation Bot moved this to Todo in Docs PRs Dec 8, 2025
@bedevere-app bedevere-app Bot mentioned this pull request Dec 8, 2025
Indicate that surrogate literals are not allowed in docstrings since Python 3.13 #142411
Closed
@bedevere-app bedevere-app Bot added the awaiting review label Dec 8, 2025
nedbat
nedbat reviewed Dec 10, 2025
View reviewed changes
Comment thread Doc/tutorial/controlflow.rst
indented less should not occur, but if they occur all their leading whitespace
should be stripped. Equivalence of whitespace should be tested after expansion
of tabs (to 8 spaces, normally).
The Python parser strips indentation from multi-line string literals when they

@nedbat nedbat Dec 10, 2025

Copy link
Copy Markdown
Member

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.

TIL!

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
nedbat
nedbat reviewed Dec 10, 2025
View reviewed changes
Comment thread Doc/library/functions.rst Outdated

- :exc:`SyntaxError` if the compiled source is invalid
- :exc:`ValueError` if the source contains null bytes
- :exc:`UnicodeDecodeError` if the source code contains docstrings that

@nedbat nedbat Dec 10, 2025

Copy link
Copy Markdown
Member

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 wouldn't try to keep this list precise and complete. The exceptions change over time, and it's not like people are going to write except blocks for these specific exceptions. Details are in the versionchanged blocks below. Here can we say that SyntaxError happens if the source is invalid, and other exceptions if the text can't be read in various ways?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@decorator-factory decorator-factory Dec 10, 2025 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor Author

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 now changed the description to this:

This function raises :exc:`SyntaxError` or :exc:`ValueError` if the compiled source is invalid.

To summarize some things about compile's interface:

  • If the source contains null bytes (whether it's a bytes object or a str object), SyntaxError is raised since Python 3.11, and not ValueError, contrary to current documentation.
  • If the source is an ast.Module, null bytes and surrogates seem to be allowed (but lead to bizzarre behaviour)
  • If the source is a bytes, SyntaxError will be raise if the source is encoded incorrectly
  • If the source is valid, -OO is not enabled, and any docstings would have a surrogate, UnicodeDecodeError (subclass of ValueError) is raised

It seems like the error conditions are a bit complicated and may change from version to version, so maybe it's good to keep it a bit opaque? Meaning: if you want to use this function and you expect the input to sometimes be invalid, prepare to catch both SyntaxError and ValueError

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
decorator-factory added 3 commits December 10, 2025 17:21
@decorator-factory
Change documentation to reflect the new docstring adjustments in 3.13
aa307bf
@decorator-factory
Clarify in the example what "strip indentation" means
3b2c009
@decorator-factory
Make compile() exception description more vague
eeb1ceb
@decorator-factory
decorator-factory force-pushed the df-compile-surrogatedoc branch from 1b5431a to eeb1ceb Compare December 10, 2025 14:21
nedbat
nedbat approved these changes Dec 12, 2025
View reviewed changes
@bedevere-app bedevere-app Bot added awaiting merge and removed awaiting review labels Dec 12, 2025
@decorator-factory
Merge branch 'main' into df-compile-surrogatedoc
5ef16ca
@hugovk hugovk added needs backport to 3.13 only security fixes needs backport to 3.14 bugs and security fixes labels Dec 13, 2025
@hugovk
hugovk merged commit f6b6a99 into python:main Dec 13, 2025
32 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@github-project-automation github-project-automation Bot moved this from Todo to Done in Docs PRs Dec 13, 2025
@miss-islington-app

miss-islington-app Bot commented Dec 13, 2025

Copy link
Copy Markdown

Thanks @decorator-factory for the PR, and @hugovk for merging it 🌮🎉.. I'm working now to backport this PR to: 3.13, 3.14.
🐍🍒⛏🤖

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-app bedevere-app Bot removed the awaiting merge label Dec 13, 2025
@miss-islington-app

miss-islington-app Bot commented Dec 13, 2025

Copy link
Copy Markdown

Sorry, @decorator-factory and @hugovk, I could not cleanly backport this to 3.14 due to a conflict.
Please backport using cherry_picker on command line.

cherry_picker f6b6a99aa5d63702b8e8101864ae08e615131702 3.14
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@miss-islington-app miss-islington-app Bot assigned hugovk Dec 13, 2025
@miss-islington-app

miss-islington-app Bot commented Dec 13, 2025

Copy link
Copy Markdown

Sorry, @decorator-factory and @hugovk, I could not cleanly backport this to 3.13 due to a conflict.
Please backport using cherry_picker on command line.

cherry_picker f6b6a99aa5d63702b8e8101864ae08e615131702 3.13
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@hugovk

hugovk commented Dec 13, 2025

Copy link
Copy Markdown
Member

@decorator-factory Would you like to have a go at backporting? See instructions above.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@decorator-factory

decorator-factory commented Dec 13, 2025

Copy link
Copy Markdown
Contributor Author

@hugovk Yes, I'll try to do that. Backports are just pull requests to branches other than main, correct? And in this case, miss Islington failed to generate a PR due to conflicts, and now I just need to make those PRs to 3.13 and 3.14 branches?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

decorator-factory added a commit to decorator-factory-clones/cpython that referenced this pull request Dec 14, 2025
@decorator-factory
[3.14] pythongh-142411: Change documentation to reflect the new docst…
1080708
…ring adjustments in 3.13 (pythonGH-142413)

(cherry picked from commit f6b6a99)

Co-authored-by: decorator-factory <[email protected]>
@bedevere-app

bedevere-app Bot commented Dec 14, 2025

Copy link
Copy Markdown

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

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-app bedevere-app Bot removed the needs backport to 3.14 bugs and security fixes label Dec 14, 2025
@bedevere-app

bedevere-app Bot commented Dec 14, 2025

Copy link
Copy Markdown

GH-142690 is a backport of this pull request to the 3.13 branch.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-app bedevere-app Bot removed the needs backport to 3.13 only security fixes label Dec 14, 2025
hugovk pushed a commit that referenced this pull request Dec 14, 2025
@decorator-factory
[3.14] gh-142411: Change documentation to reflect the new docstring a…
78dd2d5
…djustments in 3.13 (GH-142413) (#142689)
hugovk pushed a commit that referenced this pull request Dec 14, 2025
@decorator-factory
[3.13] gh-142411: Change documentation to reflect the new docstring a…
d2ba756
…djustments in 3.13 (GH-142413) (#142690)
@hugovk

hugovk commented Dec 14, 2025

Copy link
Copy Markdown
Member

@hugovk Yes, I'll try to do that. Backports are just pull requests to branches other than main, correct? And in this case, miss Islington failed to generate a PR due to conflicts, and now I just need to make those PRs to 3.13 and 3.14 branches?

Exactly so. Thanks, merged!

decorator-factory reacted with rocket emoji
All reactions
  • 🚀 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@nedbat nedbat nedbat approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

@hugovk hugovk

Labels

docs Documentation in the Doc dir skip news

Projects

Docs PRs
Status: Done

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

3 participants

@decorator-factory @hugovk @nedbat
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.