Skip to content

prevent assert usage in non-test code — add codemod, CI check, and contributing guidance#279

Open
Satyasubhash01 wants to merge 1 commit intoaboutcode-org:mainfrom
Satyasubhash01:fix/no-asserts
Open

prevent assert usage in non-test code — add codemod, CI check, and contributing guidance#279
Satyasubhash01 wants to merge 1 commit intoaboutcode-org:mainfrom
Satyasubhash01:fix/no-asserts

Conversation

@Satyasubhash01
Copy link

No production assert statements were found in the repository, so no runtime replacements were necessary. This PR adds tooling and documentation to prevent future use of assert in non-test code and provides a codemod for simple automated fixes.

Changes
Add: [check_no_asserts.py] — CI/check script to fail if assert appears in non-test files
Add: [replace_asserts.py] — codemod (dry-run / apply) for common assert patterns
Add: [check-no-asserts.yml] — CI job to run the assert check
Update: [CONTRIBUTING.md] — guidance: avoid assert for runtime checks; raise explicit exceptions instead

Notes: codemod dry-run found no matches; no source files were modified.

How to test locally
Run the assert check: python scripts/check_no_asserts.py
Dry-run the codemod: python tools/replace_asserts.py
(Optional) Apply codemod: python tools/replace_asserts.py --apply
Run tests and linters: python -m pytest
flake8 || true
Rationale
assert statements are removed with Python optimization flags (-O/-OO) and must not be used for runtime validation. Explicit checks that raise informative exceptions are required for library/production code.

Signed-off-by: Satyasubhash01

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant