MyPy? #555
-
Looking through requirements.txt, I see we have Do people have thoughts on this? Also, is this the right place to put questions like this? It's not exactly an "Issue"... |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
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:
Did you catch the bug? If
and then you know you need to handle the Annotating return values is really good for thinking about functions, their input, and their output. It stops you from making a function too complicated, since you know that if you're making the return signature too complicated, then your function is probably too complicated! As for adding annotations, I would say the best way to do it is to start with the code you are writing and move forward, and only "upgrade" the bits of code when you touch it. If your IDE is configured correctly, it will anyway start to tell you when you are doing things you shouldn't be, and it will start highlighting areas in your code where you're probably not doing what you think you're doing. |
Beta Was this translation helpful? Give feedback.
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:
Did you catch the bug? If
foo
isn't inmydict
, thenget
will, by default, returnNone
. Calling.split
onNone
is an error. When the typechecker lets you know this, it will cause you to write: