3 ms·
I mean...Come on, it's not like that's news to me :p. The mypy stuff in particular is somewhat promising, but it's a pretty awkward retrofit. A lot of the key
by syllogism 7y ago
I mean...Come on, it's not like that's news to me :p.
The mypy stuff in particular is somewhat promising, but it's a pretty awkward retrofit. A lot of the key APIs (e.g. numpy) were not designed around type declarations, so numpy will very often return either a float or an array depending on the input operations, keyword arguments, etc. This sort of thing is super common.
- dllthomas 7y ago> numpy will very often return either a float or an array depending on the input operations, keyword arguments, etc That makes it harder to find good types, but it doesn't rule it out. Either you can tell what the shape of the output should be without calling the function in question or you can't. If you can't, you should be checking the shape of the output after the call, and the type of the output should be some kind of union so the type system encourages this. On the other hand, if you can look at the arguments and easily know how the output should look, there's a fair chance you can push this knowledge into the type system. I've done similar things in flow. As a recent example, the download function in the google storage API returns a promise of the file's contents, unless the argument contains a 'destination' key in which case it returns a promise of void. Describing that as the intersection of the two function types got me the checking I want. Amusingly, I don't think there's a way to write a function with this type without a cast through any, but that's not a problem for describing an untyped API. All of that said, I don't know how well this works out with numpy and mypy in particular.
- johnfactorial 7y agoI just love the Hacker News guideline that comments get more thoughtful and substantive as a topic gets more divisive, I think we all benefit a lot from that aspect of this site. Honestly I only posted my comment to stir deeper public discussion on the topic, while trying to be clear at the end that it's possible but I certainly don't think it's encouraged or any fun at all. I figured it wasn't news to you, but thought the topic worth opening, perhaps news to someone else. Cheers.