[Python-checkins] r82555 - in python/branches/py3k: Lib/test/test_parser.py Modules/parsermodule.c
mark.dickinson
python-checkins at python.org
Sun Jul 4 20:38:57 CEST 2010
Author: mark.dickinson
Date: Sun Jul 4 20:38:57 2010
New Revision: 82555
Log:
Issue #9130: Validate ellipsis tokens in relative imports.
Modified:
python/branches/py3k/Lib/test/test_parser.py
python/branches/py3k/Modules/parsermodule.c
Modified: python/branches/py3k/Lib/test/test_parser.py
==============================================================================
--- python/branches/py3k/Lib/test/test_parser.py (original)
+++ python/branches/py3k/Lib/test/test_parser.py Sun Jul 4 20:38:57 2010
@@ -192,8 +192,14 @@
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"
Modified: python/branches/py3k/Modules/parsermodule.c
==============================================================================
--- python/branches/py3k/Modules/parsermodule.c (original)
+++ python/branches/py3k/Modules/parsermodule.c Sun Jul 4 20:38:57 2010
@@ -1754,17 +1754,17 @@
&& 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 | '.'+)
More information about the Python-checkins
mailing list