Skip to content

fix(pkg-py): resolve circular import on import shinychat#212

Merged
cpsievert merged 2 commits intomainfrom
fix/circular-import
May 8, 2026
Merged

fix(pkg-py): resolve circular import on import shinychat#212
cpsievert merged 2 commits intomainfrom
fix/circular-import

Conversation

@cpsievert
Copy link
Copy Markdown
Collaborator

Closes #207

Summary

  • import shinychat failed with a circular import when shiny was installed, because _chat_bookmark.py imported shiny.types.Jsonifiable at module level — triggering shiny.__init__shiny.ui._chatfrom shinychat import Chat before shinychat finished initializing.
  • Deferred the shiny.types.Jsonifiable import to TYPE_CHECKING (it's only used in annotations) and added from __future__ import annotations to _chat_bookmark.py.
  • Added a subprocess-based test that catches circular imports in a clean interpreter.

Test plan

  • python -c "import shinychat" succeeds
  • uv run pyright passes (0 errors)
  • uv run pytest pkg-py/tests/pytest/test_import.py passes

… shiny's init (#207)

The import chain `shinychat` → `_chat_bookmark` → `shiny.types` → `shiny.__init__`
→ `shiny.ui._chat` → `shinychat` caused a circular import error because `shinychat`
was still initializing. Defer the `shiny.types.Jsonifiable` import to `TYPE_CHECKING`
since it's only used in annotations.

This comment was marked as resolved.

@cpsievert cpsievert merged commit a252b47 into main May 8, 2026
5 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.

import shinychat fails due to circular imports

2 participants