Skip to content

C API: Remove deprecated PyBytesObject.ob_shash member, or remove the deprecation #158074

Description

@vstinner

@methane deprecated PyBytesObject.ob_shash member in Python 3.11 with commit 2d8b764 and the instruction: "Use PyObject_Hash() instead."

We are now at Python 3.16, 5 releases later. So should we remove PyBytesObject.ob_shash member? Or should we keep it just remove the deprecation and keep the member (forever)?

Cython uses it in 3 places:

Cython/Utility/ModuleSetupCode.c:    long hash = ((PyStringObject *) name)->ob_shash;
Cython/Utility/Optimize.c:        Py_hash_t hash1 = ((PyBytesObject*)s1)->ob_shash;
Cython/Utility/Optimize.c:        Py_hash_t hash2 = ((PyBytesObject*)s2)->ob_shash;

In PyPI top 15,000 projects (at 2026-09-17), I found 8 projects by searching for ob_shash:

  • cython (3.3.0)
  • gevent (26.9.0)
  • nuitka (4.2.1)
  • ptvsd (4.3.2)
  • pydevd (3.5.0)
  • pydevd_pycharm (263.4732.31)
  • pygments (2.21.0)
  • pyjson5 (2.0.1)

This number is low, so I think that it would be acceptable to remove the member.

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