Skip to content

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

Closed

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

  1. added
    type-bug
    extension-modules
    on Oct 31, 2025
  2. serhiy-storchaka commented on Oct 31, 2025

    @serhiy-storchaka
    Member

    Since this never worked as documented in Python 3 (it worked in Python 2), I think that this can be classified as a new feature for 3.15 and a documentation issue for older versions.

  3. added 2 commits that reference this issue on Nov 3, 2025
  4. added a commit that references this issue on Nov 4, 2025
  5. added 2 commits that reference this issue on Nov 4, 2025
  6. added a commit that references this issue on Nov 6, 2025
  7. added a commit that references this issue on Nov 7, 2025
  8. added a commit that references this issue on Nov 7, 2025
  9. added a commit that references this issue on Nov 7, 2025
  10. serhiy-storchaka commented on Nov 7, 2025

    @serhiy-storchaka
    Member

    Thank you for your contribution @aisk.

  11. added a commit that references this issue on Nov 7, 2025
  12. added 2 commits that reference this issue on Dec 6, 2025
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

    OS-windowsextension-modulestype-bug

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions