-
-
Notifications
You must be signed in to change notification settings - Fork 33.6k
gh-142411: Change documentation to reflect the new docstring adjustments in 3.13 #142413
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
base: main
Are you sure you want to change the base?
gh-142411: Change documentation to reflect the new docstring adjustments in 3.13 #142413
Conversation
| 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 |
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!
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 |
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?
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
bytesobject or astrobject),SyntaxErroris raised since Python 3.11, and notValueError, 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,SyntaxErrorwill be raise if the source is encoded incorrectly - If the source is valid,
-OOis not enabled, and any docstings would have a surrogate,UnicodeDecodeError(subclass ofValueError) 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
1b5431a to
eeb1ceb
Compare
See issue #142411 for details.
Document that
compilecan now raiseUnicodeDecodeErrorFix 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 adjustedI believe this should be backported to 3.13 and 3.14, not sure how that works.
📚 Documentation preview 📚: https://cpython-previews--142413.org.readthedocs.build/