From: Mark Dickinson Date: Sun, 4 Jul 2010 18:39:48 +0000 (+0000) Subject: Merged revisions 82555 via svnmerge from X-Git-Tag: v3.1.3rc1~551 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=0dce815c2b3dc66794e34cd589d6873003562707;p=python Merged revisions 82555 via svnmerge from svn+ssh://pythondev@svn.python.org/python/branches/py3k ........ r82555 | mark.dickinson | 2010-07-04 19:38:57 +0100 (Sun, 04 Jul 2010) | 2 lines Issue #9130: Validate ellipsis tokens in relative imports. ........ --- diff --git a/Lib/test/test_parser.py b/Lib/test/test_parser.py index 17111b07ae..04b45be0ae 100644 --- a/Lib/test/test_parser.py +++ b/Lib/test/test_parser.py @@ -193,8 +193,14 @@ class RoundtripLegalSyntaxTestCase(unittest.TestCase): def test_relative_imports(self): self.check_suite("from . import name") self.check_suite("from .. import name") + # check all the way up to '....', since '...' is tokenized + # differently from '.' (it's an ellipsis token). + self.check_suite("from ... import name") + self.check_suite("from .... import name") self.check_suite("from .pkg import name") self.check_suite("from ..pkg import name") + self.check_suite("from ...pkg import name") + self.check_suite("from ....pkg import name") def test_pep263(self): self.check_suite("# -*- coding: iso-8859-1 -*-\n" diff --git a/Modules/parsermodule.c b/Modules/parsermodule.c index c9150d9431..77b890a284 100644 --- a/Modules/parsermodule.c +++ b/Modules/parsermodule.c @@ -1750,17 +1750,17 @@ validate_import_name(node *tree) && validate_dotted_as_names(CHILD(tree, 1))); } -/* Helper function to count the number of leading dots in +/* Helper function to count the number of leading dots (or ellipsis tokens) in * 'from ...module import name' */ static int count_from_dots(node *tree) { - int i; - for (i = 1; i < NCH(tree); i++) - if (TYPE(CHILD(tree, i)) != DOT) - break; - return i-1; + int i; + for (i = 1; i < NCH(tree); i++) + if (TYPE(CHILD(tree, i)) != DOT && TYPE(CHILD(tree, i)) != ELLIPSIS) + break; + return i - 1; } /* import_from: ('from' ('.'* dotted_name | '.'+)