Python Type Hints

Becd166a81dc51c0009f602d175d0cc8?s=47 José Padilla
March 15, 2018
130

Python Type Hints

5min talk on Python Type Hints. Presented at newhaven.io

Becd166a81dc51c0009f602d175d0cc8?s=128

José Padilla

March 15, 2018
Tweet

Transcript

  1. Type Hints

  2. José Padilla

  3. Work Training

  4. Work Open Source

  5. PEP 3107

  6. None
  7. PEP 484

  8. None
  9. no type checking happens at runtime

  10. static analysis refactoring runtime type checking code generation

  11. static analysis refactoring runtime type checking code generation

  12. None
  13. Common built-in types

  14. None
  15. None
  16. None
  17. None
  18. None
  19. None
  20. None
  21. None
  22. None
  23. None
  24. None
  25. None
  26. None
  27. Generics

  28. None
  29. None
  30. mypy

  31. static type checker

  32. $ pip install mypy

  33. $ python app.py

  34. None
  35. $ python app.py f 1 Traceback (most recent call last):

    File "app.py", line 12, in <module> print(first(1)) # TypeError File "app.py", line 7, in first return seq[0] TypeError: 'int' object is not subscriptable
  36. $ mypy app.py

  37. $ mypy app.py main.py:12: error: Argument 1 to "first" has

    incompatible type "int"; expected "Sequence[<nothing>]"
  38. None
  39. mypy-lang.org

  40. Python will remain a dynamically typed language

  41. Thanks! jpadilla.com twitter.com/@jpadilla_ github.com/jpadilla