A fast, feature-rich static code analyzer & language server for Python
Find a file
2023-08-24 14:58:57 +09:00
.cargo Update with dependencies 2023-02-04 10:51:55 +09:00
.github Update release.yml 2023-05-03 15:42:20 +09:00
.vscode CI: update scripts 2023-04-29 12:36:29 +09:00
crates/py2erg fix: shadowing bug 2023-07-28 23:29:23 +09:00
docs docs: add mkdocs.yml 2023-04-30 22:35:52 +09:00
extension extension: remove CheckOnType option 2023-05-13 21:30:00 +09:00
images minor fix: logo 2023-04-02 11:25:43 +09:00
src build: update deps 2023-07-28 23:23:41 +09:00
tests fix: shadowing bug 2023-07-28 23:29:23 +09:00
.gitignore fix: display of file names 2023-03-15 18:14:56 +09:00
.pre-commit-config.yaml test: fix stack overflow 2023-02-24 16:12:04 +09:00
Cargo.lock build: update version (v0.0.41) 2023-08-24 14:58:57 +09:00
Cargo.toml build: update version (v0.0.41) 2023-08-24 14:58:57 +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-04-29 14:46:24 +09:00
LICENSE initial commit 2022-12-12 22:40:50 +09:00
mkdocs.yml docs: add mkdocs.yml 2023-04-30 22:35:52 +09:00
mkdocs_build.bat docs: add mkdocs.yml 2023-04-30 22:35:52 +09:00
pyproject.toml Update pyproject.toml 2023-04-07 11:58:44 +09:00
README.md Update README.md 2023-06-01 21:16:54 +09:00

pylyzer

pylyzer_logo_with_letters

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

Make sure that cargo/rustc is up-to-date, as pylyzer may be written with the latest language features.

pip

pip install pylyzer

If installed this way, you also need to install Erg.

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

GitHub Releases

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 (The language server is an adaptation of the Erg Language Server (ELS). For more information on the implemented features, please see here).

lsp_support

autoimport

VSCode extension

What is the difference from Ruff?

Ruff, like pylyzer, is a static code analysis tool for Python written in Rust, but Ruff is a linter and pylyzer is a type checker & language server. pylyzer does not perform linting, and Ruff does not perform type checking.

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.

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

  • Since pylyzer's type checking is conservative, you may encounter many (possibly false positive) errors. We are working on fixing this, but if you are concerned about editor errors, please turn off the diagnostics feature.

TODOs

  • type checking
    • variable
    • operator
    • function/method
    • class
  • type inference
    • variable
    • operator
    • function/method
    • class
  • builtin modules resolving (partially)
  • local scripts resolving
  • local packages resolving
  • collection types
    • list
    • dict
    • tuple
  • typing
    • Union
    • Optional
    • Literal
    • Callable
    • TypedDict
    • type variable (TypeVar, Generic)
    • Protocol
    • Final
    • Annotated
    • TypeAlias
    • type guard (TypeGuard)
    • others
  • collections.abc
    • Iterable
    • Iterator
    • Mapping
    • Sequence
    • others
  • type assertion (typing.cast)
  • type narrowing (is, isinstance)

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.