Title: Improve/fix filtering SyntaxWarnings by module · Issue #135801 · python/cpython · GitHub
Open Graph Title: Improve/fix filtering SyntaxWarnings by module · Issue #135801 · python/cpython
X Title: Improve/fix filtering SyntaxWarnings by module · Issue #135801 · python/cpython
Description: Feature or enhancement Proposal: Syntax warnings during AST parsing use _PyCompile_Warn to setup their warning context automatically. Though the filename is correct, the module is inferred and often not helpful. This is especially an iss...
Open Graph Description: Feature or enhancement Proposal: Syntax warnings during AST parsing use _PyCompile_Warn to setup their warning context automatically. Though the filename is correct, the module is inferred and ofte...
X Description: Feature or enhancement Proposal: Syntax warnings during AST parsing use _PyCompile_Warn to setup their warning context automatically. Though the filename is correct, the module is inferred and ofte...
Opengraph URL: https://github.com/python/cpython/issues/135801
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Improve/fix filtering SyntaxWarnings by module","articleBody":"# Feature or enhancement\n\n### Proposal:\n\nSyntax warnings during AST parsing use `_PyCompile_Warn` to setup their warning context automatically. Though the filename is correct, the module is inferred and often not helpful. This is especially an issue when trying to ignore specific errors in a CI environment with pytest where the module is suddenly `importlib._bootstrap`. In other cases with python alone it's often just `sys`.\n\n_AFAICT this applies mainly to the `\"is\" with '...' literal` and `'return' in 'finally' block` warnings._\n\n--\nTo reproduce\n\n```python\n# test.py\nclass A:\n def __init__(self):\n self.var = 2\n\n def func(self) -\u003e bool:\n return self.var is 2\n```\n```bash\n./python.exe -W error::SyntaxWarning:sys test.py\n```\n```py\n File \"/.../test.py\", line 7\n return self.var is 2\n ^^^^^^^^^^^^^\nSyntaxError: \"is\" with 'int' literal. Did you mean \"==\"?\n```\n\n_Note: The SyntaxWarning is changed to an error for module `sys` where `test` would have been the expected module._\n\n\n--\nThe SyntaxWarning is triggered here:\nhttps://github.com/python/cpython/blob/b14986c91464b06e9016678637e41d0e0192bbe8/Python/codegen.c#L1831-L1837\nhttps://github.com/python/cpython/blob/b14986c91464b06e9016678637e41d0e0192bbe8/Python/compile.c#L1204-L1214\n\n### Has this already been discussed elsewhere?\n\nThis is a minor feature, which does not need previous discussion elsewhere\n\n### Links to previous discussion of this feature:\n\n_No response_\n\n\u003c!-- gh-linked-prs --\u003e\n### Linked PRs\n* gh-135829\n* gh-139652\n* gh-140151\n* gh-140240\n* gh-140246\n* gh-140247\n\u003c!-- /gh-linked-prs --\u003e\n","author":{"url":"https://github.com/cdce8p","@type":"Person","name":"cdce8p"},"datePublished":"2025-06-21T22:28:19.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":5},"url":"https://github.com/135801/cpython/issues/135801"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:f6224117-302a-f10c-1876-35ce3fc40db4 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 8680:166D49:48A2EB:65CB8E:696A6B15 |
| html-safe-nonce | 25fde2dae13e564ae6bba959c1960a210973ec9d70c51bcd01f21140a79ac652 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4NjgwOjE2NkQ0OTo0OEEyRUI6NjVDQjhFOjY5NkE2QjE1IiwidmlzaXRvcl9pZCI6IjU2Mjc3MzUwMDAyMDc3NDc4NjEiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 625486ad5605f4d9ebcb9005c06766b557b5aa6aef2741142e0d97d62eae8d10 |
| hovercard-subject-tag | issue:3165474786 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python/cpython/135801/issue_layout |
| twitter:image | https://opengraph.githubassets.com/ab0a8e29a40da8de8279e826d8caf4850b9db46aa058778089c72f4e57f0734a/python/cpython/issues/135801 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/ab0a8e29a40da8de8279e826d8caf4850b9db46aa058778089c72f4e57f0734a/python/cpython/issues/135801 |
| og:image:alt | Feature or enhancement Proposal: Syntax warnings during AST parsing use _PyCompile_Warn to setup their warning context automatically. Though the filename is correct, the module is inferred and ofte... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | cdce8p |
| hostname | github.com |
| expected-hostname | github.com |
| None | 6fea32d5b7276b841b7a803796d9715bc6cfb31ed549fdf9de2948ac25d12ba6 |
| turbo-cache-control | no-preview |
| go-import | github.com/python/cpython git https://github.com/python/cpython.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 81598961 |
| octolytics-dimension-repository_nwo | python/cpython |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 81598961 |
| octolytics-dimension-repository_network_root_nwo | python/cpython |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | f2d9f6432a5a115ec709295ae70623f33bb80aee |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width