Commit 5db12dc4 authored by Mark Dickinson's avatar Mark Dickinson

Issue #9130: Validate ellipsis tokens in relative imports.

parent 51a18149
......@@ -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"
......
......@@ -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 | '.'+)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment