-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Type annotations in msgpack are incorrect #6050
Comments
The simplest type annotation is probably a Union of BytesIO and FileIO. I'm not too aware of the type options though. |
Other objects which work for |
We have |
|
Sorry, I did not read carefully enough. Something like https://stackoverflow.com/questions/41748896/the-correct-way-to-annotate-a-file-type-in-python. If you would like to add such a type to |
Note that we already have a "stream" protocol internally and it'd be good to have a corresponding Python type for it. |
There's a pull request (adafruit/Adafruit_CircuitPython_Typing#2) to add a ByteStream protocol. |
Fixed by #6085. |
In circuitpython.readthedocs.io, the API documentation for
msgpack.pack
gives thebuffer
parameter the type annotationcircuitpython_typing.WriteableBuffer
.bytearray
is listed as one of the types that implements that protocol. However, this code fails:msgpack.unpack
has a similar issue withbuffer: ReadableBuffer
.The types that are evidently acceptable here are
io.BytesIO
andFileIO
. The implementation (https://github.com/adafruit/circuitpython/blob/main/shared-module/msgpack/__init__.c) makes it clear that thebuffer
object must haveread
andwrite
methods, so I suppose the argument is a "file-like object". It's unclear to me what the appropriate type annotation should be.(The annotations are provided in the corresponding
shared-bindings
C file.)I tried this in 7.1.0 on Clue, Feather M4 Express, and Feather S2 TFT, and 7.2.0-alpha2 on M4 Express.
The text was updated successfully, but these errors were encountered: