[pypy-svn] pypy default: Try to get some more reprs in _io right.

alex_gaynor commits-noreply at bitbucket.org
Sun Jan 30 06:13:44 CET 2011


Author: Alex Gaynor <alex.gaynor at gmail.com>
Branch: 
Changeset: r41470:743ddf758825
Date: 2011-01-30 00:13 -0500
http://bitbucket.org/pypy/pypy/changeset/743ddf758825/

Log:	Try to get some more reprs in _io right.

diff --git a/pypy/module/_io/interp_textio.py b/pypy/module/_io/interp_textio.py
--- a/pypy/module/_io/interp_textio.py
+++ b/pypy/module/_io/interp_textio.py
@@ -373,8 +373,14 @@
 
     @unwrap_spec('self', ObjSpace)
     def descr_repr(self, space):
+        w_name = space.findattr(self, space.wrap("name"))
+        if w_name is None:
+            w_name_str = space.wrap("")
+        else:
+            w_name_str = space.mod(space.wrap("name=%r "), w_name)
+        w_args = space.newtuple([w_name_str, self.w_encoding])
         return space.mod(
-            space.wrap("<_io.TextIOWrapper encoding=%r>"), self.w_encoding
+            space.wrap("<_io.TextIOWrapper %sencoding=%r>"), w_args
         )
 
     @unwrap_spec('self', ObjSpace)

diff --git a/pypy/module/_io/interp_bufferedio.py b/pypy/module/_io/interp_bufferedio.py
--- a/pypy/module/_io/interp_bufferedio.py
+++ b/pypy/module/_io/interp_bufferedio.py
@@ -749,7 +749,7 @@
         self.state = STATE_OK
 
 W_BufferedReader.typedef = TypeDef(
-    '_io.BufferedReader', W_BufferedIOBase.typedef,
+    'BufferedReader', W_BufferedIOBase.typedef,
     __new__ = generic_new_descr(W_BufferedReader),
     __init__  = interp2app(W_BufferedReader.descr_init),
     __module__ = "_io",
@@ -795,7 +795,7 @@
         self.state = STATE_OK
 
 W_BufferedWriter.typedef = TypeDef(
-    '_io.BufferedWriter', W_BufferedIOBase.typedef,
+    'BufferedWriter', W_BufferedIOBase.typedef,
     __new__ = generic_new_descr(W_BufferedWriter),
     __init__  = interp2app(W_BufferedWriter.descr_init),
     __module__ = "_io",
@@ -897,7 +897,7 @@
     __init__  = interp2app(W_BufferedRWPair.descr_init),
     closed = GetSetProperty(W_BufferedRWPair.closed_get_w),
     **methods
-    )
+)
 
 class W_BufferedRandom(BufferedMixin, W_BufferedIOBase):
     @unwrap_spec('self', ObjSpace, W_Root, int, int)
@@ -923,7 +923,7 @@
         self.state = STATE_OK
 
 W_BufferedRandom.typedef = TypeDef(
-    '_io.BufferedRandom', W_BufferedIOBase.typedef,
+    'BufferedRandom', W_BufferedIOBase.typedef,
     __new__ = generic_new_descr(W_BufferedRandom),
     __init__ = interp2app(W_BufferedRandom.descr_init),
     __module__ = "_io",

diff --git a/pypy/module/_io/test/test_textio.py b/pypy/module/_io/test/test_textio.py
--- a/pypy/module/_io/test/test_textio.py
+++ b/pypy/module/_io/test/test_textio.py
@@ -175,6 +175,8 @@
         assert repr(t) == "<_io.TextIOWrapper encoding='ascii'>"
         t = _io.TextIOWrapper(_io.BytesIO(""), encoding=u"utf-8")
         assert repr(t) == "<_io.TextIOWrapper encoding='utf-8'>"
+        t.name = "dummy"
+        assert repr(t) == "<_io.TextIOWrapper name='dummy' encoding='utf-8'>"
 
 
 class AppTestIncrementalNewlineDecoder:


More information about the Pypy-commit mailing list