[pypy-svn] r75812 - in pypy/branch/fast-forward/pypy/objspace/std: . test

benjamin at codespeak.net benjamin at codespeak.net
Sat Jul 3 01:46:10 CEST 2010


Author: benjamin
Date: Sat Jul  3 01:46:09 2010
New Revision: 75812

Modified:
   pypy/branch/fast-forward/pypy/objspace/std/inttype.py
   pypy/branch/fast-forward/pypy/objspace/std/longtype.py
   pypy/branch/fast-forward/pypy/objspace/std/test/test_intobject.py
   pypy/branch/fast-forward/pypy/objspace/std/test/test_longobject.py
Log:
give int and long numerator and denominator attributes

Modified: pypy/branch/fast-forward/pypy/objspace/std/inttype.py
==============================================================================
--- pypy/branch/fast-forward/pypy/objspace/std/inttype.py	(original)
+++ pypy/branch/fast-forward/pypy/objspace/std/inttype.py	Sat Jul  3 01:46:09 2010
@@ -1,4 +1,4 @@
-from pypy.interpreter import gateway
+from pypy.interpreter import gateway, typedef
 from pypy.interpreter.error import OperationError
 from pypy.objspace.std.stdtypedef import StdTypeDef
 from pypy.objspace.std.strutil import (string_to_int, string_to_w_long,
@@ -134,6 +134,12 @@
         W_IntObject.__init__(w_obj, value)
         return w_obj
 
+def descr_get_numerator(space, w_obj):
+    return space.int(w_obj)
+
+def descr_get_denominator(space, w_obj):
+    return space.wrap(1)
+
 # ____________________________________________________________
 
 int_typedef = StdTypeDef("int",
@@ -146,4 +152,6 @@
 non-string. If the argument is outside the integer range a long object
 will be returned instead.''',
     __new__ = gateway.interp2app(descr__new__),
+    numerator = typedef.GetSetProperty(descr_get_numerator),
+    denominator = typedef.GetSetProperty(descr_get_denominator),
     )

Modified: pypy/branch/fast-forward/pypy/objspace/std/longtype.py
==============================================================================
--- pypy/branch/fast-forward/pypy/objspace/std/longtype.py	(original)
+++ pypy/branch/fast-forward/pypy/objspace/std/longtype.py	Sat Jul  3 01:46:09 2010
@@ -1,5 +1,5 @@
 from pypy.interpreter.error import OperationError
-from pypy.interpreter import gateway
+from pypy.interpreter import gateway, typedef
 from pypy.objspace.std.stdtypedef import StdTypeDef
 from pypy.objspace.std.strutil import string_to_w_long, ParseStringError
 
@@ -65,6 +65,12 @@
     W_LongObject.__init__(w_obj, w_value.num)
     return w_obj
 
+def descr_get_numerator(space, w_obj):
+    return space.long(w_obj)
+
+def descr_get_denominator(space, w_obj):
+    return space.newlong(1)
+
 # ____________________________________________________________
 
 long_typedef = StdTypeDef("long",
@@ -76,4 +82,6 @@
 string, use the optional base.  It is an error to supply a base when
 converting a non-string.''',
     __new__ = gateway.interp2app(descr__new__),
+    numerator = typedef.GetSetProperty(descr_get_numerator),
+    denominator = typedef.GetSetProperty(descr_get_denominator),
     )

Modified: pypy/branch/fast-forward/pypy/objspace/std/test/test_intobject.py
==============================================================================
--- pypy/branch/fast-forward/pypy/objspace/std/test/test_intobject.py	(original)
+++ pypy/branch/fast-forward/pypy/objspace/std/test/test_intobject.py	Sat Jul  3 01:46:09 2010
@@ -293,6 +293,12 @@
     def test_int_callable(self):
         assert 43 == int(43)
 
+    def test_numerator_denominator(self):
+        assert (1).numerator == 1
+        assert (1).denominator == 1
+        assert (42).numerator == 42
+        assert (42).denominator == 1
+
     def test_int_string(self):
         assert 42 == int("42")
         assert 10000000000 == long("10000000000")

Modified: pypy/branch/fast-forward/pypy/objspace/std/test/test_longobject.py
==============================================================================
--- pypy/branch/fast-forward/pypy/objspace/std/test/test_longobject.py	(original)
+++ pypy/branch/fast-forward/pypy/objspace/std/test/test_longobject.py	Sat Jul  3 01:46:09 2010
@@ -65,6 +65,12 @@
         a = 31415926L // 10000000L
         assert a == 3L
 
+    def test_numerator_denominator(self):
+        assert (1L).numerator == 1L
+        assert (1L).denominator == 1L
+        assert (42L).numerator == 42L
+        assert (42L).denominator == 1L
+
     def test_compare(self):
         for BIG in (1L, 1L << 62, 1L << 9999):
             assert 0 == 0L



More information about the Pypy-commit mailing list