Skip to content

Replace remaining runtime asserts with explicit exceptions - #332

Merged
Flerpharos merged 1 commit into
mainfrom
fix/81-remaining-asserts
Sep 11, 2026
Merged

Replace remaining runtime asserts with explicit exceptions#332
Flerpharos merged 1 commit into
mainfrom
fix/81-remaining-asserts

Conversation

@Flerpharos

Copy link
Copy Markdown
Collaborator

Fixes #81

Summary

Replaces the last two library-runtime assert statements (stripped under python -O, which would silently change behavior) with explicit exceptions:

  • src/labapi/tree/page.py NotebookPage.copy_to: assert entry_content is not None -> raise ValueError(...) with a clear message. Still caught by the existing broad except Exception in copy_to and reported as a per-entry RuntimeWarning, so behavior for callers is unchanged — it now just doesn't rely on assertions being enabled.
  • src/labapi/entry/attachment.py Attachment.from_file: assert not isinstance(file, PathLike) -> raise TypeError(...) explaining that a bytes-fspath PathLike isn't accepted (str-fspath PathLike objects are already handled earlier in the function via is_strpathlike).

Test plan

  • uv run pytest --ignore=tests/test_integration.py -q (433 passed)
  • uv run ruff check .
  • New tests: test_copy_to_warns_and_continues_when_entry_content_is_none and test_attachment_from_file_rejects_bytes_pathlike.

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.
@Flerpharos
Flerpharos merged commit 13f1121 into main Sep 11, 2026
52 checks passed
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.

Replace runtime asserts in library code with explicit exceptions

1 participant