Commit e989f760 authored by demiurg337's avatar demiurg337 Committed by Stefan Behnel

Allow await inside of f-strings (GH-3070)

parent 6b01c372
......@@ -38,7 +38,7 @@ cdef class PyrexScanner(Scanner):
cdef public list indentation_stack
cdef public indentation_char
cdef public int bracket_nesting_level
cdef bint async_enabled
cdef readonly bint async_enabled
cdef public sy
cdef public systring
......
......@@ -322,12 +322,25 @@ class PyrexScanner(Scanner):
def __init__(self, file, filename, parent_scanner=None,
scope=None, context=None, source_encoding=None, parse_comments=True, initial_pos=None):
Scanner.__init__(self, get_lexicon(), file, filename, initial_pos)
if filename.is_python_file():
self.in_python_file = True
self.keywords = set(py_reserved_words)
else:
self.in_python_file = False
self.keywords = set(pyx_reserved_words)
self.async_enabled = 0
if parent_scanner:
self.context = parent_scanner.context
self.included_files = parent_scanner.included_files
self.compile_time_env = parent_scanner.compile_time_env
self.compile_time_eval = parent_scanner.compile_time_eval
self.compile_time_expr = parent_scanner.compile_time_expr
if parent_scanner.async_enabled:
self.enter_async()
else:
self.context = context
self.included_files = scope.included_files
......@@ -338,17 +351,11 @@ class PyrexScanner(Scanner):
self.compile_time_env.update(context.options.compile_time_env)
self.parse_comments = parse_comments
self.source_encoding = source_encoding
if filename.is_python_file():
self.in_python_file = True
self.keywords = set(py_reserved_words)
else:
self.in_python_file = False
self.keywords = set(pyx_reserved_words)
self.trace = trace_scanner
self.indentation_stack = [0]
self.indentation_char = None
self.bracket_nesting_level = 0
self.async_enabled = 0
self.begin('INDENT')
self.sy = ''
self.next()
......
......@@ -513,3 +513,21 @@ def percent_s_unicode(u, int i):
x\u0194z-12
"""
return u"%s-%d" % (u, i)
########################################
# await inside f-string
def test_await_inside_f_string():
"""
>>> test_await_inside_f_string()
PARSED_SUCCESSFULLY
"""
async def f():
return "some value"
async def main():
print(f"{await f()}")
print("PARSED_SUCCESSFULLY")
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment