diff options
author | Antoine Pitrou <solipsis@pitrou.net> | 2011-01-09 20:38:15 (GMT) |
---|---|---|
committer | Antoine Pitrou <solipsis@pitrou.net> | 2011-01-09 20:38:15 (GMT) |
commit | a4815caa7ccf21aa994d0e0eec66873072f0e352 (patch) | |
tree | 5ccb44937ddfdd59ebae4590d2f4cfc05dcced3d /Lib/_pyio.py | |
parent | a6c91f5e3b013be1447454b3a479d6fabbf16806 (diff) | |
download | cpython-a4815caa7ccf21aa994d0e0eec66873072f0e352.zip cpython-a4815caa7ccf21aa994d0e0eec66873072f0e352.tar.gz cpython-a4815caa7ccf21aa994d0e0eec66873072f0e352.tar.bz2 |
Issue #10872: The repr() of TextIOWrapper objects now includes the mode
if available.
(at Georg's request)
Diffstat (limited to 'Lib/_pyio.py')
-rw-r--r-- | Lib/_pyio.py | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/Lib/_pyio.py b/Lib/_pyio.py index 2a6e7a8..3c1e805 100644 --- a/Lib/_pyio.py +++ b/Lib/_pyio.py @@ -1504,13 +1504,20 @@ class TextIOWrapper(TextIOBase): # - "chars_..." for integer variables that count decoded characters def __repr__(self): + result = "<_pyio.TextIOWrapper" try: name = self.name except AttributeError: - return "<_pyio.TextIOWrapper encoding={0!r}>".format(self.encoding) + pass + else: + result += " name={0!r}".format(name) + try: + mode = self.mode + except AttributeError: + pass else: - return "<_pyio.TextIOWrapper name={0!r} encoding={1!r}>".format( - name, self.encoding) + result += " mode={0!r}".format(mode) + return result + " encoding={0!r}>".format(self.encoding) @property def encoding(self): |