[pypy-dev] Bug report: AST stage crash in PyPy3.5

hubo hubo at jiedaibao.com
Fri Jul 27 06:18:07 EDT 2018


In PyPy 3.5, the following small piece of code cannot be imported, and causes a SystemError:

def test(*a: lambda x: None):
    pass

Stderr:

# pypy3 test.py
RPython traceback:
  File "pypy_interpreter.c", line 33969, in BuiltinCode_funcrun_obj
  File "pypy_module___builtin__.c", line 2705, in compile
  File "pypy_interpreter.c", line 50963, in PythonAstCompiler__compile_ast
  File "pypy_interpreter_astcompiler.c", line 1543, in compile_ast
  File "pypy_interpreter_astcompiler.c", line 5995, in Module_walkabout
  File "pypy_interpreter_astcompiler.c", line 13362, in PythonCodeGenerator__handle_body
  File "pypy_interpreter_astcompiler_2.c", line 20473, in PythonCodeGenerator_visit_FunctionDef
  File "pypy_interpreter_astcompiler_2.c", line 37632, in _visit_function__FunctionCodeGenerator
  File "pypy_interpreter_astcompiler_2.c", line 61299, in _visit_annotations__pypy_interpreter_astcompiler_1
  File "pypy_interpreter_astcompiler_3.c", line 8128, in PythonCodeGenerator__visit_arg_annotation
  File "pypy_interpreter_astcompiler_2.c", line 22498, in PythonCodeGenerator_visit_Lambda
  File "pypy_interpreter_astcompiler_2.c", line 35719, in PythonCodeGenerator_sub_scope
  File "pypy_interpreter_astcompiler.c", line 11371, in PythonCodeGenerator___init__
SystemError: unexpected internal exception (please report a bug): <KeyError object at 0x7efeb2749d20>; internal traceback was dumped to stderr

The crash appears when:
A varaible argument of a function has an annotation (like *args or **kwargs, normal arguments are not affected), and
A lambda expression is used in the annotation
Both criterias must be met.

This cannot be reproduced on CPython3.5+. Also, Python document says:

Parameters may have annotations of the form “: expression” following the parameter name. Any parameter may have an annotation even those of the form *identifier or **identifier. Functions may have “return” annotation of the form “-> expression” after the parameter list. These annotations can be any valid Python expression. The presence of annotations does not change the semantics of a function. The annotation values are available as values of a dictionary keyed by the parameters’ names in the __annotations__ attribute of the function object.

Mutiple versions of PyPy 3.5 have this bug,  including 5.8, 5.10 and 6.0

2018-07-27


hubo 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/pypy-dev/attachments/20180727/b29c5383/attachment-0001.html>


More information about the pypy-dev mailing list