Skip to content

Raise on existing files in mkdir_p and makedirs_p - #255

Closed
vitalivo wants to merge 2 commits into
jaraco:mainfrom
vitalivo:fix/mkdir-p-existing-file
Closed

vitalivo wants to merge 2 commits into
jaraco:mainfrom
vitalivo:fix/mkdir-p-existing-file

Conversation

@vitalivo

@vitalivo vitalivo commented Sep 12, 2026

Copy link
Copy Markdown

Path.mkdir_p() and Path.makedirs_p() silently succeeds when its path is an existing regular file. Its documented exception is for an existing directory, so callers can incorrectly proceed assuming a usable directory was created.

Only suppress FileExistsError if the existing path is a directory. Added regressions for file collisions in both methods and a control for creating a new directory, alongside the existing directory test. Includes a changelog fragment.

Validation: the file-collision tests fail before the fix; 145 tests/doctests pass (1 skipped) on Python 3.10 and 3.14. Ruff formatting passes; the current lint diagnostics are identical to the base revision.

@vitalivo vitalivo changed the title Raise for file collisions in mkdir_p Raise on existing files in mkdir_p and makedirs_p Sep 12, 2026
@vitalivo vitalivo closed this Sep 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant