Skip to content

Commit

Permalink
Type hint "write" methods
Browse files Browse the repository at this point in the history
  • Loading branch information
eltbus committed Jan 21, 2024
1 parent 9adde7c commit 72238e3
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions multipart/multipart.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,14 +165,14 @@ def from_value(klass, name, value):
f.finalize()
return f

def write(self, data):
def write(self, data: bytes) -> int:
"""Write some data into the form field.
:param data: a bytestring
"""
return self.on_data(data)

def on_data(self, data):
def on_data(self, data: bytes) -> int:
"""This method is a callback that will be called whenever data is
written to the Field.
Expand Down Expand Up @@ -473,14 +473,14 @@ def _get_disk_file(self):
self._actual_file_name = fname
return tmp_file

def write(self, data):
def write(self, data: bytes) -> int:
"""Write some data to the File.
:param data: a bytestring
"""
return self.on_data(data)

def on_data(self, data):
def on_data(self, data: bytes) -> int:
"""This method is a callback that will be called whenever data is
written to the File.
Expand Down Expand Up @@ -656,7 +656,7 @@ def __init__(self, callbacks={}, max_size=float('inf')):
self.max_size = max_size
self._current_size = 0

def write(self, data):
def write(self, data: bytes) -> int:
"""Write some data to the parser, which will perform size verification,
and then pass the data to the underlying callback.
Expand Down Expand Up @@ -755,7 +755,7 @@ def __init__(self, callbacks={}, strict_parsing=False,
# Should parsing be strict?
self.strict_parsing = strict_parsing

def write(self, data):
def write(self, data: bytes) -> int:
"""Write some data to the parser, which will perform size verification,
parse into either a field name or value, and then pass the
corresponding data to the underlying callback. If an error is
Expand Down Expand Up @@ -1039,7 +1039,7 @@ def __init__(self, boundary, callbacks={}, max_size=float('inf')):
# '--\r\n' is 8 bytes.
self.lookbehind = [NULL for x in range(len(boundary) + 8)]

def write(self, data):
def write(self, data: bytes) -> int:
"""Write some data to the parser, which will perform size verification,
and then parse the data into the appropriate location (e.g. header,
data, etc.), and pass this on to the underlying callback. If an error
Expand Down Expand Up @@ -1574,7 +1574,7 @@ class vars:
def on_start():
vars.f = FileClass(file_name, None, config=self.config)

def on_data(data, start, end):
def on_data(data: bytes, start: int, end: int):
vars.f.write(data[start:end])

def on_end():
Expand Down Expand Up @@ -1772,7 +1772,7 @@ def on_end():

self.parser = parser

def write(self, data):
def write(self, data: bytes) -> int:
"""Write some data. The parser will forward this to the appropriate
underlying parser.
Expand Down

0 comments on commit 72238e3

Please sign in to comment.