Skip to content
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

Struct.parse isn't exhaustively typed #24

Closed
demberto opened this issue Jun 11, 2023 · 3 comments
Closed

Struct.parse isn't exhaustively typed #24

demberto opened this issue Jun 11, 2023 · 3 comments

Comments

@demberto
Copy link

def parse(data: bytes, **contextkw: ContextKWType) -> Container[Any]

This is the type hint you have used for it. However the docstring of this function mentions it can support a whole lot of other types (from bytes, bytearray, memoryview, array etc.). The closest type hint which comes to my mind is _typeshed.ReadableBuffer for this.

@demberto
Copy link
Author

Also StreamType can be replaced with typing.BinaryIO instead, its the same (apart from an extra __enter__ method in the latter).

@timrid
Copy link
Owner

timrid commented Jun 14, 2023

I used only bytes because until Python 3.10 the documentation says

typing.ByteString

This type represents the types bytes, bytearray, and memoryview of byte sequences.

As a shorthand for this type, bytes can be used to annotate arguments of any of the types mentioned above.

(see here)

But with PEP688 this will be removed. So I will change it in the future with a better type.

@demberto
Copy link
Author

Since you mention PEP688 you can also use typing_extensions.Buffer. You will need to wait for a while tho, because even tho its present in typing_extensions, it isn't yet on typeshed. It will soon be

@timrid timrid closed this as completed in c04a905 Jul 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants