summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
Diffstat (limited to 'Lib')
-rw-r--r--Lib/_pyio.py3
-rw-r--r--Lib/test/test_io.py6
2 files changed, 9 insertions, 0 deletions
diff --git a/Lib/_pyio.py b/Lib/_pyio.py
index c6811db..535c9ca 100644
--- a/Lib/_pyio.py
+++ b/Lib/_pyio.py
@@ -1399,6 +1399,9 @@ class TextIOWrapper(TextIOBase):
# - "bytes_..." for integer variables that count input bytes
# - "chars_..." for integer variables that count decoded characters
+ def __repr__(self):
+ return "<TextIOWrapper encoding={0}>".format(self.encoding)
+
@property
def encoding(self):
return self._encoding
diff --git a/Lib/test/test_io.py b/Lib/test/test_io.py
index 5fc53ea..ef3fed9 100644
--- a/Lib/test/test_io.py
+++ b/Lib/test/test_io.py
@@ -1354,6 +1354,12 @@ class TextIOWrapperTest(unittest.TestCase):
self.assertRaises(TypeError, t.__init__, b, newline=42)
self.assertRaises(ValueError, t.__init__, b, newline='xyzzy')
+ def test_repr(self):
+ raw = self.BytesIO("hello".encode("utf-8"))
+ b = self.BufferedReader(raw)
+ t = self.TextIOWrapper(b, encoding="utf-8")
+ self.assertEqual(repr(t), "<TextIOWrapper encoding=utf-8>")
+
def test_line_buffering(self):
r = self.BytesIO()
b = self.BufferedWriter(r, 1000)