Commits

Benjamin Peterson  committed 45ac519

backport r67077 from the trunk: parser module now correctly validates relative imports

  • Participants
  • Parent commits e8c0a5a
  • Branches 2.5

Comments (0)

Files changed (4)

File Lib/test/test_parser.py

 import parser
+import os
 import unittest
 from test import test_support
 
             "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")
 Steven Bethard
 Stephen Bevan
 Ron Bickers
+David Binger
 Dominic Binks
 Philippe Biondi
 Stuart Bishop
 Core and builtins
 -----------------
 
+- Issue #4048: The parser module now correctly validates relative imports.
+
 - Issue #4176: Fixed a crash when pickling an object which ``__reduce__``
   method does not return iterators for the 4th and 5th items.
 

File Modules/parsermodule.c

 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 ')' |