-
-
Notifications
You must be signed in to change notification settings - Fork 31.1k
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
gh-123858: Improve Doc: SyntaxWarning is emitted during bytecode generation #122844
base: main
Are you sure you want to change the base?
Conversation
Could someone please help review this PR? Thank you. |
@@ -866,6 +866,8 @@ The following exceptions are used as warning categories; see the | |||
|
|||
Base class for warnings about dubious syntax. | |||
|
|||
This warning is emitted when compiling Python source code to bytecode. |
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 think this is too strong - we probably don't want to commit to only using this exception type in the compilation process. You can write an application that raises these exceptions if you want.
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.
How about this?
By default, the Python interpreter emits the SyntaxWarning
during bytecode compilation.
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.
That's not in the language spec either.
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 can't find a suitable word to describe the current behavior.
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.
That's the thing, we don't document "current behaviour". We document what we guarantee will not change without a deprecation process.
The point of your PR is to alert people that compilation errors don't show up when the code is not being compiled. This may be worth mentioning in one of the tutorials (I'm not sure which), but I don't think the SyntaxError documentation is the right place for this.
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 understand your concern that this document introduces some unofficially committed behavior for SyntaxWarning. I'm okay with leaving it here and waiting for more comments.
I searched the repository and found the following:
SyntaxWarning are only emitted once, and only when a Python file is parsed: when a cached PYC file is used, not warning is emitted -------#99011 (comment)
The problem is the warnings are only shown once, when the file is compiled.
Things would probably be improved if the warnings were always shown, as at least then devs will see the error once (although most will probably be confused when the warning doesn't repeat). --#77093 (comment)
I'm working on eliminating the
SyntaxWarning
. It's strange that this error only shows up once. After some research, I found that:However, this isn't mentioned in the documentation. I noticed other warnings have descriptions like "ignored by default." Adding this information could help reduce confusion.
📚 Documentation preview 📚: https://cpython-previews--122844.org.readthedocs.build/