New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
tempfile.template is broken #54563
Comments
>>> import tempfile
>>> tempfile.template = 'XXX'
>>> tempfile.mkdtemp()
'/tmp/tmpPf5lML'
>>> Functions that use template use it as an argument default, so changing it afterwards has no effect. |
Patch in attachment. |
The patch looks good to me, but it needs a test. |
Patch including tests is in attachment. >>> tempfile.TemporaryFile().name
'<fdopen>'
>>> tempfile.TemporaryFile(prefix='xxx').name
'<fdopen>'
>>> tempfile.SpooledTemporaryFile().name
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/giampaolo/svn/python-2.7/Lib/tempfile.py", line 574, in name
return self._file.name
AttributeError: 'cStringIO.StringO' object has no attribute 'name' I'm going to open two separate tickets. |
Adding georg.brandl to nosy list as per misc/maintainers.rst. |
Created bpo-10355 for SpooledTemporaryFile bug while TemporaryFile having no name seems to be rightful. |
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. |
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. |
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. |
+1 for just deleting it. nothing is lost by deleting code that never worked in the first place ;-) |
New changeset eafe8c7f7049 by R David Murray in branch 'default': |
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. |
backwards compatibility with what? i'd like to just remove tempfile.template in 3.5 as part of addressing bpo-24230. |
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 it...it's not likely anyone is using it, I just tend to be conservative unless there is motivation to do otherwise.) |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: