summaryrefslogtreecommitdiffstats
path: root/Lib/_pyio.py
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2009-05-23 19:04:03 (GMT)
committerAntoine Pitrou <solipsis@pitrou.net>2009-05-23 19:04:03 (GMT)
commit716c444edcac0f32c6d82d530db2e6495e3d2be9 (patch)
treef63a8b6c4839ed622022eb5f1a8fab988b1847bc /Lib/_pyio.py
parent744af4406406d8c96a5a368efbf6f377a7d79095 (diff)
downloadcpython-716c444edcac0f32c6d82d530db2e6495e3d2be9.zip
cpython-716c444edcac0f32c6d82d530db2e6495e3d2be9.tar.gz
cpython-716c444edcac0f32c6d82d530db2e6495e3d2be9.tar.bz2
Issue #5761: Add the name of the underlying file to the repr() of various IO objects.
Diffstat (limited to 'Lib/_pyio.py')
-rw-r--r--Lib/_pyio.py17
1 files changed, 16 insertions, 1 deletions
diff --git a/Lib/_pyio.py b/Lib/_pyio.py
index c9a7c5e..c1cdf43 100644
--- a/Lib/_pyio.py
+++ b/Lib/_pyio.py
@@ -736,6 +736,15 @@ class _BufferedIOMixin(BufferedIOBase):
def mode(self):
return self.raw.mode
+ def __repr__(self):
+ clsname = self.__class__.__name__
+ try:
+ name = self.name
+ except AttributeError:
+ return "<_pyio.{0}>".format(clsname)
+ else:
+ return "<_pyio.{0} name={1!r}>".format(clsname, name)
+
### Lower-level APIs ###
def fileno(self):
@@ -1455,7 +1464,13 @@ class TextIOWrapper(TextIOBase):
# - "chars_..." for integer variables that count decoded characters
def __repr__(self):
- return "<TextIOWrapper encoding={0}>".format(self.encoding)
+ try:
+ name = self.name
+ except AttributeError:
+ return "<_pyio.TextIOWrapper encoding={0!r}>".format(self.encoding)
+ else:
+ return "<_pyio.TextIOWrapper name={0!r} encoding={1!r}>".format(
+ name, self.encoding)
@property
def encoding(self):