pylyzer
is a static code analyzer / language server for Python written in Rust.
bash
cargo install pylyzer
bash
pip install pylyzer
If installed this way, type resolution for the standard libraries is not available. If you want to use it, you need to install Erg.
bash
curl -L https://github.com/mtshiba/ergup/raw/main/ergup.py | python3
On average, pylyzer can inspect Python scripts more than 100 times faster than pytype and pyright 1. This is largely due to the fact that pylyzer is implemented in Rust.
pylyzer can do more than the type checking. For example, it can detect out-of-bounds accesses to lists and accesses to nonexistent keys in dicts.
While pytype/pyright's error reports are illegible, pylyzer shows where the error occurred and provides clear error messages.
pylyzer as a language server supports various features, such as completion and renaming.
pylyzer uses the type checker of the Erg programming language internally. This language is a transpiled language that targets Python, and has a static type system.
pylyzer converts Python ASTs to Erg ASTs and passes them to Erg's type checker. It then displays the results with appropriate modifications.
pylyzer's type inspector only assumes (potentially) statically typed code, so you cannot check any code uses reflections, such as exec
, setattr
, etc.
pylyzer (= Erg's type system) has its own type declarations for the Python standard APIs. Typing of all APIs is not complete and may result in an error that such an API does not exist.
Union
Optional
list
TypeVar
, Generic
)typing.cast
)1 The performance test was conducted on MacBook (Early 2016) with 1.1 GHz Intel Core m3 processor and 8 GB 1867 MHz LPDDR3 memory.↩