René's URL Explorer Experiment


Title: gh-123961: move `PyCursesError` in `_cursesmodule.c` to a global state variable by picnixz · Pull Request #124729 · python/cpython · GitHub

Open Graph Title: gh-123961: move `PyCursesError` in `_cursesmodule.c` to a global state variable by picnixz · Pull Request #124729 · python/cpython

X Title: gh-123961: move `PyCursesError` in `_cursesmodule.c` to a global state variable by picnixz · Pull Request #124729 · python/cpython

Description: UPDATE: managed to make it smaller. Previous discussion (now resolved) Ideally, I wanted to make multiple PRs for the curses module but simply adding a module state with the minimal logic would not be helpful at all. So I decided to do the following in one go: Add a module's state that holds the curses exception type and the curses window object type. Make the window object type a heap type. Use multi-phase initialization for the module. The reason I couldn't find a way to split those changes is due to the exposed C API. The C API uses parameter-less functions and thus does not have access to the module's state. More precisely, we need to access the exception type in three different contexts without relying on a global variable (the purpose is to remove the global variables): In a parameter-less function: we need to re-import the curses module. In a window object's method: if we use a static type, we still can't access the module's state so it does not makes sense to me to make a change where I would first import the exception and in the next PR I would access it directly from the module's state. In a module's method: we can avoid using the state since the exception is stored in the module's dict, but again, this does not make sense to keep a temporary workaround for a few days. There is a way to split the PR into two, namely by getting PyCursesError via an import. Informally, we would consider the module's dict as the state (which we must do for parameter-less functions) though I honestly think it's not worth that effort for window and module's methods. Alternatively, we could first make the module a multi-phase initialization module, without any state and keep the global variables. However, I'm not sure that's a good idea. Note that I cleanly separated the commits so that I can pick them up if needed. Finally, I did not apply any cosmetic changes even though I was very tempted. The only cosmetic change I did was for the macros so that they readability is improved and if I'm anyway editing the lines. If a cosmetic change slipped through, please tell me. Issue: gh-123961

Open Graph Description: UPDATE: managed to make it smaller. Previous discussion (now resolved) Ideally, I wanted to make multiple PRs for the curses module but simply adding a module state with the minimal logic would n...

X Description: UPDATE: managed to make it smaller. Previous discussion (now resolved) Ideally, I wanted to make multiple PRs for the curses module but simply adding a module state with the minimal logic would n...

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

X: @github

direct link

Domain: github.com

IPv4 address: 140.82.114.4

react-profiling0
react-import-mapreact,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322
route-pattern/:user_id/:repository/pull/:id/files(.:format)
route-controllerpull_requests
route-actionfiles
fetch-noncev2:de4e5b76-366f-7b55-b2ec-b08244fb92b1
current-catalog-service-hashae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b
request-idB3EE:3D2C49:1AA0269:231C5BB:6B067F5E
html-safe-nonce40bba7ae6350471e48e8df4e2c1ae7a7d6be02fd965f23477040c0dfad9796dd
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCM0VFOjNEMkM0OToxQUEwMjY5OjIzMUM1QkI6NkIwNjdGNUUiLCJ2aXNpdG9yX2lkIjoiMTQwMDY2NjkzNjcwNjQ5ODM5OCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9
visitor-hmacb7510470baf9c6dec83a354905635ee479df2853973b32a8b72111887de2ea17
hovercard-subject-tagpull_request:2096975848
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/124729/files
twitter:imagehttps://avatars.githubusercontent.com/u/10796600?s=400&v=4
twitter:cardsummary_large_image
og:imagehttps://avatars.githubusercontent.com/u/10796600?s=400&v=4
og:image:altUPDATE: managed to make it smaller. Previous discussion (now resolved) Ideally, I wanted to make multiple PRs for the curses module but simply adding a module state with the minimal logic would n...
og:site_nameGitHub
og:typeobject
hostnamegithub.com
expected-hostnamegithub.com
None4462ff7ebfd3d551f202659f2423dae617b6849d23b1df6465dc504ef497d14a
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
release6d3909414814ff86ce7da4c51a0f4918a13fb41b
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/python/cpython/pull/124729/files#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fpull%2F124729%2Ffiles
GitHubRepository hosting, code review, and collaborationhttps://github.com/platform
CopilotAI coding agent for tasks, projects, and automated workhttps://github.com/features/copilot
ActionsCI/CD and automationhttps://github.com/features/actions
Code QualityQuality analysis, fixes, and enforcementhttps://github.com/features/code-quality
CodespacesCloud development environmentshttps://github.com/features/codespaces
Code SecurityVulnerability detection and remediationhttps://github.com/security/advanced-security/code-security
Secret ProtectionSecret scanning and leak preventionhttps://github.com/security/advanced-security/secret-protection
All Featureshttps://github.com/features
Documentationhttps://docs.github.com/en
Traininghttps://learn.github.com/skills
Certificationshttps://learn.github.com/credentials
Build with Copilothttps://github.com/features/ai
Customize Copilothttps://docs.github.com/en/copilot/how-tos/copilot-on-github/customize-copilot/customize-copilot-overview
Integrationshttps://github.com/marketplace
Trending reposhttps://github.com/trending
GitHub Sponsorshttps://github.com/open-source/sponsors
Developer articleshttps://github.com/resources/articles
ChangelogYour source for the latest features, improvements, and fixes across GitHub products, all in one place.https://github.blog/changelog/
Enterpriseshttps://github.com/enterprise
Teamhttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
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
See all industrieshttps://github.com/solutions/industry
Why GitHubhttps://github.com/why-github
Customer Storieshttps://github.com/customer-stories
Business insightshttps://github.com/solutions/executive-insights
Trust Centerhttps://github.com/trust-center
GitHub Advanced SecurityEnterprise-grade code securityhttps://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/enterprise/premium-support
Documentationhttps://docs.github.com/en
Resource centerhttps://github.com/resources
Bloghttps://github.blog/
Events & webinarshttps://github.com/resources/events
Community Forumhttps://github.com/orgs/community/discussions
Customer Storieshttps://github.com/customer-stories
Integrationshttps://github.com/marketplace
Customer supporthttps://help.github.com/
Traininghttps://learn.github.com/skills
GitHub Statushttps://www.githubstatus.com/
Abouthttps://github.com/about
Partnershttps://github.com/partners
Changeloghttps://github.blog/changelog/
GitHub UniverseThe event for developers, by developers — talks, workshops, and what’s next for GitHub.https://githubuniverse.com/
Pricinghttps://github.com/pricing
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fpull%2F124729%2Ffiles
Sign uphttps://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/124729/files
Reloadhttps://github.com/python/cpython/pull/124729/files
Reloadhttps://github.com/python/cpython/pull/124729/files
pythonhttps://github.com/python
cpythonhttps://github.com/python/cpython
Codehttps://github.com/python/cpython
Issues5k+ (5k+)https://github.com/python/cpython/issues
Pull requests2.4k (2.4k)https://github.com/python/cpython/pulls
Actionshttps://github.com/python/cpython/actions
Projectshttps://github.com/python/cpython/projects
Security and qualityhttps://github.com/python/cpython/security
Insightshttps://github.com/python/cpython/insights
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
vstinnerhttps://github.com/vstinner
python:mainhttps://github.com/python/cpython/tree/main
picnixz:curses/multiphase-module-123961https://github.com/picnixz/cpython/tree/curses/multiphase-module-123961
Conversation 24 https://github.com/python/cpython/pull/124729
Commits 39 https://github.com/python/cpython/pull/124729/commits
Checks 0 https://github.com/python/cpython/pull/124729/checks
Files changed https://github.com/python/cpython/pull/124729/files
Please reload this pagehttps://github.com/python/cpython/pull/124729/files
gh-123961: move PyCursesError in _cursesmodule.c to a global state variable https://github.com/python/cpython/pull/124729/files#top
Show all changes 39 commits https://github.com/python/cpython/pull/124729/files
3148d86 Introduce module's state and logic. picnixz Sep 28, 2024 https://github.com/python/cpython/pull/124729/commits/3148d86f6058beb15cac8ea35974b9e50ad58f5d
75bd7b6 Store exception in the module's state. picnixz Sep 28, 2024 https://github.com/python/cpython/pull/124729/commits/75bd7b63e8d1dcdbacd9467e958c24048711aa0d
b295919 Rename `curses_destructor` to `_curses_capi_destructor` picnixz Sep 28, 2024 https://github.com/python/cpython/pull/124729/commits/b29591902a374d625f4b859159a76faf37f3fef0
1665f38 Introduce macros for initialization checks. picnixz Sep 28, 2024 https://github.com/python/cpython/pull/124729/commits/1665f381b548c6c252cc6e9b778a675a1f181324
2a1e13a Update C API functions picnixz Sep 28, 2024 https://github.com/python/cpython/pull/124729/commits/2a1e13a0e312efb5813a6addb24b6f9b48452973
9e29bd5 Update macros checking the functions being called. picnixz Sep 28, 2024 https://github.com/python/cpython/pull/124729/commits/9e29bd52d3eb752e265d3b64ebd605c8c3ec76f0
e1cab2f Update `PyCursesCheckERR` to use the module's state picnixz Sep 28, 2024 https://github.com/python/cpython/pull/124729/commits/e1cab2f8daf5e5ce400f1014a1797841b5d62082
5f28eb8 Add `PyCursesCheckERR_FromSelf` to prepare when the type is a heap type. picnixz Sep 28, 2024 https://github.com/python/cpython/pull/124729/commits/5f28eb86cf7c7452e668a911f656525289fd3718
bcbbdd4 Update Function Prototype Macros. picnixz Sep 28, 2024 https://github.com/python/cpython/pull/124729/commits/bcbbdd49cc54193006692a21554802a73b580772
faf4e87 Update Function Body Macros. picnixz Sep 28, 2024 https://github.com/python/cpython/pull/124729/commits/faf4e874fcea15f129b862acae5f74a14771ef20
885c94c Update `PyCursesCheckERR` usage for Window methods picnixz Sep 28, 2024 https://github.com/python/cpython/pull/124729/commits/885c94c41b02925bd49057ef17926cb9bd44cc84
da98de4 Update `PyCursesCheckERR` usage for module's methods picnixz Sep 28, 2024 https://github.com/python/cpython/pull/124729/commits/da98de4be8a0464139d13e995ded368dd3401200
65c5f60 Update global references to `PyCursesError` picnixz Sep 28, 2024 https://github.com/python/cpython/pull/124729/commits/65c5f600e0daa851ee719b2282629bc11da83c47
e3e1131 Make `PyCursesWindow_Type` a heap type. picnixz Sep 28, 2024 https://github.com/python/cpython/pull/124729/commits/e3e1131fdde6ffe62206f7fcb671cb1a342ecad3
9617f50 Correct calls to `PyCursesWindow_New` picnixz Sep 28, 2024 https://github.com/python/cpython/pull/124729/commits/9617f50e80df95d240e0ec5b8f31a5d2fd0320de
1db7bea Do not expose `PyCursesWindow_Check` when compiling `_cursesmodule.c` picnixz Sep 28, 2024 https://github.com/python/cpython/pull/124729/commits/1db7bea875a11b284f54f88f1792cde31b48d551
4c207d3 Finalize multi-phase initialization for `curses`. picnixz Sep 28, 2024 https://github.com/python/cpython/pull/124729/commits/4c207d34896625650544f01131646846139e61cb
228348c Remove redundant cast to `PyObject *`. picnixz Sep 28, 2024 https://github.com/python/cpython/pull/124729/commits/228348c812a78e723d07981be36ea26d8f66d597
b8b0751 reduce diff (remove some PEP-7 changes) picnixz Sep 28, 2024 https://github.com/python/cpython/pull/124729/commits/b8b0751807a3b3dfa55febf475366cf2c531ce3a
83fab15 reduce diff (remove some PEP-7 changes) picnixz Sep 28, 2024 https://github.com/python/cpython/pull/124729/commits/83fab158eba2b25c73e65d91c64cdc4d149894ea
9ff69e4 Revert "Finalize multi-phase initialization for `curses`." picnixz Sep 28, 2024 https://github.com/python/cpython/pull/124729/commits/9ff69e426e0f087858d23411e51e5fc857ef9a8f
13bd868 Revert "Introduce module's state and logic." picnixz Sep 28, 2024 https://github.com/python/cpython/pull/124729/commits/13bd86876b3d35cbf16b1f09f06f8e21bf0e5dc7
f32dee9 Revert "Make `PyCursesWindow_Type` a heap type." picnixz Sep 28, 2024 https://github.com/python/cpython/pull/124729/commits/f32dee9ca27a852d883c7276cfe46fdf948cfeb1
fd38850 address Victor's review picnixz Sep 28, 2024 https://github.com/python/cpython/pull/124729/commits/fd388508befbfc8d88b82abcb13ad563300c390a
e70175c Revert "Remove redundant cast to `PyObject *`." picnixz Sep 28, 2024 https://github.com/python/cpython/pull/124729/commits/e70175cfbaf5abe394c974b722d50d9d0c303f67
676d1ce reduce diff picnixz Sep 28, 2024 https://github.com/python/cpython/pull/124729/commits/676d1cefcb0b2ca582f39771a3842f9d025aaa44
8a60d53 reduce diff picnixz Sep 28, 2024 https://github.com/python/cpython/pull/124729/commits/8a60d53a9429ae35c21fff74bb7850948b740cf8
e0dfc4a fix globals picnixz Sep 28, 2024 https://github.com/python/cpython/pull/124729/commits/e0dfc4ad06e0b380d6c69ba9f3cf2de752989750
e596924 fix globals picnixz Sep 28, 2024 https://github.com/python/cpython/pull/124729/commits/e596924d767a9adef280efc8e440460f09a6d53a
fc9dacb rename the state fields picnixz Sep 29, 2024 https://github.com/python/cpython/pull/124729/commits/fc9dacbf66013ade9c688d0434e0b861c3242603
f548f4b Introduce macros for initialization checks. picnixz Sep 29, 2024 https://github.com/python/cpython/pull/124729/commits/f548f4b0265c77bc73defff97de795529af27987
3e5c37c Update C API functions picnixz Sep 29, 2024 https://github.com/python/cpython/pull/124729/commits/3e5c37c02f4336315c3a4c9860fc6f7199e85320
b94438f Improve macros to use module's state when possible picnixz Sep 29, 2024 https://github.com/python/cpython/pull/124729/commits/b94438f2433bff6fbd90e7c3e11f2441f6dcd247
a4edf7e Merge branch 'curses/multiphase-module-123961' of github.com:picnixz/… picnixz Sep 29, 2024 https://github.com/python/cpython/pull/124729/commits/a4edf7e001d5a24eb2898530c529d6cff774db4e
b987499 Make use of module's state whenever possible. picnixz Sep 29, 2024 https://github.com/python/cpython/pull/124729/commits/b98749925a7158a4ba40e88ded08db75f10d94cd
e8d9d66 Make use of module's state whenever possible. picnixz Sep 29, 2024 https://github.com/python/cpython/pull/124729/commits/e8d9d665c23060aec075d33ef827e24bf9e2d24d
b02e860 remove unused function for now picnixz Sep 29, 2024 https://github.com/python/cpython/pull/124729/commits/b02e8603838e0ca2b013ee5a8ccb9d77e15f33d7
439a63f address Victor's review picnixz Sep 29, 2024 https://github.com/python/cpython/pull/124729/commits/439a63fa48cf46908d8736049a57ea8e64291542
3936143 fix test picnixz Sep 29, 2024 https://github.com/python/cpython/pull/124729/commits/3936143d9b0b357b251c9073b43502f2554b0d01
Clear filters https://github.com/python/cpython/pull/124729/files
Please reload this pagehttps://github.com/python/cpython/pull/124729/files
Please reload this pagehttps://github.com/python/cpython/pull/124729/files
py_curses.h https://github.com/python/cpython/pull/124729/files#diff-20c11bc93fa13e7529837bd28f4f11045ed1d68df5e532fe7695d3fa720c0660
_cursesmodule.c https://github.com/python/cpython/pull/124729/files#diff-f77a12c8531c26a47799058e7b02fd9b43753a458b5ed1cefc6693685aa098ce
globals-to-fix.tsv https://github.com/python/cpython/pull/124729/files#diff-8d1e9a0d5771dfc3a628047509e2d4a1027327bd89392e5a3ec5fbd3d08cfa19
Include/py_curses.hhttps://github.com/python/cpython/pull/124729/files#diff-20c11bc93fa13e7529837bd28f4f11045ed1d68df5e532fe7695d3fa720c0660
View file https://github.com/picnixz/cpython/blob/3936143d9b0b357b251c9073b43502f2554b0d01/Include/py_curses.h
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/python/cpython/pull/124729/{{ revealButtonHref }}
https://github.com/python/cpython/pull/124729/files#diff-20c11bc93fa13e7529837bd28f4f11045ed1d68df5e532fe7695d3fa720c0660
https://github.com/python/cpython/pull/124729/files#diff-20c11bc93fa13e7529837bd28f4f11045ed1d68df5e532fe7695d3fa720c0660
https://github.com/python/cpython/pull/124729/files#diff-20c11bc93fa13e7529837bd28f4f11045ed1d68df5e532fe7695d3fa720c0660
Please reload this pagehttps://github.com/python/cpython/pull/124729/files
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

Response headers:
Servergithub.com
Content-Typetext/html; charset=utf-8
Cache-Controlno-cache

Viewport: width=device-width


URLs of crawlers that visited me.