[pypy-commit] pypy builtin-module: Add a hack that makes it unnecessary to list in lib_pypy/*.py all the

arigo noreply at buildbot.pypy.org
Sun Dec 4 13:24:49 CET 2011


Author: Armin Rigo <arigo at tunes.org>
Branch: builtin-module
Changeset: r50121:411dad65158a
Date: 2011-12-04 12:05 +0100
http://bitbucket.org/pypy/pypy/changeset/411dad65158a/

Log:	Add a hack that makes it unnecessary to list in lib_pypy/*.py all
	the names starting with an underscore. This was needed because
	"import *" ignores them, but now we provide an __all__ list, so it
	works again without them.

diff --git a/lib_pypy/_continuation.py b/lib_pypy/_continuation.py
--- a/lib_pypy/_continuation.py
+++ b/lib_pypy/_continuation.py
@@ -1,4 +1,3 @@
 # indirection needed; otherwise the built-in module "_continuation" shadows
 # any file _continuation.py that would be found in the user dirs
 from __builtin__continuation import *
-from __builtin__continuation import __doc__
diff --git a/lib_pypy/_multibytecodec.py b/lib_pypy/_multibytecodec.py
--- a/lib_pypy/_multibytecodec.py
+++ b/lib_pypy/_multibytecodec.py
@@ -1,4 +1,3 @@
 # indirection needed; otherwise the built-in module "_multibytecodec" shadows
 # any file _multibytecodec.py that would be found in the user dirs
 from __builtin__multibytecodec import *
-from __builtin__multibytecodec import __getcodec
diff --git a/lib_pypy/cmath.py b/lib_pypy/cmath.py
--- a/lib_pypy/cmath.py
+++ b/lib_pypy/cmath.py
@@ -1,4 +1,3 @@
 # indirection needed; otherwise the built-in module "cmath" shadows
 # any file cmath.py that would be found in the user dirs
 from __builtin_cmath import *
-from __builtin_cmath import __doc__
diff --git a/lib_pypy/itertools.py b/lib_pypy/itertools.py
--- a/lib_pypy/itertools.py
+++ b/lib_pypy/itertools.py
@@ -2,7 +2,6 @@
 # any file itertools.py that would be found in the user dirs
 try:
     from __builtin_itertools import *
-    from __builtin_itertools import __doc__
 except ImportError:
     from _itertools import *
     from _itertools import __doc__
diff --git a/lib_pypy/math.py b/lib_pypy/math.py
--- a/lib_pypy/math.py
+++ b/lib_pypy/math.py
@@ -1,4 +1,3 @@
 # indirection needed; otherwise the built-in module "math" shadows
 # any file math.py that would be found in the user dirs
 from __builtin_math import *
-from __builtin_math import __doc__
diff --git a/lib_pypy/struct.py b/lib_pypy/struct.py
--- a/lib_pypy/struct.py
+++ b/lib_pypy/struct.py
@@ -2,7 +2,6 @@
 # any file struct.py that would be found in the user dirs
 try:
     from __builtin_struct import *
-    from __builtin_struct import __doc__
 except ImportError:
     from _struct import *
     from _struct import __doc__
diff --git a/lib_pypy/termios.py b/lib_pypy/termios.py
--- a/lib_pypy/termios.py
+++ b/lib_pypy/termios.py
@@ -1,4 +1,3 @@
 # indirection needed; otherwise the built-in module "termios" shadows
 # any file termios.py that would be found in the user dirs
 from __builtin_termios import *
-from __builtin_termios import __doc__
diff --git a/lib_pypy/unicodedata.py b/lib_pypy/unicodedata.py
--- a/lib_pypy/unicodedata.py
+++ b/lib_pypy/unicodedata.py
@@ -1,4 +1,3 @@
 # indirection needed; otherwise the built-in module "unicodedata" shadows
 # any file unicodedata.py that would be found in the user dirs
 from __builtin_unicodedata import *
-from __builtin_unicodedata import _get_code
diff --git a/pypy/interpreter/mixedmodule.py b/pypy/interpreter/mixedmodule.py
--- a/pypy/interpreter/mixedmodule.py
+++ b/pypy/interpreter/mixedmodule.py
@@ -56,8 +56,22 @@
 
         if self.w_initialdict is None:
             Module.init(self, space)
-            if not self.lazy and self.w_initialdict is None:
-                self.w_initialdict = space.call_method(self.w_dict, 'items')
+            if not self.lazy:
+                self._initial_nonlazy_init(space)
+
+    def _initial_nonlazy_init(self, space):
+        # for modules called '__builtin_*', build a default '__all__'
+        # that has all keys, including the ones starting with '_'.
+        if space.str_w(self.w_name).startswith('__builtin_'):
+            w_all = space.call_method(self.w_dict, 'keys')
+            try:
+                space.call_method(w_all, 'remove', space.wrap('__file__'))
+            except OperationError:
+                pass
+            space.setitem(self.w_dict, space.wrap('__all__'), w_all)
+        #
+        if self.w_initialdict is None:
+            self.w_initialdict = space.call_method(self.w_dict, 'items')
 
 
     def get_applevel_name(cls):
@@ -124,7 +138,7 @@
                 w_value = self.get(name)
                 space.setitem(self.w_dict, space.new_interned_str(name), w_value)
             self.lazy = False
-            self.w_initialdict = space.call_method(self.w_dict, 'items')
+            self._initial_nonlazy_init(space)
         return self.w_dict
 
     def _freeze_(self):
diff --git a/pypy/module/_io/__init__.py b/pypy/module/_io/__init__.py
--- a/pypy/module/_io/__init__.py
+++ b/pypy/module/_io/__init__.py
@@ -28,7 +28,7 @@
         'IncrementalNewlineDecoder': 'interp_textio.W_IncrementalNewlineDecoder',
         }
 
-    def init(self, space):
+    def startup(self, space):
         w_UnsupportedOperation = space.call_function(
             space.w_type,
             space.wrap('UnsupportedOperation'),


More information about the pypy-commit mailing list