Site Tools


python_type

https://github.com/dropbox/pyston
https://mail.python.org/pipermail/python-ideas/2014-August/028618.html
https://tech.dropbox.com/2014/04/introducing-pyston-an-upcoming-jit-based-python-implementation/
https://github.com/eigenein/aicup/blob/master/MyStrategy.py

Discussion

Constantin Conovaloff, 2015/09/15 18:15

В python3 Изначально можно писать таким синтаксисом. TypeHinting при этом будет игнорироваться.
mypy ( http://mypy-lang.org/ ) при этом умеет статически анализировать код выдавая сообщения о неправильных типах.

#!/usr/bin/env python
# coding: utf-8

"""
Image utilities.
"""

from PIL.Image import ANTIALIAS, Image


def make_thumbnail(image: Image, size: int) -> Image:
    """
    Makes grayscale thumbnail.
    """
    return image.resize((size, size), ANTIALIAS).convert("L")


def get_average(image: Image) -> int:
    """
    Gets pixel value average.
    """
    return sum(image.getdata()) // (image.size[0] * image.size[1])


def make_features(image: Image, thumbnail_size: int):
    """
    Makes feature vector.
    """
    thumbnail = make_thumbnail(image, thumbnail_size)
    average = get_average(thumbnail)
    return map(lambda value: 0 if value < average else 1, thumbnail.getdata())
You could leave a comment if you were logged in.
python_type.txt · Last modified: 2019/10/19 17:38 (external edit)

Page Tools