Skip to content

MyPy? #555

Answered by ahankinson
jacobdgm asked this question in General
MyPy? #555
Feb 13, 2023 · 1 comment
Discussion options

You must be logged in to vote

I 100% recommend adding type annotations whenever and whereever you can. Personally, and professionally, it is a requirement for any code I write, or any code I review.

My IDE (IntelliJ) doesn't use mypy, but its own built-in checker. I do run mypy occasionally, but I find it's actually a bit too much. If you can get your IDE to do basic type checking then you're getting about 90% of the way there. It's super handy to check things like this:

mystr: str = mydict.get("foo")
first, last = mystr.split("-")

Did you catch the bug? If foo isn't in mydict, then get will, by default, return None. Calling .split on None is an error. When the typechecker lets you know this, it will cause you to write:

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by jacobdgm
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants