summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMark Dickinson <dickinsm@gmail.com>2010-07-04 18:38:57 (GMT)
committerMark Dickinson <dickinsm@gmail.com>2010-07-04 18:38:57 (GMT)
commitfeb3b758182df8ee94eb00b919af02a5d25ab515 (patch)
tree41be56c4ddf38dd5da17a28382ace356187fed06
parent3445b482b3be846d1760072a284877f81844b48a (diff)
downloadcpython-feb3b758182df8ee94eb00b919af02a5d25ab515.zip
cpython-feb3b758182df8ee94eb00b919af02a5d25ab515.tar.gz
cpython-feb3b758182df8ee94eb00b919af02a5d25ab515.tar.bz2
Issue #9130: Validate ellipsis tokens in relative imports.
-rw-r--r--Lib/test/test_parser.py6
-rw-r--r--Modules/parsermodule.c12
2 files changed, 12 insertions, 6 deletions
diff --git a/Lib/test/test_parser.py b/Lib/test/test_parser.py
index dad9619..7afd08e 100644
--- a/Lib/test/test_parser.py
+++ b/Lib/test/test_parser.py
@@ -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"
diff --git a/Modules/parsermodule.c b/Modules/parsermodule.c
index bead663..8c57f86 100644
--- a/Modules/parsermodule.c
+++ b/Modules/parsermodule.c
@@ -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 | '.'+)