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
Open
prevent assert usage in non-test code — add codemod, CI check, and contributing guidance#279Satyasubhash01 wants to merge 1 commit intoaboutcode-org:mainfrom
Satyasubhash01 wants to merge 1 commit intoaboutcode-org:mainfrom
Conversation
… workflow, and contributing guidance
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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