Skip to content

gh-89721: Add copy_dir_stat parameter to shutil.copytree() - #160076

Merged
ambv merged 3 commits into
python:mainfrom
ambv:gh-89721-copytree-copy-dir-stat
Oct 22, 2026
Merged

ambv merged 3 commits into
python:mainfrom
ambv:gh-89721-copytree-copy-dir-stat

Conversation

@ambv

@ambv ambv commented Oct 21, 2026

Copy link
Copy Markdown
Contributor

Supersedes #109717 (closed).

Adds a copy_dir_stat parameter (default true) to shutil.copytree(). When false, directory permissions and times are not copied with copystat(), e.g. to copy a read-only tree into a writable one. Unlike the superseded PR, the flag propagates through recursive calls, and file metadata stays with copy_function (documented). Includes tests, docs, and a news entry.

copytree() now accepts copy_dir_stat (default true).  When false,
directory permissions and times are not copied with copystat(), e.g.
to copy a read-only tree into a writable one.  The flag propagates
through recursive calls; file metadata is unaffected and remains
handled by copy_function.  Document the parameter and cover both
behaviors with tests.

Co-authored-by: Muse Code (Meta Muse Spark)
@read-the-docs-community

read-the-docs-community Bot commented Oct 21, 2026 •

Copy link
Copy Markdown

Documentation build overview

📚 cpython-previews | 🛠️ Build #35332257 | 📁 Comparing 7ebe48c against main (796b26b)

  🔍 Preview build  

43 files changed · + 1 added · ± 42 modified

+ Added

± Modified

WASI cannot change file mode bits, so skip the new copytree mode
tests there like the other chmod-dependent tests in test_shutil.

Co-authored-by: Muse Code (Meta Muse Spark)

@itamaro itamaro left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does this need a whatsnew bullet too?

Comment thread Lib/shutil.py Resolved
Comment thread Doc/library/shutil.rst Resolved
Comment thread Lib/test/test_shutil.py Resolved
Comment thread Doc/library/shutil.rst Resolved
Make copy_dir_stat keyword-only (ignore_dangling_symlinks and
dirs_exist_ok stay positional-or-keyword: they date back to 3.2 and
3.8). Convert the recursive calls accordingly.

Document that copy_dir_stat=False alone does not make a read-only
tree writable; file metadata stays with copy_function. Say
"directory metadata" instead of the narrower "permissions and times".

Assert directory mtimes are not copied either. Add a What's New
entry.

Co-authored-by: Muse Code (Meta Muse Spark)
@ambv
ambv requested a review from AA-Turner as a code owner October 22, 2026 17:22
@ambv
ambv merged commit e2766c0 into python:main Oct 22, 2026
53 checks passed
@ambv
ambv deleted the gh-89721-copytree-copy-dir-stat branch October 24, 2026 20:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type-feature A feature request or enhancement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants