def test_functiondef(self): import _ast as ast fAst = ast.FunctionDef( name="foo", args=ast.arguments( args=[], vararg=None, kwarg=None, defaults=[], kwonlyargs=[], kw_defaults=[]), body=[], decorator_list=[], lineno=5, col_offset=0) exprAst = ast.Interactive(body=[fAst]) compiled = compile(exprAst, "<foo>", "single") # d = {} eval(compiled, d, d) assert type(d['foo']) is type(lambda: 42) assert d['foo']() is None
def interactive(body: List[_ast.stmt]) -> _ast.Interactive: return _ast.Interactive(body=body)