From 688dfaad24ca551574e1a278a0c6470b3bddf929 Mon Sep 17 00:00:00 2001 From: Dave Halter Date: Sun, 16 Jul 2017 18:49:19 +0200 Subject: [PATCH] Make ellipsis work for the differences between 2 and 3. --- parso/python/tokenize.py | 7 ++++++- test/test_parser_tree.py | 10 ++++++++++ test/test_pgen2.py | 5 +++++ 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/parso/python/tokenize.py b/parso/python/tokenize.py index e3a4fd8..a98f28b 100644 --- a/parso/python/tokenize.py +++ b/parso/python/tokenize.py @@ -159,7 +159,12 @@ def _create_token_collection(version_int): r"~") Bracket = '[][(){}]' - Special = group(r'\r?\n', r'\.\.\.', r'[:;.,@]') + + special_args = [r'\r?\n', r'[:;.,@]'] + if version_int >= 30: + special_args.insert(0, r'\.\.\.') + Special = group(*special_args) + Funny = group(Operator, Bracket, Special) # First (or only) line of ' or " string. diff --git a/test/test_parser_tree.py b/test/test_parser_tree.py index dd8a933..08a09c8 100644 --- a/test/test_parser_tree.py +++ b/test/test_parser_tree.py @@ -106,3 +106,13 @@ def test_default_and_annotation_param(each_py3_version): assert param.default.value == '42' assert param.annotation.value == '3' assert not param.star_count + + +def test_ellipsis_py2(each_py2_version): + module = parse('[0][...]', version=each_py2_version, error_recovery=False) + expr = module.children[0] + trailer = expr.children[-1] + print(expr) + subscript = trailer.children[1] + assert subscript.type == 'subscript' + assert [leaf.value for leaf in subscript.children] == ['.', '.', '.'] diff --git a/test/test_pgen2.py b/test/test_pgen2.py index bcdfb5a..9febd72 100644 --- a/test/test_pgen2.py +++ b/test/test_pgen2.py @@ -285,6 +285,11 @@ def test_multiline_bytes_tripquote_literals(each_version): _parse(s, each_version) +def test_ellipsis(works_ge_py3, each_version): + works_ge_py3.parse("...") + _parse("[0][...]", version=each_version) + + def test_multiline_str_literals(each_version): s = """ md5test("\xaa" * 80,