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: Documentation of tempfile.gettempdir() does not mention it only supports existing directories
Type: Stage: resolved
Components: Documentation, Library (Lib) Versions: Python 3.6, Python 3.4, Python 3.5
process
Status: closed Resolution: rejected
Dependencies: Superseder:
Assigned To: docs@python Nosy List: Valentin.Lorentz, docs@python, r.david.murray, steven.daprano
Priority: normal Keywords:

Created on 2016-05-14 17:39 by Valentin.Lorentz, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Messages (6)
msg265539 - (view) Author: ProgVal (Valentin.Lorentz) Date: 2016-05-14 17:39
Documentation of tempfile.gettempdir() <https://docs.python.org/3/library/tempfile.html#tempfile.gettempdir> does not mention it only supports existing directories.

This led to this question on Stackoverflow: http://stackoverflow.com/q/37229398/539465
msg265569 - (view) Author: Steven D'Aprano (steven.daprano) * (Python committer) Date: 2016-05-15 02:38
I don't understand. The documentation clearly states:

"Python searches a standard list of directories to find one which the calling user can create files in." How do you expect to be able to write files to a directory that doesn't exist?
msg265590 - (view) Author: ProgVal (Valentin.Lorentz) Date: 2016-05-15 07:08
The directory could be created
msg265620 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2016-05-15 15:32
No, it shouldn't.

The design is that different systems use different locations for the default tempdir, and we look down a list of ones we know about until we find one that exists and can be used.  Likewise, different shells use different environment variables, so we look at a sequence of those as well.

It is arguable whether the fact that an environment variable that points to an invalid directory is ignored is a feature or a bug, but at this point tempfile has behaved that was for so long that we must class it as a feature.

In any case, I would find it objectionable for a program to create a temporary directory for me unasked.  It would be much more likely that I misspelled the directory when I set the environment variable.
msg265630 - (view) Author: ProgVal (Valentin.Lorentz) Date: 2016-05-15 16:27
I know, that's why I did not ask to change the code. Only the doc to make that behavior more explicit.
msg265632 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2016-05-15 16:45
As Steve pointed out, the documentation is explicit: "to *find* one the user can craete files in".  You can't find something that doesn't yet exist.
History
Date User Action Args
2022-04-11 14:58:31adminsetgithub: 71210
2016-05-15 16:45:40r.david.murraysetmessages: + msg265632
2016-05-15 16:27:55Valentin.Lorentzsetmessages: + msg265630
2016-05-15 15:32:51r.david.murraysetstatus: open -> closed

nosy: + r.david.murray
messages: + msg265620

resolution: rejected
stage: resolved
2016-05-15 07:08:12Valentin.Lorentzsetmessages: + msg265590
2016-05-15 02:38:54steven.dapranosetnosy: + steven.daprano
messages: + msg265569
2016-05-14 17:39:43Valentin.Lorentzcreate