Skip to content

Commit 70dd3bd

Browse files
baldulinjonathanslenders
authored andcommitted
Enable use of await in assignment expressions
This tries to fix prompt-toolkit#447 and some other bugs concerning expressions, like for instance `for` loops. Which cannot contain awaitables otherwise.
1 parent b6d9bc7 commit 70dd3bd

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

ptpython/repl.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -271,9 +271,14 @@ async def eval_async(self, line: str) -> object:
271271
self._store_eval_result(result)
272272
return result
273273

274-
# If not a valid `eval` expression, run using `exec` instead.
274+
# If not a valid `eval` expression, compile as `exec` expression
275+
# but still run with eval to get an awaitable in case of a
276+
# awaitable expression.
275277
code = self._compile_with_flags(line, "exec")
276-
exec(code, self.get_globals(), self.get_locals())
278+
result = eval(code, self.get_globals(), self.get_locals())
279+
280+
if _has_coroutine_flag(code):
281+
result = await result
277282

278283
return None
279284

0 commit comments

Comments
 (0)