$ mypy --strict foo.py
foo.py:26: error: Function is missing a type annotation
foo.py:28: error: Revealed type is 'typing.Iterator[builtins.int*]'
I know, this is a bit awkward to use, but it's there if you need it.
Second, I'm not quite sure why mypy does not infer return types - maybe it's a bug, maybe it's a design decision. The question came up for Rust by the way and I think the rationale may apply to Python too.
Finally, if you're still wondering whether to give mypy a go, I have compiled a real-world list of changes caused by the transition to static typing in this rather long blog post. You may find it interesting :)
I'm going to give it another go soon. The issue about self-referential types is essentially fixed in an upcoming Python release, and I can import from future now.
The return types are still annoying, but the reveal types will help. I got another comment that mypy may add an option to allow inferred return types.
At the moment, doing a refactoring, I'm leaning towards typing all the return types is the lesser of evils -- when compared to hunting down type mismatches.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Thanks for the detailed article and the nice examples - it allows for an interesting discussion.
Here's my take on the subject (disclaimer: I'm using mypy in all my "serious" projects for a little bit than a year now)
First, maybe you missed the fact that
mypy
has areveal_type
function precisely so that you don't have to remember and or guess all the types.I know, this is a bit awkward to use, but it's there if you need it.
Second, I'm not quite sure why
mypy
does not infer return types - maybe it's a bug, maybe it's a design decision. The question came up for Rust by the way and I think the rationale may apply to Python too.Finally, if you're still wondering whether to give
mypy
a go, I have compiled a real-world list of changes caused by the transition to static typing in this rather long blog post. You may find it interesting :)Cheers!
Thank you.
I'm going to give it another go soon. The issue about self-referential types is essentially fixed in an upcoming Python release, and I can import from future now.
The return types are still annoying, but the reveal types will help. I got another comment that mypy may add an option to allow inferred return types.
At the moment, doing a refactoring, I'm leaning towards typing all the return types is the lesser of evils -- when compared to hunting down type mismatches.