-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Looser type annotations for wrap_file() and FileWrapper #2130
Comments
Is there a reason this isn't available in |
That said, if you are uncomfortable using |
That's fine then, is there documentation about the |
We don't have documentation at the moment, except for the comments in the file itself, but we should probably add some. I will bring it up! |
Using |
There's lots of other places that use |
Good point about
with my_binary_io_returning_open():
... |
I'm running in the same typing issue with from zipfile import ZipFile
from werkzeug.datastructures import FileStorage
with ZipFile(FileStorage()) as zf:
pass
|
werkzeug.wsgi.wrap_file()
andFileWrapper
require thefile
argument to have typeBinaryIO
. Generally, the use ofIO
classes is discouraged, especially as arguments, since they are normally much too strict and incompatible with each other. In my particular use case, I got an error message 'Argument 2 to "wrap_file" has incompatible type "IO[bytes]"; expected "BinaryIO"'.As
FileWrapper
only requires theread()
method to be present (although it uses more methods if they exist), the old typeshed stubs annotated thefile
arguments withSupportsRead[bytes]
, which is available in_typeshed
during type checking:Alternatively a similar protocol can be defined like this:
The text was updated successfully, but these errors were encountered: