Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

code_richcompare swallows errors #146199

Copy link
Copy link
@brijkapadia

Description

@brijkapadia
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

Reactions are currently unavailable

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
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.