Skip to content

Conversation

@rpxchoudhury
Copy link

@rpxchoudhury rpxchoudhury commented Apr 23, 2025

Fixes issue #132322 by normalizing return types in shutil.copy, copy2, copyfile, copytree, and move using os.fspath(), so that they consistently return str even when pathlib.Path is passed.

All relevant tests pass locally

Fixes issue python#132322 by normalizing return types in shutil.copy, copy2, copyfile, copytree, and move using os.fspath(), so that they consistently return str even when pathlib.Path is passed.

All relevant tests pass locally
@python-cla-bot
Copy link

python-cla-bot bot commented Apr 23, 2025

All commit authors signed the Contributor License Agreement.

CLA signed

@bedevere-app
Copy link

bedevere-app bot commented Apr 23, 2025

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

Copy link
Member

@ZeroIntensity ZeroIntensity left a comment

Choose a reason for hiding this comment

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

Would you mind adding a test?

@@ -0,0 +1 @@
shutil.copy, copy2, copyfile, copytree, and move now consistently return str even when passed pathlib.Path arguments.
Copy link
Member

Choose a reason for hiding this comment

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

Use Sphinx refs:

Suggested change
shutil.copy, copy2, copyfile, copytree, and move now consistently return str even when passed pathlib.Path arguments.
:func:`shutil.copy`, :func:`~shutil.copy2`, :func:`~shutil.copyfile`, :func:`~shutil.copytree`, and :func:`~shutil.move` now consistently return :class:`str` even when passed :class:`pathlib.Path` arguments.

Copy link
Author

Choose a reason for hiding this comment

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

Yes, just added a unit test in the test_shutil.py file regarding this commit

…e with Path arguments

Adds a unit test to test_shutil.py that ensures shutil.copy() returns a str even when given pathlib.Path objects as arguments. This addresses the  inconsistent behavior where shutil.copy() could return a Path when the  destination was a Path object.

The test fails on the original implementation and passes with the fix introduced in this PR. This regression test helps enforce consistent  return types for shutil functions.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants