mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
Issue #5761: Add the name of the underlying file to the repr() of various IO objects.
This commit is contained in:
parent
744af44064
commit
716c444edc
7 changed files with 107 additions and 14 deletions
17
Lib/_pyio.py
17
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):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue