Skip to content

Commit ee1fb1b

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

File tree

5 files changed

+7
-6
lines changed

5 files changed

+7
-6
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/requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ numpy==1.16.6; python_version<"3.6" and sys_platform!="win32" and platform_pytho
22
numpy==1.19.0; platform_python_implementation=="PyPy" and sys_platform=="linux" and python_version=="3.6"
33
numpy==1.20.0; platform_python_implementation=="PyPy" and sys_platform=="linux" and python_version=="3.7"
44
numpy==1.19.3; platform_python_implementation!="PyPy" and python_version=="3.6"
5-
numpy==1.21.3; platform_python_implementation!="PyPy" and python_version>="3.7"
5+
numpy==1.21.3; platform_python_implementation!="PyPy" and python_version>="3.7" and python_version<"3.11"
66
py @ git+https://github.com/pytest-dev/py; python_version>="3.11"
77
pytest==4.6.9; python_version<"3.5"
88
pytest==6.1.2; python_version=="3.5"

tests/test_buffers.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ def test_to_python():
6262
assert cstats.alive() == 1
6363
del mat2 # holds a mat reference
6464
pytest.gc_collect()
65+
pytest.gc_collect() # Needed for PyPy
6566
assert cstats.alive() == 0
6667
assert cstats.values() == ["5x4 matrix"]
6768
assert cstats.copy_constructions == 0

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:

tests/test_embed/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ if("${PYTHON_MODULE_EXTENSION}" MATCHES "pypy" OR "${Python_INTERPRETER_ID}" STR
77
return()
88
endif()
99

10-
find_package(Catch 2.13.2)
10+
find_package(Catch 2.13.7)
1111

1212
if(CATCH_FOUND)
1313
message(STATUS "Building interpreter tests using Catch v${CATCH_VERSION}")

0 commit comments

Comments
 (0)