[issue27023] Documentation of tempfile.gettempdir() does not mention it only supports existing directories
New submission from ProgVal: 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 ---------- assignee: docs@python components: Documentation, Library (Lib) messages: 265539 nosy: Valentin.Lorentz, docs@python priority: normal severity: normal status: open title: Documentation of tempfile.gettempdir() does not mention it only supports existing directories versions: Python 3.4, Python 3.5, Python 3.6 _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue27023> _______________________________________
Steven D'Aprano added the comment: 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? ---------- nosy: +steven.daprano _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue27023> _______________________________________
ProgVal added the comment: The directory could be created ---------- _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue27023> _______________________________________
R. David Murray added the comment: 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. ---------- nosy: +r.david.murray resolution: -> rejected stage: -> resolved status: open -> closed _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue27023> _______________________________________
ProgVal added the comment: I know, that's why I did not ask to change the code. Only the doc to make that behavior more explicit. ---------- _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue27023> _______________________________________
R. David Murray added the comment: 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. ---------- _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue27023> _______________________________________
participants (3)
-
ProgVal -
R. David Murray -
Steven D'Aprano