Title: weakrefobject.c: binary, ternary, or comparison operations ref leak with dead proxy · Issue #153058 · python/cpython · GitHub
Open Graph Title: weakrefobject.c: binary, ternary, or comparison operations ref leak with dead proxy · Issue #153058 · python/cpython
X Title: weakrefobject.c: binary, ternary, or comparison operations ref leak with dead proxy · Issue #153058 · python/cpython
Description: Bug report Bug description: Original gist: https://gist.github.com/devdanzin/f7d0c7694b2be2345f4cf85f4eedc3ee Summary When first UNWRAP(x) succeeds but second UNWRAP(y) fails (dead proxy), x's new reference is leaked. Affects ~20 binary ...
Open Graph Description: Bug report Bug description: Original gist: https://gist.github.com/devdanzin/f7d0c7694b2be2345f4cf85f4eedc3ee Summary When first UNWRAP(x) succeeds but second UNWRAP(y) fails (dead proxy), x's new ...
X Description: Bug report Bug description: Original gist: https://gist.github.com/devdanzin/f7d0c7694b2be2345f4cf85f4eedc3ee Summary When first UNWRAP(x) succeeds but second UNWRAP(y) fails (dead proxy), x's ...
Opengraph URL: https://github.com/python/cpython/issues/153058
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"weakrefobject.c: binary, ternary, or comparison operations ref leak with dead proxy","articleBody":"# Bug report\n\n### Bug description:\n\nOriginal gist: https://gist.github.com/devdanzin/f7d0c7694b2be2345f4cf85f4eedc3ee\n\n\n\u003e ## Summary\n\u003e \n\u003e When first `UNWRAP(x)` succeeds but second `UNWRAP(y)` fails (dead proxy), `x`'s new reference is leaked. Affects ~20 binary operators (+, -, *, /, |, \u0026, ^, etc.).\n\u003e \n\u003e ## Reproducer\n\u003e \n\u003e ```python\n\u003e import weakref, sys, gc\n\u003e \n\u003e class C:\n\u003e def __add__(self, other): return NotImplemented\n\u003e def __radd__(self, other): return NotImplemented\n\u003e \n\u003e obj = type('D', (), {})()\n\u003e dead = weakref.proxy(obj)\n\u003e del obj; gc.collect()\n\u003e \n\u003e live_obj = C()\n\u003e live = weakref.proxy(live_obj)\n\u003e \n\u003e before = sys.gettotalrefcount()\n\u003e for i in range(10000):\n\u003e try:\n\u003e live + dead\n\u003e except ReferenceError:\n\u003e pass\n\u003e after = sys.gettotalrefcount()\n\u003e print(f\"Leaked {after - before} refs (~{(after-before)//10000}/call)\")\n\u003e ```\n\nActually, ternary, or comparison operations have the same problem.\n\n### CPython versions tested on:\n\nCPython main branch\n\n### Operating systems tested on:\n\n_No response_\n\n\u003c!-- gh-linked-prs --\u003e\n### Linked PRs\n* gh-153059\n\u003c!-- /gh-linked-prs --\u003e\n","author":{"url":"https://github.com/aisk","@type":"Person","name":"aisk"},"datePublished":"2026-07-05T02:52:01.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":0},"url":"https://github.com/153058/cpython/issues/153058"}
| 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:67e8c774-2821-1338-3873-60995ee32ab9 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | B46A:48B83:453C8C6:60020A3:6A50C9A6 |
| html-safe-nonce | 5ebd668cbfb6929cb588016ce9b4c136656ae92757537c8ad278759d062063ae |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCNDZBOjQ4QjgzOjQ1M0M4QzY6NjAwMjBBMzo2QTUwQzlBNiIsInZpc2l0b3JfaWQiOiI3OTUwMjgxNjY5ODI2NjI4MDA2IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | d4e4cc610d838c0bc7eae90a80a16750f04db3369df618bbfe6c1d499fa315af |
| hovercard-subject-tag | issue:4811393682 |
| 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/153058/issue_layout |
| twitter:image | https://opengraph.githubassets.com/0bdd068e5fb0a8eb08a2dde64c0d3584072d2cccef8ee0c5e04c649d2cc0f5f5/python/cpython/issues/153058 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/0bdd068e5fb0a8eb08a2dde64c0d3584072d2cccef8ee0c5e04c649d2cc0f5f5/python/cpython/issues/153058 |
| og:image:alt | Bug report Bug description: Original gist: https://gist.github.com/devdanzin/f7d0c7694b2be2345f4cf85f4eedc3ee Summary When first UNWRAP(x) succeeds but second UNWRAP(y) fails (dead proxy), x's new ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | aisk |
| hostname | github.com |
| expected-hostname | github.com |
| None | 72b13e0e8d0319acdd27a145cfe73f4f06c791713d0ac4690e41fb68ad28cac0 |
| 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 | 08e79d53fc070870d5b168356afebb1e286a2ffe |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width