How I find what breaks before I change a Python function
Описание и применение
Blastradius – инструмент статического анализа зависимостей в Python, позволяющий определить, какие функции и тесты затронутся при изменении вспомогательной функции.
Задача
Changing a helper function can unintentionally break code far from the change, and existing tests may not cover all affected paths.
Результат
blastradius provides a quick, local analysis of call dependencies, revealing which parts of the codebase and which tests are impacted by a change.
Рабочий процесс
- Install blastradius via pip
- Run blastradius on the target function or file
- Review the output showing direct callers, transitive dependents, and affected tests
- Run the identified tests before making the change
Доказательства
blastradius helps a little, but it tells you where a name appears, not what depends on it.
blastradius: 6 files, 11 definitions, 13 edges (0.00s) Target: shop/money.py::apply_tax defined at shop/money.py:5 Direct callers (1) shop/billing.py:12 Invoice.total -> apply_tax Transitive dependents (3, up to 3 hops) hop 2 shop/billing.py:15 charge (via Invoice.total <- apply_tax) hop 3 shop/api.py:4 checkout (via charge <- Invoice.total) hop 3 tests/test_billing.py:4 test_charge (via charge <- Invoice.total) [test] Affected tests (1) tests/test_billing.py:4 test_charge Summary: 1 direct, 3 transitive, 3 other files (2 non-test), 1 tests
It walks every .py file and parses it with the standard-library ast module. It records definitions, calls and imports (including relative imports and aliases), then resolves each call in a fixed order... The key design choice is this: if a call is ambiguous, it is dropped, not guessed.
- Дата записи: 2026-10-01T08:38:13.286Z