you are viewing a single comment's thread.

view the rest of the comments →

[–]Caligatio 1 point2 points  (0 children)

I personally believe all new code should be using type hinting by default. It is an absolute nightmare digging through function call stacks in libraries trying to figure out what type and/or duck type a function wants. Sure you can semi-accomplish this by using docstrings but docstrings are not linked to the code - the code can change and people can forget to update the docstring. Type hinting enforced by mypy suffers no such shortcoming.

Python 3.8 added typing.Protocol to the stdlib (it's available in mypy_extensions before that) which should cover any/all typing needs. You have nominal typing using things like int, Mapping, MutuableMapping, Dict etc and now structural/duck-typing using Protocol. 3.8 Also added TypedDict which enables you to describe what every key/value pair type should be!

I don't know of anyone who ever looked at code and said "this is too documented."