[pypy-svn] pypy default: (rguillebert, arigo)
arigo
commits-noreply at bitbucket.org
Tue Apr 26 11:47:01 CEST 2011
Author: Armin Rigo <arigo at tunes.org>
Branch:
Changeset: r43620:4ff59c1c4f93
Date: 2011-04-26 11:46 +0200
http://bitbucket.org/pypy/pypy/changeset/4ff59c1c4f93/
Log: (rguillebert, arigo)
Test and fix. As usual, of the kind "let's whack a bit more at
imports, hopefully not too randomly".
diff --git a/pypy/module/imp/test/test_import.py b/pypy/module/imp/test/test_import.py
--- a/pypy/module/imp/test/test_import.py
+++ b/pypy/module/imp/test/test_import.py
@@ -53,10 +53,13 @@
relative_f = "from .imp import get_magic",
relative_g = "import imp; from .imp import get_magic",
)
- setuppkg("pkg.pkg1",
+ setuppkg("pkg.pkg1",
+ __init__ = 'from . import a',
a = '',
relative_d = "from __future__ import absolute_import\nfrom ..string import inpackage",
relative_e = "from __future__ import absolute_import\nfrom .. import string",
+ relative_g = "from .. import pkg1\nfrom ..pkg1 import b",
+ b = "insubpackage = 1",
)
setuppkg("pkg.pkg2", a='', b='')
setuppkg("pkg_r", inpkg = "import x.y")
@@ -402,6 +405,12 @@
from pkg.pkg1 import relative_e
assert relative_e.string.inpackage == 1
+ def test_future_relative_import_level_3(self):
+ from pkg.pkg1 import relative_g
+ assert relative_g.b.insubpackage == 1
+ import pkg.pkg1
+ assert pkg.pkg1.__package__ == 'pkg.pkg1'
+
def test_future_relative_import_error_when_in_non_package(self):
exec """def imp():
from .string import inpackage
diff --git a/pypy/module/imp/importing.py b/pypy/module/imp/importing.py
--- a/pypy/module/imp/importing.py
+++ b/pypy/module/imp/importing.py
@@ -215,10 +215,12 @@
space.setitem(w_globals, w("__package__"), ctxt_w_name)
else:
# Normal module, so work out the package name if any
- if '.' not in ctxt_name:
+ last_dot_position = ctxt_name.rfind('.')
+ if last_dot_position < 0:
space.setitem(w_globals, w("__package__"), space.w_None)
- elif rel_modulename:
- space.setitem(w_globals, w("__package__"), w(rel_modulename))
+ else:
+ space.setitem(w_globals, w("__package__"),
+ w(ctxt_name[:last_dot_position]))
if modulename:
if rel_modulename:
More information about the Pypy-commit
mailing list