(compiler, expr, root, is_async, tp, params, body)
| 1590 | maybe_annotated(lambda_list), |
| 1591 | many(FORM)]) |
| 1592 | def compile_function_lambda(compiler, expr, root, is_async, tp, params, body): |
| 1593 | params, returns = params |
| 1594 | posonly, args, rest, kwonly, kwargs = params |
| 1595 | has_annotations = returns is not None or any( |
| 1596 | isinstance(param, tuple) and param[1] is not None |
| 1597 | for param in (posonly or []) + args + kwonly + [rest, kwargs] |
| 1598 | ) |
| 1599 | args, ret = compile_lambda_list(compiler, params) |
| 1600 | with compiler.local_state(), compiler.scope.create(ScopeFn, args, is_async) as scope: |
| 1601 | body = compiler._compile_branch(body) |
| 1602 | |
| 1603 | # Compile to lambda if we can |
| 1604 | if not (has_annotations or tp or body.stmts or is_async): |
| 1605 | return ret + asty.Lambda(expr, args=args, body=body.force_expr) |
| 1606 | |
| 1607 | # Otherwise create a standard function |
| 1608 | node = asty.AsyncFunctionDef if is_async else asty.FunctionDef |
| 1609 | name = compiler.get_anon_var() |
| 1610 | ret += compile_function_node( |
| 1611 | compiler, expr, node, [], tp, name, args, returns, body, scope |
| 1612 | ) |
| 1613 | |
| 1614 | # return its name as the final expr |
| 1615 | return ret + Result(expr=ret.temp_variables[0]) |
| 1616 | |
| 1617 | |
| 1618 | @pattern_macro("defn", [ |
nothing calls this directly
no test coverage detected