fix: replace assert with proper exception in python_build_standalone#2859
Open
henryiii wants to merge 1 commit into
Open
fix: replace assert with proper exception in python_build_standalone#2859henryiii wants to merge 1 commit into
henryiii wants to merge 1 commit into
Conversation
Assert statements are skipped under python -O, making them unsuitable for runtime validation. Replace assert with an explicit check that raises PythonBuildStandaloneError if the target directory already exists. Assisted-by: OpenCode:glm-5
agriyakhetarpal
approved these changes
May 16, 2026
Member
agriyakhetarpal
left a comment
There was a problem hiding this comment.
Thanks! I think it might be a good idea to add S101: https://docs.astral.sh/ruff/rules/assert/
joerick
approved these changes
May 16, 2026
Contributor
|
I'd be opposed to S101 - asserts are mighty useful to check for programmer mistakes, and handy to tell the type system something that you as a programmer know to be true. |
Member
|
@joerick oh, the idea would be to add S101 for the source directories only – not the test directories, because we need assert statements there. Like this: |
Contributor
Author
|
Assert is used to narrow type checkers. The AI was able to detect a usage that was not for type checking, but the general ruff check can't do that. |
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.
See #2854.
🤖 Human triggered, AI assisted PR (using this skill). AI text below. 🤖
Summary
Replaces
assert not python_base_dir.exists()incibuildwheel/util/python_build_standalone.py:178with an explicit check that raisesPythonBuildStandaloneError. Assert statements are skipped underpython -O, making them unsuitable for runtime validation.Identified in #2854 ("Uses assert for runtime validation — It is skipped with
python -O").Assisted-by: OpenCode:glm-5