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

Conversation

bebound
Copy link

@bebound bebound commented Aug 9, 2024

I'm working on eliminating the SyntaxWarning. It's strange that this error only shows up once. After some research, I found that:

A SyntaxWarning is emitted when the compiler compiles Python sources to bytecode. (Ref: #79031 (comment))

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/

Copy link

cpython-cla-bot bot commented Aug 9, 2024

All commit authors signed the Contributor License Agreement.
CLA signed

@bebound
Copy link
Author

bebound commented Aug 29, 2024

Could someone please help review this PR? Thank you.

@bebound bebound changed the title Docs: SyntaxWarning is emitted during bytecode generation GH-123858: Improve Doc: SyntaxWarning is emitted during bytecode generation Sep 9, 2024
@bebound bebound changed the title GH-123858: Improve Doc: SyntaxWarning is emitted during bytecode generation gh-123858: Improve Doc: SyntaxWarning is emitted during bytecode generation Sep 10, 2024
@@ -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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting review docs Documentation in the Doc dir skip news
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants