I only typehint certain parts of the code where i find it usefull. Typehinting everything makes Python code really hard to read IMO.
I only typehint certain parts of the code where i find it usefull. Typehinting everything makes Python code really hard to read IMO.
- tests fail faster
- code documentation
- IDE’s complain better
- teams collaborate better
It becomes more helpful as projects and teams mature.I’d say that types aren’t the last step though, I’m starting to prefer protocols and those are proving to be even more loosely coupled and more pythonic to me. They let you “type” the behavior rather than the actual type. Say there is a case when you don’t care if it’s a set, tuple, or a list because all you’re going to do is Iterate, we’ll you’d go the behavior route and say you want an Iterator. You can create your own protocols as well and it has the effect that you document what you intend to do with the objects passed to you such that it doesn’t matter what you pass as long as it adheres to the protocol you defined. It’s documented duck typing. Here’s a great video that explains how it can simplify your code https://m.youtube.com/watch?v=xvb5hGLoK0A