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 type hint to helper functions #112

Merged
merged 1 commit into from
Feb 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions multipart/multipart.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,15 +141,15 @@ class MultipartState(IntEnum):
# str on Py2, and bytes on Py3. Same with getting the ordinal value of a byte,
# and joining a list of bytes together.
# These functions abstract that.
def lower_char(c):
def lower_char(c: int) -> int:
return c | 0x20


def ord_char(c):
def ord_char(c: int) -> int:
return c


def join_bytes(b):
def join_bytes(b: bytes) -> bytes:
return bytes(list(b))


Expand Down Expand Up @@ -290,7 +290,7 @@ def field_name(self) -> bytes:
return self._name

@property
def value(self):
def value(self) -> bytes | None:
"""This property returns the value of the form field."""
if self._cache is _missing:
self._cache = b"".join(self._value)
Expand Down Expand Up @@ -424,7 +424,7 @@ def file_object(self):
return self._fileobj

@property
def size(self):
def size(self) -> int:
"""The total size of this file, counted as the number of bytes that
currently have been written to the file.
"""
Expand Down Expand Up @@ -1142,15 +1142,15 @@ def set_mark(name: str):
self.marks[name] = i

# Remove a mark.
def delete_mark(name: str, reset: bool = False):
def delete_mark(name: str, reset: bool = False) -> None:
self.marks.pop(name, None)

# Helper function that makes calling a callback with data easier. The
# 'remaining' parameter will callback from the marked value until the
# end of the buffer, and reset the mark, instead of deleting it. This
# is used at the end of the function to call our callbacks with any
# remaining data in this chunk.
def data_callback(name: str, remaining: bool = False):
def data_callback(name: str, remaining: bool = False) -> None:
marked_index = self.marks.get(name)
if marked_index is None:
return
Expand Down Expand Up @@ -1531,7 +1531,7 @@ def finalize(self) -> None:
# error or otherwise state that we're not finished parsing.
pass

def __repr__(self):
def __repr__(self) -> str:
return f"{self.__class__.__name__}(boundary={self.boundary!r})"


Expand Down