3 ms·
> Ordinary in-line type hints won't lie or go out of sync without complaining somewhere though This is demonstrably untrue with the default configuration of My
by packetlost 3y ago
> Ordinary in-line type hints won't lie or go out of sync without complaining somewhere though
This is demonstrably untrue with the default configuration of Mypy. It will silently ignore explicit hints, inline or not, in certain situations.
- LegibleCrimson 3y agoI'm going to need an example of that. I tend to use Pyright, but when I used MyPy, I never had it simply ignore explicit hints. If it's demonstrably untrue, you should be able to demonstrate it, right?
- packetlost 3y agoHere's the quickest, simplest example I could come up with off the top of my head: https://paste.sr.ht/~chiefnoah/7e07a961cf266fa620d1fd2d31ba2ce01d492f4a https://paste.sr.ht/~chiefnoah/7e07a961cf266fa620d1fd2d31ba2... This particular issue will get picked up with `--strict`, but it's nearly impossible to do that on a large codebase with typing added post-hoc. Pyright has saner defaults, it catches this particular issue: https://paste.sr.ht/~chiefnoah/80816fded2a08a03ca80804d524ee42ba4ae5fd2 https://paste.sr.ht/~chiefnoah/80816fded2a08a03ca80804d524ee...
- LegibleCrimson 3y agoThanks for the example. That's happening because the `main` function is an untyped function. You can fix that by changing `def main():` to `def main -> None:` You can also make it pick up with `--check-untyped-defs`. I always used mypy with --strict, so I forgot that it wasn't the default configuration. I agree, though. Pyright has better defaults. It's not great that mypy just completely skips all functions without typing information given. It makes a lot more sense for it to just check everything and assume Any on all unspecified arguments and returns. It's still valuable to type-check the contents of functions with unspecified types.