[pypy-commit] pypy builtin-module: Clean up the hack, replacing it with a simpler hack...

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


Author: Armin Rigo <arigo at tunes.org>
Branch: builtin-module
Changeset: r50122:4875ef10dc16
Date: 2011-12-04 13:06 +0100
http://bitbucket.org/pypy/pypy/changeset/4875ef10dc16/

Log:	Clean up the hack, replacing it with a simpler hack...

diff --git a/pypy/interpreter/mixedmodule.py b/pypy/interpreter/mixedmodule.py
--- a/pypy/interpreter/mixedmodule.py
+++ b/pypy/interpreter/mixedmodule.py
@@ -56,22 +56,8 @@
 
         if self.w_initialdict is None:
             Module.init(self, space)
-            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')
+            if not self.lazy and self.w_initialdict is None:
+                self.w_initialdict = space.call_method(self.w_dict, 'items')
 
 
     def get_applevel_name(cls):
@@ -138,7 +124,7 @@
                 w_value = self.get(name)
                 space.setitem(self.w_dict, space.new_interned_str(name), w_value)
             self.lazy = False
-            self._initial_nonlazy_init(space)
+            self.w_initialdict = space.call_method(self.w_dict, 'items')
         return self.w_dict
 
     def _freeze_(self):
@@ -167,6 +153,10 @@
                 loaders['__file__'] = cls.get__file__
             if '__doc__' not in loaders:
                 loaders['__doc__'] = cls.get__doc__
+            if '__all__' not in loaders:
+                if ((cls.applevel_name or '').startswith('__builtin_') and
+                        cls.applevel_name != '__builtin__'):
+                    loaders['__all__'] = cls.get__all__Ellipsis
 
     buildloaders = classmethod(buildloaders)
 
@@ -204,6 +194,10 @@
         return space.wrap(cls.__doc__)
     get__doc__ = classmethod(get__doc__)
 
+    def get__all__Ellipsis(cls, space):
+        return space.w_Ellipsis
+    get__all__Ellipsis = classmethod(get__all__Ellipsis)
+
 
 def getinterpevalloader(pkgroot, spec):
     """ NOT_RPYTHON """
diff --git a/pypy/interpreter/pyopcode.py b/pypy/interpreter/pyopcode.py
--- a/pypy/interpreter/pyopcode.py
+++ b/pypy/interpreter/pyopcode.py
@@ -1488,6 +1488,12 @@
             skip_leading_underscores = True
         else:
             skip_leading_underscores = False
+            # pypy extension, for __builtin_* modules
+            if all is Ellipsis:
+                all = set(module.__dict__)
+                all.discard('__name__')
+                all.discard('__file__')
+                all.discard('__all__')
         for name in all:
             if skip_leading_underscores and name[0]=='_':
                 continue


More information about the pypy-commit mailing list