Visitar URL original
fix: replace assert with proper exception in python_build_standalone by henryiii · Pull Request #2859 · pypa/cibuildwheel · GitHub
Skip to content

fix: replace assert with proper exception in python_build_standalone - #2859

Merged
henryiii merged 1 commit into
pypa:mainfrom
henryiii:henryiii/fix/assert-runtime-validation
May 17, 2026
Merged

henryiii merged 1 commit into
pypa:mainfrom
henryiii:henryiii/fix/assert-runtime-validation

Conversation

@henryiii

@henryiii henryiii commented May 16, 2026 •

Copy link
Copy Markdown
Contributor

See #2854.

🤖 Human triggered, AI assisted PR (using this skill). AI text below. 🤖

Summary

Replaces assert not python_base_dir.exists() in cibuildwheel/util/python_build_standalone.py:178 with an explicit check that raises PythonBuildStandaloneError. Assert statements are skipped under python -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

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 agriyakhetarpal left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! I think it might be a good idea to add S101: https://docs.astral.sh/ruff/rules/assert/

@joerick

joerick commented May 16, 2026

Copy link
Copy Markdown
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.

@agriyakhetarpal

Copy link
Copy Markdown
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:

https://github.com/pybamm-team/PyBaMM/blob/9c8823baa1a8207ff35f2f4620a5caa3d9148d41/pyproject.toml#L189

https://github.com/pybamm-team/PyBaMM/blob/9c8823baa1a8207ff35f2f4620a5caa3d9148d41/pyproject.toml#L210-L211

@henryiii

Copy link
Copy Markdown
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.

@henryiii
henryiii merged commit 51b25dc into pypa:main May 17, 2026
45 checks passed
@henryiii
henryiii deleted the henryiii/fix/assert-runtime-validation branch May 17, 2026 18:26
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.

3 participants