Live data from Hacker News

Ask HN: Which Python type checker should I use?

news.ycombinator.com

21–30 of 83 posts

Re: Ask HN: Which Python type checker should I use?

#21
post #19

My experience is pretty negative with all of them, I would be almost more tempted to ignore type checking in Python until it has drastically improved. In particular, if you're experienced with Typescript, you're probably going to be very disappointed when trying to do similar things in Python. The most recent one I've tried was Pyright. Pyright is faster than Mypy, and can also be configured to be quite strict, both…

Very good points. Did you also tried ignoring some rules that are overly strict? Or reduce them to warnings?

Re: Ask HN: Which Python type checker should I use?

#22
pyright is state of the art right now thanks to eric. If you use VSCode+Pylance you will feel right at home coming from Rust/TS.

just be aware a lot of community packages aren't ready for typed python. if you stick to the good stuff like fastapi and pydantic, you will be fine.

Re: Ask HN: Which Python type checker should I use?

#23
post #19

My experience is pretty negative with all of them, I would be almost more tempted to ignore type checking in Python until it has drastically improved. In particular, if you're experienced with Typescript, you're probably going to be very disappointed when trying to do similar things in Python. The most recent one I've tried was Pyright. Pyright is faster than Mypy, and can also be configured to be quite strict, both…

i've often thought a more interesting approach for python's duck typing would be if the interpreter looked for anomalous types on assignment. so build a compact distribution of type "shape" for every assignment and then either throw exceptions or log warnings when apparent outliers are encountered.

Re: Ask HN: Which Python type checker should I use?

#25
post #8

Would also be interested in what is friendly with Django. Using VSCode + the Python extension, the default checker (Pylance?) just pukes on the ORM magic.

To get the type checker to work with Django you need to install django-stubs[1]. It works great with mypy, but should also work well with pyright.

[1]: https://github.com/typeddjango/django-stubs

Re: Ask HN: Which Python type checker should I use?

#26

Pyright is the Microsoft provided lsp: does anyone else feel uneasy about using this? Especially given the EEE playbook "that we definitely won't do this time" - would love to have a discussion on this if someone could talk me into using it. I just use a combination of black, flake, and mypy. Apparently ruff is quite good as well. For lsp I use Jedi, which actually worked faster on my company's code base than pyright…

Can the extension be used on VSCodium builds? If memory serves, C# tooling extensions are proprietary and are subject to unfortunate treatment when using open-source builds of VSCode.

You are correct. It is not supported on vscodium.

Re: Ask HN: Which Python type checker should I use?

#28
I would not personally use any of them. Typed python in previous workplace was pretty much shitshow, and if starting from scratch instead of untyped codebase it might be worth it, maybe, for some specific cases, but in general combination of bad library typing and bad type checking tools leads to horrible user experience.

So going forward my personal projects continue to be ducktyped, and if I care about types, I use rust or go.

Re: Ask HN: Which Python type checker should I use?

#29

Earlier quoted context omitted.

Can the extension be used on VSCodium builds? If memory serves, C# tooling extensions are proprietary and are subject to unfortunate treatment when using open-source builds of VSCode.

You are correct. It is not supported on vscodium.

Yea, and if you're a company making more than $1M in revenue or have over 250 PCs, then you need a commercial license.

Microsoft definitely seems to be pushing proprietary VSCode extensions where it's free to get users hooked on the product (and kill competitors) and then charge companies lots of money for the tools they got everyone hooked on because they appeared to be free.

Re: Ask HN: Which Python type checker should I use?

#30

I would not personally use any of them. Typed python in previous workplace was pretty much shitshow, and if starting from scratch instead of untyped codebase it might be worth it, maybe, for some specific cases, but in general combination of bad library typing and bad type checking tools leads to horrible user experience. So going forward my personal projects continue to be ducktyped, and if I care about types, I use…

My experience couldn't be more different. I've had the experience of introducing type annotations into legacy Python 2 codebases and it's been a godsend and the only way to get them to Python 3. I've also had the experience of writing greenfield Python 3 code fully-typed from the start and its also been a useful tool there.
Post reply on HN