gh-132322: Ensure shutil functions return str when using pathlib#132820
Open
rpxchoudhury wants to merge 4 commits intopython:mainfrom
Open
gh-132322: Ensure shutil functions return str when using pathlib#132820rpxchoudhury wants to merge 4 commits intopython:mainfrom
rpxchoudhury wants to merge 4 commits intopython:mainfrom
Conversation
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
|
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 |
Member
ZeroIntensity
left a comment
There was a problem hiding this comment.
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. | |||
Member
There was a problem hiding this comment.
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. |
Author
There was a problem hiding this comment.
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
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