()
| 361 | |
| 362 | |
| 363 | def test_numpy_int_convert(): |
| 364 | np = pytest.importorskip("numpy") |
| 365 | |
| 366 | convert, noconvert = m.int_passthrough, m.int_passthrough_noconvert |
| 367 | |
| 368 | def require_implicit(v): |
| 369 | pytest.raises(TypeError, noconvert, v) |
| 370 | |
| 371 | # `np.intc` is an alias that corresponds to a C++ `int` |
| 372 | assert convert(np.intc(42)) == 42 |
| 373 | assert noconvert(np.intc(42)) == 42 |
| 374 | |
| 375 | # The implicit conversion from np.float32 is undesirable but currently accepted. |
| 376 | # TODO: Avoid DeprecationWarning in `PyLong_AsLong` (and similar) |
| 377 | # TODO: PyPy 3.8 does not behave like CPython 3.8 here yet (7.3.7) |
| 378 | # https://github.com/pybind/pybind11/issues/3408 |
| 379 | if (3, 8) <= sys.version_info < (3, 10) and env.CPYTHON: |
| 380 | with pytest.deprecated_call(): |
| 381 | assert convert(np.float32(3.14159)) == 3 |
| 382 | else: |
| 383 | assert convert(np.float32(3.14159)) == 3 |
| 384 | require_implicit(np.float32(3.14159)) |
| 385 | |
| 386 | |
| 387 | def test_tuple(doc): |
nothing calls this directly
no test coverage detected