A fast, feature-rich static code analyzer & language server for Python
Find a file
2023-02-24 19:38:37 +09:00
.cargo Update with dependencies 2023-02-04 10:51:55 +09:00
.github Update rust.yml 2023-02-24 16:26:57 +09:00
crates/py2erg Support operator checks for user-defined classes 2023-02-24 14:57:08 +09:00
docs/source Add options.md 2022-12-26 16:57:16 +09:00
extension Update README.md 2022-12-14 19:06:20 +09:00
images add lsp_support.png 2023-02-13 23:44:23 +09:00
src fix: #2 2023-02-06 03:54:32 +09:00
tests support unary operator checks 2023-02-24 15:39:25 +09:00
.gitignore Update 2022-12-14 11:12:05 +09:00
.pre-commit-config.yaml test: fix stack overflow 2023-02-24 16:12:04 +09:00
Cargo.lock update version (v0.0.8) 2023-02-24 17:30:31 +09:00
Cargo.toml update version (v0.0.8) 2023-02-24 17:30:31 +09:00
cargo_publish.ps1 Update cargo_publish.ps1 2023-02-24 19:38:37 +09:00
cargo_publish.sh Update cargo_publish.sh 2023-02-24 19:35:55 +09:00
LICENSE initial commit 2022-12-12 22:40:50 +09:00
pyproject.toml Rename the project 2022-12-13 17:25:17 +09:00
README.md Update README.md 2023-02-24 16:19:49 +09:00

pylyzer

vsm-version Build status Build status

pylyzer is a static code analyzer / language server for Python written in Rust.

Installation

cargo (rust package manager)

cargo install pylyzer

pip

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.

curl -L https://github.com/mtshiba/ergup/raw/main/ergup.py | python3

What is the advantage over pylint, pyright, pytype, etc.?

  • Performance 🌟

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.

performance

  • Detailed analysis 🩺

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.

analysis

  • Reports readability 📖

While pytype/pyright's error reports are illegible, pylyzer shows where the error occurred and provides clear error messages.

pylyzer 😃

report

pyright 🙃

pyright_report

  • Rich LSP support 📝

pylyzer as a language server supports various features, such as completion and renaming.

lsp_support

How it works

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.

Limitations

  • pylyzer's type inspector only assumes (potentially) statically typed code, so you cannot check any code uses reflections, such as exec, setattr, etc.

  • Type checking of compound types such as Union types is not supported yet (will be implemented soon).

  • 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.

TODOs

  • type checking
    • variable
    • operator
    • function/method
    • class
  • type inferring
    • variable
    • operator
    • function/method
    • class
  • builtin modules resolving (partially)
  • local scripts resolving
  • local packages resolving
  • compound type checking
  • type assertion

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.