New GitHub issue #115961 from serhiy-storchaka:<br>

<hr>

<pre>
# Feature or enhancement

Regular file objects returned by the `open()` building have `name` and `name` and `mode` attributes. Some code may use these optional attributes for different purposes, for example to distinguish readable files from writable files, binary files from text files, or just for formatting the repr or error messages. For example:

* https://github.com/python/cpython/blob/main/Lib/tarfile.py#L1666
* https://github.com/python/cpython/blob/main/Lib/tarfile.py#L1669
* https://github.com/python/cpython/blob/main/Lib/socket.py#L455
* https://github.com/python/cpython/blob/main/Lib/gzip.py#L201
* https://github.com/python/cpython/blob/main/Lib/asyncio/base_events.py#L982
* https://github.com/python/cpython/blob/main/Lib/wave.py#L654

There are several file-like objects in compressing modules `gzip`, `bz2` and `lama` and archiving modules `zipfile` and `tarfile`. They usually implement the raw or buffered file protocols from `io`, but not always have `name` and `mode` attributes, and when they have, they not always have common semantic.

`GzipFile`, unlike to `BZ2File` and `LZMAFile`, has `name` and `mode` attributes, but `mode` is an integer, that confuses `tarfile` (see #62775).

`ZipExtFile` has the `mode` attribute which is always `'r'`. It is a legacy from Python 2, when it could also be `'U'` or `'rU'` for files with universal newlines. But this mode was removed long time ago, and since it is a binary file, its mode should be `'rb'`.

See also #68446, #91373, #91374. I opened this issue because consider it all the parts of larger image.
</pre>

<hr>

<a href="https://github.com/python/cpython/issues/115961">View on GitHub</a>
<p>Labels: type-feature</p>
<p>Assignee: serhiy-storchaka</p>