mirror of
https://github.com/pybind/pybind11.git
synced 2026-04-20 06:49:25 +00:00
object_api: support the number protocol
This commit revamps the object_api class so that it maps most C++ operators to their Python analogs. This makes it possible to, e.g. perform arithmetic using a py::int_ or py::array.
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
from __future__ import division
|
||||
import pytest
|
||||
import sys
|
||||
|
||||
@@ -238,3 +239,10 @@ def test_hash():
|
||||
assert m.hash_function(Hashable(42)) == 42
|
||||
with pytest.raises(TypeError):
|
||||
m.hash_function(Unhashable())
|
||||
|
||||
|
||||
def test_number_protocol():
|
||||
for a, b in [(1, 1), (3, 5)]:
|
||||
li = [a == b, a != b, a < b, a <= b, a > b, a >= b, a + b,
|
||||
a - b, a * b, a / b, a | b, a & b, a ^ b, a >> b, a << b]
|
||||
assert m.test_number_protocol(a, b) == li
|
||||
|
||||
Reference in New Issue
Block a user