[issue9299] os.mkdir() and os.makedirs() add a keyword argument to suppress "File exists" exception.
Terry J. Reedy
report at bugs.python.org
Mon Jul 19 18:03:14 CEST 2010
Terry J. Reedy <tjreedy at udel.edu> added the comment:
Since this is a library issue, it can go into 3.2.
It is definitely a feature request, hence not in 2.7. Code that depends on the exception suppression would crash on an earlier release.
Guido said "Well, it really should have behaved like mkdir -p in the first place.", so this is accepted pending patch approval.
The patch includes doc, test, and code patches.
The name 'ensure_exist' for the new parameter strikes me as wrong, as well as too long for something that will nearly always be set to True. The function always ensures that the directory exists. The question is whether it is ok that it exist previously. I strongly suggest something shorter like 'exist_ok' as an alternative.
The name 'excl' used in #
The code looks OK as far as I can read it, but someone else should look at the C code for posimodule-mkdir.
Does the use of 'base = support.TESTFN' ensure that the test junk gets cleaned up?
This versus #1675: the presenting issues are different -- parent race condition leading to error versus leaf existence leading to error. However, the patches are nearly the same and would have much the same effect. The differences:
* Test: 1675 lacks a new test; there should be one.
* New parameter name: they use different names, I do not like either. They use opposite senses -- exist_ok versus exist_bad for the new parameter. I think a good name is more important.
* Location of error suppression: this patches posixfile.mkdir; 1675 wraps it with a new os.mkdir function that does the suppression. I can see an argument for each approach.
* Propagation to parent directories: this passes exist_ok to parent mkdir(); 1675 passes exist_ok=True, so that it is never an error for parent directories to exist. This is a change in behavior and might be bad for the same reason we do not make exist_ok=True the default. In any case, I believe either patch could be changed to mimic the other.
Thus there are three choices to make before committing.
resolution: -> accepted
stage: -> patch review
type: -> feature request
versions: +Python 3.2 -Python 2.7, Python 3.3
Python tracker <report at bugs.python.org>
More information about the Python-bugs-list