[pypy-svn] r49540 - pypy/branch/pypy-interp-file/module/bz2

arigo at codespeak.net arigo at codespeak.net
Fri Dec 7 21:40:02 CET 2007


Author: arigo
Date: Fri Dec  7 21:40:01 2007
New Revision: 49540

Modified:
   pypy/branch/pypy-interp-file/module/bz2/interp_bz2.py
Log:
hacking hacking... can't just use the name "__init__" again
because the RTyper is confused about the two direct__init__() with
a different signature, confusion caused by the fact that
W_File.file__init__() would appear to contain an indirect
call to one of the two versions of direct__init__().


Modified: pypy/branch/pypy-interp-file/module/bz2/interp_bz2.py
==============================================================================
--- pypy/branch/pypy-interp-file/module/bz2/interp_bz2.py	(original)
+++ pypy/branch/pypy-interp-file/module/bz2/interp_bz2.py	Fri Dec  7 21:40:01 2007
@@ -170,7 +170,8 @@
 
 class W_BZ2File(W_File):
 
-    def direct___init__(self, name, mode='r', buffering=-1, compresslevel=9):
+    def direct_bz2__init__(self, name, mode='r', buffering=-1,
+                           compresslevel=9):
         self.direct_close()
         # the stream should always be opened in binary mode
         if "b" not in mode:
@@ -182,17 +183,22 @@
         self.fdopenstream(stream, fd, mode, name)
 
     _exposed_method_names = []
-    W_File._decl.im_func(locals(), "__init__", ['self', str, str, int, int],
+    W_File._decl.im_func(locals(), "bz2__init__", ['self', str, str, int, int],
           """Opens a BZ2-compressed file.""")
+    # XXX ^^^ hacking hacking... can't just use the name "__init__" again
+    # because the RTyper is confused about the two direct__init__() with
+    # a different signature, confusion caused by the fact that
+    # W_File.file__init__() would appear to contain an indirect call to
+    # one of the two versions of direct__init__().
 
-    def bz2file__repr__(self):
+    def file_bz2__repr__(self):
         if self.stream is None:
             head = "closed"
         else:
             head = "open"
         info = "%s bz2.BZ2File '%s', mode '%s'" % (head, self.name, self.mode)
         return self.getrepr(self.space, info)
-    bz2file__repr__.unwrap_spec = ['self']
+    file_bz2__repr__.unwrap_spec = ['self']
 
 def descr_bz2file__new__(space, w_subtype, args):
     bz2file = space.allocate_instance(W_BZ2File, w_subtype)
@@ -206,11 +212,6 @@
     'name', 'mode', 'encoding', 'closed', 'newlines', 'softspace',
     '__weakref__'])
 
-extra_attrs = dict([(name, interp2app(getattr(W_BZ2File, 'file_' + name)))
-                    for name in W_BZ2File._exposed_method_names])
-extra_attrs.update(dict([(name, W_File.typedef.rawdict[name])
-                         for name in same_attributes_as_in_file]))
-
 W_BZ2File.typedef = TypeDef(
     "BZ2File",
     __doc__ = """\
@@ -229,8 +230,10 @@
 '\\r\\n' or a tuple containing all the newline types seen. Universal
 newlines are available only when reading.""",
     __new__  = interp2app(descr_bz2file__new__),
-    __repr__ = interp2app(W_BZ2File.bz2file__repr__),
-    **extra_attrs)
+    __init__ = interp2app(W_BZ2File.file_bz2__init__),
+    __repr__ = interp2app(W_BZ2File.file_bz2__repr__),
+    **dict([(name, W_File.typedef.rawdict[name])
+            for name in same_attributes_as_in_file]))
 
 # ____________________________________________________________
 



More information about the Pypy-commit mailing list