[pypy-svn] r17592 - in pypy/dist/pypy/interpreter/pyparser: . test

ac at codespeak.net ac at codespeak.net
Fri Sep 16 13:38:17 CEST 2005


Author: ac
Date: Fri Sep 16 13:38:17 2005
New Revision: 17592

Modified:
   pypy/dist/pypy/interpreter/pyparser/astbuilder.py
   pypy/dist/pypy/interpreter/pyparser/test/test_astbuilder.py
   pypy/dist/pypy/interpreter/pyparser/test/test_astcompiler.py
Log:
Change strategy for creating numeric constants in order
to be more compliant.



Modified: pypy/dist/pypy/interpreter/pyparser/astbuilder.py
==============================================================================
--- pypy/dist/pypy/interpreter/pyparser/astbuilder.py	(original)
+++ pypy/dist/pypy/interpreter/pyparser/astbuilder.py	Fri Sep 16 13:38:17 2005
@@ -1594,9 +1594,6 @@
         """temporary implementation
         eval_number intends to replace number = eval(value) ; return number
         """
-        from pypy.objspace.std.strutil import string_to_int, string_to_float
-        from pypy.objspace.std.strutil import string_to_w_long, interp_string_to_float
-        from pypy.objspace.std.strutil import ParseStringError
         space = self.space
         base = 10
         if value.startswith("0x") or value.startswith("0X"):
@@ -1604,15 +1601,17 @@
         elif value.startswith("0"):
             base = 8
         if value.endswith('l') or value.endswith('L'):
-            value = value[:-1]
-            return string_to_w_long( space, value, base=base )
+            l = space.builtin.get('long')
+            return space.call_function(l, space.wrap(value), space.wrap(base))
         if value.endswith('j') or value.endswith('J'):
             c = space.builtin.get('complex') 
             return space.call_function(c, space.wrap(value))
         try:
-            return space.wrap(string_to_int(value, base=base))
-        except ParseStringError:
-            return space.wrap(interp_string_to_float(space,value))
+            i = space.builtin.get('int')
+            return space.call_function(i, space.wrap(value), space.wrap(base))
+        except: 
+            f = space.builtin.get('float')
+            return space.call_function(f, space.wrap(value))
 
     def is_string_const(self, expr):
         if not isinstance(expr,ast.Const):

Modified: pypy/dist/pypy/interpreter/pyparser/test/test_astbuilder.py
==============================================================================
--- pypy/dist/pypy/interpreter/pyparser/test/test_astbuilder.py	(original)
+++ pypy/dist/pypy/interpreter/pyparser/test/test_astbuilder.py	Fri Sep 16 13:38:17 2005
@@ -11,8 +11,6 @@
 
 from pypy.interpreter.astcompiler import ast
 
-from pypy.objspace.std import objspace
-
 def arglist_equal(left,right):
     """needs special case because we handle the argumentlist differently"""
     for l,r in zip(left,right):
@@ -93,6 +91,8 @@
     "3.9",
     "-3.6",
     "1.8e19",
+    "90000000000000",
+    "90000000000000.",
     "3j"
     ]
 
@@ -499,6 +499,7 @@
     ]
 
 TESTS = [
+    constants,
     expressions,
     augassigns,
     comparisons,
@@ -580,9 +581,14 @@
     def call_method(self, obj, meth, *args):
         return getattr(obj, meth)(*args)
 
-def ast_parse_expr(expr, target='single', space=FakeSpace):
+    def call_function(self, func, *args):
+        return func(*args)
+
+    builtin = dict(int=int, long=long, float=float, complex=complex)
+
+def ast_parse_expr(expr, target='single'):
     target = TARGET_DICT[target]
-    builder = AstBuilder(space=space())
+    builder = AstBuilder(space=FakeSpace())
     PYTHON_PARSER.parse_source(expr, target, builder)
     return builder
 
@@ -610,14 +616,6 @@
         for expr in family:
             yield check_expression, expr, 'exec'
 
-def check_constant(expr):
-    ast_parse_expr(expr, 'single', objspace.StdObjSpace)
-    
-def test_constants():
-    for expr in constants:
-        yield check_constant, expr
-
-
 SNIPPETS = [    
     'snippet_1.py',
     'snippet_several_statements.py',
@@ -633,9 +631,7 @@
     'snippet_2.py',
     'snippet_3.py',
     'snippet_4.py',
-    # XXX: skip snippet_comment because we don't have a replacement of
-    #      eval for numbers and strings (eval_number('0x1L') fails)
-    # 'snippet_comment.py',
+    'snippet_comment.py',
     'snippet_encoding_declaration2.py',
     'snippet_encoding_declaration3.py',
     'snippet_encoding_declaration.py',

Modified: pypy/dist/pypy/interpreter/pyparser/test/test_astcompiler.py
==============================================================================
--- pypy/dist/pypy/interpreter/pyparser/test/test_astcompiler.py	(original)
+++ pypy/dist/pypy/interpreter/pyparser/test/test_astcompiler.py	Fri Sep 16 13:38:17 2005
@@ -17,12 +17,13 @@
     listmakers, genexps, dictmakers, multiexpr, attraccess, slices, imports,\
     asserts, execs, prints, globs, raises_, imports_newstyle, augassigns, \
     if_stmts, one_stmt_classdefs, one_stmt_funcdefs, tryexcepts, docstrings, \
-    returns, SNIPPETS, SINGLE_INPUTS, LIBSTUFF
+    returns, SNIPPETS, SINGLE_INPUTS, LIBSTUFF, constants
 
 from test_astbuilder import FakeSpace
 
 
 TESTS = [
+    constants,
     expressions,
     augassigns,
     comparisons,



More information about the Pypy-commit mailing list