summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBenjamin Peterson <benjamin@python.org>2008-11-03 15:14:51 (GMT)
committerBenjamin Peterson <benjamin@python.org>2008-11-03 15:14:51 (GMT)
commit6624a9fdddc3d77a426173f22ab941e8e279dec7 (patch)
tree559996f8531c3aac857bf53047791d911653901e
parent8928a7e911357e57b92aa1738940fec241ded28e (diff)
downloadcpython-6624a9fdddc3d77a426173f22ab941e8e279dec7.zip
cpython-6624a9fdddc3d77a426173f22ab941e8e279dec7.tar.gz
cpython-6624a9fdddc3d77a426173f22ab941e8e279dec7.tar.bz2
#4048 make the parser module accept relative imports as valid
-rw-r--r--Lib/test/test_parser.py2
-rw-r--r--Misc/ACKS1
-rw-r--r--Misc/NEWS2
-rw-r--r--Modules/parsermodule.c4
4 files changed, 7 insertions, 2 deletions
diff --git a/Lib/test/test_parser.py b/Lib/test/test_parser.py
index 9ecca51..94b6113 100644
--- a/Lib/test/test_parser.py
+++ b/Lib/test/test_parser.py
@@ -1,4 +1,5 @@
import parser
+import os
import unittest
import sys
from test import test_support
@@ -179,6 +180,7 @@ class RoundtripLegalSyntaxTestCase(unittest.TestCase):
"from sys.path import (dirname, basename as my_basename)")
self.check_suite(
"from sys.path import (dirname, basename as my_basename,)")
+ self.check_suite("from .bogus import x")
def test_basic_import_statement(self):
self.check_suite("import sys")
diff --git a/Misc/ACKS b/Misc/ACKS
index ac8f6ed..72b18c9 100644
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -62,6 +62,7 @@ Eric Beser
Steven Bethard
Stephen Bevan
Ron Bickers
+David Binger
Dominic Binks
Philippe Biondi
Stuart Bishop
diff --git a/Misc/NEWS b/Misc/NEWS
index 234a15d..8dd9ffb 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -12,6 +12,8 @@ What's New in Python 2.7 alpha 1
Core and Builtins
-----------------
+- Issue #4048: The parser module now correctly validates relative imports.
+
- Issue #4225: ``from __future__ import unicode_literals`` didn't work in an
exec statement.
diff --git a/Modules/parsermodule.c b/Modules/parsermodule.c
index 423a0b3..bea78c2 100644
--- a/Modules/parsermodule.c
+++ b/Modules/parsermodule.c
@@ -1879,10 +1879,10 @@ static int
count_from_dots(node *tree)
{
int i;
- for (i = 0; i < NCH(tree); i++)
+ for (i = 1; i < NCH(tree); i++)
if (TYPE(CHILD(tree, i)) != DOT)
break;
- return i;
+ return i-1;
}
/* 'from' ('.'* dotted_name | '.') 'import' ('*' | '(' import_as_names ')' |