Skip to content

Commit

Permalink
Don't instrument Expr containing docstring, #1481
Browse files Browse the repository at this point in the history
  • Loading branch information
aivarannamaa committed Dec 14, 2020
1 parent a1cced2 commit 08d86f9
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion thonny/plugins/cpython/cpython_backend.py
Expand Up @@ -1300,7 +1300,15 @@ def _prepare_ast(self, source, filename, mode):
def _instrument_repl_code(self, root):
# modify all expression statements to print and register their non-None values
for node in ast.walk(root):
if isinstance(node, ast.Expr):
if (
isinstance(node, ast.FunctionDef)
or hasattr(ast, "AsyncFunctionDef")
and isinstance(node, ast.AsyncFunctionDef)
):
first_stmt = node.body[0]
if isinstance(first_stmt, ast.Expr) and isinstance(first_stmt.value, ast.Str):
first_stmt.contains_docstring = True
if isinstance(node, ast.Expr) and not getattr(node, "contains_docstring", False):
node.value = ast.Call(
func=ast.Name(id=_REPL_HELPER_NAME, ctx=ast.Load()),
args=[node.value],
Expand Down

0 comments on commit 08d86f9

Please sign in to comment.