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: tempfile.tempdir cannot be unset
Type: behavior Stage: resolved
Components: Documentation Versions: Python 3.7, Python 3.6, Python 2.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: docs@python Nosy List: docs@python, eric.smith, iritkatriel, pablogsal, philiprowlands
Priority: normal Keywords: patch

Created on 2018-06-18 07:34 by philiprowlands, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 7829 merged thatiparthy, 2018-06-20 20:07
PR 7841 merged miss-islington, 2018-06-21 07:56
PR 7842 merged miss-islington, 2018-06-21 07:57
Messages (8)
msg319867 - (view) Author: Philip Rowlands (philiprowlands) Date: 2018-06-18 07:34
Quoting https://docs.python.org/3/library/tempfile.html
"""
tempfile.tempdir
When set to a value other than None, this variable defines the default value for the dir argument to the functions defined in this module.

If tempdir is unset or None at any call to any of the above functions except gettempprefix() it is initialized following the algorithm described in gettempdir().
"""

"If tempdir is unset ..." is not true:

$ python3 -c 'import tempfile; del tempfile.tempdir; t = tempfile.mkdtemp()'
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/usr/lib/python3.2/tempfile.py", line 298, in mkdtemp
    dir = gettempdir()
  File "/usr/lib/python3.2/tempfile.py", line 238, in gettempdir
    if tempdir is None:
NameError: global name 'tempdir' is not defined

No strong preference whether the docs change to match the implementation, or vice-versa.
msg319872 - (view) Author: Eric V. Smith (eric.smith) * (Python committer) Date: 2018-06-18 08:57
"If tempdir is unset or None" means "If tempdir has not been assigned to, or if it has been assigned the value None". "Unset" doesn't mean "delete from the module".

I agree the documentation wording could be improved.
msg319894 - (view) Author: Philip Rowlands (philiprowlands) Date: 2018-06-18 16:00
How about

- If tempdir is unset or None at any call to
+ If tempdir is None (the default) at any call to

This avoids headaches over the meaning of "unset", and accurately reflects the code at:
https://github.com/python/cpython/blob/3.6/Lib/tempfile.py#L289
msg319922 - (view) Author: Pablo Galindo Salgado (pablogsal) * (Python committer) Date: 2018-06-18 23:57
What about:

"If tempdir is unset or None (the default value has not been modified) ..." 

?
msg319923 - (view) Author: Eric V. Smith (eric.smith) * (Python committer) Date: 2018-06-19 00:38
I like philiprowlands' version:

- If tempdir is unset or None at any call to
+ If tempdir is None (the default) at any call to

Care to produce a PR?
msg320142 - (view) Author: Eric V. Smith (eric.smith) * (Python committer) Date: 2018-06-21 08:05
New changeset b225cb770fb17596298f5a05c41a7c90c470c4f8 by Eric V. Smith (Miss Islington (bot)) in branch '3.6':
bpo-33894: Clarified the tempfile.tempdir documentation (GH-7829) (GH-7842)
https://github.com/python/cpython/commit/b225cb770fb17596298f5a05c41a7c90c470c4f8
msg320268 - (view) Author: Philip Rowlands (philiprowlands) Date: 2018-06-22 20:55
Thanks for the edit. I did try a PR but was defeated by build/doc tool's recent version requirements (and didn't want to send untested changes, however minor).

The reason for getting rid of "unset" is the confusion of "state", i.e. it has never been assigned to, or "action", i.e. the user is unsetting it.
msg378269 - (view) Author: Irit Katriel (iritkatriel) * (Python committer) Date: 2020-10-08 18:43
This is complete and can be closed.
History
Date User Action Args
2022-04-11 14:59:01adminsetgithub: 78075
2020-10-08 20:11:50eric.smithsetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2020-10-08 18:43:46iritkatrielsetnosy: + iritkatriel
messages: + msg378269
2018-06-22 20:55:34philiprowlandssetmessages: + msg320268
2018-06-21 08:05:10eric.smithsetmessages: + msg320142
2018-06-21 07:57:55miss-islingtonsetpull_requests: + pull_request7452
2018-06-21 07:56:15miss-islingtonsetpull_requests: + pull_request7451
2018-06-20 20:07:40thatiparthysetkeywords: + patch
stage: patch review
pull_requests: + pull_request7437
2018-06-19 00:38:43eric.smithsetmessages: + msg319923
versions: + Python 2.7, Python 3.6, Python 3.7
2018-06-18 23:57:26pablogsalsetnosy: + pablogsal
messages: + msg319922
2018-06-18 16:00:05philiprowlandssetmessages: + msg319894
2018-06-18 08:57:54eric.smithsetnosy: + docs@python, eric.smith
messages: + msg319872

assignee: docs@python
components: + Documentation
type: crash -> behavior
2018-06-18 07:34:43philiprowlandscreate