You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[doc] mention that os.mkdir() raises FileNotFound if path does not exist #74862
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
assignee=Noneclosed_at=<Date2022-03-14.20:53:04.659>created_at=<Date2017-06-15.14:08:58.623>labels= ['easy', '3.9', '3.10', '3.11', 'type-feature', 'docs']
title='[doc] mention that os.mkdir() raises FileNotFound if path does not exist'updated_at=<Date2022-03-14.20:53:04.659>user='https://bugs.python.org/ebianchi'
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
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 :)
changed the title [-]Enhance documentation of os.mkdir()[/-][+][doc] mention that os.mkdir() raises FileNotFound if path does not exist[/+]on Jan 11, 2022
New changeset efa7250 by Miss Islington (bot) in branch '3.10':
[3.10] bpo-30677: [doc] mention that os.mkdir() can raise FileNotFoundError (GH-31548) (GH-31877) efa7250
New changeset b4fd91b by Miss Islington (bot) in branch '3.9':
[3.9] bpo-30677: [doc] mention that os.mkdir() can raise FileNotFoundError (GH-31548) (GH-31878) b4fd91b
Activity
ebianchi commentedon Jun 15, 2017
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
bitdancer commentedon Jun 15, 2017
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 :)
[-]Enhance documentation of os.mkdir()[/-][+][doc] mention that os.mkdir() raises FileNotFound if path does not exist[/+]iritkatriel commentedon Mar 14, 2022
New changeset 879fbd9 by slateny in branch 'main':
bpo-30677: [doc] mention that os.mkdir() can raise FileNotFoundError (GH-31548)
879fbd9
miss-islington commentedon Mar 14, 2022
New changeset efa7250 by Miss Islington (bot) in branch '3.10':
[3.10] bpo-30677: [doc] mention that os.mkdir() can raise FileNotFoundError (GH-31548) (GH-31877)
efa7250
miss-islington commentedon Mar 14, 2022
New changeset b4fd91b by Miss Islington (bot) in branch '3.9':
[3.9] bpo-30677: [doc] mention that os.mkdir() can raise FileNotFoundError (GH-31548) (GH-31878)
b4fd91b