How to properly use mypy with PyTorch?

Hi there,
Could anyone please provide an example on how to setup mypy to properly work with PyTorch?
I’m currently using :

[mypy-torch.*]
# https://github.com/pytorch/pytorch/issues/42787#issuecomment-672419289  
implicit_reexport = True

I am aware that typing with PyTorch is still a work in progress. So it would be very much appreciated if additional suggested flags could come with some explanation as to why we currently need them instead of pure strict.
If you also feel this could be useful in your project, please comment or like this post.
Thanks!

Hi,

You can check our own mypy ini file here: https://github.com/pytorch/pytorch/blob/master/mypy.ini
It is updated every time we add typing to new part of our code base.

1 Like