type annotation of files: IO[bytes] -> Protocol with seek and read?
#3611
Unanswered
FynnBe
asked this question in
Potential Issue
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
First up: I have enjoyed working with httpx a lot and particularly appreciate all the type annotations in it!
Could you please consider replacing the
IO[bytes]in theFileContentannotation with a limited protocol for an object supportingread()andseek()?Motivation
I have a custom
BytesReaderobject that does not implement the complete set of methods required to type check asIO[bytes]with all itsflush,close,isatty, etc methods.I would love to not simply ignore the type checking error (nor to implement a set of methods that are actually not needed).
httpx only uses read and seek (I think)
It seems that in the httpx code this object is handled in the
FileFieldclass, specifically inhttpx/httpx/_multipart.py
Lines 203 to 217 in 4fb9528
So you really only require and object with a seek and a read method as far as I can tell. It would be great if this could be reflected in your type annotations...
Potential solution
Using a protocol such as:
Beta Was this translation helpful? Give feedback.
All reactions