[pypy-svn] pypy default: Fix the imp module to better handle the __package__ attribute
amauryfa
commits-noreply at bitbucket.org
Mon Apr 4 21:12:28 CEST 2011
Author: Amaury Forgeot d'Arc <amauryfa at gmail.com>
Branch:
Changeset: r43161:5cefa0984ff6
Date: 2011-04-04 20:56 +0200
http://bitbucket.org/pypy/pypy/changeset/5cefa0984ff6/
Log: Fix the imp module to better handle the __package__ attribute
diff --git a/pypy/module/imp/interp_imp.py b/pypy/module/imp/interp_imp.py
--- a/pypy/module/imp/interp_imp.py
+++ b/pypy/module/imp/interp_imp.py
@@ -135,7 +135,7 @@
return importing.check_sys_modules(space, w_modulename)
def new_module(space, w_name):
- return space.wrap(Module(space, w_name))
+ return space.wrap(Module(space, w_name, add_package=False))
def init_builtin(space, w_name):
name = space.str_w(w_name)
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
@@ -134,11 +134,13 @@
if ctxt_package is not None:
# __package__ is set, so use it
+ if ctxt_package == '' and level < 0:
+ return None, 0
+
package_parts = ctxt_package.split('.')
while level > 1 and package_parts:
level -= 1
- if package_parts:
- package_parts.pop()
+ package_parts.pop()
if not package_parts:
if len(ctxt_package) == 0:
msg = "Attempted relative import in non-package"
@@ -162,9 +164,9 @@
"while handling absolute import" % ctxt_package,
space.w_RuntimeWarning)
+ rel_level = len(package_parts)
if modulename:
package_parts.append(modulename)
- rel_level = len(package_parts)
rel_modulename = '.'.join(package_parts)
else:
# __package__ not set, so figure it out and set it
More information about the Pypy-commit
mailing list