This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Improve repr for files to show whether the file is open or closed.
Type: enhancement Stage: resolved
Components: Versions: Python 3.6
process
Status: closed Resolution: out of date
Dependencies: Superseder:
Assigned To: pitrou Nosy List: pitrou, rhettinger, serhiy.storchaka
Priority: normal Keywords:

Created on 2015-11-03 17:49 by rhettinger, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Messages (2)
msg254007 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2015-11-03 17:49
Good news in Python 3.5, the __repr__ for locks now indicates whether the lock is in a locked state.   Bad news for Python 3.x, the __repr__ for files lost the indication of the file's open/closed status:

Python 3:
---------
  $ python3.5
  Python 3.5.0 (v3.5.0:374f501f4567, Sep 12 2015, 11:00:19) 
  [GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
  Type "help", "copyright", "credits" or "license" for more information.
  >>> open('hamlet.txt')
  <_io.TextIOWrapper name='hamlet.txt' mode='r' encoding='UTF-8'>

Python 2:
---------
  # python2.7
  Python 2.7.10 (v2.7.10:15c95b7d81dc, May 23 2015, 09:33:12) 
  [GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
  Type "help", "copyright", "credits" or "license" for more information.
  >>> open('hamlet.txt')
  <open file 'hamlet.txt', mode 'r' at 0x1006a0660>

    ^----- status
msg254010 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2015-11-03 18:22
>>> f = open('/dev/null', 'rb', buffering=0)
>>> f
<_io.FileIO name='/dev/null' mode='rb' closefd=True>
>>> f.close()
>>> f
<_io.FileIO [closed]>
History
Date User Action Args
2022-04-11 14:58:23adminsetgithub: 69733
2017-03-07 19:15:38serhiy.storchakasetstatus: pending -> closed
resolution: not a bug -> out of date
2016-01-04 03:45:13ezio.melottisetstatus: open -> pending
resolution: not a bug
stage: needs patch -> resolved
2015-11-03 18:22:33serhiy.storchakasetnosy: + serhiy.storchaka
messages: + msg254010
2015-11-03 17:49:00rhettingercreate