Skip to content

bpo-37144: Convert path-like object to regular path #13817

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 8 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Convert path-like object to regular path
  • Loading branch information
0x29a committed Jun 4, 2019
commit 7cfe6171a120b9d53d3743a5fca787d503325a0c
2 changes: 1 addition & 1 deletion Lib/tarfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ def __init__(self, name, mode, comptype, fileobj, bufsize):
fileobj = _StreamProxy(fileobj)
comptype = fileobj.getcomptype()

self.name = name or ""
self.name = os.path.abspath(name) if name else ""
Copy link
Member

Choose a reason for hiding this comment

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

os.fspath looks like a good solution to me. Please add a test in Lib/test/test_tarfile.py that opens gzipname with mode 'w|gz' flag to make sure there is no AttributeError

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@tirkarthi after opening gzipname with mode w|gz all remaining tests, that need to extract data from gzipname will not pass, because opening rewrites file content.

I added test to StreamWriteTest class, where I open for write tmpname, because it's designed for writing and insensitive to content change. Also, since this test inside of StreamWriteTest, opening by path-like filename will be performed for each mode (gz, lz, bz).

self.mode = mode
self.comptype = comptype
self.fileobj = fileobj
Expand Down