Automated tools catch errors and style issues you'd miss manually.
Automatyczne narzędzia wychwytują błędy i problemy stylistyczne które przegapisz ręcznie.
They enforce consistency across team projects — everyone's code looks the same.
Wymuszają spójność w projektach zespołowych — kod każdego wygląda tak samo.
There's debate here — some want formatting control, others prefer automated consistency.
Jest tu debata — niektórzy chcą kontroli nad formatowaniem, inni preferują automatyczną spójność.
In practice, consistency helps more than personal style preferences.
W praktyce, spójność pomaga bardziej niż osobiste preferencje stylu.
Documentation:
Ruff is extremely fast linter and formatter written in Rust.
Ruff to ekstremalnie szybki linter i formater napisany w Rust.
It replaces Black, Flake8, isort and more — all in one.
Zastępuje Black, Flake8, isort i więcej — wszystko w jednym.
Install:
Zainstaluj:
uv add --dev ruffCreate messy_code.py with issues:
Utwórz messy_code.py z problemami:
import os
import sys
def calculate(x,y):
result=x+y
return result
unused_variable = 42Run linter:
Uruchom linter:
uv run ruff check messy_code.pyFix automatically:
Napraw automatycznie:
uv run ruff check --fix messy_code.pyUnused imports are gone!
Nieużywane importy zniknęły!
uv run ruff format messy_code.pyNow spacing is fixed:
Teraz odstępy są naprawione:
def calculate(x, y):
result = x + y
return result
unused_variable = 42Create pyproject.toml with production-ready settings:
Utwórz pyproject.toml z ustawieniami produkcyjnymi:
[tool.ruff]
line-length = 120
target-version = "py313"
[tool.ruff.lint]
select = [
"E", # pycodestyle errors
"W", # pycodestyle warnings
"F", # pyflakes
"I", # isort (import sorting)
"B", # flake8-bugbear (common bugs)
"UP", # pyupgrade (modern Python syntax)
"S", # flake8-bandit (security issues)
"C4", # flake8-comprehensions
"SIM", # flake8-simplify
]
[tool.ruff.lint.per-file-ignores]
"tests/**/*.py" = ["S101"] # Allow assert in tests
[tool.ruff.format]
quote-style = "double"
indent-style = "space"
[tool.mypy]
python_version = "3.13"
warn_return_any = true
warn_unused_configs = true
disallow_untyped_defs = trueRun checks:
Uruchom sprawdzenia:
uv run ruff check .
uv run ruff format .
uv run mypy .What this catches / Co to wyłapuje:
S(bandit) - hardcoded passwords, SQL injection, unsafe yaml.load()B(bugbear) - mutable default arguments, unused loop variablesUP(pyupgrade) - outdated syntax likeList[str]instead oflist[str]SIM(simplify) - overcomplicated code that can be simplified
mypy verifies type hints.
mypy weryfikuje type hints.
Install:
Zainstaluj:
uv add --dev mypyCreate type_demo.py:
Utwórz type_demo.py:
def add(a: int, b: int) -> int:
return a + b
result = add(5, 3)
wrong = add("hello", "world") # Type error!Run:
Uruchom:
uv run mypy type_demo.pyOutput:
Wynik:
type_demo.py:5: error: Argument 1 to "add" has incompatible type "str"; expected "int"mypy caught the error!
mypy złapał błąd!
VS Code:
Install Ruff extension (charliermarsh.ruff).
Zainstaluj rozszerzenie Ruff (charliermarsh.ruff).
Add to .vscode/settings.json:
Dodaj do .vscode/settings.json:
{
"[python]": {
"editor.defaultFormatter": "charliermarsh.ruff",
"editor.formatOnSave": true
}
}PyCharm:
Settings → Tools → File Watchers → Add Ruff
After this section you can:
Po tej sekcji potrafisz:
-
use Ruff to lint and format code
używać Ruff do lintowania i formatowania kodu
-
automatically fix common issues
automatycznie naprawiać powszechne problemy
-
verify type hints with mypy
weryfikować type hints z mypy
-
integrate tools into IDE
integrować narzędzia z IDE
-
maintain code quality consistently
utrzymywać jakość kodu spójnie
Next: 2.7 — Mini-projekt