René's URL Explorer Experiment


Title: gh-86298: Ensure that __loader__ and __spec__.loader agree in warnings.warn_explicit() by warsaw · Pull Request #97803 · python/cpython · GitHub

Open Graph Title: gh-86298: Ensure that __loader__ and __spec__.loader agree in warnings.warn_explicit() by warsaw · Pull Request #97803 · python/cpython

X Title: gh-86298: Ensure that __loader__ and __spec__.loader agree in warnings.warn_explicit() by warsaw · Pull Request #97803 · python/cpython

Description: In _warnings.c, in the C equivalent of warnings.warn_explicit(), if the module globals are given (and not None), the warning will attempt to get the source line for the issued warning. To do this, it needs the module's loader. Previously, it would only look up __loader__ in the module globals. In #86298 we want to defer to the __spec__.loader if available. The first step on this journey is to check that loader == __spec__.loader and issue another warning if it is not. This commit does that. Since this is a PoC, only manual testing for now. # /tmp/foo.py import warnings import bar warnings.warn_explicit( 'warning!', RuntimeWarning, 'bar.py', 2, module='bar knee', module_globals=bar.__dict__, ) # /tmp/bar.py import sys import os import pathlib # __loader__ = pathlib.Path() Then running this: ./python.exe -Wdefault /tmp/foo.py Produces: bar.py:2: RuntimeWarning: warning! import os Uncomment the __loader__ = line in bar.py and try it again: sys:1: ImportWarning: Module bar; __loader__ != __spec__.loader (<_frozen_importlib_external.SourceFileLoader object at 0x109f7dfa0> != PosixPath('.')) bar.py:2: RuntimeWarning: warning! import os Issue: gh-86298 Automerge-Triggered-By: GH:warsaw

Open Graph Description: In _warnings.c, in the C equivalent of warnings.warn_explicit(), if the module globals are given (and not None), the warning will attempt to get the source line for the issued warning. To do this,...

X Description: In _warnings.c, in the C equivalent of warnings.warn_explicit(), if the module globals are given (and not None), the warning will attempt to get the source line for the issued warning. To do this,...

Opengraph URL: https://github.com/python/cpython/pull/97803

X: @github

direct link

Domain: github.com

route-pattern/:user_id/:repository/pull/:id/files(.:format)
route-controllerpull_requests
route-actionfiles
fetch-noncev2:e9eef0a7-f00c-9411-76f2-e4676272e01c
current-catalog-service-hashae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b
request-idD6B0:1CEAED:11BE226:17AAECF:696AD2CA
html-safe-nonce613f70f4f140890adb4f1b811012c2155ecbd3afe000061f42f7e81838e89c09
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJENkIwOjFDRUFFRDoxMUJFMjI2OjE3QUFFQ0Y6Njk2QUQyQ0EiLCJ2aXNpdG9yX2lkIjoiNjQwNzI1OTgzNDg3NjA4OTAzNCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9
visitor-hmac0fe22591283a42f76c8823265d12892bf9ddaa0d596f16ffb67246ec4688d687
hovercard-subject-tagpull_request:1075269931
github-keyboard-shortcutsrepository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///pull_requests/show/files
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/python/cpython/pull/97803/files
twitter:imagehttps://avatars.githubusercontent.com/u/210184?s=400&v=4
twitter:cardsummary_large_image
og:imagehttps://avatars.githubusercontent.com/u/210184?s=400&v=4
og:image:altIn _warnings.c, in the C equivalent of warnings.warn_explicit(), if the module globals are given (and not None), the warning will attempt to get the source line for the issued warning. To do this,...
og:site_nameGitHub
og:typeobject
hostnamegithub.com
expected-hostnamegithub.com
Nonec785f4ce187e9e7331257791b36ddee01625bb8e292a9b4fe2c16d4c006abf5d
turbo-cache-controlno-preview
diff-viewunified
go-importgithub.com/python/cpython git https://github.com/python/cpython.git
octolytics-dimension-user_id1525981
octolytics-dimension-user_loginpython
octolytics-dimension-repository_id81598961
octolytics-dimension-repository_nwopython/cpython
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id81598961
octolytics-dimension-repository_network_root_nwopython/cpython
turbo-body-classeslogged-out env-production page-responsive full-width
disable-turbotrue
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
releasec718a376fcf780eb22089171adb84a543f660bf7
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/python/cpython/pull/97803/files#start-of-content
https://github.com/
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fpull%2F97803%2Ffiles
GitHub CopilotWrite better code with AIhttps://github.com/features/copilot
GitHub SparkBuild and deploy intelligent appshttps://github.com/features/spark
GitHub ModelsManage and compare promptshttps://github.com/features/models
MCP RegistryNewIntegrate external toolshttps://github.com/mcp
ActionsAutomate any workflowhttps://github.com/features/actions
CodespacesInstant dev environmentshttps://github.com/features/codespaces
IssuesPlan and track workhttps://github.com/features/issues
Code ReviewManage code changeshttps://github.com/features/code-review
GitHub Advanced SecurityFind and fix vulnerabilitieshttps://github.com/security/advanced-security
Code securitySecure your code as you buildhttps://github.com/security/advanced-security/code-security
Secret protectionStop leaks before they starthttps://github.com/security/advanced-security/secret-protection
Why GitHubhttps://github.com/why-github
Documentationhttps://docs.github.com
Bloghttps://github.blog
Changeloghttps://github.blog/changelog
Marketplacehttps://github.com/marketplace
View all featureshttps://github.com/features
Enterpriseshttps://github.com/enterprise
Small and medium teamshttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
App Modernizationhttps://github.com/solutions/use-case/app-modernization
DevSecOpshttps://github.com/solutions/use-case/devsecops
DevOpshttps://github.com/solutions/use-case/devops
CI/CDhttps://github.com/solutions/use-case/ci-cd
View all use caseshttps://github.com/solutions/use-case
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
View all industrieshttps://github.com/solutions/industry
View all solutionshttps://github.com/solutions
AIhttps://github.com/resources/articles?topic=ai
Software Developmenthttps://github.com/resources/articles?topic=software-development
DevOpshttps://github.com/resources/articles?topic=devops
Securityhttps://github.com/resources/articles?topic=security
View all topicshttps://github.com/resources/articles
Customer storieshttps://github.com/customer-stories
Events & webinarshttps://github.com/resources/events
Ebooks & reportshttps://github.com/resources/whitepapers
Business insightshttps://github.com/solutions/executive-insights
GitHub Skillshttps://skills.github.com
Documentationhttps://docs.github.com
Customer supporthttps://support.github.com
Community forumhttps://github.com/orgs/community/discussions
Trust centerhttps://github.com/trust-center
Partnershttps://github.com/partners
GitHub SponsorsFund open source developershttps://github.com/sponsors
Security Labhttps://securitylab.github.com
Maintainer Communityhttps://maintainers.github.com
Acceleratorhttps://github.com/accelerator
Archive Programhttps://archiveprogram.github.com
Topicshttps://github.com/topics
Trendinghttps://github.com/trending
Collectionshttps://github.com/collections
Enterprise platformAI-powered developer platformhttps://github.com/enterprise
GitHub Advanced SecurityEnterprise-grade security featureshttps://github.com/security/advanced-security
Copilot for BusinessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/premium-support
Pricinghttps://github.com/pricing
Search syntax tipshttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
documentationhttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fpull%2F97803%2Ffiles
Sign up https://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fpull_requests%2Fshow%2Ffiles&source=header-repo&source_repo=python%2Fcpython
Reloadhttps://github.com/python/cpython/pull/97803/files
Reloadhttps://github.com/python/cpython/pull/97803/files
Reloadhttps://github.com/python/cpython/pull/97803/files
python https://github.com/python
cpythonhttps://github.com/python/cpython
Please reload this pagehttps://github.com/python/cpython/pull/97803/files
Notifications https://github.com/login?return_to=%2Fpython%2Fcpython
Fork 33.9k https://github.com/login?return_to=%2Fpython%2Fcpython
Star 71.1k https://github.com/login?return_to=%2Fpython%2Fcpython
Code https://github.com/python/cpython
Issues 5k+ https://github.com/python/cpython/issues
Pull requests 2.1k https://github.com/python/cpython/pulls
Actions https://github.com/python/cpython/actions
Projects 31 https://github.com/python/cpython/projects
Security Uh oh! There was an error while loading. Please reload this page. https://github.com/python/cpython/security
Please reload this pagehttps://github.com/python/cpython/pull/97803/files
Insights https://github.com/python/cpython/pulse
Code https://github.com/python/cpython
Issues https://github.com/python/cpython/issues
Pull requests https://github.com/python/cpython/pulls
Actions https://github.com/python/cpython/actions
Projects https://github.com/python/cpython/projects
Security https://github.com/python/cpython/security
Insights https://github.com/python/cpython/pulse
Sign up for GitHub https://github.com/signup?return_to=%2Fpython%2Fcpython%2Fissues%2Fnew%2Fchoose
terms of servicehttps://docs.github.com/terms
privacy statementhttps://docs.github.com/privacy
Sign inhttps://github.com/login?return_to=%2Fpython%2Fcpython%2Fissues%2Fnew%2Fchoose
miss-islingtonhttps://github.com/miss-islington
python:mainhttps://github.com/python/cpython/tree/main
warsaw:issue-86298https://github.com/warsaw/cpython/tree/issue-86298
Conversation 17 https://github.com/python/cpython/pull/97803
Commits 17 https://github.com/python/cpython/pull/97803/commits
Checks 0 https://github.com/python/cpython/pull/97803/checks
Files changed https://github.com/python/cpython/pull/97803/files
Please reload this pagehttps://github.com/python/cpython/pull/97803/files
gh-86298: Ensure that __loader__ and __spec__.loader agree in warnings.warn_explicit() https://github.com/python/cpython/pull/97803/files#top
Show all changes 17 commits https://github.com/python/cpython/pull/97803/files
37b581a PoC for checking both __loader__ and __spec__.loader warsaw Oct 3, 2022 https://github.com/python/cpython/pull/97803/commits/37b581aa480cb309fa8f68f649802af96f6d25c5
049910b Merge branch 'main' into issue-86298 warsaw Oct 3, 2022 https://github.com/python/cpython/pull/97803/commits/049910bbee193317d8e4b8194918334c883e3415
317e253 Add a test for the __loader__ == __spec__.loader cases warsaw Oct 4, 2022 https://github.com/python/cpython/pull/97803/commits/317e253b6de0bf5f1c2cb95960559e692eea62fb
428d863 Add news warsaw Oct 4, 2022 https://github.com/python/cpython/pull/97803/commits/428d863c6d1b3f4746fb22a03588ae18c342efcb
06d686d Merge branch 'main' into issue-86298 warsaw Oct 4, 2022 https://github.com/python/cpython/pull/97803/commits/06d686d5e2b1eb9b552ae4999bbca9da0c7b10c2
fc50fe1 Update some documentation warsaw Oct 4, 2022 https://github.com/python/cpython/pull/97803/commits/fc50fe143ac56f2658187a8e765cd0584aaeaa42
1066b9f Use a helper function warsaw Oct 6, 2022 https://github.com/python/cpython/pull/97803/commits/1066b9facc64accfe53b057dc639045ab38d29db
4602366 Merge branch 'main' into issue-86298 warsaw Oct 6, 2022 https://github.com/python/cpython/pull/97803/commits/460236660c802c5597632a367ecdc31087e91164
831f832 Pass warnings tests warsaw Oct 6, 2022 https://github.com/python/cpython/pull/97803/commits/831f8322c736580e1d8f1e8ec7d3017777264570
37254cf Merge branch 'main' into issue-86298 warsaw Oct 6, 2022 https://github.com/python/cpython/pull/97803/commits/37254cf42542e1cdc37c362e7cb0f7720419c4d2
fe9d62e Move warnings tests to helper tests warsaw Oct 6, 2022 https://github.com/python/cpython/pull/97803/commits/fe9d62eecf72beeb095cb3e8a244230f3efbc8c3
3bcdba9 Clean up a few last minute things warsaw Oct 6, 2022 https://github.com/python/cpython/pull/97803/commits/3bcdba951c4f6df2ff19ff630708d744da8a2350
f5cef9c Merge branch 'main' into issue-86298 warsaw Oct 7, 2022 https://github.com/python/cpython/pull/97803/commits/f5cef9c0f5daa3a68b3beca4fdc0c0ee0caf81aa
5600c9c Update Lib/importlib/_bootstrap_external.py warsaw Oct 7, 2022 https://github.com/python/cpython/pull/97803/commits/5600c9c54f99034b28f40d6efff04492373b4bf6
8631e53 Update Lib/test/test_importlib/import_/test_helpers.py warsaw Oct 7, 2022 https://github.com/python/cpython/pull/97803/commits/8631e535a04a20915908ed5c2f3026ab431ee360
b1b0d86 Update Lib/test/test_importlib/import_/test_helpers.py warsaw Oct 7, 2022 https://github.com/python/cpython/pull/97803/commits/b1b0d864245cb366e762f431189465c9d955d5d5
823400c Merge branch 'main' into issue-86298 warsaw Oct 7, 2022 https://github.com/python/cpython/pull/97803/commits/823400c8eae156480551057ad5f5f1d80b9f5663
Clear filters https://github.com/python/cpython/pull/97803/files
Please reload this pagehttps://github.com/python/cpython/pull/97803/files
Please reload this pagehttps://github.com/python/cpython/pull/97803/files
import.rst https://github.com/python/cpython/pull/97803/files#diff-a691e0a2b6cd3161c948365aa7aa3f73719c0a77724240331f9ce03e1a816c1d
_bootstrap_external.py https://github.com/python/cpython/pull/97803/files#diff-efefe383b3a81d16150c280db0b64eed7569254299418f64cc0d749f8e16f3a4
test_helpers.py https://github.com/python/cpython/pull/97803/files#diff-1e766f600dc0f149ac13db94f81210a62d1a5f2db84e862e90ce732ba7888771
2022-10-04-14-04-40.gh-issue-86298.QVM7G1.rst https://github.com/python/cpython/pull/97803/files#diff-feb1582ddf42e06af32b9866813d500c38573b48fe11d8af79d38ab52c2c3b6f
_warnings.c https://github.com/python/cpython/pull/97803/files#diff-868cb9c3ec7f49459c652319e480e03ee132976b45fbedacb94958f8e0a9ea58
https://github.com/python/cpython/blob/main/.github/CODEOWNERS#L260
Doc/reference/import.rsthttps://github.com/python/cpython/pull/97803/files#diff-a691e0a2b6cd3161c948365aa7aa3f73719c0a77724240331f9ce03e1a816c1d
View file https://github.com/warsaw/cpython/blob/823400c8eae156480551057ad5f5f1d80b9f5663/Doc/reference/import.rst
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/python/cpython/pull/97803/{{ revealButtonHref }}
https://github.com/python/cpython/pull/97803/files#diff-a691e0a2b6cd3161c948365aa7aa3f73719c0a77724240331f9ce03e1a816c1d
https://github.com/python/cpython/pull/97803/files#diff-a691e0a2b6cd3161c948365aa7aa3f73719c0a77724240331f9ce03e1a816c1d
https://github.com/python/cpython/pull/97803/files#diff-a691e0a2b6cd3161c948365aa7aa3f73719c0a77724240331f9ce03e1a816c1d
https://github.com/python/cpython/blob/main/.github/CODEOWNERS#L260
Lib/importlib/_bootstrap_external.pyhttps://github.com/python/cpython/pull/97803/files#diff-efefe383b3a81d16150c280db0b64eed7569254299418f64cc0d749f8e16f3a4
View file https://github.com/warsaw/cpython/blob/823400c8eae156480551057ad5f5f1d80b9f5663/Lib/importlib/_bootstrap_external.py
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/python/cpython/pull/97803/{{ revealButtonHref }}
https://github.com/python/cpython/pull/97803/files#diff-efefe383b3a81d16150c280db0b64eed7569254299418f64cc0d749f8e16f3a4
Please reload this pagehttps://github.com/python/cpython/pull/97803/files
Please reload this pagehttps://github.com/python/cpython/pull/97803/files
Please reload this pagehttps://github.com/python/cpython/pull/97803/files
https://github.com/python/cpython/pull/97803/files#diff-efefe383b3a81d16150c280db0b64eed7569254299418f64cc0d749f8e16f3a4
https://github.com/python/cpython/blob/main/.github/CODEOWNERS#L260
Lib/test/test_importlib/import_/test_helpers.pyhttps://github.com/python/cpython/pull/97803/files#diff-1e766f600dc0f149ac13db94f81210a62d1a5f2db84e862e90ce732ba7888771
View file https://github.com/warsaw/cpython/blob/823400c8eae156480551057ad5f5f1d80b9f5663/Lib/test/test_importlib/import_/test_helpers.py
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/python/cpython/pull/97803/{{ revealButtonHref }}
https://github.com/python/cpython/pull/97803/files#diff-1e766f600dc0f149ac13db94f81210a62d1a5f2db84e862e90ce732ba7888771
https://github.com/python/cpython/pull/97803/files#diff-1e766f600dc0f149ac13db94f81210a62d1a5f2db84e862e90ce732ba7888771
https://github.com/python/cpython/pull/97803/files#diff-1e766f600dc0f149ac13db94f81210a62d1a5f2db84e862e90ce732ba7888771
Please reload this pagehttps://github.com/python/cpython/pull/97803/files
Please reload this pagehttps://github.com/python/cpython/pull/97803/files
Misc/NEWS.d/next/Core and Builtins/2022-10-04-14-04-40.gh-issue-86298.QVM7G1.rsthttps://github.com/python/cpython/pull/97803/files#diff-feb1582ddf42e06af32b9866813d500c38573b48fe11d8af79d38ab52c2c3b6f
View file https://github.com/warsaw/cpython/blob/823400c8eae156480551057ad5f5f1d80b9f5663/Misc/NEWS.d/next/Core%20and%20Builtins/2022-10-04-14-04-40.gh-issue-86298.QVM7G1.rst
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/python/cpython/pull/97803/{{ revealButtonHref }}
Python/_warnings.chttps://github.com/python/cpython/pull/97803/files#diff-868cb9c3ec7f49459c652319e480e03ee132976b45fbedacb94958f8e0a9ea58
View file https://github.com/warsaw/cpython/blob/823400c8eae156480551057ad5f5f1d80b9f5663/Python/_warnings.c
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/python/cpython/pull/97803/{{ revealButtonHref }}
https://github.com/python/cpython/pull/97803/files#diff-868cb9c3ec7f49459c652319e480e03ee132976b45fbedacb94958f8e0a9ea58
Please reload this pagehttps://github.com/python/cpython/pull/97803/files
https://github.com/python/cpython/pull/97803/files#diff-868cb9c3ec7f49459c652319e480e03ee132976b45fbedacb94958f8e0a9ea58
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.