Replace remaining runtime asserts with explicit exceptions - #332
Merged
Conversation
assert statements are stripped under python -O, silently changing behavior. Replace the last two library-runtime asserts with explicit exceptions: NotebookPage.copy_to now raises ValueError when an entry's content is None (still caught and reported as a per-entry warning, same as before), and Attachment.from_file now raises TypeError for a bytes-fspath PathLike input instead of asserting it away.
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.
Fixes #81
Summary
Replaces the last two library-runtime
assertstatements (stripped underpython -O, which would silently change behavior) with explicit exceptions:src/labapi/tree/page.pyNotebookPage.copy_to:assert entry_content is not None->raise ValueError(...)with a clear message. Still caught by the existing broadexcept Exceptionincopy_toand reported as a per-entryRuntimeWarning, so behavior for callers is unchanged — it now just doesn't rely on assertions being enabled.src/labapi/entry/attachment.pyAttachment.from_file:assert not isinstance(file, PathLike)->raise TypeError(...)explaining that a bytes-fspathPathLikeisn't accepted (str-fspathPathLikeobjects are already handled earlier in the function viais_strpathlike).Test plan
uv run pytest --ignore=tests/test_integration.py -q(433 passed)uv run ruff check .test_copy_to_warns_and_continues_when_entry_content_is_noneandtest_attachment_from_file_rejects_bytes_pathlike.