Open utterances-bot opened 4 years ago
I think you are missing one big reason for using type annotations: to help a future reader! Mainly, python type hints are a form of documentation, to help read the code. But unlike simple documentation, it's one form of documentation that will remain consistent with the actual code as long as you keep type checking in CI.
A second reason is one that you mention already: if some piece of code is too clever and confuses the type checker, it probably will similarly confuse the future reader of the code, and it's probably better to refactor. At least to some extent. You could also claim that, at this point, mypy is not complete enough. For instance, decorator support in mypy is pretty awful, and it's damn difficult to preserve type checking across even a simple decorator that doesn't even change the type signature.
Thanks, good post!
@gjcarneiro A friend of mine, very into C++ and not a lover of Python, put it as "in Python the syntax is more readable, but the intent is more obscure". Needless to say he thinks annotation make the code much more understandable.
Thanks @dvarrazzo for this insightful feedback on a quite subjective topic in the Python community.
I'm not convinced that annotation makes intent of code readable. For complex code, I tend to write a big comment for reviewer. Usually, something that ends in the commit message could end in a code comment, which I find more accessible.
Actually, static type analysis is good for some class of bugs and also for code completion. I prefer pyright for it's good inference.
Regards,
"It's like using a language less flexible than Python, but it still runs as slow as Python, because it's not compiled. Ehm... the worst of two world?" love it. How did you get github comments on your blog?
@matthewchung74 take a look at https://utteranc.es :)
awesome, thanks!
On Sat, Jul 10, 2021 at 4:38 PM Daniele Varrazzo @.***> wrote:
@matthewchung74 https://github.com/matthewchung74 take a look at utteranc.es :)
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/dvarrazzo/www.varrazzo.com/issues/6#issuecomment-877717267, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAM3RRANUW2R3MYZON33IRDTXDKWJANCNFSM4LYUUGVQ .
-- Regards, Matt
First Experience with Mypy — Daniele Varrazzo
https://www.varrazzo.com/blog/2020/03/31/first-experience-mypy/