Skip to content

The comparison behavior of winreg.HKEYType is inconsistent with its documentation #140826

Description

@aisk

Bug report

Bug description:

There is the document for winreg.HKEYType:

The object also support comparison semantics, so handle objects will compare
true if they both reference the same underlying Windows handle value.

But the winreg.HKEYType don't have a custom compare implementation, so it will be compared by id.

And there is a compare function in the codebase, which actually is a dead code, and still compared by id:

cpython/PC/winreg.c

Lines 184 to 191 in 81cec22

static int
PyHKEY_compareFunc(PyObject *ob1, PyObject *ob2)
{
PyHKEYObject *pyhkey1 = (PyHKEYObject *)ob1;
PyHKEYObject *pyhkey2 = (PyHKEYObject *)ob2;
return pyhkey1 == pyhkey2 ? 0 :
(pyhkey1 < pyhkey2 ? -1 : 1);
}

CPython versions tested on:

CPython main branch

Operating systems tested on:

Windows

Linked PRs

Activity

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

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions