René's URL Explorer Experiment


Title: warn_explicit() issues a warning or an error when used directly in a script · Issue #123011 · python/cpython · GitHub

Open Graph Title: warn_explicit() issues a warning or an error when used directly in a script · Issue #123011 · python/cpython

X Title: warn_explicit() issues a warning or an error when used directly in a script · Issue #123011 · python/cpython

Description: For example, running the following script: import warnings warnings.warn_explicit('eggs', UserWarning, 'bar', 1, module_globals=globals()) emits a warning: $ ./python t.py :932: DeprecationWarning: M...

Open Graph Description: For example, running the following script: import warnings warnings.warn_explicit('eggs', UserWarning, 'bar', 1, module_globals=globals()) emits a warning: $ ./python t.py

X Description: For example, running the following script: import warnings warnings.warn_explicit('eggs', UserWarning, 'bar', 1, module_globals=globals()) emits a warning: $ ./python t.py <froze...

Opengraph URL: https://github.com/python/cpython/issues/123011

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"warn_explicit() issues a warning or an error when used directly in a script","articleBody":"For example, running the following script:\r\n```py\r\nimport warnings\r\nwarnings.warn_explicit('eggs', UserWarning, 'bar', 1, module_globals=globals())\r\n```\r\nemits a warning:\r\n```\r\n$ ./python t.py\r\n\u003cfrozen importlib._bootstrap_external\u003e:932: DeprecationWarning: Module globals is missing a __spec__.loader\r\n/home/serhiy/py/cpython3.13/t.py:1: UserWarning: eggs\r\n  import warnings\r\n```\r\n\r\nRunning it as a module produces an error:\r\n```\r\n$ ./python -m t\r\nTraceback (most recent call last):\r\n  File \"/home/serhiy/py/cpython3.13/Lib/runpy.py\", line 198, in _run_module_as_main\r\n    return _run_code(code, main_globals, None,\r\n                     \"__main__\", mod_spec)\r\n  File \"/home/serhiy/py/cpython3.13/Lib/runpy.py\", line 88, in _run_code\r\n    exec(code, run_globals)\r\n    ~~~~^^^^^^^^^^^^^^^^^^^\r\n  File \"/home/serhiy/py/cpython3.13/t.py\", line 2, in \u003cmodule\u003e\r\n    warnings.warn_explicit('eggs', UserWarning, __file__, 1, module_globals=globals())\r\n    ~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\r\n  File \"\u003cfrozen importlib._bootstrap_external\u003e\", line 1073, in get_source\r\n  File \"\u003cfrozen importlib._bootstrap_external\u003e\", line 674, in _check_name_wrapper\r\nImportError: loader for t cannot handle __main__\r\n```\r\n\r\nRunning it in the REPL produces similar error:\r\n```pycon\r\n\u003e\u003e\u003e import warnings\r\n... warnings.warn_explicit('eggs', UserWarning, 'bar', 1, module_globals=globals())\r\n... \r\nTraceback (most recent call last):\r\n  File \"\u003cpython-input-0\u003e\", line 2, in \u003cmodule\u003e\r\n    warnings.warn_explicit('eggs', UserWarning, 'bar', 1, module_globals=globals())\r\n    ~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\r\n  File \"\u003cfrozen importlib._bootstrap_external\u003e\", line 1073, in get_source\r\n  File \"\u003cfrozen importlib._bootstrap_external\u003e\", line 674, in _check_name_wrapper\r\nImportError: loader for _pyrepl.__main__ cannot handle __main__\r\n```\r\n\r\nBut importing it as a module is OK:\r\n```pycon\r\n\u003e\u003e\u003e import t\r\n/home/serhiy/py/cpython3.13/t.py:1: UserWarning: eggs\r\n  import warnings\r\n```\r\n\r\nThe warning was introduced in #86298, but I think that it was for modules created in non-standard way. Running Python code as a script is pretty standard, this is not a user error. We should handle this case specially.\r\n\r\ncc @brettcannon, @warsaw","author":{"url":"https://github.com/serhiy-storchaka","@type":"Person","name":"serhiy-storchaka"},"datePublished":"2024-08-14T13:50:59.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":0},"url":"https://github.com/123011/cpython/issues/123011"}

route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:c20e6ad0-1e88-34ac-5606-f3b43fceee18
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idEB76:392B41:AFA4D2:F17DB2:696A86C1
html-safe-nonce2ae9141c05fc2847169b538350eb31c3a4c572aad6715b56e8d19585b4c81171
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFQjc2OjM5MkI0MTpBRkE0RDI6RjE3REIyOjY5NkE4NkMxIiwidmlzaXRvcl9pZCI6Ijc5MTAzNDMzNzg4MTEzODk2MzMiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ==
visitor-hmacc612ba1e7481d8d1858a2df7445fed53a9f3da1f94281db28a491d1be4619176
hovercard-subject-tagissue:2465902755
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python/cpython/123011/issue_layout
twitter:imagehttps://opengraph.githubassets.com/1cce9a48c9ba54b5dd7076591eea5156748e4c94e697f05f40778f766274e611/python/cpython/issues/123011
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/1cce9a48c9ba54b5dd7076591eea5156748e4c94e697f05f40778f766274e611/python/cpython/issues/123011
og:image:altFor example, running the following script: import warnings warnings.warn_explicit('eggs', UserWarning, 'bar', 1, module_globals=globals()) emits a warning: $ ./python t.py
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernameserhiy-storchaka
hostnamegithub.com
expected-hostnamegithub.com
Noned2aa6dedd7d97fa651b17c40401f2605f309df5ca5fb659bf0554cf34f1de825
turbo-cache-controlno-preview
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
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
releasec1dbca8981c5e3d6a69bce2f1d289e732b86241d
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/python/cpython/issues/123011#start-of-content
https://github.com/
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fissues%2F123011
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%2Fissues%2F123011
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%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=python%2Fcpython
Reloadhttps://github.com/python/cpython/issues/123011
Reloadhttps://github.com/python/cpython/issues/123011
Reloadhttps://github.com/python/cpython/issues/123011
python https://github.com/python
cpythonhttps://github.com/python/cpython
Please reload this pagehttps://github.com/python/cpython/issues/123011
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/issues/123011
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
New issuehttps://github.com/login?return_to=https://github.com/python/cpython/issues/123011
New issuehttps://github.com/login?return_to=https://github.com/python/cpython/issues/123011
warn_explicit() issues a warning or an error when used directly in a scripthttps://github.com/python/cpython/issues/123011#top
type-bugAn unexpected behavior, bug, or errorhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22type-bug%22
https://github.com/serhiy-storchaka
https://github.com/serhiy-storchaka
serhiy-storchakahttps://github.com/serhiy-storchaka
on Aug 14, 2024https://github.com/python/cpython/issues/123011#issue-2465902755
#86298https://github.com/python/cpython/issues/86298
@brettcannonhttps://github.com/brettcannon
@warsawhttps://github.com/warsaw
type-bugAn unexpected behavior, bug, or errorhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22type-bug%22
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.