Skip to content

Commit

Permalink
Add type hint to helper functions (#112)
Browse files Browse the repository at this point in the history
  • Loading branch information
Kludex authored Feb 12, 2024
1 parent f4479c6 commit 5c7dce8
Showing 1 changed file with 8 additions and 8 deletions.
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

0 comments on commit 5c7dce8

Please sign in to comment.