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.
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
Accurate overloads for
ZipFile.__init__
#12119Accurate overloads for
ZipFile.__init__
#12119Changes from 3 commits
c2505eb
6eafa4e
6bc28bd
4cf07ab
7f75295
c9704b9
377ce76
aca61a7
3af922f
0f7c9e0
d82e36f
97a4a95
a682d36
0b52c6a
814ab6b
524d7d7
56d44c0
d98196a
cc520e2
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aren't all following overloads shadowed by this one?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No - for example,
IO[bytes]
is broader than_ZipReadable
, which will lead to the second overload getting chosen if you just an object that is readable.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As for
_ZipFileMode
, iffile
doesn't match we'll end up skipping over the overload. The tests show that this is working properly.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But that's exactly the problem. It's my understanding that overloads are processed in order (although the typing spec doesn't mention that), so
IO[bytes]
always matches before_ZipReadable
can match.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've opened python/typing#1803 for clarification.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How is that a problem though?
_ZipReadable
will get matched ifIO[bytes]
isn't fully fulfilled, or am I misunderstanding something?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While
_ZipTellable
won't immediately error, I don't think the resulting object can be used for anything right? Unless I'm missing some use case, I think we should keep itStrPath | _ZipWritable
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh in fact it's definitely wrong, because
__del__
will triggerclose
will trigger a write attemptThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let me fix this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
d98196a
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@hauntsaninja Should be resolved now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this right? I'm not sure
_ZipSeekTellable
is enough, e.g._RealGetContents
requires readThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right, we want a protocol that is seekable/readable if it's a valid zip file, otherwise it should implement
tell
: 0b52c6aThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think likely misread this, and assumed if an attribute error occurred it just needed to be tellable.