← Back to context

Comment by mjr00

1 year ago

> I don’t use an IDE, so code completion or whatever you get for it doesn’t apply to me.

This is a reasonable take if you're a solo developer working without an IDE. Though I suspect you'd still find a few missing None checks with type checking.

If you're working on a team, though, the idea is to put type-checking into your build server, alongside your tests, linting, and whatnot.

> You see extraneous code like x: int = 1 in Python now.

This shouldn't be necessary in most cases; Python type checkers are fine with inferring types.

> Third party libs have bonkers types. This function signature is ridiculous:

It is. Part of that is that core infrastructure libraries tend to have wonky signatures just by their nature. A bigger part, though, is that a lot of APIs in popular Python libraries are poorly designed, in that they're extremely permissive (like pandas APIs allowing dataframes, ndarrays, list of dicts, and whatever else) and use kwargs inappropriately. Type declarations just bring that to the surface.

What's wrong with being extremely permissive? I'd argue that's a strength of the python ecosystem. It's true that very dense api:s are difficult to type, but I wouldn't say they're typically poorly designed because of it.

  • When you’ve got to pass in something that isn’t permitted and the list of things that is permitted isn’t documented you’ve got to dig 12 levels down into the library across 9 branching paths to figure out what input it actually does support.

  • Permissive libraries violate the "one and only one obvious way" philosophy.

    I suspect they probably confuse AI tools more than restrictive APIs too, and give non-AI auto complete less to go on.

Even without an IDE, I use Mypy like a test suite. It catches real bugs that would be either hard to find in testing, or intrusive and annoying to test for.