[pypy-svn] pypy default: Only add '__package__' to the names in modules created
arigo
commits-noreply at bitbucket.org
Sun Feb 13 10:58:20 CET 2011
Author: Armin Rigo <arigo at tunes.org>
Branch:
Changeset: r41868:41dd0bdbc028
Date: 2011-02-13 10:57 +0100
http://bitbucket.org/pypy/pypy/changeset/41dd0bdbc028/
Log: Only add '__package__' to the names in modules created internally,
but not in modules created from Python code, as in CPython.
diff --git a/pypy/interpreter/test/test_module.py b/pypy/interpreter/test/test_module.py
--- a/pypy/interpreter/test/test_module.py
+++ b/pypy/interpreter/test/test_module.py
@@ -70,5 +70,6 @@
import sys
import os
- assert type(sys)('foo').__package__ is None
- assert os.__package__ is None
\ No newline at end of file
+ assert sys.__package__ is None
+ assert os.__package__ is None
+ assert not hasattr(type(sys)('foo'), '__package__')
diff --git a/pypy/interpreter/module.py b/pypy/interpreter/module.py
--- a/pypy/interpreter/module.py
+++ b/pypy/interpreter/module.py
@@ -11,7 +11,7 @@
_frozen = False
- def __init__(self, space, w_name, w_dict=None):
+ def __init__(self, space, w_name, w_dict=None, add_package=True):
self.space = space
if w_dict is None:
w_dict = space.newdict(module=True)
@@ -19,7 +19,11 @@
self.w_name = w_name
if w_name is not None:
space.setitem(w_dict, space.new_interned_str('__name__'), w_name)
- space.setitem(w_dict, space.new_interned_str('__package__'), space.w_None)
+ if add_package:
+ # add the __package__ attribute only when created from internal
+ # code, but not when created from Python code (as in CPython)
+ space.setitem(w_dict, space.new_interned_str('__package__'),
+ space.w_None)
self.startup_called = False
def setup_after_space_initialization(self):
@@ -54,7 +58,7 @@
def descr_module__new__(space, w_subtype, __args__):
module = space.allocate_instance(Module, w_subtype)
- Module.__init__(module, space, None)
+ Module.__init__(module, space, None, add_package=False)
return space.wrap(module)
def descr_module__init__(self, w_name, w_doc=None):
@@ -64,7 +68,6 @@
w_doc = space.w_None
space.setitem(self.w_dict, space.new_interned_str('__name__'), w_name)
space.setitem(self.w_dict, space.new_interned_str('__doc__'), w_doc)
- space.setitem(self.w_dict, space.new_interned_str('__package__'), space.w_None)
def descr__reduce__(self, space):
w_name = space.finditem(self.w_dict, space.wrap('__name__'))
More information about the Pypy-commit
mailing list