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.

Title: tempfile.template is broken
Type: Stage: resolved
Components: Library (Lib) Versions: Python 3.1, Python 3.2, Python 2.7
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: eric.araujo, eric.smith, georg.brandl, giampaolo.rodola, gregory.p.smith, python-dev, r.david.murray, rhettinger
Priority: normal Keywords: patch

Created on 2010-11-08 11:28 by giampaolo.rodola, last changed 2022-04-11 14:57 by admin. This issue is now closed.

File name Uploaded Description Edit
tempfile.patch giampaolo.rodola, 2010-11-08 11:33 review
tempfile.patch giampaolo.rodola, 2010-11-08 12:04 review
Messages (14)
msg120729 - (view) Author: Giampaolo Rodola' (giampaolo.rodola) * (Python committer) Date: 2010-11-08 11:28
>>> import tempfile
>>> tempfile.template = 'XXX'
>>> tempfile.mkdtemp()

Functions that use template use it as an argument default, so changing it afterwards has no effect.
msg120730 - (view) Author: Giampaolo Rodola' (giampaolo.rodola) * (Python committer) Date: 2010-11-08 11:33
Patch in attachment.
msg120732 - (view) Author: Eric V. Smith (eric.smith) * (Python committer) Date: 2010-11-08 11:44
The patch looks good to me, but it needs a test.
msg120734 - (view) Author: Giampaolo Rodola' (giampaolo.rodola) * (Python committer) Date: 2010-11-08 12:04
Patch including tests is in attachment.
I think I've just found two further bugs though:

>>> tempfile.TemporaryFile().name
>>> tempfile.TemporaryFile(prefix='xxx').name
>>> tempfile.SpooledTemporaryFile().name
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/giampaolo/svn/python-2.7/Lib/", line 574, in name
AttributeError: 'cStringIO.StringO' object has no attribute 'name'

I'm going to open two separate tickets.
msg120735 - (view) Author: Giampaolo Rodola' (giampaolo.rodola) * (Python committer) Date: 2010-11-08 12:07
Adding georg.brandl to nosy list as per misc/maintainers.rst.
msg120737 - (view) Author: Giampaolo Rodola' (giampaolo.rodola) * (Python committer) Date: 2010-11-08 12:23
Created issue 10355 for SpooledTemporaryFile bug while TemporaryFile having no name seems to be rightful.
msg120746 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2010-11-08 14:57
Shouldn't the global template variable just be deleted in python3?  It is no longer documented except for what is probably an overlooked mention in the introduction.
msg120828 - (view) Author: Eric V. Smith (eric.smith) * (Python committer) Date: 2010-11-09 00:55
I sort of agree with David.

The global "template" is a bad name and a bad design. And since it doesn't work I don't think anything would be lost by modifying the code to ignore it; document that it's unused and deprecated; and remove it in a future version.
msg120834 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2010-11-09 02:32
It has been documented as deprecated since 2.0. I'm sure the intent was for all mention of it to have been deleted from the 3.x docs already, but that first paragraph was overlooked.
msg120835 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2010-11-09 02:41
+1 for just deleting it.   nothing is lost by deleting code that never worked in the first place ;-)
msg138844 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2011-06-23 01:01
New changeset eafe8c7f7049 by R David Murray in branch 'default':
#10354: remove last public mentions of 'template' and comment as private.
msg138845 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2011-06-23 01:03
I have removed the last mentions of template from the docs and docstrings, and added a comment that it is a private variable despite its name.  I do not see a reason to break backward compatibility just to have a leading underscore in the name.  If there is disagreement on this we can reopen the issue.
msg243551 - (view) Author: Gregory P. Smith (gregory.p.smith) * (Python committer) Date: 2015-05-19 01:08
backwards compatibility with what?  i'd like to just remove tempfile.template in 3.5 as part of addressing issue24230.
msg243553 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2015-05-19 01:29
Backward compatibility in that someone might be using the constant in their code.  You could just leave the existing value there with a comment that it is unused and use a leading _ for the new constants.  (Or you could delete's not likely anyone is using it, I just tend to be conservative unless there is motivation to do otherwise.)
Date User Action Args
2022-04-11 14:57:08adminsetgithub: 54563
2015-05-19 01:29:47r.david.murraysetmessages: + msg243553
2015-05-19 01:08:03gregory.p.smithsetnosy: + gregory.p.smith
messages: + msg243551
2011-06-23 01:03:55r.david.murraysetstatus: open -> closed
resolution: fixed
messages: + msg138845

stage: test needed -> resolved
2011-06-23 01:01:50python-devsetnosy: + python-dev
messages: + msg138844
2010-11-09 02:41:48rhettingersetnosy: + rhettinger
messages: + msg120835
2010-11-09 02:33:00r.david.murraysetmessages: + msg120834
2010-11-09 00:55:53eric.smithsetmessages: + msg120828
2010-11-08 15:08:34eric.araujosetnosy: + eric.araujo
2010-11-08 14:57:20r.david.murraysetnosy: + r.david.murray
messages: + msg120746
2010-11-08 12:23:09giampaolo.rodolasetmessages: + msg120737
2010-11-08 12:07:08giampaolo.rodolasetnosy: + georg.brandl
messages: + msg120735
2010-11-08 12:04:57giampaolo.rodolasetfiles: + tempfile.patch

messages: + msg120734
2010-11-08 11:44:33eric.smithsetnosy: + eric.smith

messages: + msg120732
stage: test needed
2010-11-08 11:33:24giampaolo.rodolasetfiles: + tempfile.patch
keywords: + patch
messages: + msg120730
2010-11-08 11:28:09giampaolo.rodolacreate