[pypy-commit] pypy default: Simplify misc.as_long()

arigo pypy.commits at gmail.com
Sat Sep 15 17:41:39 EDT 2018


Author: Armin Rigo <arigo at tunes.org>
Branch: 
Changeset: r95121:048ec4801682
Date: 2018-09-15 23:02 +0200
http://bitbucket.org/pypy/pypy/changeset/048ec4801682/

Log:	Simplify misc.as_long()

diff --git a/pypy/module/_cffi_backend/misc.py b/pypy/module/_cffi_backend/misc.py
--- a/pypy/module/_cffi_backend/misc.py
+++ b/pypy/module/_cffi_backend/misc.py
@@ -153,18 +153,9 @@
     # Same as as_long_long(), but returning an int instead.
     if space.isinstance_w(w_ob, space.w_int):  # shortcut
         return space.int_w(w_ob)
-    try:
-        bigint = space.bigint_w(w_ob, allow_conversion=False)
-    except OperationError as e:
-        if not e.match(space, space.w_TypeError):
-            raise
-        if _is_a_float(space, w_ob):
-            raise
-        bigint = space.bigint_w(space.int(w_ob), allow_conversion=False)
-    try:
-        return bigint.toint()
-    except OverflowError:
-        raise OperationError(space.w_OverflowError, space.newtext(ovf_msg))
+    if _is_a_float(space, w_ob):
+        space.bigint_w(w_ob, allow_conversion=False)   # raise the right error
+    return space.int_w(space.int(w_ob))
 
 def as_unsigned_long_long(space, w_ob, strict):
     # (possibly) convert and cast a Python object to an unsigned long long.


More information about the pypy-commit mailing list