- Ruff v0.4.0 Availability: Available now. Install via PyPI or package manager.
pip install --upgrade ruff
. Features:
- An extremely fast Python linter and formatter written in Rust. Can replace multiple tools and execute much faster.
- New milestone with a hand-written recursive descent parser, which is >2x faster, resulting in a 20-40% speedup for linting and formatting.
Parsers:
- Generated parser: Created using a parser generator (LALRPOP) with grammar defined in a.DSL file and converted to Rust code.
- Hand-written parser: Encodes parsing rules directly in Rust code using functions for individual nodes.
- Parser History: Initially used the Python parser from RustPython. Later pulled it into Ruff and maintained separately as AST structure evolved. Victor Hugo Gomes proposed a hand-written parser with several advantages.
Advantages of Hand-written Parser:
- Control and flexibility: Can handle edge cases like parenthesized
with
items more easily. - Performance: Significantly faster than the generated parser, with micro-benchmark comparisons showing >2x speedup.
- Error handling: Provides better error messages for syntax errors.
- Error resilience: Enables error recovery, allowing the linter to continue analyzing code with syntax errors and provide diagnostics.
- Control and flexibility: Can handle edge cases like parenthesized
- Next Steps: Aim to improve parsing capabilities with complete error recovery, report all syntax errors, and enable continuous analysis.
- Acknowledgments: Thank the RustPython project for enabling early development. Thank Victor Hugo Gomes for the hand-written parser and Addison Crump for the fuzzer. View the full changelog on GitHub. Read about Astral on their website.
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。