Some additional comments. On Thu, Dec 09, 2021 at 08:32:43PM +0000, deavid wrote:
1) On really big codebases and complex projects, it's very easy to lose track of what things do. Types help detecting bugs early.
Static types help detecting *some* kinds of bugs early. Python doesn't stop you from running static type checks on your code. That's what mypy, and other type checkers, already do. What does integration gain us apart from forcing people who care nothing about static type checking to care, whether they want to or not?
(Ask anyone that has used Rust + Clippy, the amount of errors that are catched is amazing, programs tend to work on the first try)
Isn't that a contradiction? If the work on the first try, then obviously there weren't any errors to be caught. If there are errors that are caught and need to be fixed, then it wasn't your first try. In any case, I can often say the same about Python code, with no static checking. Typically, after writing some functions, and fixing a handful of typos -- I've been writing Python more than 20 years and I still sometimes write {key=value} in dicts -- my unit tests Just Work. (Unless they don't. *cough*) But when they don't work, it's almost never *type* checks that fail. Its logic errors and programming errors in the algorithm, and static typing doesn't solve those.
2) Libraries are currently the top bottleneck for any team to start using MyPy/Pytype. Making types mandatory would ensure all libraries have type support.
Making types mandatory would more like ensure that many libraries would just stop being supported and they would move to other languages.
Of course, types have their own set of drawbacks; for example it could make Python look harder to code for newcomers, or it might get in the way for things like Jupyter notebooks, ML, and similar stuff.
Right.
Because of this, an escape hatch must always exist. (maybe there are even more problems I am not aware about, I'd love to hear)
But if there is an escape hatch, then the types are not mandatory, and many libraries will not use them, many projects will not use them, and you have the status quo except mypy is bundled with CPython. So all you will actually gain is avoiding running pip install mypy or whatever command you use to install it. That's a lot of disruption to the entire Python ecosystem just so people can avoid installing mypy. -- Steve