Skip to content

Raise on existing files in mkdir_p and makedirs_p - #257

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

Raise on existing files in mkdir_p and makedirs_p#257
vitalivo wants to merge 2 commits into
jaraco:mainfrom
vitalivo:fix/mkdir-p-existing-file

Conversation

@vitalivo

Copy link
Copy Markdown

This replaces #255, which was accidentally closed and its source fork deleted. The implementation is unchanged; the original discussion and reviews remain linked there.


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.

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