Title: `code_richcompare` swallows errors · Issue #146199 · python/cpython · GitHub
Open Graph Title: `code_richcompare` swallows errors · Issue #146199 · python/cpython
X Title: `code_richcompare` swallows errors · Issue #146199 · python/cpython
Description: Bug report Bug description: This is a sub-issue for #146102 and more details can be found here. In code_richcompare on line 2608, PyObject_RichCompareBool can return an error (-1), but that is treated incorrectly since !(-1) == 0 . Repro...
Open Graph Description: Bug report Bug description: This is a sub-issue for #146102 and more details can be found here. In code_richcompare on line 2608, PyObject_RichCompareBool can return an error (-1), but that is trea...
X Description: Bug report Bug description: This is a sub-issue for #146102 and more details can be found here. In code_richcompare on line 2608, PyObject_RichCompareBool can return an error (-1), but that is trea...
Opengraph URL: https://github.com/python/cpython/issues/146199
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"`code_richcompare` swallows errors","articleBody":"# Bug report\n\n### Bug description:\n\n\nThis is a sub-issue for #146102 and more details can be found [here](https://gist.github.com/devdanzin/d602d174ce2b8959759c94729a35c54e).\n\n---\nIn `code_richcompare` on line 2608, `PyObject_RichCompareBool` can return an error (-1), but that is treated incorrectly since `!(-1) == 0 `. Reproducer:\n```python\n\nclass BadStr(str):\n _armed = False\n def __eq__(self, other):\n if BadStr._armed and isinstance(other, str) and str.__eq__(self, other):\n raise RuntimeError(\"Poison!\")\n return str.__eq__(self, other)\n def __hash__(self): return str.__hash__(self)\n\nc1 = compile(\"pass\", \"test\", \"exec\")\nc2 = c1.replace(co_name=BadStr(\"poison\"))\nc3 = compile(\"pass\", \"poison\", \"exec\")\nBadStr._armed = True\nc2 == c3 # assertion: !_PyErr_Occurred(tstate)\n```\n\n### CPython versions tested on:\n\nCPython main branch\n\n### Operating systems tested on:\n\nLinux\n\n\u003c!-- gh-linked-prs --\u003e\n### Linked PRs\n* gh-146200\n\u003c!-- /gh-linked-prs --\u003e\n","author":{"url":"https://github.com/brijkapadia","@type":"Person","name":"brijkapadia"},"datePublished":"2026-03-20T10:31:15.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":0},"url":"https://github.com/146199/cpython/issues/146199"}
| 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:cf794f9b-7ef8-e987-e188-25d5ce86bfc4 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | C19C:2362FD:A93C0A1:ACB9D47:6A50B911 |
| html-safe-nonce | 059cb7f745e4e967d78cb61adf7ea4d2b2985880ba3b34c8f042dc644c0c03d6 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDMTlDOjIzNjJGRDpBOTNDMEExOkFDQjlENDc6NkE1MEI5MTEiLCJ2aXNpdG9yX2lkIjoiODEyNjYzMTQ5Nzk5MjAyNjM4NSIsInJlZ2lvbl9lZGdlIjoic2VhIiwicmVnaW9uX3JlbmRlciI6InNlYSJ9 |
| visitor-hmac | 4d44195f14d3f9cbc81e5a3f64b8c6a06fe1a2517183d7ade4a0ba66f042be56 |
| hovercard-subject-tag | issue:4107096196 |
| 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/146199/issue_layout |
| twitter:image | https://opengraph.githubassets.com/07b8843d53c021b133e83b2778af52488eea4d7ccc93692fe7bbe68a4983df57/python/cpython/issues/146199 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/07b8843d53c021b133e83b2778af52488eea4d7ccc93692fe7bbe68a4983df57/python/cpython/issues/146199 |
| og:image:alt | Bug report Bug description: This is a sub-issue for #146102 and more details can be found here. In code_richcompare on line 2608, PyObject_RichCompareBool can return an error (-1), but that is trea... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | brijkapadia |
| hostname | github.com |
| expected-hostname | github.com |
| None | 63772747707af4093f0d5fc7aa1bb3bb55f412a9865207c4f421aa34c64cc404 |
| 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 | ded53fe94e3ff1bb4dbf8cc77e285396c92580fb |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width