4 ms·
I was just playing around with Python 3.10 for the first time today. I made an algebraic/sum-type (dataclasses + typing.Union), then did some structural pattern
by frou_dh 4y ago
I was just playing around with Python 3.10 for the first time today. I made an algebraic/sum-type (dataclasses + typing.Union), then did some structural pattern matching on a value of that type (match statement), and Mypy could tell me statically when the pattern matching wasn't exhaustive!
I think it's pretty damn amazing how well Python has been able to evolve into the realm of static typing. And no unofficial superset syntax required!
- davidatbu 4y agoThat's wonderful to hear! It's been > 1 year since I used daily-drove Python, so my comments do lag behind the progress by at least a year. Maybe an unofficial superset syntax is indeed not required!!
- svetb 4y agoMypy can work really well in many cases, but we seem to get bitten by bugs on a daily/weekly basis. There are >1,000 currently open on Github [0], so it doesn't take much effort to hit one. And having the type-checker tell you that something's not valid when it actually is is a real turn-off...means that we end up with code that's riddled with "# type: ignore", which kind of defeats the point. Pylance (the VSCode built-in linter, based on Pyright I believe) tends to do a better job than Mypy, but not as easy to integrate into CI. It's a real shame that the Python ecosystem doesn't have anything nearly as robust as TypeScript. [0] https://github.com/python/mypy/issues?q=is%3Aopen+is%3Aissue+label%3Abug https://github.com/python/mypy/issues?q=is%3Aopen+is%3Aissue...
- gilch 4y agoMypy still couldn't handle recursive types, last I checked. Pyright can do it, but seems to have trouble with even basic type inference. The annotation syntax is working OK, although it tends a bit verbose, but the type checkers are still crippled IMHO.
- LtWorf 4y agoThe fact that it's written in js, probably not by python developers makes me distrust it. Anyway I tried it on a mypy clean codebase and it gave a gazillion false positives so I never bothered to integrate it more properly.
- davidatbu 4y agoI absolutely feel comfortable vouching for Pyright! Last I used it, it was miles ahead of mypy in terms of speed, easy-of-use (it's an LSP!), correctness (simply has less bugs), and feature completeness (has implemented every new static typing feature that I've wanted to use months ahead of mypy). The maintainer was also super-responsive on Github: replied to my issues in hours/minutes, and often released minor versions with bugfixes one or two days after issues are reported.
- aslilac 4y agoI’ll also vouch for it. Plus, at least half a dozen highly funded people have tried to recreate TypeScript and have failed. Microsoft is flawed, but they can make a mean type checker.