Description: Fix a crash in the AST compiler
Origin: Upstream, https://bitbucket.org/pypy/pypy/commits/75ab5316ff3f
                  https://bitbucket.org/pypy/pypy/commits/27aa8184f00f
Author: Armin Rigo <arigo@tunes.org>

diff --git a/pypy/module/_ast/test/test_ast.py b/pypy/module/_ast/test/test_ast.py
--- a/pypy/module/_ast/test/test_ast.py
+++ b/pypy/module/_ast/test/test_ast.py
@@ -425,3 +425,8 @@
         str_node2 = copy.deepcopy(str_node)
         dict_res = str_node2.__dict__
         assert dict_res == {'n':2, 'lineno':2}
+
+    def test_bug_null_in_objspace_type(self):
+        import ast
+        code = ast.Expression(lineno=1, col_offset=1, body=ast.ListComp(lineno=1, col_offset=1, elt=ast.Call(lineno=1, col_offset=1, func=ast.Name(lineno=1, col_offset=1, id='str', ctx=ast.Load(lineno=1, col_offset=1)), args=[ast.Name(lineno=1, col_offset=1, id='x', ctx=ast.Load(lineno=1, col_offset=1))], keywords=[]), generators=[ast.comprehension(lineno=1, col_offset=1, target=ast.Name(lineno=1, col_offset=1, id='x', ctx=ast.Store(lineno=1, col_offset=1)), iter=ast.List(lineno=1, col_offset=1, elts=[ast.Num(lineno=1, col_offset=1, n=23)], ctx=ast.Load(lineno=1, col_offset=1, )), ifs=[])]))
+        compile(code, '<template>', 'eval')

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
@@ -22,9 +22,11 @@
 
 def get_field(space, w_node, name, optional):
     w_obj = w_node.getdictvalue(space, name)
-    if w_obj is None and not optional:
-        raise oefmt(space.w_TypeError,
+    if w_obj is None:
+        if not optional:
+            raise oefmt(space.w_TypeError,
                 "required field \"%s\" missing from %T", name, w_node)
+        w_obj = space.w_None
     return w_obj
 
 
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
@@ -405,9 +405,11 @@
 
 def get_field(space, w_node, name, optional):
     w_obj = w_node.getdictvalue(space, name)
-    if w_obj is None and not optional:
-        raise oefmt(space.w_TypeError,
+    if w_obj is None:
+        if not optional:
+            raise oefmt(space.w_TypeError,
                 "required field \"%s\" missing from %T", name, w_node)
+        w_obj = space.w_None
     return w_obj
 
 
