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 #277

Merged
merged 2 commits into from
Nov 23, 2024
Merged

add typing information #277

merged 2 commits into from
Nov 23, 2024

Conversation

Kriechi
Copy link
Member

@Kriechi Kriechi commented Nov 16, 2024

also closes #274

Copy link
Contributor

@BYK BYK left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shall we add black too in a follow up?

@@ -143,11 +138,11 @@ def _dict_to_iterable(header_dict):
yield key, header_dict[key]


def _to_bytes(string):
def _to_bytes(string: Union[bytes, str, Any]) -> bytes:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just Any probably covers all but I like you calling out the "expected" types. Maybe add a comment about this to avoid confusion in future readers?

@@ -575,7 +572,7 @@ def _decode_literal(self, data, should_index):
high_byte = data[0]
indexed_name = high_byte & 0x0F
name_len = 4
not_indexable = high_byte & 0x10
not_indexable = bool(high_byte & 0x10)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good one!

src/hpack/huffman.py Show resolved Hide resolved

from .exceptions import InvalidTableIndex

log = logging.getLogger(__name__)


def table_entry_size(name, value):
def table_entry_size(name: Union[bytes, str], value: Union[bytes, str]) -> int:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we can abstract this Union[bytes, str] and tuple[bytes, bytes] into type definitions as they are used in a bunch of places. Something like RawHeaderPiece and UntypedHeaderTuple respectively?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes! It was on my ToDo list, but didn't make it for this first PR - happy to be refactored in a future PR!
I'm working on a similar PR for the h2 library as well, so we might want to hold off on type aliases until we have a full picture.

src/hpack/table.py Outdated Show resolved Hide resolved
@Kriechi Kriechi force-pushed the typing branch 2 times, most recently from 04b0c41 to 1534dfe Compare November 16, 2024 18:44
src/hpack/struct.py Outdated Show resolved Hide resolved
@Kriechi Kriechi force-pushed the typing branch 2 times, most recently from fc455ed to 1702e21 Compare November 23, 2024 08:12
@Kriechi Kriechi merged commit 131b44c into python-hyper:master Nov 23, 2024
8 checks passed
@Kriechi Kriechi deleted the typing branch November 23, 2024 08:23
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.

When will be the time to drop Python 2 compatibility?
2 participants