Author: Armin Rigo <[email protected]>
Branch: py3.5
Changeset: r86678:2039ed00c6cd
Date: 2016-08-29 11:50 +0200
http://bitbucket.org/pypy/pypy/changeset/2039ed00c6cd/
Log: Fix for test_kw_defaults_None
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
@@ -432,7 +432,7 @@
_body = [stmt.from_object(space, w_item) for w_item in body_w]
decorator_list_w = space.unpackiterable(w_decorator_list)
_decorator_list = [expr.from_object(space, w_item) for w_item in
decorator_list_w]
- _returns = expr.from_object(space, w_returns) if w_returns is not None
else None
+ _returns = expr.from_object(space, w_returns)
_lineno = space.int_w(w_lineno)
_col_offset = space.int_w(w_col_offset)
return FunctionDef(_name, _args, _body, _decorator_list, _returns,
_lineno, _col_offset)
@@ -508,7 +508,7 @@
_body = [stmt.from_object(space, w_item) for w_item in body_w]
decorator_list_w = space.unpackiterable(w_decorator_list)
_decorator_list = [expr.from_object(space, w_item) for w_item in
decorator_list_w]
- _returns = expr.from_object(space, w_returns) if w_returns is not None
else None
+ _returns = expr.from_object(space, w_returns)
_lineno = space.int_w(w_lineno)
_col_offset = space.int_w(w_col_offset)
return AsyncFunctionDef(_name, _args, _body, _decorator_list,
_returns, _lineno, _col_offset)
@@ -630,7 +630,7 @@
w_value = get_field(space, w_node, 'value', True)
w_lineno = get_field(space, w_node, 'lineno', False)
w_col_offset = get_field(space, w_node, 'col_offset', False)
- _value = expr.from_object(space, w_value) if w_value is not None else
None
+ _value = expr.from_object(space, w_value)
_lineno = space.int_w(w_lineno)
_col_offset = space.int_w(w_col_offset)
return Return(_value, _lineno, _col_offset)
@@ -1190,8 +1190,8 @@
w_cause = get_field(space, w_node, 'cause', True)
w_lineno = get_field(space, w_node, 'lineno', False)
w_col_offset = get_field(space, w_node, 'col_offset', False)
- _exc = expr.from_object(space, w_exc) if w_exc is not None else None
- _cause = expr.from_object(space, w_cause) if w_cause is not None else
None
+ _exc = expr.from_object(space, w_exc)
+ _cause = expr.from_object(space, w_cause)
_lineno = space.int_w(w_lineno)
_col_offset = space.int_w(w_col_offset)
return Raise(_exc, _cause, _lineno, _col_offset)
@@ -1314,7 +1314,7 @@
_test = expr.from_object(space, w_test)
if _test is None:
raise_required_value(space, w_node, 'test')
- _msg = expr.from_object(space, w_msg) if w_msg is not None else None
+ _msg = expr.from_object(space, w_msg)
_lineno = space.int_w(w_lineno)
_col_offset = space.int_w(w_col_offset)
return Assert(_test, _msg, _lineno, _col_offset)
@@ -2312,7 +2312,7 @@
w_value = get_field(space, w_node, 'value', True)
w_lineno = get_field(space, w_node, 'lineno', False)
w_col_offset = get_field(space, w_node, 'col_offset', False)
- _value = expr.from_object(space, w_value) if w_value is not None else
None
+ _value = expr.from_object(space, w_value)
_lineno = space.int_w(w_lineno)
_col_offset = space.int_w(w_col_offset)
return Yield(_value, _lineno, _col_offset)
@@ -3101,9 +3101,9 @@
w_lower = get_field(space, w_node, 'lower', True)
w_upper = get_field(space, w_node, 'upper', True)
w_step = get_field(space, w_node, 'step', True)
- _lower = expr.from_object(space, w_lower) if w_lower is not None else
None
- _upper = expr.from_object(space, w_upper) if w_upper is not None else
None
- _step = expr.from_object(space, w_step) if w_step is not None else None
+ _lower = expr.from_object(space, w_lower)
+ _upper = expr.from_object(space, w_upper)
+ _step = expr.from_object(space, w_step)
return Slice(_lower, _upper, _step)
State.ast_type('Slice', 'slice', ['lower', 'upper', 'step'])
@@ -3583,7 +3583,7 @@
w_body = get_field(space, w_node, 'body', False)
w_lineno = get_field(space, w_node, 'lineno', False)
w_col_offset = get_field(space, w_node, 'col_offset', False)
- _type = expr.from_object(space, w_type) if w_type is not None else None
+ _type = expr.from_object(space, w_type)
_name = space.str_or_None_w(w_name)
body_w = space.unpackiterable(w_body)
_body = [stmt.from_object(space, w_item) for w_item in body_w]
@@ -3664,12 +3664,12 @@
w_defaults = get_field(space, w_node, 'defaults', False)
args_w = space.unpackiterable(w_args)
_args = [arg.from_object(space, w_item) for w_item in args_w]
- _vararg = arg.from_object(space, w_vararg) if w_vararg is not None
else None
+ _vararg = arg.from_object(space, w_vararg) if not space.is_w(w_vararg,
space.w_None) else None
kwonlyargs_w = space.unpackiterable(w_kwonlyargs)
_kwonlyargs = [arg.from_object(space, w_item) for w_item in
kwonlyargs_w]
kw_defaults_w = space.unpackiterable(w_kw_defaults)
_kw_defaults = [expr.from_object(space, w_item) for w_item in
kw_defaults_w]
- _kwarg = arg.from_object(space, w_kwarg) if w_kwarg is not None else
None
+ _kwarg = arg.from_object(space, w_kwarg) if not space.is_w(w_kwarg,
space.w_None) else None
defaults_w = space.unpackiterable(w_defaults)
_defaults = [expr.from_object(space, w_item) for w_item in defaults_w]
return arguments(_args, _vararg, _kwonlyargs, _kw_defaults, _kwarg,
_defaults)
@@ -3705,7 +3705,7 @@
_arg = space.identifier_w(w_arg)
if _arg is None:
raise_required_value(space, w_node, 'arg')
- _annotation = expr.from_object(space, w_annotation) if w_annotation is
not None else None
+ _annotation = expr.from_object(space, w_annotation)
return arg(_arg, _annotation)
State.ast_type('arg', 'AST', ['arg', 'annotation'])
@@ -3805,7 +3805,7 @@
_context_expr = expr.from_object(space, w_context_expr)
if _context_expr is None:
raise_required_value(space, w_node, 'context_expr')
- _optional_vars = expr.from_object(space, w_optional_vars) if
w_optional_vars is not None else None
+ _optional_vars = expr.from_object(space, w_optional_vars)
return withitem(_context_expr, _optional_vars)
State.ast_type('withitem', 'AST', ['context_expr', 'optional_vars'])
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
@@ -160,7 +160,17 @@
else:
extractor = "%s.from_object(space, %s)" % (field.type, value)
if field.opt:
- extractor += " if %s is not None else None" % (value,)
+ if field.type == 'expr':
+ # the expr.from_object() method should accept w_None and
+ # return None; nothing more to do here
+ pass
+ elif field.type == 'arg':
+ # the method arg.from_object() doesn't accept w_None
+ extractor += (
+ ' if not space.is_w(%s, space.w_None) else None'
+ % (value,))
+ else:
+ raise NotImplementedError(field.type)
return extractor
def get_field_converter(self, field):
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit