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(( |
|
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 | |
@@ -319,7 +320,16 b' def test_check_complete():' | |||||
319 | assert cc("def f():\n x=0\n \\\n ") == ("incomplete", 2) |
|
320 | assert cc("def f():\n x=0\n \\\n ") == ("incomplete", 2) | |
320 |
|
321 | |||
321 |
|
322 | |||
322 | def test_check_complete_II(): |
|
323 | @pytest.mark.skipif(platform.python_implementation() == "PyPy", reason="fail on pypy") | |
|
324 | @pytest.mark.parametrize( | |||
|
325 | "value, expected", | |||
|
326 | [ | |||
|
327 | ('''def foo():\n """''', ("incomplete", 4)), | |||
|
328 | ("""async with example:\n pass""", ("incomplete", 4)), | |||
|
329 | ("""async with example:\n pass\n """, ("complete", None)), | |||
|
330 | ], | |||
|
331 | ) | |||
|
332 | def test_check_complete_II(value, expected): | |||
323 | """ |
|
333 | """ | |
324 | Test that multiple line strings are properly handled. |
|
334 | Test that multiple line strings are properly handled. | |
325 |
|
335 | |||
@@ -327,25 +337,31 b' def test_check_complete_II():' | |||||
327 |
|
337 | |||
328 | """ |
|
338 | """ | |
329 | cc = ipt2.TransformerManager().check_complete |
|
339 | cc = ipt2.TransformerManager().check_complete | |
330 | assert cc('''def foo():\n """''') == ("incomplete", 4) |
|
340 | assert cc(value) == expected | |
331 |
|
341 | |||
332 |
|
342 | |||
333 | def test_check_complete_invalidates_sunken_brackets(): |
|
343 | @pytest.mark.parametrize( | |
|
344 | "value, expected", | |||
|
345 | [ | |||
|
346 | (")", ("invalid", None)), | |||
|
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 | ], | |||
|
357 | ) | |||
|
358 | def test_check_complete_invalidates_sunken_brackets(value, expected): | |||
334 | """ |
|
359 | """ | |
335 | Test that a single line with more closing brackets than the opening ones is |
|
360 | Test that a single line with more closing brackets than the opening ones is | |
336 | interpreted as invalid |
|
361 | interpreted as invalid | |
337 | """ |
|
362 | """ | |
338 | cc = ipt2.TransformerManager().check_complete |
|
363 | cc = ipt2.TransformerManager().check_complete | |
339 | assert cc(")") == ("invalid", None) |
|
364 | 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 |
|
365 | |||
350 |
|
366 | |||
351 | def test_null_cleanup_transformer(): |
|
367 | def test_null_cleanup_transformer(): |
General Comments 0
You need to be logged in to leave comments.
Login now