3 ms·
It was a bear to get set up (oh NixOS...), but I imagine it's easier on other platforms: `pytype` from Google is the God Linter for Python. It: - seamlessly s
by benreesman 4y ago
It was a bear to get set up (oh NixOS...), but I imagine it's easier on other platforms: `pytype` from Google is the God Linter for Python.
It:
- seamlessly supports everything from old-ass Python 2 code up to very recent (like 3.10 or someting)
- it can and does exploit `mypy`-style annotations, but needs none to deeply analyze your code and actually find bugs
- it seems to do fairly serious deep PLT magicks. i admittedly haven't dived deep here but it's doing stuff that looks like escape analysis-level whole-program analysis
- it heavily caches and optimizes it's (understandably) heavy lifting via Ninja
It demolishes everything else I've tried. I will definitely take `Ruff` for a spin, we've got a lot of Python and I'm always up for discovering there's a better tool, but the dark magic PLT wizards at Google have probably gotten pretty close to what can be done.
- wocram 4y agoI see it's not in nixpkgs, what's difficult about setting it up?
- benreesman 4y agoIIRC I had to patch the Ninja executable path-resolution to get around differences from how pip installs it. A sibling has asked for a patch, I’ll try to remember to post it here when I extract it from our thing.
- zem 4y agoif you can provide a write-up, we would be happy to add it to the pytype docs!
- the_duke 4y agoCan you share your nix package?
- benreesman 4y agoProbably! It would need a little detangling from the proprietary stuff but not much. Please drop me a line at ben@rocinanteresearch.net so it goes on my todo list (which I’m a bit behind on this week, I’m aiming to clear the inbox tasks this weekend).
- zem 4y agopytype dev here - thanks for the kind words :) whole-program analysis on unannotated or partially-annotated code is our particular focus, but there's surprisingly little dark PLT magic involved, and you certainly don't need to be an academic type theory wizard to understand how it works. our developer docs[1] have more info, but at a high level we have an interpreter that virtually executes python bytecode, tracking types where the cpython interpreter would have tracked values. it's worth exploring some of the other type checkers as well, since they make different tradeoffs - in particular, microsoft's pyright[2] (written in typescript!) can run incrementally within vscode, and tends to add new and experimentally proposed typing PEPs faster than we do. [1] https://github.com/google/pytype/blob/main/docs/developers/index.md https://github.com/google/pytype/blob/main/docs/developers/i... [2] https://github.com/microsoft/pyright https://github.com/microsoft/pyright
- benreesman 4y agoThank you for the amazing software!
- davidatbu 4y agoJust a minor note that Pyright is an LSP server, so will work with pretty much any IDE/editor. Thanks for all your work on pytype!