Skip to content

add typing information - #1289

Merged
Kriechi merged 5 commits into
python-hyper:masterfrom
Kriechi:typing
Jan 22, 2025
Merged

Kriechi merged 5 commits into
python-hyper:masterfrom
Kriechi:typing

Conversation

@Kriechi

@Kriechi Kriechi commented Nov 17, 2024 •

Copy link
Copy Markdown
Member

closes #368

Based on the recently released hyperframe and hpack library updates to support typing now in h2 as well.

@Kriechi

Kriechi commented Nov 17, 2024

Copy link
Copy Markdown
Member Author

@BYK happy to hear your thoughts on the header typing dilemma!

@Kriechi
Kriechi force-pushed the typing branch 3 times, most recently from da55817 to 53fa0ba Compare November 18, 2024 22:06
@Kriechi

Kriechi commented Nov 18, 2024

Copy link
Copy Markdown
Member Author

@BYK I think I solved the headers type confusion and now all tests pass again. mypy is almost happy, but I think I would like to hear your input on the few remaining findings as they mostly relate to #1286 :

src/h2/utilities.py:130: error: Argument 1 to "startswith" of "str" has incompatible type "bytes"; expected "str | tuple[str, ...]"  [arg-type]
src/h2/utilities.py:138: error: Argument 1 to "startswith" of "str" has incompatible type "bytes"; expected "str | tuple[str, ...]"  [arg-type]
src/h2/utilities.py:259: error: Argument 1 to "search" of "Pattern" has incompatible type "bytes | str"; expected "Buffer"  [arg-type]
src/h2/utilities.py:604: error: Argument 1 to "append" of "list" has incompatible type "bytes | str"; expected "bytes"  [arg-type]
src/h2/utilities.py:624: error: Unsupported operand types for in ("bytes | str" and "bytes | str")  [operator]
src/h2/utilities.py:625: error: Argument 1 to "split" of "bytes" has incompatible type "bytes | str"; expected "Buffer | None"  [arg-type]
src/h2/utilities.py:625: error: Argument 1 to "split" of "str" has incompatible type "bytes | str"; expected "str | None"  [arg-type]
@BYK

BYK commented Nov 19, 2024

Copy link
Copy Markdown
Contributor

@Kriechi apologies for the very late response, got busy 😅

Regarding your solution for HeaderTuple and its variations, I'm guessing that's the new Headers thing from hpack/struct which I cannot see on the repo. So I need to see that code first to be able to comment.

Regarding the errors you pointed out, I'm quite sure they'll go away when you merge #1286 as the whole point of that patch was to remove these inconsistencies and lock everything to bytes. Makes sense?

@Kriechi

Kriechi commented Nov 19, 2024

Copy link
Copy Markdown
Member Author

@BYK the new Headers is defined here https://github.com/python-hyper/hpack/pull/277/files#diff-e10aaf7dbceff5ef795c06588c5b846012815fd4c2fec5b1008255699e9c7b0bR48

Though, I just noticed this syntax is not yet supported on Python 3.9... so I need to find a different solution.

@BYK

BYK commented Nov 19, 2024

Copy link
Copy Markdown
Contributor

@Kriechi made a suggestion over there. I think that also takes care of the py3.9 issue as it doesn't have nested Unions?

@Kriechi
Kriechi marked this pull request as ready for review January 17, 2025 19:13
@Kriechi
Kriechi merged commit 0b98b24 into python-hyper:master Jan 22, 2025
@Kriechi
Kriechi deleted the typing branch January 22, 2025 21:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants