Skip to content
This repository was archived by the owner on Dec 9, 2025. It is now read-only.

Commit fcb666d

Browse files
habermancopybara-github
authored andcommitted
Fixed comparison of maps in Python.
The `__eq__` method from our base class was not getting called, because we defined `tp_hash` as `NotImplemented`. Per [the docs on `tp_hash`](https://docs.python.org/3/c-api/typeobj.html#c.PyTypeObject.tp_hash), `tp_hash` and `tp_richcompare` are inherited together, so defining `tp_hash` was inhibiting the inheritance of `tp_richcompare`. PiperOrigin-RevId: 465184018
1 parent 79b735a commit fcb666d

1 file changed

Lines changed: 0 additions & 2 deletions

File tree

python/map.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,6 @@ static PyType_Slot PyUpb_ScalarMapContainer_Slots[] = {
386386
{Py_tp_methods, PyUpb_ScalarMapContainer_Methods},
387387
{Py_tp_iter, PyUpb_MapIterator_New},
388388
{Py_tp_repr, PyUpb_MapContainer_Repr},
389-
{Py_tp_hash, PyObject_HashNotImplemented},
390389
{0, NULL},
391390
};
392391

@@ -432,7 +431,6 @@ static PyType_Slot PyUpb_MessageMapContainer_Slots[] = {
432431
{Py_tp_methods, PyUpb_MessageMapContainer_Methods},
433432
{Py_tp_iter, PyUpb_MapIterator_New},
434433
{Py_tp_repr, PyUpb_MapContainer_Repr},
435-
{Py_tp_hash, PyObject_HashNotImplemented},
436434
{0, NULL}};
437435

438436
static PyType_Spec PyUpb_MessageMapContainer_Spec = {

0 commit comments

Comments
 (0)