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

Type compatibility with h11._headers.Header #173

Open
vxgmichel opened this issue Jul 8, 2022 · 1 comment
Open

Type compatibility with h11._headers.Header #173

vxgmichel opened this issue Jul 8, 2022 · 1 comment

Comments

@vxgmichel
Copy link

At the moment, the wsproto.typing.Header type is not compatible with h11._headers.Header which is defined as the following, starting with version 0.13.0:

class Headers(Sequence[Tuple[bytes, bytes]]):
    [...]

The following patch might provide this compatibility:

diff --git a/src/wsproto/typing.py b/src/wsproto/typing.py
index a44b27e..1786501 100644
--- a/src/wsproto/typing.py
+++ b/src/wsproto/typing.py
@@ -1,3 +1,3 @@
-from typing import List, Tuple
+from typing import Sequence, Tuple
 
-Headers = List[Tuple[bytes, bytes]]
+Headers = Sequence[Tuple[bytes, bytes]]

This would fix mypy errors such as:

error: Argument "headers" to "initiate_upgrade_connection" of "WSConnection" has incompatible type "Headers"; expected "List[Tuple[bytes, bytes]]"  [arg-type]

Would that make sense? I can make a PR if necessary.

@pgjones
Copy link
Member

pgjones commented Aug 23, 2022

I think the issue here is that wsproto doesn't accept (by typing) a h11.Headers instance as an argument to initiate_upgrade_connection. I think this is correct as I don't think h11.Headers should be used in other libraries. It is also possible to convert a h11.Headers to a list for wsproto via something like list(headers).

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