Replies: 2 comments 4 replies
-
The only place I've used |
Beta Was this translation helpful? Give feedback.
-
I think there are a couple of considerations here. Casting is basically a no-op, so if you really know for sure, e.g. that a variable |
Beta Was this translation helpful? Give feedback.
-
mypy
has some limits on what it can infer about types from the code and so occasionally reports typing errors that are 'incorrect'. One way of removing those is to add# type: ignore
on the affected line and that stops it. We should never do that just to getmypy
to shut up but always with a comment explaining whymypy
is incorrect. We can also extend# type: ignore
to makemypy
only ignore specific typing errors on a line by usingmypy
codes:# type: ignore [union-attr]
There is an example in the code addressed this comment #122 (comment):
However, in that comment @alexdewar pointed out another way of muting
mypy
using eithertyping.cast
and it turns out you can also useassert
to updatemypy
's knowledge of what types apply to a variable.At the moment, we have a few cases, all of which are solved using
# type: ignore
but we should do this consistently. Thoughts?Beta Was this translation helpful? Give feedback.
All reactions