yodacheck
AST-based linter that detects and auto-fixes Yoda conditions in Python source files.
A Yoda condition is a comparison where the literal is on the left side:
# Yoda — flagged
if 5 == x: ...
if None == obj: ...
if True == flag: ...
# Normal — not flagged
if x == 5: ...
if obj is None: ...
if flag is True: ...
Features
- Detects all Yoda patterns (
==,!=,<,<=,>,>=,is,is not) - Smart fixes:
None ==→is None,True/False ==→is True/False, all else → swap - Auto-fix with timestamped
.bakbackup before writing - Chained comparisons (
1 < x < 3) flagged but not auto-fixed (ambiguous) in/not inwith literal on left intentionally ignored (normal membership syntax)- Output formats:
pretty(default),plain,json - Color auto-detected (TTY), forced via
--color/--no-color - Default excludes:
.venv,__pycache__,.git,build,dist
Installation
pip install yodacheck
After install the yodacheck command is available globally.
Or install from source:
git clone https://github.com/SytxLabs/yodacheck.git
cd yodacheck
pip install .
Usage
# Scan file or directory
yodacheck path/to/file.py
yodacheck src/
# Multiple paths
yodacheck src/ tests/ setup.py
# Show N context lines per issue
yodacheck src/ --context 1
# Auto-fix (creates .bak backup first)
yodacheck src/ --fix
# Exclude paths (glob or dir name, repeatable)
yodacheck . --exclude "migrations/*" --exclude vendor/
# Output format
yodacheck src/ --format plain
yodacheck src/ --format json
# Color
yodacheck src/ --color
yodacheck src/ --no-color
Output
3 issues · 1 file
src/auth.py
42:3 None == token → token is None [is None]
67:3 0 == status_code → status_code == 0
99:3 1 < retry_count < 5 ⚠ chained, no fix
With --context 1:
42:3 None == token → token is None [is None]
40 │
41 │ def validate(token):
42 │ if None == token:
^
43 │ raise ValueError
44 │
Fix behavior
--fix applies all fixable replacements in one pass per file. Chained comparisons are skipped.
yodacheck src/ --fix
# fixed src/auth.py (auth.py.bak.20260504T150000Z)
JSON output
yodacheck src/ --format json
[
{
"path": "src/auth.py",
"lineno": 42,
"col": 3,
"expr": "None == token",
"tag": "is None",
"replacement": "token is None",
"chained": false
}
]
tag values: "is None", "is not None", "bool", "" (plain swap), "" with chained: true.
Test file
examples/example.py — runnable collection of every detectable pattern:
yodacheck examples/example.py --color
yodacheck examples/example.py --color --context 1
Running tests
python -m unittest discover -s tests -v
Requirements
Python 3.8+. No external dependencies.
Metadata
Release files for yodacheck 0.1.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| yodacheck-0.1.2.tar.gz | 8.8 kB | With provenance | Details for yodacheck-0.1.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| yodacheck-0.1.2-py3-none-any.whl | Python 3 | none | any | Details for yodacheck-0.1.2-py3-none-any.whl |
Total release size: 16.5 kB
Release files / yodacheck-0.1.2.tar.gz
| Download URL | yodacheck-0.1.2.tar.gz |
|---|---|
| Size | 8.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
9a78af1eda40d8c580e84b6dc2d997385334a044639848c77bec6a1cbb935364
|
|
BLAKE2b-256 checksum How to use checksums |
4250788bd37814e8a30b088de42786a105c127c898aa2247d9b5f88f99b92fc1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on May 4, 2026.
Transparency logRelease files / yodacheck-0.1.2-py3-none-any.whl
| Download URL | yodacheck-0.1.2-py3-none-any.whl |
|---|---|
| Size | 7.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
908c430f50978a6b529ca461d2bcc11f3abe39e021b2478a8aad10416300f2be
|
|
BLAKE2b-256 checksum How to use checksums |
c3c8b3be5ad03916ae0a1636b89bf8dbcbeb9d4b05e18a4f91a723728e4be36e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on May 4, 2026.
Transparency logSecurity for yodacheck 0.1.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for yodacheck-0.1.2.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on May 4, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.