Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ class CodeBlock(Component, MarkdownComponentMap):

alias = "SyntaxHighlighter"

theme: Var[Theme | str] = field(
theme: Var[Theme] = field(
default=Theme.one_light, doc='The theme to use ("light" or "dark").'
)
Comment on lines +390 to 392
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2 Misleading docstring conflicts with new type restriction

The doc string 'The theme to use ("light" or "dark").' implies that plain string values like "light" or "dark" are acceptable, which directly contradicts the narrowed type Var[Theme] that now rejects strings at create time. A user following the docstring will hit a TypeError. Consider updating it to reflect the correct usage, e.g. 'The theme to use (e.g. Theme.one_light or Theme.one_dark).'

Suggested change
theme: Var[Theme] = field(
default=Theme.one_light, doc='The theme to use ("light" or "dark").'
)
theme: Var[Theme] = field(
default=Theme.one_light, doc="The theme to use (e.g. Theme.one_light or Theme.one_dark)."
)

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.

valid concern by greptile here


Expand Down
2 changes: 1 addition & 1 deletion pyi_hashes.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"packages/reflex-components-code/src/reflex_components_code/code.pyi": "a879ccd253e901964a7ab7ea7154f904",
"packages/reflex-components-code/src/reflex_components_code/code.pyi": "d3b9e3fe258afa06a1125aa81dc94983",
"packages/reflex-components-code/src/reflex_components_code/shiki_code_block.pyi": "d3e0c33fdc34f5c154ac387d550c0d29",
"packages/reflex-components-core/src/reflex_components_core/__init__.pyi": "82b29d23f2490161d42fd21021bd39c3",
"packages/reflex-components-core/src/reflex_components_core/base/__init__.pyi": "7009187aaaf191814d031e5462c48318",
Expand Down
5 changes: 5 additions & 0 deletions tests/units/components/datadisplay/test_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,8 @@ def test_code_light_dark_theme(theme, expected):
code_block = CodeBlock.create(theme=theme)

assert code_block.theme._js_expr == expected # pyright: ignore [reportAttributeAccessIssue]


def test_code_block_rejects_string_theme():
with pytest.raises(TypeError, match=r"CodeBlock\.theme"):
CodeBlock.create("print('Hello')", theme="one_dark") # pyright: ignore[reportArgumentType]
Loading