mirror of
https://github.com/python/cpython.git
synced 2025-08-30 13:38:43 +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):
|
def test_relative_imports(self):
|
||||||
self.check_suite("from . import name")
|
self.check_suite("from . import name")
|
||||||
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")
|
||||||
|
self.check_suite("from ...pkg import name")
|
||||||
|
self.check_suite("from ....pkg import name")
|
||||||
|
|
||||||
def test_pep263(self):
|
def test_pep263(self):
|
||||||
self.check_suite("# -*- coding: iso-8859-1 -*-\n"
|
self.check_suite("# -*- coding: iso-8859-1 -*-\n"
|
||||||
|
|
|
@ -1754,17 +1754,17 @@ validate_import_name(node *tree)
|
||||||
&& validate_dotted_as_names(CHILD(tree, 1)));
|
&& 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'
|
* 'from ...module import name'
|
||||||
*/
|
*/
|
||||||
static int
|
static int
|
||||||
count_from_dots(node *tree)
|
count_from_dots(node *tree)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
for (i = 1; i < NCH(tree); 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;
|
break;
|
||||||
return i-1;
|
return i - 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* import_from: ('from' ('.'* dotted_name | '.'+)
|
/* import_from: ('from' ('.'* dotted_name | '.'+)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue