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

add typing information #1289

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft

add typing information #1289

wants to merge 2 commits into from

Conversation

Kriechi
Copy link
Member

@Kriechi Kriechi commented Nov 17, 2024

closes #368

This PR goes hand in hand with python-hyper/hpack#277 and python-hyper/hyperframe#163 and might be refined together.

This PR is still a draft. The major outstanding issues are around handling of Headers, with their (bytes, bytes) or (str, str) or HeaderTuple types. I'm open to suggestions on how to best address these issues. Currently, mypy still reports about 26 typing-related errors and a few tests are failing.

`H2Stream` does not have such an attribute - probably added by accident.
@Kriechi
Copy link
Member Author

Kriechi commented Nov 17, 2024

@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
Copy link
Member Author

Kriechi commented Nov 18, 2024

@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
Copy link

BYK commented Nov 19, 2024

@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
Copy link
Member Author

Kriechi commented Nov 19, 2024

@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
Copy link

BYK commented Nov 19, 2024

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

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

Successfully merging this pull request may close these issues.

Add type information to API
2 participants