Skip to content

Commit fe41ab1

Browse files
committed
add test for non-json serializable attrs
1 parent f9ab950 commit fe41ab1

File tree

4 files changed

+14
-9
lines changed

4 files changed

+14
-9
lines changed

src/py/reactpy/reactpy/backend/_common.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ def vdom_head_elements_to_html(head: Sequence[VdomDict] | VdomDict | str) -> str
114114
head = cast(VdomDict, {**head, "tagName": ""})
115115
return vdom_to_html(head)
116116
else:
117-
return vdom_to_html(html._(head))
117+
return vdom_to_html(html._(*head))
118118

119119

120120
@dataclass

src/py/reactpy/reactpy/core/serve.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ async def _single_outgoing_loop(
5757
if not REACTPY_DEBUG_MODE.current:
5858
msg = (
5959
"Failed to send update. More info may be available "
60-
"if you enabling debug mode by settings "
60+
"if you enabling debug mode by setting "
6161
"`reactpy.config.REACTPY_DEBUG_MODE.current = True`."
6262
)
6363
logger.error(msg)

src/py/reactpy/reactpy/core/vdom.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
from __future__ import annotations
22

33
import json
4-
import logging
54
from collections.abc import Mapping, Sequence
65
from functools import wraps
76
from typing import Any, Protocol, cast, overload
@@ -26,9 +25,6 @@
2625
VdomJson,
2726
)
2827

29-
logger = logging.getLogger()
30-
31-
3228
VDOM_JSON_SCHEMA = {
3329
"$schema": "http://json-schema.org/draft-07/schema",
3430
"$ref": "#/definitions/element",
@@ -328,18 +324,18 @@ def _is_single_child(value: Any) -> bool:
328324

329325
def _validate_child_key_integrity(value: Any) -> None:
330326
if hasattr(value, "__iter__") and not hasattr(value, "__len__"):
331-
logger.error(
327+
warn(
332328
f"Did not verify key-path integrity of children in generator {value} "
333329
"- pass a sequence (i.e. list of finite length) in order to verify"
334330
)
335331
else:
336332
for child in value:
337333
if isinstance(child, ComponentType) and child.key is None:
338-
logger.error(f"Key not specified for child in list {child}")
334+
warn(f"Key not specified for child in list {child}")
339335
elif isinstance(child, Mapping) and "key" not in child:
340336
# remove 'children' to reduce log spam
341337
child_copy = {**child, "children": _EllipsisRepr()}
342-
logger.error(f"Key not specified for child in list {child_copy}")
338+
warn(f"Key not specified for child in list {child_copy}")
343339

344340

345341
class _CustomVdomDictConstructor(Protocol):

src/py/reactpy/tests/test_core/test_hooks.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1257,3 +1257,12 @@ def bad_effect():
12571257
await layout.render()
12581258
component_hook.latest.schedule_render()
12591259
await layout.render() # no error
1260+
1261+
1262+
@pytest.mark.skipif(
1263+
not REACTPY_DEBUG_MODE.current,
1264+
reason="only check json serialization in debug mode",
1265+
)
1266+
def test_raise_for_non_json_attrs():
1267+
with pytest.raises(TypeError, match="JSON serializable"):
1268+
reactpy.html.div({"non_json_serializable_object": object()})

0 commit comments

Comments
 (0)