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: io.FileIO.mode doesn't comply with the docs
Type: behavior Stage: resolved
Components: Documentation, IO Versions: Python 3.7
process
Status: closed Resolution: duplicate
Dependencies: Superseder: File mode wb+ appears as rb+
View: 25341
Assigned To: docs@python Nosy List: benjamin.peterson, docs@python, iritkatriel, mike.parker, serhiy.storchaka, stutzbach
Priority: normal Keywords:

Created on 2020-04-26 00:50 by mike.parker, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Messages (3)
msg367288 - (view) Author: (mike.parker) Date: 2020-04-26 00:50
io.FileIO.mode doesn't reflect "The mode as given in the constructor." as per the documentation(https://docs.python.org/3/library/io.html#io.FileIO.mode).
Was noted in issue4362, but seems to be still relevant.

Example:
>>> f = open("t.tmp", "w+b")
>>> f.mode
'rb+'
msg377824 - (view) Author: Irit Katriel (iritkatriel) * (Python committer) Date: 2020-10-02 17:19
The mode string is calculated here: https://github.com/python/cpython/blob/master/Modules/_io/fileio.c#L1055

and is based on these four values in the fileio struct:

    unsigned int created : 1;
    unsigned int readable : 1;
    unsigned int writable : 1;
    unsigned int appending : 1;

This is not enough information to distinguish between r+ and w+. That distinction was lost in _io_FileIO___init___impl, where it specified the flags that went into creating fd, but these flags are not saved.

The bit fields in this struct add up to 7 bits, so it seems possible to fix this if another bit is allocated for this purpose.

If it's not worth it, then the documentation needs to change a little.
msg377827 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2020-10-02 18:56
It is a duplicate of issue25341.
History
Date User Action Args
2022-04-11 14:59:29adminsetgithub: 84571
2020-10-02 18:56:35serhiy.storchakasetstatus: open -> closed

superseder: File mode wb+ appears as rb+

nosy: + serhiy.storchaka
messages: + msg377827
resolution: duplicate
stage: resolved
2020-10-02 17:19:20iritkatrielsetnosy: + iritkatriel
messages: + msg377824
2020-04-26 00:50:56mike.parkercreate