MCPcopy Create free account
hub / github.com/ipython/ipython / _async_parse_cell

Function _async_parse_cell

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

This is a compatibility shim for pre-3.7 when async outside of a function is a syntax error at the parse stage. It will return an abstract syntax tree parsed as if async and await outside of a function were not a syntax error.

(cell: str)

Source from the content-addressed store, hash-verified

123
124
125def _async_parse_cell(cell: str) -> ast.AST:
126 """
127 This is a compatibility shim for pre-3.7 when async outside of a function
128 is a syntax error at the parse stage.
129
130 It will return an abstract syntax tree parsed as if async and await outside
131 of a function were not a syntax error.
132 """
133 if sys.version_info < (3, 7):
134 # Prior to 3.7 you need to asyncify before parse
135 wrapped_parse_tree = ast.parse(_asyncify(cell))
136 return wrapped_parse_tree.body[0].body[0]
137 else:
138 return ast.parse(cell)
139
140
141def _should_be_async(cell: str) -> bool:

Callers 1

_should_be_asyncFunction · 0.85

Calls 2

_asyncifyFunction · 0.85
parseMethod · 0.45

Tested by

no test coverage detected