Commits

Maciej Fijalkowski  committed b1537cf

fix translation (maybe)

  • Participants
  • Parent commits a87df44

Comments (0)

Files changed (4)

File pypy/interpreter/function.py

     assert not func.can_change_code
     return func.code
 
-
 class Function(W_Root):
     """A function is a code object captured with some environment:
     an object space, a dictionary of globals, default arguments,

File pypy/interpreter/gateway.py

     d = {}
     exec func_code.compile() in d
     f = d['f']
+    f.__module__ = func.__module__
+    # necessary for unique identifiers for pickling
     f.func_name = func.func_name
     if unwrap_spec is None:
         unwrap_spec = {}

File pypy/objspace/std/floatobject.py

 import operator
-from pypy.interpreter import gateway
 from pypy.interpreter.error import OperationError
 from pypy.objspace.std import model, newformat
+from pypy.objspace.std.floattype import float_typedef, W_AbstractFloatObject
 from pypy.objspace.std.multimethod import FailedToImplementArgs
 from pypy.objspace.std.model import registerimplementation, W_Object
 from pypy.objspace.std.register_all import register_all
 import math
 from pypy.objspace.std.intobject import W_IntObject
 
-class W_AbstractFloatObject(W_Object):
-    __slots__ = ()
-
-    def is_w(self, space, w_other):
-        from rpython.rlib.longlong2float import float2longlong
-        if not isinstance(w_other, W_AbstractFloatObject):
-            return False
-        if self.user_overridden_class or w_other.user_overridden_class:
-            return self is w_other
-        one = float2longlong(space.float_w(self))
-        two = float2longlong(space.float_w(w_other))
-        return one == two
-
-    def immutable_unique_id(self, space):
-        if self.user_overridden_class:
-            return None
-        from rpython.rlib.longlong2float import float2longlong
-        from pypy.objspace.std.model import IDTAG_FLOAT as tag
-        val = float2longlong(space.float_w(self))
-        b = rbigint.fromrarith_int(val)
-        b = b.lshift(3).or_(rbigint.fromint(tag))
-        return space.newlong_from_rbigint(b)
-
 
 class W_FloatObject(W_AbstractFloatObject):
     """This is a implementation of the app-level 'float' type.
     The constructor takes an RPython float as an argument."""
-    from pypy.objspace.std.floattype import float_typedef as typedef
     _immutable_fields_ = ['floatval']
 
+    typedef = float_typedef
+
     def __init__(w_self, floatval):
         w_self.floatval = floatval
 
         return self.floatval
 
     def int(self, space):
+        if (type(self) is not W_FloatObject and
+            space.is_overloaded(self, space.w_float, '__int__')):
+            return W_Object.int(self, space)
         try:
             value = ovfcheck_float_to_int(self.floatval)
         except OverflowError:

File pypy/objspace/std/floattype.py

 from rpython.rlib.unroll import unrolling_iterable
 from rpython.rlib import rfloat, rarithmetic
 from pypy.interpreter import typedef
-from pypy.interpreter.gateway import interp2app, unwrap_spec, WrappedDefault
-from pypy.interpreter.baseobjspace import ObjSpace, W_Root
+from pypy.interpreter.gateway import interp2app, unwrap_spec, WrappedDefault,\
+     interpindirect2app
 from pypy.interpreter.error import OperationError
 from pypy.objspace.std.register_all import register_all
 from pypy.objspace.std.stdtypedef import StdTypeDef, SMM
 from pypy.objspace.std.strutil import ParseStringError
 from pypy.objspace.std.strutil import string_to_float
+from pypy.objspace.std.model import W_Object
+from rpython.rlib.rbigint import rbigint
 
 
 float_as_integer_ratio = SMM("as_integer_ratio", 1)
 
 # ____________________________________________________________
 
+class W_AbstractFloatObject(W_Object):
+    __slots__ = ()
+
+    def is_w(self, space, w_other):
+        from rpython.rlib.longlong2float import float2longlong
+        if not isinstance(w_other, W_AbstractFloatObject):
+            return False
+        if self.user_overridden_class or w_other.user_overridden_class:
+            return self is w_other
+        one = float2longlong(space.float_w(self))
+        two = float2longlong(space.float_w(w_other))
+        return one == two
+
+    def immutable_unique_id(self, space):
+        if self.user_overridden_class:
+            return None
+        from rpython.rlib.longlong2float import float2longlong
+        from pypy.objspace.std.model import IDTAG_FLOAT as tag
+        val = float2longlong(space.float_w(self))
+        b = rbigint.fromrarith_int(val)
+        b = b.lshift(3).or_(rbigint.fromint(tag))
+        return space.newlong_from_rbigint(b)
+
+    def int(self, space):
+        raise NotImplementedError
+
 float_typedef = StdTypeDef("float",
     __doc__ = '''float(x) -> floating point number
 
     conjugate = interp2app(descr_conjugate),
     real = typedef.GetSetProperty(descr_get_real),
     imag = typedef.GetSetProperty(descr_get_imag),
+    __int__ = interpindirect2app(W_AbstractFloatObject.int),
 )
 float_typedef.registermethods(globals())