GeezerVison is showing github.com — gh-86533: Restore os.makedirs() ability to apply *mode* recursively by nessita · Pull Request #150011 · python/cpython
Conversation
nessita
commented
May 18, 2026
•
edited by bedevere-app
Bot
Loading
Uh oh!
There was an error while loading. Please reload this page.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Allow os.makedirs() to apply the *mode* argument to any intermediate
directories that are created.
- Replace recursive_mode with more intuitive parent_mode parameter
- parent_mode=None (default): intermediate dirs use default permissions
- parent_mode=<mode>: intermediate dirs use specified permissions
- parent_mode=mode: matches Python 3.6 behavior
- Update documentation with version markers and usage examples
- Add comprehensive test coverage with separate focused test functions
- Fix test permissions to avoid cleanup issues (0o555 → 0o705)
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <[email protected]>
- Add parent_mode parameter to Path.mkdir() for specifying intermediate
directory permissions when parents=True
- Maintain pathlib's independence by using recursive implementation
rather than delegating to os.makedirs
- Add comprehensive tests including umask behavior verification
- Update documentation and whatsnew entries
- Provides consistency with os.makedirs parent_mode parameter
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <[email protected]>
Use st_mode & 0o777 masking instead of stat.S_IMODE() to ignore
filesystem-specific bits like setgid, matching the approach used
in os.makedirs tests.
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <[email protected]>
|
All commit authors signed the Contributor License Agreement.

|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
@gpshead Hi! This is the PR we talked abut with the conflict fixed.
|
gpshead reacted with thumbs up emoji
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
…dir tests
Address review feedback on the parent_mode addition:
- Docs (os.makedirs, Path.mkdir): state that parent_mode, like mode, is
combined with the process umask; it does not bypass it.
- Mark the parameter as added in 3.15 (approved for the 3.15 backport)
instead of "next", which on main would resolve to 3.16.
- Replace the misleading "parent_mode overrides umask" test with one
that verifies umask IS applied to parent_mode (0o777 + umask 0o022 ->
0o755); add the matching os.makedirs test.
- Make MakedirTests cleanup name-agnostic and robust via
os_helper.rmtree() instead of a hard-coded dir1/.../dir6 walk.
- Align the new test_os skips with the pathlib tests
(Emscripten/WASI/Android); restore the original 0o555 case in
test_mode.
- Use os_helper.temp_umask() in the pathlib tests instead of a manual
os.umask() try/finally.
Uh oh!
There was an error while loading. Please reload this page.
|
Thanks @nessita for the PR, and @gpshead for merging it 🌮🎉.. I'm working now to backport this PR to: 3.15.
🐍🍒⛏🤖
|
nessita reacted with hooray emoji
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
⚠️⚠️⚠️ Buildbot failure ⚠️⚠️⚠️
Hi! The buildbot AMD64 CentOS9 NoGIL 3.x (tier-1) has failed when building commit 9770e32.
What do you need to do:
- Don't panic.
- Check the buildbot page in the devguide if you don't know what the buildbots are or how they work.
- Go to the page of the buildbot that failed (https://buildbot.python.org/#/builders/1609/builds/5752) and take a look at the build logs.
- Check if the failure is related to this commit (9770e32) or if it is a false positive.
- If the failure is related to this commit, please, reflect that on the issue and make a new Pull Request with a fix.
You can take a look at the buildbot page here:
https://buildbot.python.org/#/builders/1609/builds/5752
Failed tests:
Failed subtests:
- test_mkdir_with_parent_mode - test.test_pathlib.test_pathlib.PathSubclassTest.test_mkdir_with_parent_mode
- test_mkdir_parent_mode_deep_hierarchy - test.test_pathlib.test_pathlib.PathSubclassTest.test_mkdir_parent_mode_deep_hierarchy
- test_mkdir_parent_mode_same_as_mode - test.test_pathlib.test_pathlib.PosixPathTest.test_mkdir_parent_mode_same_as_mode
- test_mkdir_parent_mode_same_as_mode - test.test_pathlib.test_pathlib.PathTest.test_mkdir_parent_mode_same_as_mode
- test_mkdir_parent_mode_deep_hierarchy - test.test_pathlib.test_pathlib.PathTest.test_mkdir_parent_mode_deep_hierarchy
- test_mkdir_parent_mode_deep_hierarchy - test.test_pathlib.test_pathlib.PosixPathTest.test_mkdir_parent_mode_deep_hierarchy
- test_mkdir_parent_mode_same_as_mode - test.test_pathlib.test_pathlib.PathSubclassTest.test_mkdir_parent_mode_same_as_mode
- test_mkdir_with_parent_mode - test.test_pathlib.test_pathlib.PathTest.test_mkdir_with_parent_mode
- test_mkdir_with_parent_mode - test.test_pathlib.test_pathlib.PosixPathTest.test_mkdir_with_parent_mode
Summary of the results of the build (if available):
==
Click to see traceback logs
Traceback (most recent call last):
File "/home/buildbot/buildarea/3.x.itamaro-centos-aws.nogil/build/Lib/test/test_pathlib/test_pathlib.py", line 2534, in test_mkdir_with_parent_mode
self.assertEqual(p.stat().st_mode & 0o777, 0o755)
~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: 448 != 493
Traceback (most recent call last):
File "/home/buildbot/buildarea/3.x.itamaro-centos-aws.nogil/build/Lib/test/test_pathlib/test_pathlib.py", line 2559, in test_mkdir_parent_mode_deep_hierarchy
self.assertEqual(p.stat().st_mode & 0o777, 0o755)
~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: 448 != 493
Traceback (most recent call last):
File "/home/buildbot/buildarea/3.x.itamaro-centos-aws.nogil/build/Lib/test/test_pathlib/test_pathlib.py", line 2599, in test_mkdir_parent_mode_same_as_mode
self.assertEqual(p.stat().st_mode & 0o777, 0o705)
~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: 448 != 453
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
⚠️⚠️⚠️ Buildbot failure ⚠️⚠️⚠️
Hi! The buildbot ARM Raspbian 3.x (tier-3) has failed when building commit 9770e32.
What do you need to do:
- Don't panic.
- Check the buildbot page in the devguide if you don't know what the buildbots are or how they work.
- Go to the page of the buildbot that failed (https://buildbot.python.org/#/builders/424/builds/13744) and take a look at the build logs.
- Check if the failure is related to this commit (9770e32) or if it is a false positive.
- If the failure is related to this commit, please, reflect that on the issue and make a new Pull Request with a fix.
You can take a look at the buildbot page here:
https://buildbot.python.org/#/builders/424/builds/13744
Failed tests:
Failed subtests:
- test_mkdir_with_parent_mode - test.test_pathlib.test_pathlib.PathSubclassTest.test_mkdir_with_parent_mode
- test_mkdir_parent_mode_deep_hierarchy - test.test_pathlib.test_pathlib.PathSubclassTest.test_mkdir_parent_mode_deep_hierarchy
- test_mkdir_parent_mode_same_as_mode - test.test_pathlib.test_pathlib.PosixPathTest.test_mkdir_parent_mode_same_as_mode
- test_mkdir_parent_mode_same_as_mode - test.test_pathlib.test_pathlib.PathTest.test_mkdir_parent_mode_same_as_mode
- test_mkdir_parent_mode_deep_hierarchy - test.test_pathlib.test_pathlib.PathTest.test_mkdir_parent_mode_deep_hierarchy
- test_mkdir_parent_mode_deep_hierarchy - test.test_pathlib.test_pathlib.PosixPathTest.test_mkdir_parent_mode_deep_hierarchy
- test_mkdir_parent_mode_same_as_mode - test.test_pathlib.test_pathlib.PathSubclassTest.test_mkdir_parent_mode_same_as_mode
- test_mkdir_with_parent_mode - test.test_pathlib.test_pathlib.PathTest.test_mkdir_with_parent_mode
- test_mkdir_with_parent_mode - test.test_pathlib.test_pathlib.PosixPathTest.test_mkdir_with_parent_mode
Summary of the results of the build (if available):
==
Click to see traceback logs
Traceback (most recent call last):
File "/var/lib/buildbot/workers/3.x.gps-raspbian.nondebug/build/Lib/test/test_pathlib/test_pathlib.py", line 2599, in test_mkdir_parent_mode_same_as_mode
self.assertEqual(p.stat().st_mode & 0o777, 0o705)
~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: 448 != 453
Traceback (most recent call last):
File "/var/lib/buildbot/workers/3.x.gps-raspbian.nondebug/build/Lib/test/test_pathlib/test_pathlib.py", line 2534, in test_mkdir_with_parent_mode
self.assertEqual(p.stat().st_mode & 0o777, 0o755)
~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: 448 != 493
Traceback (most recent call last):
File "/var/lib/buildbot/workers/3.x.gps-raspbian.nondebug/build/Lib/test/test_pathlib/test_pathlib.py", line 2559, in test_mkdir_parent_mode_deep_hierarchy
self.assertEqual(p.stat().st_mode & 0o777, 0o755)
~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: 448 != 493
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
⚠️⚠️⚠️ Buildbot failure ⚠️⚠️⚠️
Hi! The buildbot ARM64 MacOS M1 NoGIL 3.x (tier-2) has failed when building commit 9770e32.
What do you need to do:
- Don't panic.
- Check the buildbot page in the devguide if you don't know what the buildbots are or how they work.
- Go to the page of the buildbot that failed (https://buildbot.python.org/#/builders/1270/builds/7602) and take a look at the build logs.
- Check if the failure is related to this commit (9770e32) or if it is a false positive.
- If the failure is related to this commit, please, reflect that on the issue and make a new Pull Request with a fix.
You can take a look at the buildbot page here:
https://buildbot.python.org/#/builders/1270/builds/7602
Failed tests:
Failed subtests:
- test_mkdir_with_parent_mode - test.test_pathlib.test_pathlib.PathSubclassTest.test_mkdir_with_parent_mode
- test_mkdir_parent_mode_deep_hierarchy - test.test_pathlib.test_pathlib.PathSubclassTest.test_mkdir_parent_mode_deep_hierarchy
- test_mkdir_parent_mode_same_as_mode - test.test_pathlib.test_pathlib.PosixPathTest.test_mkdir_parent_mode_same_as_mode
- test_mkdir_parent_mode_same_as_mode - test.test_pathlib.test_pathlib.PathTest.test_mkdir_parent_mode_same_as_mode
- test_mkdir_parent_mode_deep_hierarchy - test.test_pathlib.test_pathlib.PathTest.test_mkdir_parent_mode_deep_hierarchy
- test_mkdir_parent_mode_deep_hierarchy - test.test_pathlib.test_pathlib.PosixPathTest.test_mkdir_parent_mode_deep_hierarchy
- test_mkdir_parent_mode_same_as_mode - test.test_pathlib.test_pathlib.PathSubclassTest.test_mkdir_parent_mode_same_as_mode
- test_mkdir_with_parent_mode - test.test_pathlib.test_pathlib.PathTest.test_mkdir_with_parent_mode
- test_mkdir_with_parent_mode - test.test_pathlib.test_pathlib.PosixPathTest.test_mkdir_with_parent_mode
Summary of the results of the build (if available):
==
Click to see traceback logs
Traceback (most recent call last):
File "/Users/buildbot/buildarea/3.x.itamaro-macos-arm64-aws.macos-with-brew.nogil/build/Lib/test/test_pathlib/test_pathlib.py", line 2559, in test_mkdir_parent_mode_deep_hierarchy
self.assertEqual(p.stat().st_mode & 0o777, 0o755)
~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: 448 != 493
Traceback (most recent call last):
File "/Users/buildbot/buildarea/3.x.itamaro-macos-arm64-aws.macos-with-brew.nogil/build/Lib/test/test_pathlib/test_pathlib.py", line 2534, in test_mkdir_with_parent_mode
self.assertEqual(p.stat().st_mode & 0o777, 0o755)
~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: 448 != 493
Traceback (most recent call last):
File "/Users/buildbot/buildarea/3.x.itamaro-macos-arm64-aws.macos-with-brew.nogil/build/Lib/test/test_pathlib/test_pathlib.py", line 2599, in test_mkdir_parent_mode_same_as_mode
self.assertEqual(p.stat().st_mode & 0o777, 0o705)
~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: 448 != 453
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
gpshead
added a commit
that referenced
this pull request
May 19, 2026
…ively (GH-150011) (#150036)
bpo-42367: Restore os.makedirs() and pathlib.mkdir() ability to apply *mode* recursively via a new parent_mode= keyword argument.
(cherry picked from commit 9770e32)
+ Make Path.mkdir parent_mode tests umask-independent
test_mkdir_with_parent_mode, test_mkdir_parent_mode_deep_hierarchy and
test_mkdir_parent_mode_same_as_mode assert exact directory mode bits but
did not pin the process umask. On buildbots running with a restrictive
umask (e.g. 0o077) the 0o755 leaf was masked down to 0o700, failing the
assertions. Wrap them in os_helper.temp_umask(0o022), matching the
other umask-aware mkdir tests in this file.
---------
Co-authored-by: nessita <[email protected]>
Co-authored-by: Zackery Spytz <[email protected]>
Co-authored-by: Erlend E. Aasland <[email protected]>
Co-authored-by: Gregory P. Smith <[email protected]>
Uh oh!
There was an error while loading. Please reload this page.
Milestone
No milestone
Development
Successfully merging this pull request may close these issues.
Uh oh!
There was an error while loading. Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
|