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
Don't do isinstance checks in zipapp #67845
Comments
As it stand, zipapp's code checks for str and then otherwise assumes an object is a file-like object. It might work out better to do some duck typing and simply check if an object has 'read' and 'readline' attributes then it's a file-like object and otherwise that it's a path. Doing this would then potentially make it easier to use pathlib.Path through the module rather than the os module. |
That sounds reasonable. I'll have a look at this. The code was originally based on a similar pattern in the zipfile module, so maybe zipfile should be changed in the same way? |
Here is a proposed patch that does what I was thinking. What do you think? As for updating zipfile, it's possible but slightly risky because of backwards-compatibility. Since this is all-new code there is no worry about breaking someone's pre-existing code because they were relying on str being treated in a special way instead of the file-like object case. |
Looks good. Would it be worth adding tests for providing pathlib.Path objects, or is that overkill? |
Depends on whether you want to support pathlib.Path objects explicitly. =) If so then yes, we should add tests. Which reminds me, it might be time for you to request commit privileges so you can commit patches like this yourself. |
Cool, I'll look at sorting it out. |
Updated version of the patch with tests, plus doc update noting that path objects are explicitly supported. |
Updated patch. Added the requested test and a set of tests for the command line API. This also highlighted a bug in the command line --info option, which is also fixed. Coverage now: Name Stmts Miss Cover Missing Remaining misses are Unix-only tests (this was run on Windows) and the __main__ block. |
Updated patch with fixes for review comments. I did remove the tests for the exact error messages, as testing for a non-zero exit code was actually what I was trying to do, and I found a better way of doing that. |
New changeset 0b2993742650 by Paul Moore in branch 'default': |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: