Skip to content

Commit

Permalink
Python 3.13+ API - Replace PyMapping_HasKeyString with PyMapping_HasK…
Browse files Browse the repository at this point in the history
…eyStringWithError
  • Loading branch information
buffer committed Nov 20, 2024
1 parent 263dfef commit 9ebbd9f
Showing 1 changed file with 26 additions and 5 deletions.
31 changes: 26 additions & 5 deletions src/Wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,12 @@ v8::Intercepted CPythonObject::NamedGetter(v8::Local<v8::Name> prop, const v8::P
}

if (::PyMapping_Check(obj.ptr()) &&
::PyMapping_HasKeyString(obj.ptr(), *name))
#if PY_VERSION_EX >= 0x030d0000
::PyMapping_HasKeyStringWithError(obj.ptr(), *name) == 1
#else
::PyMapping_HasKeyString(obj.ptr(), *name)
#endif
)
{
py::object result(py::handle<>(::PyMapping_GetItemString(obj.ptr(), *name)));

Expand Down Expand Up @@ -423,7 +428,13 @@ v8::Intercepted CPythonObject::NamedQuery(v8::Local<v8::Name> prop, const v8::Pr

if (*name)
exists = PyGen_Check(obj.ptr()) || ::PyObject_HasAttrString(obj.ptr(), *name) ||
(::PyMapping_Check(obj.ptr()) && ::PyMapping_HasKeyString(obj.ptr(), *name));
(::PyMapping_Check(obj.ptr()) &&
#if PY_VERSION_EX >= 0x030d0000
::PyMapping_HasKeyStringWithError(obj.ptr(), *name) == 1
#else
::PyMapping_HasKeyString(obj.ptr(), *name)
#endif
);

if (exists)
CALLBACK_RETURN_HANDLED(v8::Integer::New(info.GetIsolate(), v8::None));
Expand All @@ -446,7 +457,12 @@ v8::Intercepted CPythonObject::NamedDeleter(v8::Local<v8::Name> prop, const v8::

if (!::PyObject_HasAttrString(obj.ptr(), *name) &&
::PyMapping_Check(obj.ptr()) &&
::PyMapping_HasKeyString(obj.ptr(), *name))
#if PY_VERSION_EX >= 0x030d0000
::PyMapping_HasKeyStringWithError(obj.ptr(), *name) == 1
#else
::PyMapping_HasKeyString(obj.ptr(), *name)
#endif
)
{
CALLBACK_RETURN_HANDLED(-1 != ::PyMapping_DelItemString(obj.ptr(), *name));
}
Expand Down Expand Up @@ -646,8 +662,13 @@ v8::Intercepted CPythonObject::IndexedQuery(uint32_t index, const v8::PropertyCa

snprintf(buf, sizeof(buf), "%d", index);

if (::PyMapping_HasKeyString(obj.ptr(), buf) ||
::PyMapping_HasKey(obj.ptr(), py::long_(index).ptr()))
if (
#if PY_VERSION_EX >= 0x030d0000
::PyMapping_HasKeyStringWithError(obj.ptr(), buf) == 1
#else
::PyMapping_HasKeyString(obj.ptr(), buf)
#endif
|| ::PyMapping_HasKey(obj.ptr(), py::long_(index).ptr()))
{
CALLBACK_RETURN_HANDLED(v8::Integer::New(info.GetIsolate(), v8::None));
}
Expand Down

0 comments on commit 9ebbd9f

Please sign in to comment.