Issue 26261: NamedTemporaryFile documentation is vague about the name attribute (original) (raw)

Created on 2016-02-01 17:21 by ztane, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
tempfile-name.patch martin.panter,2016-02-20 07:45 review
Messages (5)
msg259334 - (view) Author: Antti Haapala (ztane) * Date: 2016-02-01 17:21
The documentation for NamedTemporaryFile is a bit vague. It says [--] That name can be retrieved from the name attribute of the file object. [--] The returned object is always a file-like object whose file attribute is the underlying true file object. This file-like object can be used in a with statement, just like a normal file. That `file-like object` vs `true file object` made me assume that I need to do f = NamedTemporaryFile() f.file.name to get the filename, which sort of worked, but only later realized that `f.file.name` is actually the file descriptor number on Linux, a.k.a an integer. Thus I suggest that the one sentence be changed to "That name can be retrieved from the name attribute of the returned file-like object."
msg259352 - (view) Author: Martin Panter (martin.panter) * (Python committer) Date: 2016-02-02 02:37
Also the doc string could be updated. I guess suggesting “file.name” is even more confusing :)
msg259433 - (view) Author: Tamás Bence Gedai (beng94) * Date: 2016-02-02 21:17
Antti, would you like to provide a patch? If you don't want to work on it, I can give it a try.
msg260561 - (view) Author: Martin Panter (martin.panter) * (Python committer) Date: 2016-02-20 07:45
Here is my proposed patch.
msg260666 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2016-02-22 10:12
New changeset f1982e1426ce by Martin Panter in branch '3.5': Issue #26261: Clarify NamedTemporaryFile name attribute vs file.name https://hg.python.org/cpython/rev/f1982e1426ce New changeset 837bae8c8ae7 by Martin Panter in branch 'default': Issue #26261: Merge NamedTemporaryFile docs from 3.5 https://hg.python.org/cpython/rev/837bae8c8ae7 New changeset 27a140558a47 by Martin Panter in branch '2.7': Issue #26261: Clarify NamedTemporaryFile name attribute vs file.name https://hg.python.org/cpython/rev/27a140558a47
History
Date User Action Args
2022-04-11 14:58:27 admin set github: 70449
2016-02-22 10:55:43 martin.panter set status: open -> closedresolution: fixedstage: patch review -> resolved
2016-02-22 10:12:13 python-dev set nosy: + python-devmessages: +
2016-02-20 07:45:21 martin.panter set files: + tempfile-name.patchkeywords: + patchmessages: + stage: needs patch -> patch review
2016-02-02 21:17:50 beng94 set nosy: + beng94messages: +
2016-02-02 02:37:34 martin.panter set versions: + Python 2.7, Python 3.5, Python 3.6nosy: + martin.pantermessages: + stage: needs patch
2016-02-01 17:21:36 ztane set type: enhancement
2016-02-01 17:21:22 ztane create