Live data from Hacker News

Ask HN: Which Python type checker should I use?

news.ycombinator.com

51–60 of 83 posts

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

#52
post #41

Earlier quoted context omitted.

Better than Pycharm?

Kind of hard to say. With pylance the type checking will be definitively better in vscode. But pycharm had a lot going on to make up for it. Just as a reference I use pycharm mainly but before sending a PR I will rely on vscode to fix typing issues. Just use what you likes best.

I maintain aiosmtpd using PyCharm and... That's it.

Playing around with Ruff nowadays.

mypy was proposed early during aiosmtpd development but we decided it's not worth the headache.

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

#53
post #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.

Use lots of typing.Protocol and you get all the goodness of duck-typing.

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

#54

The recent takeover of rye by the guys doing ruff[1] has some likelihood of rendering the python typing and packaging scene into something more coherent. Having the tool get started with Ronacher, of Flask fame, gives it some mindshare among those paying attention. It would be better still if the PSF were endorsing, but that gets too political, I suppose. [1] https://astral.sh/blog/uv

Well the guys at astral has no plans in the near future to create a static type checker.

Ruff is great, though. I now stop using flake8+black+isort and have gone all-in with Ruff.

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

#55
post #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?

That was part of the wasted day I was talking about - trying to configure the system so that the rules would be more useful. I could disable the warnings per-line with comments - although this meant that my code was then filled with these lines and the formatting was awful - but I couldn't disable the warnings globally for some reason. I never managed to figure out why, unfortunately.

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

#56
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.

PyCharm professional understands Django natively. Maybe try that? PyCharm also has its own type-checker that's a lot less fussy than mypy.

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

#57
post #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.

That's roughly a structural type system, and it's part of what makes Typescript work well (although it has some disadvantages in that you can't easily describe the type "an object with only these attributes). You can somewhat get that effect with Protocols in Python, but it often feels a bit boilerplate-y to me.

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

#58
post #20
post #16

(eclipse+pydev - for the IDE part) + mypy (better dmypy for performance) + ruff (both as linter and as formatter) is the way I go. an in my pyproject I set the strict mode for mypy, and almost all rules for rust with extend-select

Why eclipse and pydev? It is a lot slower than vs code

1st I want an IDE, not a notepad++ clone 2nd vs code is ugly as hell to me

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

#59
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 really appreciate all the detail. Disappointing, though! Surprised about the Unknown, too.
Post reply on HN