Skip to content

Commit 2abb0d4

Browse files
committed
fix: better PyPy support
1 parent c82bbaa commit 2abb0d4

File tree

3 files changed

+5
-4
lines changed

3 files changed

+5
-4
lines changed

include/pybind11/eval.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ PYBIND11_NAMESPACE_BEGIN(PYBIND11_NAMESPACE)
1919
PYBIND11_NAMESPACE_BEGIN(detail)
2020

2121
inline void ensure_builtins_in_globals(object &global) {
22-
#if PY_VERSION_HEX < 0x03080000
22+
#if defined(PYPY_VERSION) || PY_VERSION_HEX < 0x03080000
2323
// Running exec and eval on Python 2 and 3 adds `builtins` module under
2424
// `__builtins__` key to globals if not yet present.
2525
// Python 3.8 made PyRun_String behave similarly. Let's also do that for
26-
// older versions, for consistency.
26+
// older versions, for consistency. This was missing from PyPy3.8 7.3.7.
2727
if (!global.contains("__builtins__"))
2828
global["__builtins__"] = module_::import(PYBIND11_BUILTINS_MODULE);
2929
#else

tests/test_buffers.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ def test_to_python():
5959
assert cstats.alive() == 1
6060
del mat
6161
pytest.gc_collect()
62+
pytest.gc_collect() # Needed for PyPy
6263
assert cstats.alive() == 1
6364
del mat2 # holds a mat reference
6465
pytest.gc_collect()

tests/test_builtin_casters.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ def cant_convert(v):
299299
assert noconvert(7) == 7
300300
cant_convert(3.14159)
301301
# TODO: Avoid DeprecationWarning in `PyLong_AsLong` (and similar)
302-
if (3, 8) <= env.PY < (3, 10):
302+
if (3, 8) <= env.PY < (3, 10) and env.CPYTHON:
303303
with env.deprecated_call():
304304
assert convert(Int()) == 42
305305
else:
@@ -334,7 +334,7 @@ def require_implicit(v):
334334

335335
# The implicit conversion from np.float32 is undesirable but currently accepted.
336336
# TODO: Avoid DeprecationWarning in `PyLong_AsLong` (and similar)
337-
if (3, 8) <= env.PY < (3, 10):
337+
if (3, 8) <= env.PY < (3, 10) and env.CPYTHON:
338338
with env.deprecated_call():
339339
assert convert(np.float32(3.14159)) == 3
340340
else:

0 commit comments

Comments
 (0)