-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
file_digest.file_digest
signature is overly strict
#12414
Comments
I/O types are a mess, which is why we're moving more into tight protocols for arguments as used in I think your analysis is correct. In fact,
|
Closes: python#12414
Doesn't it return |
I blame my the heat and my tiredness for overlooking this quite obvious code path ... That said, I'd be interested in which situation Another is probably if an opened file descriptor has the non-blocking flag set. I see two possible solutions: Make |
In fact, https://github.com/python/cpython/blob/2a5d1eb7073179a13159bce937afdbe240432e7d/Lib/socket.py#L713 |
Using
hashlib.file_digest
with a file object obtained viapathlib.Path.open
failed to typecheck with a protocol compatibility error:I'm reasonably sure this is a
typeshed
issue rather than amypy
issue.My first thought was that this looks like an internal inconsistency in
typeshed
, as_FileDigestFileObj
is declared specifically withbytearray
rather than the more generalWriteableBuffer
(hence filing the issue here).However, my second thought was that this signature declaration is presumably as it is because
file_digest
will specifically pass abytearray
instance toreadinto
, andbytearray
is compatible withBuffer
, somypy
shouldn't be complaining about that. That means the conflict is presumably on the return type rather than on parameter types.The declared type signature nominally indicates that
file_digest
can't cope withreadinto
returningNone
, andmypy
is correctly flagging that as inconsistent with the waytypeshed
declares the file and socket IO types (allowing them to returnNone
here).Searching the typeshed code suggests this particular inconsistency exists across several different IO consumer type declarations: https://github.com/search?q=repo%3Apython%2Ftypeshed%20readinto&type=code
The text was updated successfully, but these errors were encountered: