[pypy-commit] pypy py3k: fix generic extraction of optional fields

pjenvey noreply at buildbot.pypy.org
Tue Aug 26 20:06:00 CEST 2014


Author: Philip Jenvey <pjenvey at underboss.org>
Branch: py3k
Changeset: r73072:f82f65bb5aec
Date: 2014-08-26 11:03 -0700
http://bitbucket.org/pypy/pypy/changeset/f82f65bb5aec/

Log:	fix generic extraction of optional fields

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
@@ -153,7 +153,10 @@
         elif field.type.value in ("bool",):
             return "space.bool_w(%s)" % (value,)
         else:
-            return "%s.from_object(space, %s)" % (field.type, value)
+            extractor = "%s.from_object(space, %s)" % (field.type, value)
+            if field.opt:
+                extractor += " if %s is not None else None" % (value,)
+            return extractor
 
     def get_field_converter(self, field):
         if field.seq:


More information about the pypy-commit mailing list