python type hints

19
PYTHON TYPE HINTS Igor Leroy

Upload: igor-leroy

Post on 16-Jul-2015

173 views

Category:

Technology


0 download

TRANSCRIPT

PYTHON TYPE HINTS

Igor Leroy

PYTHON

• python 2 e 3

• Fortemente tipada

• Dinamicamente tipada

TIPAGEM FORTE

TIPAGEM DINÂMICA

TIPAGEM DINÂMICA

- o que pode ser num?- o que ela retorna?- e a documentação?

TIPAGENS ESTÁTICAS

TIPAGENS DINÂMICAS

terra typescript ruby 3 python 3.5

hack

PEP 484https://github.com/ambv/typehinting

WHY?• Editors/IDEs

• Linter capabilities

• Documentation

• Refactoring

TYPESint # integer objects of arbitrary sizefloat # floating point numberbool # boolean valuestr # unicode stringbytes # 8-bit stringobject # the common base classList[str] # list of str objectsDict[str, int] # dictionary from str to intIterable[int] # iterable object containing intsSequence[bool] # sequence of booleans

ACABOU A MAGIA?

Any # dynamically typed valueUnion[str, bytes] # set of expected types for a single argumentCallable # lambda and functions objectsAnyStr # equivalent to TypeVar('AnyStr', str, bytes)

e mais…

IGNORING TYPE CHECKER

@no_type_check decorator on classes and functions

a # type: ignore comment on arbitrary lines

PYTHON 3.5?VAI QUEBRAR TUDO!

MENTIRA

PYHTON 3.5previsão:13 de setembro de 2015

REFERÊNCIAS

• http://mypy-lang.org/

• http://sdtimes.com/python-3-5-include-type-hinting/

• https://www.youtube.com/watch?v=2wDvzy6Hgxg

OBRIGADO!

lerrua lerrua