Issue 27023: Documentation of tempfile.gettempdir() does not mention it only supports existing directories (original) (raw)

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:31 admin set github: 71210
2016-05-15 16:45:40 r.david.murray set messages: +
2016-05-15 16:27:55 Valentin.Lorentz set messages: +
2016-05-15 15:32:51 r.david.murray set status: open -> closednosy: + r.david.murraymessages: + resolution: rejectedstage: resolved
2016-05-15 07:08:12 Valentin.Lorentz set messages: +
2016-05-15 02:38:54 steven.daprano set nosy: + steven.dapranomessages: +
2016-05-14 17:39:43 Valentin.Lorentz create