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: suffix parameter in NamedTemporaryFile silently fails when not prepending with a period
Type: enhancement Stage: resolved
Components: Documentation Versions: Python 3.6, Python 3.5, Python 2.7
process
Status: closed Resolution: rejected
Dependencies: Superseder:
Assigned To: terry.reedy Nosy List: Jason.Myers, dloewenherz, docs@python, ezio.melotti, georg.brandl, martin.panter, ncoghlan, python-dev, terry.reedy
Priority: normal Keywords: easy, patch

Created on 2013-08-13 20:54 by dloewenherz, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
docstring.patch Jason.Myers, 2013-11-06 03:18 Docstring patch review
Messages (9)
msg195097 - (view) Author: Dan Loewenherz (dloewenherz) Date: 2013-08-13 20:54
Basically, when creating a NamedTemporaryFile, passing a value to the "suffix" parameter has no effect unless it's prepended with a period.

IMO, there are three options here...

1. Add a note in the documentation that this parameter only accepts period-prepended values (not ideal but better than the status quo).
2. Change the behavior to throw an exception when a non-period prepended value is provided (probably bad since it would break stuff).
3. Strip invalid values from this input and silently fail if the resulting string is of length 0 (might also break stuff).
msg195495 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2013-08-17 17:21
>>> import tempfile
>>> f = tempfile.NamedTemporaryFile(suffix='$')
>>> f.name
'/tmp/tmpumyks8ju$'

I see an effect.
msg195496 - (view) Author: Ezio Melotti (ezio.melotti) * (Python committer) Date: 2013-08-17 17:45
Works for me on Linux too (all branches, with different types of suffix).
Maybe it's a Windows issue?
msg195514 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2013-08-17 19:59
'Filename extensions' are a proper subset of 'suffixes'.
https://en.wikipedia.org/wiki/Filename_extension
Dan 'solutions' indicates that he thinks that the two sets are or should be the same, which they are not. The only thing that is DOS/Windows specific is its more special treatment of '.'.  That said, I can see how a Windows user might be confused by the following awkward sentence.

    If 'suffix' is specified, the file name will end with that suffix,
    otherwise there will be no suffix.

as 'no suffix' is easily read as 'no extension. The manual, but not the docstring, addresses the possible confusion by adding

  mkstemp() does not put a dot between the file name and the suffix;
  if you need one, put it at the beginning of suffix.

I think the prefix sentence is also a bit awkward.

    If 'prefix' is specified, the file name will begin with that prefix,
    otherwise a default prefix is used.

I think both parameters should be explained in both docstring and doc with one shorter and clearer entry.

"The file name will begin with *prefix* (default 'tmp') and end with *suffix* (default ''). The is no automatic addition of a period ('.') before the suffix."
msg195516 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2013-08-17 20:25
I don't think any explanation is needed. A docstring should be short, we can't duplicate a manual in it.

The mentioning suffix default is redundant because it already exposed in the function signature. The mentioning prefix default adds duplication. The purpose of introducing of the template attribute is get rid of such duplication.
msg195518 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2013-08-17 20:49
It would be fine with me to shorten the suggestion and not repeat the defaults. They are currently in both doc and docstring, but with *more* words than I used.

"The file name will begin with *prefix* and end with *suffix*. There is no automatic addition of a period ('.') before the suffix."

The explanation of . is already in the doc in a wordier form (too wordy in my view). The above is much shorter than what is currently in the docstring.
msg202253 - (view) Author: Jason Myers (Jason.Myers) Date: 2013-11-06 03:18
This is a patch based on terry.reedy 's suggestion
msg265098 - (view) Author: Martin Panter (martin.panter) * (Python committer) Date: 2016-05-07 22:44
I think Terry may have had the mkstemp() doc string in mind. The NamedTemporaryFile() doc string already points to that function, and it doesn’t make sense to single NamedTemporaryFile() out above other functions.
msg265105 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2016-05-07 23:37
Correct.  The doc I quoted was for the unlying mkstemp function.  I should have said so even though this fact was easily discovered. So by docstring, I meant the one for mkstemp also, which is currently 27 lines.  The docstring for the high level functions should not change.

I proposed to shorten the docstring by combining the sentences for prefix and suffix, while adding a bit of info.  I decided to withdraw this suggestion and close this issue.
History
Date User Action Args
2022-04-11 14:57:49adminsetgithub: 62930
2016-05-07 23:37:15terry.reedysetstatus: open -> closed
messages: + msg265105

assignee: docs@python -> terry.reedy
resolution: rejected
stage: patch review -> resolved
2016-05-07 22:44:46martin.pantersetnosy: + martin.panter
messages: + msg265098
2016-05-07 14:47:00serhiy.storchakasetnosy: + docs@python
versions: + Python 3.5, Python 3.6, - Python 3.3, Python 3.4
assignee: docs@python
components: + Documentation, - Library (Lib)
type: behavior -> enhancement
stage: needs patch -> patch review
2013-11-06 03:18:30Jason.Myerssetfiles: + docstring.patch

nosy: + Jason.Myers
messages: + msg202253

keywords: + patch
2013-09-11 23:06:36pitrousetnosy: + georg.brandl, ncoghlan
2013-09-11 22:34:21serhiy.storchakasetnosy: - serhiy.storchaka
2013-09-01 23:41:05terry.reedysetmessages: - msg196681
2013-08-31 22:19:13python-devsetnosy: + python-dev
messages: + msg196681
2013-08-17 20:49:20terry.reedysetmessages: + msg195518
2013-08-17 20:25:41serhiy.storchakasetmessages: + msg195516
2013-08-17 19:59:20terry.reedysetstatus: pending -> open

messages: + msg195514
stage: test needed -> needs patch
2013-08-17 17:45:36ezio.melottisetstatus: open -> pending
2013-08-17 17:45:08ezio.melottisetstatus: pending -> open
nosy: + terry.reedy
messages: + msg195496

2013-08-17 17:21:45serhiy.storchakasetstatus: open -> pending
nosy: + serhiy.storchaka
messages: + msg195495

2013-08-17 14:08:04ezio.melottisetkeywords: + easy
nosy: + ezio.melotti
stage: test needed

versions: + Python 3.3, Python 3.4
2013-08-13 20:54:00dloewenherzcreate