MCPcopy Index your code
hub / github.com/ipython/ipython / _should_be_async

Function _should_be_async

IPython/core/async_helpers.py:138–150  ·  view source on GitHub ↗

Detect if a block of code needs to be wrapped in an `async def` If the code block has a top-level return statement or is otherwise invalid, `False` will be returned.

(cell: str)

Source from the content-addressed store, hash-verified

136
137
138def _should_be_async(cell: str) -> bool:
139 """Detect if a block of code needs to be wrapped in an `async def`
140
141 If the code block has a top-level return statement or is otherwise
142 invalid, `False` will be returned.
143 """
144 try:
145 code = compile(
146 cell, "<>", "exec", flags=getattr(ast, "PyCF_ALLOW_TOP_LEVEL_AWAIT", 0x0)
147 )
148 return inspect.CO_COROUTINE & code.co_flags == inspect.CO_COROUTINE
149 except (SyntaxError, ValueError, MemoryError):
150 return False

Callers 2

test_should_be_asyncMethod · 0.90
should_run_asyncMethod · 0.85

Calls

no outgoing calls

Tested by 1

test_should_be_asyncMethod · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…