Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup conditional assert #36543

Merged
merged 1 commit into from
Nov 5, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 0 additions & 31 deletions src/sage/cpython/dict_del_by_value.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -46,31 +46,6 @@ cdef extern from "dict_internal.h":
PyObject * me_key
PyObject * me_value


# dk_lookup was removed in python 3.11
DEF HAS_DK_LOOKUP = PY_VERSION_HEX < 0x30b0000

IF HAS_DK_LOOKUP:

cdef extern from *:
"""
#define DK_LOOKUP(dk) ((dk)->dk_lookup)
"""
ctypedef void * dict_lookup_func # Precise definition not needed
dict_lookup_func DK_LOOKUP(PyDictKeysObject *mp)

cdef dict_lookup_func lookdict

def init_lookdict():
global lookdict
# A dict which a non-string key uses the generic "lookdict"
# as lookup function
cdef object D = {}
D[0] = 0
lookdict = DK_LOOKUP((<PyDictObject *>D).ma_keys)

init_lookdict()

cdef int del_dictitem_by_exact_value(PyDictObject *mp, PyObject *value, Py_hash_t hash) except -1:
"""
This is used in callbacks for the weak values of :class:`WeakValueDictionary`.
Expand Down Expand Up @@ -147,12 +122,6 @@ cdef int del_dictitem_by_exact_value(PyDictObject *mp, PyObject *value, Py_hash_
return 0
ep = &(entries[ix])

# We need the lookup function to be the generic lookdict, otherwise
# deletions may not work correctly
IF HAS_DK_LOOKUP:
# Can this fail? In any case dk_lookup was removed in python 3.11
assert DK_LOOKUP(keys) is lookdict

T = PyList_New(2)
PyList_SetItem(T, 0, ep.me_key)
PyList_SetItem(T, 1, ep.me_value)
Expand Down
Loading