Author: Richard Plangger <[email protected]>
Branch: py3.5-async
Changeset: r86138:3c775a43b9af
Date: 2016-08-11 12:44 +0200
http://bitbucket.org/pypy/pypy/changeset/3c775a43b9af/
Log: several changes for translation renamed argument name in
Python.asdl, will resolve an issue for the new type singleton which
is an object correctly emitting from/to_object for singleton and
bytes type check for generator added commented old validation code
for starargs varargannotation ...
diff --git a/pypy/interpreter/astcompiler/ast.py
b/pypy/interpreter/astcompiler/ast.py
--- a/pypy/interpreter/astcompiler/ast.py
+++ b/pypy/interpreter/astcompiler/ast.py
@@ -16,7 +16,7 @@
if not (space.isinstance_w(w_obj, space.w_str) or
space.isinstance_w(w_obj, space.w_unicode)):
raise oefmt(space.w_TypeError,
- "AST string must be of type str or unicode")
+ "AST string must be of type str or unicode")
return w_obj
def get_field(space, w_node, name, optional):
@@ -2568,7 +2568,7 @@
def to_object(self, space):
w_node = space.call_function(get(space).w_Bytes)
- w_s = self.s.to_object(space) # bytes
+ w_s = self.s # bytes
space.setattr(w_node, space.wrap('s'), w_s)
w_lineno = space.wrap(self.lineno) # int
space.setattr(w_node, space.wrap('lineno'), w_lineno)
@@ -2581,7 +2581,7 @@
w_s = get_field(space, w_node, 's', False)
w_lineno = get_field(space, w_node, 'lineno', False)
w_col_offset = get_field(space, w_node, 'col_offset', False)
- _s = bytes.from_object(space, w_s)
+ _s = check_string(space, w_s)
if _s is None:
raise_required_value(space, w_node, 's')
_lineno = space.int_w(w_lineno)
@@ -2593,8 +2593,8 @@
class NameConstant(expr):
- def __init__(self, value, lineno, col_offset):
- self.value = value
+ def __init__(self, single, lineno, col_offset):
+ self.single = single
expr.__init__(self, lineno, col_offset)
def walkabout(self, visitor):
@@ -2605,8 +2605,8 @@
def to_object(self, space):
w_node = space.call_function(get(space).w_NameConstant)
- w_value = self.value.to_object(space) # singleton
- space.setattr(w_node, space.wrap('value'), w_value)
+ w_single = self.single # singleton
+ space.setattr(w_node, space.wrap('single'), w_single)
w_lineno = space.wrap(self.lineno) # int
space.setattr(w_node, space.wrap('lineno'), w_lineno)
w_col_offset = space.wrap(self.col_offset) # int
@@ -2615,17 +2615,17 @@
@staticmethod
def from_object(space, w_node):
- w_value = get_field(space, w_node, 'value', False)
+ w_single = get_field(space, w_node, 'single', False)
w_lineno = get_field(space, w_node, 'lineno', False)
w_col_offset = get_field(space, w_node, 'col_offset', False)
- _value = singleton.from_object(space, w_value)
- if _value is None:
- raise_required_value(space, w_node, 'value')
+ _single = w_single
+ if _single is None:
+ raise_required_value(space, w_node, 'single')
_lineno = space.int_w(w_lineno)
_col_offset = space.int_w(w_col_offset)
- return NameConstant(_value, _lineno, _col_offset)
-
-State.ast_type('NameConstant', 'expr', ['value'])
+ return NameConstant(_single, _lineno, _col_offset)
+
+State.ast_type('NameConstant', 'expr', ['single'])
class Ellipsis(expr):
@@ -2952,8 +2952,8 @@
class Const(expr):
- def __init__(self, value, lineno, col_offset):
- self.value = value
+ def __init__(self, obj, lineno, col_offset):
+ self.obj = obj
expr.__init__(self, lineno, col_offset)
def walkabout(self, visitor):
@@ -2964,8 +2964,8 @@
def to_object(self, space):
w_node = space.call_function(get(space).w_Const)
- w_value = self.value # object
- space.setattr(w_node, space.wrap('value'), w_value)
+ w_obj = self.obj # object
+ space.setattr(w_node, space.wrap('obj'), w_obj)
w_lineno = space.wrap(self.lineno) # int
space.setattr(w_node, space.wrap('lineno'), w_lineno)
w_col_offset = space.wrap(self.col_offset) # int
@@ -2974,17 +2974,17 @@
@staticmethod
def from_object(space, w_node):
- w_value = get_field(space, w_node, 'value', False)
+ w_obj = get_field(space, w_node, 'obj', False)
w_lineno = get_field(space, w_node, 'lineno', False)
w_col_offset = get_field(space, w_node, 'col_offset', False)
- _value = w_value
- if _value is None:
- raise_required_value(space, w_node, 'value')
+ _obj = w_obj
+ if _obj is None:
+ raise_required_value(space, w_node, 'obj')
_lineno = space.int_w(w_lineno)
_col_offset = space.int_w(w_col_offset)
- return Const(_value, _lineno, _col_offset)
-
-State.ast_type('Const', 'expr', ['value'])
+ return Const(_obj, _lineno, _col_offset)
+
+State.ast_type('Const', 'expr', ['obj'])
class expr_context(AST):
diff --git a/pypy/interpreter/astcompiler/asthelpers.py
b/pypy/interpreter/astcompiler/asthelpers.py
--- a/pypy/interpreter/astcompiler/asthelpers.py
+++ b/pypy/interpreter/astcompiler/asthelpers.py
@@ -152,7 +152,7 @@
def as_node_list(self, space):
try:
- values_w = space.unpackiterable(self.value)
+ values_w = space.unpackiterable(self.obj)
except OperationError:
return None
line = self.lineno
diff --git a/pypy/interpreter/astcompiler/codegen.py
b/pypy/interpreter/astcompiler/codegen.py
--- a/pypy/interpreter/astcompiler/codegen.py
+++ b/pypy/interpreter/astcompiler/codegen.py
@@ -1047,7 +1047,7 @@
def visit_Const(self, const):
self.update_position(const.lineno)
- self.load_const(const.value)
+ self.load_const(const.obj)
def visit_Ellipsis(self, e):
self.load_const(self.space.w_Ellipsis)
diff --git a/pypy/interpreter/astcompiler/optimize.py
b/pypy/interpreter/astcompiler/optimize.py
--- a/pypy/interpreter/astcompiler/optimize.py
+++ b/pypy/interpreter/astcompiler/optimize.py
@@ -65,7 +65,7 @@
class __extend__(ast.Const):
def as_constant(self):
- return self.value
+ return self.obj
class __extend__(ast.Index):
def as_constant(self):
diff --git a/pypy/interpreter/astcompiler/tools/Python.asdl
b/pypy/interpreter/astcompiler/tools/Python.asdl
--- a/pypy/interpreter/astcompiler/tools/Python.asdl
+++ b/pypy/interpreter/astcompiler/tools/Python.asdl
@@ -71,7 +71,8 @@
| Num(object n) -- a number as a PyObject.
| Str(string s) -- need to specify raw, unicode, etc?
| Bytes(bytes s)
- | NameConstant(singleton value)
+ -- PyPy mod. first argument name must not be value
+ | NameConstant(singleton single)
| Ellipsis
-- the following expression can appear in assignment context
@@ -83,7 +84,7 @@
| Tuple(expr* elts, expr_context ctx)
-- PyPy modification
- | Const(object value)
+ | Const(object obj)
-- col_offset is the byte offset in the utf8 string the parser uses
attributes (int lineno, int col_offset)
diff --git a/pypy/interpreter/astcompiler/tools/asdl_py.py
b/pypy/interpreter/astcompiler/tools/asdl_py.py
--- a/pypy/interpreter/astcompiler/tools/asdl_py.py
+++ b/pypy/interpreter/astcompiler/tools/asdl_py.py
@@ -130,7 +130,7 @@
if field.opt:
wrapper += " if %s is not None else space.w_None" % (value,)
return wrapper
- elif field.type in ("object", "string"):
+ elif field.type in ("object", "singleton", "string", "bytes"):
return value
elif field.type in ("int", "bool"):
return "space.wrap(%s)" % (value,)
@@ -145,9 +145,9 @@
def get_value_extractor(self, field, value):
if field.type in self.data.simple_types:
return "%s.from_object(space, %s)" % (field.type, value)
- elif field.type in ("object",):
+ elif field.type in ("object","singleton"):
return value
- elif field.type in ("string",):
+ elif field.type in ("string","bytes"):
return "check_string(space, %s)" % (value,)
elif field.type in ("identifier",):
if field.opt:
diff --git a/pypy/interpreter/astcompiler/validate.py
b/pypy/interpreter/astcompiler/validate.py
--- a/pypy/interpreter/astcompiler/validate.py
+++ b/pypy/interpreter/astcompiler/validate.py
@@ -152,15 +152,15 @@
def visit_arguments(self, node):
self.visit_sequence(node.args)
- if node.varargannotation:
- if not node.vararg:
- raise ValidationError("varargannotation but no vararg on
arguments")
- self._validate_expr(node.varargannotation)
+ # XXX py3.5 missing if node.varargannotation:
+ # XXX py3.5 missing if not node.vararg:
+ # XXX py3.5 missing raise ValidationError("varargannotation
but no vararg on arguments")
+ # XXX py3.5 missing self._validate_expr(node.varargannotation)
self.visit_sequence(node.kwonlyargs)
- if node.kwargannotation:
- if not node.kwarg:
- raise ValidationError("kwargannotation but no kwarg on
arguments")
- self._validate_expr(node.kwargannotation)
+ # XXX py3.5 missing if node.kwargannotation:
+ # XXX py3.5 missing if not node.kwarg:
+ # XXX py3.5 missing raise ValidationError("kwargannotation but
no kwarg on arguments")
+ # XXX py3.5 missing self._validate_expr(node.kwargannotation)
if self._len(node.defaults) > self._len(node.args):
raise ValidationError("more positional defaults than args on
arguments")
if self._len(node.kw_defaults) != self._len(node.kwonlyargs):
@@ -184,10 +184,10 @@
self._validate_exprs(node.bases)
self.visit_sequence(node.keywords)
self._validate_exprs(node.decorator_list)
- if node.starargs:
- self._validate_expr(node.starargs)
- if node.kwargs:
- self._validate_expr(node.kwargs)
+ # XXX py3.5 missing if node.starargs:
+ # XXX py3.5 missing self._validate_expr(node.starargs)
+ # XXX py3.5 missing if node.kwargs:
+ # XXX py3.5 missing self._validate_expr(node.kwargs)
def visit_Return(self, node):
if node.value:
@@ -373,10 +373,10 @@
self._validate_expr(node.func)
self._validate_exprs(node.args)
self.visit_sequence(node.keywords)
- if node.starargs:
- self._validate_expr(node.starargs)
- if node.kwargs:
- self._validate_expr(node.kwargs)
+ # XXX py3.5 missing if node.starargs:
+ # XXX py3.5 missing self._validate_expr(node.starargs)
+ # XXX py3.5 missing if node.kwargs:
+ # XXX py3.5 missing self._validate_expr(node.kwargs)
def visit_Num(self, node):
space = self.space
diff --git a/pypy/interpreter/generator.py b/pypy/interpreter/generator.py
--- a/pypy/interpreter/generator.py
+++ b/pypy/interpreter/generator.py
@@ -316,7 +316,8 @@
res = space.get_and_call_function(w_await, self)
if res is not None:
if (isinstance(res, Coroutine) or
- res.pycode.co_flags & consts.CO_ITERABLE_COROUTINE):
+ (isinstance(res, GeneratorIterator) and \
+ res.pycode.co_flags & consts.CO_ITERABLE_COROUTINE)):
raise oefmt(space.w_TypeError,
"__await__() returned a coroutine")
elif space.lookup(self, "__next__") is None:
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit