##// END OF EJS Templates
Merge pull request #13436 from Carreau/fix-async-with...
Matthias Bussonnier -
r27443:6edc05a6 merge
parent child Browse files
Show More
@@ -507,9 +507,12 b' def make_tokens_by_line(lines:List[str]):'
507
507
508 # reexported from token on 3.7+
508 # reexported from token on 3.7+
509 NEWLINE, NL = tokenize.NEWLINE, tokenize.NL # type: ignore
509 NEWLINE, NL = tokenize.NEWLINE, tokenize.NL # type: ignore
510 tokens_by_line:List[List[Any]] = [[]]
510 tokens_by_line: List[List[Any]] = [[]]
511 if len(lines) > 1 and not lines[0].endswith(('\n', '\r', '\r\n', '\x0b', '\x0c')):
511 if len(lines) > 1 and not lines[0].endswith(("\n", "\r", "\r\n", "\x0b", "\x0c")):
512 warnings.warn("`make_tokens_by_line` received a list of lines which do not have lineending markers ('\\n', '\\r', '\\r\\n', '\\x0b', '\\x0c'), behavior will be unspecified")
512 warnings.warn(
513 "`make_tokens_by_line` received a list of lines which do not have lineending markers ('\\n', '\\r', '\\r\\n', '\\x0b', '\\x0c'), behavior will be unspecified",
514 stacklevel=2,
515 )
513 parenlev = 0
516 parenlev = 0
514 try:
517 try:
515 for token in tokenize.generate_tokens(iter(lines).__next__):
518 for token in tokenize.generate_tokens(iter(lines).__next__):
@@ -782,9 +785,6 b' class MaybeAsyncCompile(Compile):'
782 super().__init__()
785 super().__init__()
783 self.flags |= extra_flags
786 self.flags |= extra_flags
784
787
785 def __call__(self, *args, **kwds):
786 return compile(*args, **kwds)
787
788
788
789 class MaybeAsyncCommandCompiler(CommandCompiler):
789 class MaybeAsyncCommandCompiler(CommandCompiler):
790 def __init__(self, extra_flags=0):
790 def __init__(self, extra_flags=0):
@@ -4,6 +4,7 b' Line-based transformers are the simpler ones; token-based transformers are'
4 more complex. See test_inputtransformer2_line for tests for line-based
4 more complex. See test_inputtransformer2_line for tests for line-based
5 transformations.
5 transformations.
6 """
6 """
7 import platform
7 import string
8 import string
8 import sys
9 import sys
9 from textwrap import dedent
10 from textwrap import dedent
@@ -291,6 +292,7 b' def test_check_complete_param(code, expected, number):'
291 assert cc(code) == (expected, number)
292 assert cc(code) == (expected, number)
292
293
293
294
295 @pytest.mark.xfail(platform.python_implementation() == "PyPy", reason="fail on pypy")
294 @pytest.mark.xfail(
296 @pytest.mark.xfail(
295 reason="Bug in python 3.9.8 – bpo 45738",
297 reason="Bug in python 3.9.8 – bpo 45738",
296 condition=sys.version_info in [(3, 9, 8, "final", 0), (3, 11, 0, "alpha", 2)],
298 condition=sys.version_info in [(3, 9, 8, "final", 0), (3, 11, 0, "alpha", 2)],
@@ -319,7 +321,16 b' def test_check_complete():'
319 assert cc("def f():\n x=0\n \\\n ") == ("incomplete", 2)
321 assert cc("def f():\n x=0\n \\\n ") == ("incomplete", 2)
320
322
321
323
322 def test_check_complete_II():
324 @pytest.mark.xfail(platform.python_implementation() == "PyPy", reason="fail on pypy")
325 @pytest.mark.parametrize(
326 "value, expected",
327 [
328 ('''def foo():\n """''', ("incomplete", 4)),
329 ("""async with example:\n pass""", ("incomplete", 4)),
330 ("""async with example:\n pass\n """, ("complete", None)),
331 ],
332 )
333 def test_check_complete_II(value, expected):
323 """
334 """
324 Test that multiple line strings are properly handled.
335 Test that multiple line strings are properly handled.
325
336
@@ -327,25 +338,31 b' def test_check_complete_II():'
327
338
328 """
339 """
329 cc = ipt2.TransformerManager().check_complete
340 cc = ipt2.TransformerManager().check_complete
330 assert cc('''def foo():\n """''') == ("incomplete", 4)
341 assert cc(value) == expected
331
342
332
343
333 def test_check_complete_invalidates_sunken_brackets():
344 @pytest.mark.parametrize(
345 "value, expected",
346 [
347 (")", ("invalid", None)),
348 ("]", ("invalid", None)),
349 ("}", ("invalid", None)),
350 (")(", ("invalid", None)),
351 ("][", ("invalid", None)),
352 ("}{", ("invalid", None)),
353 ("]()(", ("invalid", None)),
354 ("())(", ("invalid", None)),
355 (")[](", ("invalid", None)),
356 ("()](", ("invalid", None)),
357 ],
358 )
359 def test_check_complete_invalidates_sunken_brackets(value, expected):
334 """
360 """
335 Test that a single line with more closing brackets than the opening ones is
361 Test that a single line with more closing brackets than the opening ones is
336 interpreted as invalid
362 interpreted as invalid
337 """
363 """
338 cc = ipt2.TransformerManager().check_complete
364 cc = ipt2.TransformerManager().check_complete
339 assert cc(")") == ("invalid", None)
365 assert cc(value) == expected
340 assert cc("]") == ("invalid", None)
341 assert cc("}") == ("invalid", None)
342 assert cc(")(") == ("invalid", None)
343 assert cc("][") == ("invalid", None)
344 assert cc("}{") == ("invalid", None)
345 assert cc("]()(") == ("invalid", None)
346 assert cc("())(") == ("invalid", None)
347 assert cc(")[](") == ("invalid", None)
348 assert cc("()](") == ("invalid", None)
349
366
350
367
351 def test_null_cleanup_transformer():
368 def test_null_cleanup_transformer():
General Comments 0
You need to be logged in to leave comments. Login now