4 ms·
What type checker do you recommend?
by Buttons840 2y ago
What type checker do you recommend?
- Ey7NFZ3P0nzAe 2y agoBeartype is incredible. It is soo fast I put it as decorator on all functions of all my projects. It's day and night compared to typeguard. Also the dev is... Completely out of this world
- HenriTEL 2y agoI don't get the point of a runtime type checker. It adds a lot of noise with those decorators everywhere and you need to call each section of the code to get full coverage, meaning 100% test coverage. At that point just use rust, or am I missing something?
- Buttons840 2y agoIt looks like you call a function near the beginning of your Python program / application that does all the type checking at startup time. IDK for sure, I haven't used the library. Someone using Python doesn't "just use Rust", there are very clear pros and cons and people already using Python are doing so for a reason. It is sometimes helpful to have type checks in Python though.
- HenriTEL 2y agoFrom the doc it does not seem to be the case. > Use beartype to assure the quality of Python code beyond what tests alone can assure. If you have yet to test, do that first with a pytest-based test suite, tox configuration, and continuous integration (CI). If you have any time, money, or motivation left, annotate callables and classes with PEP-compliant type hints and decorate those callables and classes with the @beartype.beartype decorator. Don't get me wrong, I think static type checking is great. Now if you need to add a decorator on top of each class and function AND maintain 100% code coverage, well that does not sound like "zero-cost" to me. I can hardly think of a greater cost just to continue dynamically typing your code and maintain guarantees about external dependencies with no type hints.
- Ey7NFZ3P0nzAe 2y agoAdding the decorator on top of every def takes max 5s in any good IDE so I really don't get why changing the language would be worth it. And anyway beartype has a mechanism to run a hook once and it will automagically decorate all functions.
- wdroz 2y agodisclaimer: I don't work on big codebases. Pylance with pyright[0] while developing (with strict mode) and mypy[1] with pre-commit and CI. Previously, I had to rely on pyright in pre-commit and CI for a while because mypy didn’t support PEP 695 until its 1.11 release in July. [0] -- https://github.com/microsoft/pyright https://github.com/microsoft/pyright [1] -- https://github.com/python/mypy https://github.com/python/mypy
- cbenz 2y agoI would tend to rely on a single tool, do you see advantages to use both? Do you happen to have discrepancies between both? (e.g. an error raised by one and not the other)
- wdroz 2y agoI prefer mypy but sometimes pyright supports new PEPs before mypy, so if you like experimenting with cutting-edge python, you may have to switch time to time.