How you can benefit from type hints
summary
PEP 484 adds optional type hints to Python 3 and the claim is concrete: simple annotations let tools catch real bugs (ElementTree code that passes bytes where str and an illegal indexed iterator), with mypy and PyCharm reporting the errors (PyCharm underlines, mypy prints messages). PyCharm 4.5 has partial support and 5 aims for full support. Use type stubs (.pyi) for Python 2 or third‑party libs, and annotate public APIs with simple types first.
AI-written summary · about
chapters (22)
- 0:00Intro
- 1:17What This Talk is About
- 1:57Quick Poll
- 2:36Type Hints Used to Be Informal • An example from the standard library
- 3:06PEP 484: Type Hints . Based on function annotations, Python 3.5 - Explicit is better than implicit
- 3:40The Main Benefit • Improved readability for both humans and tools • Documentation - More compact and easier to grasp than lengthy native
- 4:34The Tools
- 5:49The Example: ElementTree
- 7:17Exceptions
- 7:43Add Type Hints • Start with a few function annotations
- 8:18Type Checking
- 8:47Let's Annotate ElementTree's API - Most type hints are simple
- 9:56Type Inference • Tools can infer types in some cases Follow assignments to variables Return types of local functions
- 13:49Code Completion • Context-sensitive code completion
- 15:58Docs with Type Hints • From the docstring using the Sphinx autodoc extension
- 17:25Type Hints for Your Public APIs
- 19:26From Simple to Complex
- 20:20Liberal vs Conservative
- 21:54Type Hints in Your Code • Type hints in Python 3 function annotations It's enough to pip install a library • Compatible with Python 3.5
- 23:16Python Stubs
- 26:21Available Type Hints
- 27:22Try Type Hints!
related talks
29mPython Type hints and how they can supercharge CS education.
28mGradual Typing in Python
32mPython's New Type Hints in Action… In JavaScript
27m"How to Use Static Typing in Python with Type Hints, MyPy and Pydantic"
46mHow to make a static type checker your best friend
23mmypy Python's gradual typing implementation
12mType Annotations in Python: Terribly Intimidating or Tremendously Informative?
31mTaming the Duck with Type Hints
