Search code examples
mypy

Is there any reason to enabled other "disallow" options if you have disallow_untyped_defs = true?


I've been adding type hints to an existing project, and over time I've enabled more "disallow" options in mypy to ensure future work on it doesn't regress the typing. Finally I've come to the point where I can set disallow_untyped_defs = true, but I still have the other options disallow_incomplete_defs = true, disallow_untyped_calls = true, and disallow_untyped_decorators = true set as I used them when working up to this point.

Does keeping these provide any additional checks or can I safely remove them without losing anything? I understand disallow_incomplete_defs is a superset of disallow_untyped_defs, but I can't find any definitive information about the others.


Solution

  • Apart from the obvious difference (disallow_incomplete/untyped_defs displays errors at the function definition site, while the others display errors at the usage site), disallow_untyped_calls and disallow_untyped_decorators warn you if you're using such untyped items imported from anywhere, including third-party libraries.

    Third-party untyped items are (by default) not checked for typing coverage or soundness by mypy, so disallow_incomplete/untyped_defs does not activate for them.