Skip to content

Commit

Permalink
chore: add type annotations to targets
Browse files Browse the repository at this point in the history
  • Loading branch information
siddhantgoel committed May 9, 2020
1 parent 57297e8 commit 75da97d
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions streaming_form_data/targets.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import hashlib
from typing import Callable, Optional


class BaseTarget:
Expand All @@ -16,7 +17,7 @@ class BaseTarget:
the :code:`Content-Type` HTTP header
"""

def __init__(self, validator=None):
def __init__(self, validator: Optional[Callable] = None):
self.multipart_filename = None
self.multipart_content_type = None

Expand Down Expand Up @@ -85,7 +86,9 @@ class FileTarget(BaseTarget):
"""FileTarget writes (streams) the input to an on-disk file.
"""

def __init__(self, filename, allow_overwrite=True, *args, **kwargs):
def __init__(
self, filename: str, allow_overwrite: bool = True, *args, **kwargs
):
super().__init__(*args, **kwargs)

self.filename = filename
Expand All @@ -97,10 +100,12 @@ def on_start(self):
self._fd = open(self.filename, self._mode)

def on_data_received(self, chunk: bytes):
self._fd.write(chunk)
if self._fd:
self._fd.write(chunk)

def on_finish(self):
self._fd.close()
if self._fd:
self._fd.close()


class SHA256Target(BaseTarget):
Expand Down

0 comments on commit 75da97d

Please sign in to comment.