Added some type annotations (no functional differences)

This commit is contained in:
Sybren A. Stüvel 2017-03-31 13:14:07 +02:00
parent 1cb7a92e40
commit c711a04e6c

View File

@ -84,7 +84,9 @@ def index(file_name=None):
def _process_image(bucket: Bucket, def _process_image(bucket: Bucket,
file_id, local_file, src_file): file_id: ObjectId,
local_file: tempfile._TemporaryFileWrapper,
src_file: dict):
from PIL import Image from PIL import Image
im = Image.open(local_file) im = Image.open(local_file)
@ -127,7 +129,10 @@ def _process_image(bucket: Bucket,
src_file['status'] = 'complete' src_file['status'] = 'complete'
def _process_video(gcs, file_id, local_file, src_file): def _process_video(gcs,
file_id: ObjectId,
local_file: tempfile._TemporaryFileWrapper,
src_file: dict):
"""Video is processed by Zencoder; the file isn't even stored locally.""" """Video is processed by Zencoder; the file isn't even stored locally."""
log.info('Processing video for file %s', file_id) log.info('Processing video for file %s', file_id)
@ -175,14 +180,14 @@ def _process_video(gcs, file_id, local_file, src_file):
'backend': j['backend']} 'backend': j['backend']}
def process_file(bucket: Bucket, file_id, local_file): def process_file(bucket: Bucket,
file_id: typing.Union[str, ObjectId],
local_file: tempfile._TemporaryFileWrapper):
"""Process the file by creating thumbnails, sending to Zencoder, etc. """Process the file by creating thumbnails, sending to Zencoder, etc.
:param file_id: '_id' key of the file :param file_id: '_id' key of the file
:type file_id: ObjectId or str
:param local_file: locally stored file, or None if no local processing is :param local_file: locally stored file, or None if no local processing is
needed. needed.
:type local_file: file
""" """
file_id = ObjectId(file_id) file_id = ObjectId(file_id)
@ -211,7 +216,7 @@ def process_file(bucket: Bucket, file_id, local_file):
log.info('Not processing video file %s for non-admin user', file_id) log.info('Not processing video file %s for non-admin user', file_id)
# Run the required processor, based on the MIME category. # Run the required processor, based on the MIME category.
processors = { processors: typing.Mapping[str, typing.Callable] = {
'image': _process_image, 'image': _process_image,
'video': _process_video, 'video': _process_video,
} }