mirror of
https://github.com/python/cpython.git
synced 2025-08-31 14:07:50 +00:00
Issue #9130: Validate ellipsis tokens in relative imports.
This commit is contained in:
parent
3445b482b3
commit
feb3b75818
2 changed files with 12 additions and 6 deletions
|
@ -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,7 +1754,7 @@ 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
|
||||
|
@ -1762,7 +1762,7 @@ count_from_dots(node *tree)
|
|||
{
|
||||
int i;
|
||||
for (i = 1; i < NCH(tree); i++)
|
||||
if (TYPE(CHILD(tree, i)) != DOT)
|
||||
if (TYPE(CHILD(tree, i)) != DOT && TYPE(CHILD(tree, i)) != ELLIPSIS)
|
||||
break;
|
||||
return i - 1;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue