Title: Clarify pickle `__reduce__()` behavior when a string is returned (singleton support). · Issue #148669 · python/cpython · GitHub
Open Graph Title: Clarify pickle `__reduce__()` behavior when a string is returned (singleton support). · Issue #148669 · python/cpython
X Title: Clarify pickle `__reduce__()` behavior when a string is returned (singleton support). · Issue #148669 · python/cpython
Description: Documentation The documentation about __reduce__() mentions: cpython/Doc/library/pickle.rst Lines 693 to 696 in 2a07ff9 If a string is returned, the string should be interpreted as the name of a global variable. It should be the object's...
Open Graph Description: Documentation The documentation about __reduce__() mentions: cpython/Doc/library/pickle.rst Lines 693 to 696 in 2a07ff9 If a string is returned, the string should be interpreted as the name of a gl...
X Description: Documentation The documentation about __reduce__() mentions: cpython/Doc/library/pickle.rst Lines 693 to 696 in 2a07ff9 If a string is returned, the string should be interpreted as the name of a gl...
Opengraph URL: https://github.com/python/cpython/issues/148669
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Clarify pickle `__reduce__()` behavior when a string is returned (singleton support).","articleBody":"### Documentation\n\nThe documentation about [`__reduce__()`](https://docs.python.org/3/library/pickle.html#object.__reduce__) mentions:\n\nhttps://github.com/python/cpython/blob/2a07ff980b412559f6cedafd432118684faa8d09/Doc/library/pickle.rst?plain=1#L693-L696\n\nIt is unclear what _the pickle module searches the module namespace to determine the object's module_ means, in particular whether for a specific `obj` to be pickled, the object's `__module__` is used (i.e. `obj.__module__`) or the module of the object's type (i.e. `type(obj).__module__`).\n\nWhile in most cases, it would be expected to look up on the class (as the `__module__` attribute is only [documented as being set on a class or function](https://docs.python.org/3/library/stdtypes.html#definition.__module__)), the current implementation does the attribute lookup on the object:\n\nhttps://github.com/python/cpython/blob/2a07ff980b412559f6cedafd432118684faa8d09/Lib/pickle.py#L336-L339\n\nThis behavior isn't clearly documented, but is relied on in multiple places, e.g. to [pickle functions](https://github.com/python/cpython/blob/2a07ff980b412559f6cedafd432118684faa8d09/Lib/pickle.py#L1270), [`TypeVar` instances](https://github.com/python/cpython/blob/2a07ff980b412559f6cedafd432118684faa8d09/Objects/typevarobject.c#L825-L835), the draft [PEP 661 implementation](https://github.com/JelleZijlstra/cpython/pull/4/changes#diff-68301e09a7fa43b9e8dfe94fb7b248c80db53503fde34d24566d66b8eaa274f8R104-R109) (and I believe [types themselves](https://github.com/python/cpython/blob/2a07ff980b412559f6cedafd432118684faa8d09/Lib/pickle.py#L597-L601)?)\n\nThis issue can be seen as a sub-issue of https://github.com/python/cpython/issues/60455.\n\nOriginal discussion about PEP 611 Sentinels can be found here: https://discuss.python.org/t/9126/262.\n\nI will have a PR up shortly.\n\n\u003c!-- gh-linked-prs -->\n### Linked PRs\n* gh-148670\n* gh-149703\n* gh-149704\n* gh-149705\n\u003c!-- /gh-linked-prs -->\n","author":{"url":"https://github.com/Viicos","@type":"Person","name":"Viicos"},"datePublished":"2026-04-17T09:01:40Z","url":"https://github.com/python/cpython/issues/148669"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| 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:c87d7caa-e7f6-ad2d-9de2-1bf726e113ac |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | BCA4:317608:39C1433:4929195:6B01F35A |
| html-safe-nonce | c0aaa4cc83137a8300e23f2f5023abf33d7db28eabc41902250641471e9d5454 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCQ0E0OjMxNzYwODozOUMxNDMzOjQ5MjkxOTU6NkIwMUYzNUEiLCJ2aXNpdG9yX2lkIjoiODE1Mjg2OTQzMTc0MDA2ODY5OCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 3ef192f3ddeae4d4db756547efe4949f6515c5df10e3121c09194b2525804d03 |
| hovercard-subject-tag | issue:4281395385 |
| 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/148669/issue_layout |
| twitter:image | https://opengraph.githubassets.com/d72b70a7b0d52fc1bd8cdcf58b879effa4e15841aadfe89c0f4208c522342e1c/python/cpython/issues/148669 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/d72b70a7b0d52fc1bd8cdcf58b879effa4e15841aadfe89c0f4208c522342e1c/python/cpython/issues/148669 |
| og:image:alt | Documentation The documentation about __reduce__() mentions: cpython/Doc/library/pickle.rst Lines 693 to 696 in 2a07ff9 If a string is returned, the string should be interpreted as the name of a gl... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | Viicos |
| hostname | github.com |
| expected-hostname | github.com |
| None | 87e774ee7c6b3bee0490394e4d3e57ec9dbc956f74b87ea685dc8996c1676456 |
| 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 | 423dbb54c5e7bfecc838eb387c1435eb3d0e760d |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width