Skip to content
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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Doc/library/exceptions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Copy link
Member

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.

Copy link
Author

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.

Copy link
Member

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.

Copy link
Author

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.

Copy link
Member

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.

Copy link
Author

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)



.. exception:: RuntimeWarning

Expand Down
3 changes: 2 additions & 1 deletion Doc/library/warnings.rst
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ The following warnings category classes are currently defined:
| | unless triggered by code in ``__main__``). |
+----------------------------------+-----------------------------------------------+
| :exc:`SyntaxWarning` | Base category for warnings about dubious |
| | syntactic features. |
| | syntactic features (emitted when compiling |
| | Python source code to bytecode). |
+----------------------------------+-----------------------------------------------+
| :exc:`RuntimeWarning` | Base category for warnings about dubious |
| | runtime features. |
Expand Down
Loading