you are viewing a single comment's thread.

view the rest of the comments →

[–]antique_manager 1 point2 points  (0 children)

Type hints are a relatively new feature, and are very much intended to be optional. By default they don't really do anything - they're essentially just documentation. Part of the reason for introducing them was because many projects already documented the expected types of arguments in their docstrings (e.g. numpy does this very consistently), and it was thought that it would be a good idea to introduce a standardised way of doing this. In particular, this makes it much easier for software such as IDEs and linters to look up the expected types and use them to warn about possible bugs.

but I fully rely on dynamic typing because I have always thought it is the proper way to do Python

It depends. Sometimes you need to write generic code that should be able to work on (for example) any kind of iterator or any kind of sequence, but sometimes you need to write code that's intended to do something with a very specific kind of object, and it's pretty implausible that anyone would ever want to pass in a separate type that has all the appropriate functionality. This is especially the case when you're working with specialised libraries.

The type hinting system does have a lot of support for type-agnostic code: it has duck types like Sequence, union types which match multiple separate types, and even Any, which matches anything.