Skip to content

bpo-29435: Allow is_tarfile to take a filelike obj #18090

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

Merged
merged 5 commits into from
Jan 23, 2020

Conversation

woodruffw
Copy link
Contributor

@woodruffw woodruffw commented Jan 20, 2020

This makes tarfile.is_tarfile behave similarly to zipfile.is_zipfile: instead of just a string or path-like, the single positional argument can also be a file or file-like.

Ref: https://bugs.python.org/issue29435

https://bugs.python.org/issue29435

@the-knights-who-say-ni
Copy link

Hello, and thanks for your contribution!

I'm a bot set up to make sure that the project can legally accept this contribution by verifying everyone involved has signed the PSF contributor agreement (CLA).

CLA Missing

Our records indicate the following people have not signed the CLA:

@woodruffw

For legal reasons we need all the people listed to sign the CLA before we can look at your contribution. Please follow the steps outlined in the CPython devguide to rectify this issue.

If you have recently signed the CLA, please wait at least one business day
before our records are updated.

You can check yourself to see if the CLA has been received.

Thanks again for the contribution, we look forward to reviewing it!

@tirkarthi
Copy link
Member

This will need a test similar to one in test_zipfile and also update to docs that the argument could be a file like object with a versionchanged directive like is_zipfile docs.

@woodruffw
Copy link
Contributor Author

This will need a test similar to one in test_zipfile and also update to docs that the argument could be a file like object with a versionchanged directive like is_zipfile docs.

Thanks, will do.

@ethanfurman ethanfurman self-assigned this Jan 22, 2020
@woodruffw
Copy link
Contributor Author

Okay, added tests (for all is_tarfile cases, not just files and file-likes) and updated the docs.

Copy link
Member

@ethanfurman ethanfurman left a comment

Choose a reason for hiding this comment

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

Looking good.

A couple minor changes to the docs text are needed.

Please add yourself to the Misc/ACKS file.

@@ -159,7 +159,10 @@ Some facts and figures:
.. function:: is_tarfile(name)

Return :const:`True` if *name* is a tar archive file, that the :mod:`tarfile`
module can read.
module can read. *name* may be a file or file-like object too.
Copy link
Member

Choose a reason for hiding this comment

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

Change last sentence to:

*name* may be a :class:`str`, file, or file-like object.

Lib/tarfile.py Outdated
@@ -2461,9 +2461,14 @@ def __exit__(self, type, value, traceback):
def is_tarfile(name):
"""Return True if name points to a tar archive that we
are able to handle, else return False.

The name argument may be a file or file-like object.
Copy link
Member

Choose a reason for hiding this comment

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

Change last sentence to:

'name' should be a string, file, or file-like object.

@bedevere-bot
Copy link

A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated.

Once you have made the requested changes, please leave a comment on this pull request containing the phrase I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

@woodruffw
Copy link
Contributor Author

I have made the requested changes; please review again!

@bedevere-bot
Copy link

Thanks for making the requested changes!

@ethanfurman: please review the changes made to this pull request.

@woodruffw woodruffw deleted the fix-29435 branch January 23, 2020 02:50
shihai1991 pushed a commit to shihai1991/cpython that referenced this pull request Jan 31, 2020
`is_tarfile()` now supports `name` being a file or file-like object.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants