Commits

Philip Jenvey committed 9813b8a

cache UnsupportedOperation to avoid issues w/ io being frozen, fix __module__
again

Comments (0)

Files changed (3)

pypy/module/_io/__init__.py

     interpleveldefs = {
         'DEFAULT_BUFFER_SIZE': 'space.wrap(interp_iobase.DEFAULT_BUFFER_SIZE)',
         'BlockingIOError': 'interp_io.W_BlockingIOError',
+        'UnsupportedOperation':
+            'space.fromcache(interp_io.Cache).w_unsupportedoperation',
         '_IOBase': 'interp_iobase.W_IOBase',
         '_RawIOBase': 'interp_iobase.W_RawIOBase',
         '_BufferedIOBase': 'interp_bufferedio.W_BufferedIOBase',
         'IncrementalNewlineDecoder': 'interp_textio.W_IncrementalNewlineDecoder',
         }
 
-    def init(self, space):
-        MixedModule.init(self, space)
-        w_UnsupportedOperation = space.call_function(
-            space.w_type,
-            space.wrap('UnsupportedOperation'),
-            space.newtuple([space.w_ValueError, space.w_IOError]),
-            space.newdict())
-        space.setattr(self, space.wrap('UnsupportedOperation'),
-                      w_UnsupportedOperation)
-
     def shutdown(self, space):
         # at shutdown, flush all open streams.  Ignore I/O errors.
         from pypy.module._io.interp_iobase import get_autoflushher

pypy/module/_io/interp_io.py

 from rpython.rtyper.module.ll_os_stat import STAT_FIELD_TYPES
 
 
+class Cache:
+    def __init__(self, space):
+        self.w_unsupportedoperation = space.new_exception_class(
+            "io.UnsupportedOperation",
+            space.newtuple([space.w_ValueError, space.w_IOError]))
+
 class W_BlockingIOError(W_IOError):
     def __init__(self, space):
         W_IOError.__init__(self, space)
 
 W_BlockingIOError.typedef = TypeDef(
     'BlockingIOError', W_IOError.typedef,
+    __module__ = 'io',
     __doc__ = ("Exception raised when I/O would block "
                "on a non-blocking I/O stream"),
     __new__  = generic_new_descr(W_BlockingIOError),

pypy/module/_io/test/test_io.py

 
     def test_mod(self):
         import _io
-        assert all(t.__module__ == '_io' for t in dir(_io)
+        assert all(t.__module__ in ('io', '_io') for t in vars(_io).values()
                    if isinstance(t, type))