]> granicus.if.org Git - python/commitdiff
Issue #9130: Validate ellipsis tokens in relative imports.
authorMark Dickinson <dickinsm@gmail.com>
Sun, 4 Jul 2010 18:38:57 +0000 (18:38 +0000)
committerMark Dickinson <dickinsm@gmail.com>
Sun, 4 Jul 2010 18:38:57 +0000 (18:38 +0000)
Lib/test/test_parser.py
Modules/parsermodule.c

index dad961975cb5b1d0992b58e1ca20d1a70eab9b74..7afd08e99cfa031e0b8cfc331f68fea3748929c8 100644 (file)
@@ -192,8 +192,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"
index bead663efe520bfddc9b205621af49e0178fe2b9..8c57f867c9d57b810d7095f15e5b6e8fb13b3637 100644 (file)
@@ -1754,17 +1754,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 | '.'+)