GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — `code_richcompare` swallows errors · Issue #146199 · python/cpython

code_richcompare swallows errors #146199

New issue
Copy link
New issue
Copy link
Closed
Closed
code_richcompare swallows errors#146199
Copy link
Labels
extension-modulesC modules in the Modules dirC modules in the Modules dirtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

Description

@brijkapadia
brijkapadia
opened on Mar 20, 2026
Issue body actions

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 . Reproducer:

class BadStr(str):
    _armed = False
    def __eq__(self, other):
        if BadStr._armed and isinstance(other, str) and str.__eq__(self, other):
            raise RuntimeError("Poison!")
        return str.__eq__(self, other)
    def __hash__(self): return str.__hash__(self)

c1 = compile("pass", "test", "exec")
c2 = c1.replace(co_name=BadStr("poison"))
c3 = compile("pass", "poison", "exec")
BadStr._armed = True
c2 == c3  # assertion: !_PyErr_Occurred(tstate)

CPython versions tested on:

CPython main branch

Operating systems tested on:

Linux

Linked PRs

  • gh-146199: Fix error handling in code_richcompare when PyObject_RichCompareBool fails #146200

Activity

  1. brijkapadia
    added
    type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
    on Mar 20, 2026
  2. brijkapadia
    added a commit that references this issue on Mar 20, 2026

    pythongh-146199: Fix error handling in `code_richcompare` when `PyObj…

    a388f88
  3. aisk
    added
    extension-modulesC modules in the Modules dirC modules in the Modules dir
    on Mar 20, 2026
  4. StanFromIreland
    added a parent issue on Mar 20, 2026
    • Umbrella issue: bugs found using cpython-review-toolkit #146102
  5. vstinner
    added a commit that references this issue on Mar 23, 2026

    gh-146199: Fix error handling in `code_richcompare` when `PyObject_Ri…

    e017971
  6. vstinner
    closed this as completedon Mar 23, 2026
  7. CuriousLearner
    added a commit that references this issue on Mar 24, 2026

    Merge branch 'fix-pythongh-138577' of github.com:CuriousLearner/cpyth…

    78b2c6a
  8. clin1234
    added a commit that references this issue on Apr 16, 2026

    pythongh-146199: Fix error handling in `code_richcompare` when `PyObj…

    ff603dc
  9. ljfp
    added a commit that references this issue on Apr 25, 2026

    pythongh-146199: Fix error handling in `code_richcompare` when `PyObj…

    d24feb2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    extension-modulesC modules in the Modules dirC modules in the Modules dirtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402503 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.