classification
Title: NamedTemporaryFile documentation is vague about the `name` attribute
Type: enhancement Stage: resolved
Components: Documentation Versions: Python 3.6, Python 3.5, Python 2.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: docs@python Nosy List: beng94, docs@python, martin.panter, python-dev, ztane
Priority: normal Keywords: patch

Created on 2016-02-01 17:21 by ztane, last changed 2016-02-22 10:55 by martin.panter. 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
2016-02-22 10:55:43martin.pantersetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2016-02-22 10:12:13python-devsetnosy: + python-dev
messages: + msg260666
2016-02-20 07:45:21martin.pantersetfiles: + tempfile-name.patch
keywords: + patch
messages: + msg260561

stage: needs patch -> patch review
2016-02-02 21:17:50beng94setnosy: + beng94
messages: + msg259433
2016-02-02 02:37:34martin.pantersetversions: + Python 2.7, Python 3.5, Python 3.6
nosy: + martin.panter

messages: + msg259352

stage: needs patch
2016-02-01 17:21:36ztanesettype: enhancement
2016-02-01 17:21:22ztanecreate