Formatting, Linting, and Type Checks
Python Style Checks and Static Analysis
BOTIE
PEP 484, proposed in 2014 for Python 3.5, standardized a vocabulary for optional static type analysis. A checker can follow those declarations without executing the application. This adds evidence about interfaces, while behavior tests still check requirements on actual executions. The tools have complementary scopes, rather than interchangeable definitions of correctness.
Sources for this history
The Formatter Passed a Wrong Calculation
Botie formats an alert function and sees a successful check. The function still excludes a reading on the boundary. The formatter never promised to check that rule.
We need to choose checks for the questions they answer, run each required check, and keep a skipped job distinct from a passing one.
These are supplied check results, not executions of a formatter, linter or type checker. The table is assumed to include every required check for the same code revision.
Step 1 of 1
Choose the check for the question
Interpret each success within the check's scope.
| Check | Question | Still needed |
|---|---|---|
| Formatter | Configured layout? | Behavior |
| Linter | Selected code patterns? | Application requirements |
| Type checker | Declared interfaces agree? | Runtime validation |
| Tests | Specified cases behave? | Untested inputs and integrations |
Formatter
- Question
- Configured layout?
- Still needed
- Behavior
Linter
- Question
- Selected code patterns?
- Still needed
- Application requirements
Type checker
- Question
- Declared interfaces agree?
- Still needed
- Runtime validation
Tests
- Question
- Specified cases behave?
- Still needed
- Untested inputs and integrations
Distinguish format from behavior
A failed test needs repair; a skipped check still needs to run. Keeping their status and detail shows which problem needs action.
Find the project checks that need attention
Formatting passes, but the alert-count test fails. Formatting checks how code is written; tests check the behavior promised by the program. The table contains one result for every required project check, with passed, failed or not run as its status.
BOTIE
Required checks that failed or did not run
- check
- Tests
- status
- failed
- detail
- A reading equal to 25 C was not counted
| check | status | detail |
|---|---|---|
| Tests | failed | A reading equal to 25 C was not counted |
Follow the operations
1. Results for every required project check
- check
- Formatting
- status
- passed
- detail
- Source formatting agrees
- check
- Lint
- status
- passed
- detail
- No selected lint errors
- check
- Type checking
- status
- passed
- detail
- No reported type mismatches
- check
- Tests
- status
- failed
- detail
- A reading equal to 25 C was not counted
check status detail Formatting passed Source formatting agrees Lint passed No selected lint errors Type checking passed No reported type mismatches Tests failed A reading equal to 25 C was not counted 2. Read a field from every record
- 0passed
- 1passed
- 2passed
- 3failed
3. Match a text value
- 0true
- 1true
- 2true
- 3false
4. Reverse the keep decisions
- 0false
- 1false
- 2false
- 3true
5. Keep flagged entries
- check
- Tests
- status
- failed
- detail
- A reading equal to 25 C was not counted
check status detail Tests failed A reading equal to 25 C was not counted 6. Result
- check
- Tests
- status
- failed
- detail
- A reading equal to 25 C was not counted
check status detail Tests failed A reading equal to 25 C was not counted
These are supplied check results, not executions of a formatter, linter or type checker. The table is assumed to include every required check for the same code revision.
1. Distinguish format from behavior
A formatter makes configured layout choices consistently, including spacing and line wrapping. It reduces routine formatting debate, but does not decide whether a formula matches the requirement. A formatting pass can preserve an incorrect program perfectly.
A linter inspects selected code patterns, such as an unused import or undefined name. Configure rules for the project rather than enabling every available convention without reviewing its effects. Tool success should not be renamed complete correctness.
2. Follow types without executing the application
A static checker uses annotations and inference to inspect operations and interfaces. It can identify incompatible arguments or a path that may return None where a number is expected. Its evidence depends on available type information, including untyped dependencies and Any.
It does not validate a received JSON document at runtime. Keep the boundary checks introduced earlier even when internal interfaces are annotated.
Annotations do not perform validation
Both arguments are strings, so ordinary concatenation succeeds despite the annotations.
def combine(left: int, right: int) -> int:
return left + right
print(combine("12", "3"))123A configured static checker should flag these argument types. Python execution alone does not enforce the annotations.
Check yourself
Questions on Parts 1 and 2
Question 1 of 2
What has its pass established?
Question data
A formatter accepts an incorrect threshold comparison.3. Run repeatable project commands
Expose a documented set of development commands and run the same checks locally and in continuous integration, meaning automated checks triggered by a proposed change. Use the project's recorded tool versions and environment.
Ruff provides linting and formatting. A type checker such as mypy examines declared interfaces. pytest or unittest runs behavior checks. Configure their scope and review automatic fixes rather than accepting every edit unexamined.
Run in your own environment
Local checks with separate outcomes
Run these commands from your own project root with its development environment active. They are not browser installations.
Install the selected tools through the project's recorded development dependency workflow.
Configure Ruff and mypy for the supported Python version and checked paths.
Use src only if the project has that layout; otherwise supply its actual importable package path.
python -m ruff format --check .
python -m ruff check .
python -m mypy src
python -m pytestEach command has its own result. A skipped command provides no successful evidence.
Ruff documentation. Documentation checked .
4. Keep missing evidence distinct from a pass
A release gate should require every mandatory check to have run and passed. A missing job, skipped command or stale result is not a new success. Associate recorded evidence with the source revision under review.
Inspect a failure before changing code to silence it. Removing assertions or replacing useful types with Any can hide the original problem. A justified narrow suppression should explain the actual reason and retain the relevant behavior check.
Check execution and success separately
The test job did not run, even though its stale passed field is true.
statuses = [
{"name":"format", "ran":True, "passed":True},
{"name":"tests", "ran":False, "passed":True},
]
ready = bool(statuses) and all(
item["ran"] is True and item["passed"] is True for item in statuses
)
print(ready)FalseThis gate lacks passing evidence from every required check. It does not diagnose the code repair.
Check yourself
Questions on Parts 1 to 4
Question 1 of 4
How should a release gate treat it?
Question data
A mandatory test job did not run.Try it with Botie
Build with Botie
Write and run Python