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-135801: Fix inaccurate module info for SyntaxWarnings during AST parsing by heliang666s · Pull Request #135829 · python/cpython

Conversation

@heliang666s

@heliang666s heliang666s commented Jun 23, 2025 •
edited by bedevere-app Bot
Loading

Uh oh!

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

Copy link
Copy Markdown
Contributor

This commit addresses the inaccurate module information provided for SyntaxWarnings during AST parsing, specifically reported in issue #135801.

Previously, _PyErr_EmitSyntaxWarning (used by the compiler) relied on _PyErr_WarnExplicitObjectWithContext to infer the module name from the call stack. During compilation, this often resulted in misleading module names like sys or importlib._bootstrap, making it difficult to filter warnings effectively (e.g., using -W error::SyntaxWarning:test).

To resolve this, a new internal function _PyErr_EmitSyntaxWarningFromCompiler was introduced in Python/errors.c. This function explicitly calls PyErr_WarnExplicitObject with a NULL module argument, forcing the warning system to derive the module name from the filename provided by the compiler.

The normalize_module function in Python/_warnings.c was also refined. Instead of simple string manipulation or problematic pure C path parsing, it now leverages Python's os.path module (via Python C API calls like basename, splitext, and dirname). This ensures robust and accurate extraction of module names from arbitrary file paths, including correct handling of __init__.py files, thereby providing correct module information for compiler-generated SyntaxWarning messages.

This approach ensures cross-platform compatibility and reliability by utilizing Python's battle-tested path handling capabilities, directly addressing the core issue reported.

  • Issue: Improve/fix filtering SyntaxWarnings by module #135801

Sorry, something went wrong.

Uh oh!

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

All reactions
heliang
Fix: Better module info for SyntaxWarnings during AST parsing
d971dd5
@heliang666s
heliang666s requested review from iritkatriel and markshannon as code owners June 23, 2025 01:12
@bedevere-app bedevere-app Bot added the awaiting review label Jun 23, 2025
@bedevere-app

bedevere-app Bot commented Jun 23, 2025

Copy link
Copy Markdown

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

All reactions

Sorry, something went wrong.

Uh oh!

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

@bedevere-app bedevere-app Bot mentioned this pull request Jun 23, 2025
Improve/fix filtering SyntaxWarnings by module #135801
Closed
heliang
Fix SyntaxWarning deduplication with pseudo-filenames
0deed9e
@bedevere-app

bedevere-app Bot commented Jun 23, 2025

Copy link
Copy Markdown

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

All reactions

Sorry, something went wrong.

Uh oh!

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

heliang and others added 5 commits June 23, 2025 11:05
heliang
Fix SyntaxWarning deduplication with pseudo-filenames
4b05629
heliang
Add Unit Test
423fae3
heliang
Fix test_warnings failures in CI
20c4390
heliang
Fix: Correct ImportError and NameError in test_warnings
3ddfa71
@heliang666s
Merge branch 'main' into main
93b3bca
@python-cla-bot

python-cla-bot Bot commented Jun 23, 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.

iritkatriel
iritkatriel reviewed Jun 23, 2025
View reviewed changes
Comment thread Python/errors.c Resolved

Uh oh!

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

heliang666s and others added 2 commits June 30, 2025 01:53
@heliang666s
Merge branch 'python:main' into main
15ab120
@heliang666s
Fix improves SyntaxWarning module information by directly deriving mo…
8c9913e
…dule names from filenames rather than the call stack, and streamlines warning emission.
@heliang666s

heliang666s commented Jun 30, 2025 •
edited
Loading

Uh oh!

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

Copy link
Copy Markdown
Contributor Author

@iritkatriel please review again,thanks~

All reactions

Sorry, something went wrong.

Uh oh!

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

@iritkatriel
iritkatriel requested a review from serhiy-storchaka June 30, 2025 17:15
@heliang666s
Merge branch 'main' into main
0d87aff
@cdce8p

cdce8p commented Aug 30, 2025

Copy link
Copy Markdown
Contributor

Any update here?

CC @hugovk I believe this would address some / most of the concerns raised on the forum post for PEP 765. It might make sense for 3.14.
https://discuss.python.org/t/pep-765-disallow-return-break-continue-that-exit-a-finally-block/71348/146

All reactions

Sorry, something went wrong.

Uh oh!

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

@gpshead

gpshead commented Oct 2, 2025

Copy link
Copy Markdown
Member

FWIW this seems like something that could make sense as a later bugfix in a patch release.

Deciding that mostly requires understanding if there are meaningful load bearing behavior changes that code might be relying upon in this PRs warnings and errors changes.

All reactions

Sorry, something went wrong.

Uh oh!

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

serhiy-storchaka
serhiy-storchaka reviewed Oct 2, 2025
View reviewed changes

@serhiy-storchaka serhiy-storchaka left a comment

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.

The normalize_module() change does not match the Python implementation and the documented behavior. Is it necessary to include it in this PR?

Sorry, something went wrong.

Uh oh!

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

All reactions
@serhiy-storchaka

serhiy-storchaka commented Nov 13, 2025

Copy link
Copy Markdown
Member

Thank you for your PR, @heliang666s, but this was resolved in other way.

All reactions

Sorry, something went wrong.

Uh oh!

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

@serhiy-storchaka serhiy-storchaka closed this Nov 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@iritkatriel iritkatriel iritkatriel left review comments
@serhiy-storchaka serhiy-storchaka serhiy-storchaka left review comments
@markshannon markshannon Awaiting requested review from markshannon

Uh oh!

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

Assignees

No one assigned

Labels

awaiting review

Projects

None yet

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.

5 participants

@heliang666s @cdce8p @gpshead @serhiy-storchaka @iritkatriel
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.