classification
Title: Enhance documentation of os.mkdir()
Type: enhancement Stage:
Components: Documentation Versions: Python 3.7, Python 3.6, Python 3.5, Python 3.4, Python 3.3
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: docs@python Nosy List: docs@python, ebianchi, r.david.murray
Priority: normal Keywords:

Created on 2017-06-15 14:08 by ebianchi, last changed 2017-06-15 15:28 by r.david.murray.

Messages (2)
msg296097 - (view) Author: Enrico Bianchi (ebianchi) Date: 2017-06-15 14:08
Currently, documentation for os.mkdir() (see https://docs.python.org/3.6/library/os.html#os.mkdir ) reports only FileExistsError exception if directory exists. Please, add other exceptions (e.g. FileNotFoundError if directory is created in a non existent path) or report OSError as superclass of exceptions returned from this method
msg296107 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2017-06-15 15:28
We don't generally document all exceptions that a method can raise, only those that are relevant to its specific API.  In this case, documenting the exception answers the question, "what happens if the directory already exists?"  This question is relevant to the API since the other reasonable possibility is that it would act as if the mkdir had succeeded.  As for documenting OSError, I'm sure there are ways to get os.mkdir to raise an exception that is not an OSError.

However, there is an argument to be made for documenting FileNotFound: the other reasonable thing the function could do in that case would be to create all intermediate path parts, but it does not do that (you use os.makedirs for that).  Since os.makedirs is documented right after os.mkdir, I'm not sure it is worth adding, but one can make the argument :)
History
Date User Action Args
2017-06-15 15:28:35r.david.murraysetnosy: + r.david.murray
messages: + msg296107
2017-06-15 14:08:58ebianchicreate