-
-
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
_TemporaryFileWrapper[bytes]
somehow isn't a BinaryIO
#7843
Comments
|
The @srittau If neither Some people think the answer is to use a custom But, I set out to add type annotations to my application, not design an application- or library-specific notion of what a stream should be. So presumably I ought to use some standardized pre-defined Protocols unless I have a good reason not to, or else use the Protocols from one or more of the libraries I am using that deal in streams. I saw some references to pre-defined protocols in
And then I'm back to inventing an application-specific notion of what a good stream interface should be, although at least I don't have to If I instead want to get the Protocols used by a library I use, it looks like to do that I'd have to do something like:
That Protocol is used here: typeshed/stubs/PyYAML/yaml/emitter.pyi Lines 58 to 60 in cb3c1bb
Again I find myself working with underscore-prefixed stuff that it seems like I shouldn't be touching. Are either of these what I'm supposed to be doing? |
I just use Protocols are mostly useful in library code where you want to be specific about what works and what doesn't work. For example, if your library needs |
We're working on that: python/cpython#92878. python/typing#829 should also be a useful read.
We'll probably expose more of these protocols in typing-extensions in the future so that they're easier to use outside of typeshed.
|
With this test file
repro.py
:I get this error from
mypy repro.py
:This is with
mypy
version 0.941.The
NamedTemporaryFile()
docs say that it "operates exactly as TemporaryFile() does", save for always having a name, andTemporaryFile()
is documented to return a file-like object and to default to binary mode.If
BinaryIO
is meant to represent a binary-mode file-like object, then there's something wrong with the type annotations if it's not able to match the return value ofNamedTemporaryFile()
.The text was updated successfully, but these errors were encountered: