Author: Armin Rigo <[email protected]>
Branch: cpyext-ext
Changeset: r82566:f112de2bd0fa
Date: 2016-02-26 15:22 +0100
http://bitbucket.org/pypy/pypy/changeset/f112de2bd0fa/
Log: (fijal, arigo) nb_float
diff --git a/pypy/module/cpyext/slotdefs.py b/pypy/module/cpyext/slotdefs.py
--- a/pypy/module/cpyext/slotdefs.py
+++ b/pypy/module/cpyext/slotdefs.py
@@ -349,6 +349,10 @@
return space.int(w_self)
@cpython_api([PyObject], PyObject, header=None)
+def slot_nb_float(space, w_self):
+ return space.float(w_self)
+
+@cpython_api([PyObject], PyObject, header=None)
def slot_tp_iter(space, w_self):
return space.iter(w_self)
diff --git a/pypy/module/cpyext/test/test_typeobject.py
b/pypy/module/cpyext/test/test_typeobject.py
--- a/pypy/module/cpyext/test/test_typeobject.py
+++ b/pypy/module/cpyext/test/test_typeobject.py
@@ -488,6 +488,24 @@
assert module.nb_int(-12.3) == -12
raises(ValueError, module.nb_int, "123")
+ def test_nb_float(self):
+ module = self.import_extension('foo', [
+ ("nb_float", "METH_O",
+ '''
+ if (!args->ob_type->tp_as_number ||
+ !args->ob_type->tp_as_number->nb_float)
+ {
+ PyErr_SetNone(PyExc_ValueError);
+ return NULL;
+ }
+ return args->ob_type->tp_as_number->nb_float(args);
+ '''
+ )
+ ])
+ assert module.nb_float(10) == 10.0
+ assert module.nb_float(-12.3) == -12.3
+ raises(ValueError, module.nb_float, "123")
+
def test_tp_call(self):
module = self.import_extension('foo', [
("tp_call", "METH_VARARGS",
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit