Modern Linting & Formatting with Ruff
Legacy toolchains daisy-chained Black, Flake8, isort, and pyupgrade, slowing developer feedback loops. Ruff replaces the entire stack with a single Rust binary that lints and formats code 10–100x faster ⚡.
# Configured via pyproject.toml:
# [tool.ruff.lint]
# select = ["E", "F", "I", "UP", "B"]
rule_codes = {
"E / W": "pycodestyle syntax & style",
"F": "Pyflakes (unused variables & imports)",
"I": "isort (clean import sorting)",
"UP": "pyupgrade (modern Python 3 idioms)"
}
for code, desc in rule_codes.items():
print(f"[{code:<5}] -> {desc} ⚡")
# 101. Modern Linting & Formatting with Ruff Legacy toolchains daisy-chained Black, Flake8, isort, and pyupgrade, slowing developer feedback loops. Ruff replaces the entire stack with a single Rust binary that lints and formats code 10–100x faster ⚡. ```python # Configured via pyproject.toml: # [tool.ruff.lint] # select = ["E", "F", "I", "UP", "B"] rule_codes = { "E / W": "pycodestyle syntax & style", "F": "Pyflakes (unused variables & imports)", "I": "isort (clean import sorting)", "UP": "pyupgrade (modern Python 3 idioms)" } for code, desc in rule_codes.items(): print(f"[{code:<5}] -> {desc} ⚡") ``` Running `ruff check --fix` and `ruff format` in pre-commit hooks eliminates formatting arguments and prevents syntax degradation before code ever hits pull requests 🛡️! --- ### Question What made Ruff rapidly supplant legacy linting toolchains across the Python community? 🧠 - [ ] a. It consolidates Black, Flake8, and isort into a single ultra-fast Rust binary running 10-100x faster ⚡ - [ ] b. It automatically executes code in a dedicated GPU thread - [ ] c. It disables all runtime exceptions in production builds - [ ] d. It converts dynamic Python variables into static C types --- ### Challenge Given `rules = {'E': 'style', 'F': 'flakes', 'I': 'isort', 'UP': 'pyupgrade'}`, print the description value for `'UP'`. 🎯 <details> <summary>Solution</summary> ```python rules = {'E': 'style', 'F': 'flakes', 'I': 'isort', 'UP': 'pyupgrade'} print(rules['UP']) ``` </details>