Author: Armin Rigo <[email protected]>
Branch: 
Changeset: r66044:8ac4abd50746
Date: 2013-08-09 18:47 +0200
http://bitbucket.org/pypy/pypy/changeset/8ac4abd50746/

Log:    PyNumber_Int and PyNumber_Long also accept strings. As a better
        approximation than previously, they can be written as the direct
        equivalent to the app-level "int(x)" or "long(x)".

diff --git a/pypy/module/cpyext/number.py b/pypy/module/cpyext/number.py
--- a/pypy/module/cpyext/number.py
+++ b/pypy/module/cpyext/number.py
@@ -41,13 +41,13 @@
 def PyNumber_Int(space, w_obj):
     """Returns the o converted to an integer object on success, or NULL on 
failure.
     This is the equivalent of the Python expression int(o)."""
-    return space.int(w_obj)
+    return space.call_function(space.w_int, w_obj)
 
 @cpython_api([PyObject], PyObject)
 def PyNumber_Long(space, w_obj):
     """Returns the o converted to a long integer object on success, or NULL on
     failure.  This is the equivalent of the Python expression long(o)."""
-    return space.long(w_obj)
+    return space.call_function(space.w_long, w_obj)
 
 @cpython_api([PyObject], PyObject)
 def PyNumber_Index(space, w_obj):
diff --git a/pypy/module/cpyext/test/test_number.py 
b/pypy/module/cpyext/test/test_number.py
--- a/pypy/module/cpyext/test/test_number.py
+++ b/pypy/module/cpyext/test/test_number.py
@@ -19,6 +19,8 @@
     def test_number_long(self, space, api):
         w_l = api.PyNumber_Long(space.wrap(123))
         assert api.PyLong_CheckExact(w_l)
+        w_l = api.PyNumber_Long(space.wrap("123"))
+        assert api.PyLong_CheckExact(w_l)
 
     def test_number_int(self, space, api):
         w_l = api.PyNumber_Int(space.wraplong(123L))
@@ -27,6 +29,8 @@
         assert api.PyLong_CheckExact(w_l)
         w_l = api.PyNumber_Int(space.wrap(42.3))
         assert api.PyInt_CheckExact(w_l)
+        w_l = api.PyNumber_Int(space.wrap("42"))
+        assert api.PyInt_CheckExact(w_l)
 
     def test_number_index(self, space, api):
         w_l = api.PyNumber_Index(space.wraplong(123L))
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to