News for hackers. Stuff that matters.
Re:Static Duck Typing in Python with Protocols by mynameisash on Tuesday November 23, 2021 @02:56PM (#29322527)
I have several problems with this:

* I have had the installation of mypy fail on multiple machines and crash (‽) several machines

* mypy is a separate component; yes, it's very well supported, but it's not included with python3 by default

* It's not required by packages to function, which means that packages can and do simply neglect to add typings. The package I used in my example doesn't provide any such typing information, so me using mypy wouldn't help

* Besides mypy, the package in question lacks appropriate documentation (eg, the mouseover of the function I was calling provided nothing in the IDE to give a hint). The method signature defines the shape parameter as being named "xy". Only when I went to the web site did I find that it's supposed to be either List[int, int, int, int] or List[Tuple[int, int], Tuple[int, int]] and that the second pair of values is a point and not dimensions. Were I doing this in another language, the type annotation would likely provide some details.

This is my problem with Python -- yes, you can use typing hints if you want, but nowhere is it required. This leads to a world in which I spend 45 minutes painfully debugging this kind of thing only after my code is written. In my experience, this type of bug very rarely exists in stricter, compiled languages.

There are no comments on this comment yet.