Skip to content

Commit 8c6b238

Browse files
committed
correct more tests
1 parent 93a56b2 commit 8c6b238

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

src/idom/widgets.py

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

33
from base64 import b64encode
4-
from typing import Any, Callable, Dict, List, Optional, Sequence, Tuple, TypeVar, Union
4+
from typing import Any, Callable, Iterable, Tuple, TypeVar, Union
55

66
from typing_extensions import Protocol
77

@@ -16,7 +16,7 @@
1616
def image(
1717
format: str,
1818
value: Union[str, bytes] = "",
19-
attributes: Optional[Dict[str, Any]] = None,
19+
**attributes: Any,
2020
) -> VdomDict:
2121
"""Utility for constructing an image from a string or bytes
2222
@@ -33,19 +33,19 @@ def image(
3333
base64_value = b64encode(bytes_value).decode()
3434
src = f"data:image/{format};base64,{base64_value}"
3535

36-
return {"tagName": "img", "attributes": {"src": src, **(attributes or {})}}
36+
return {"tagName": "img", "attributes": {"src": src, **attributes}}
3737

3838

3939
_Value = TypeVar("_Value")
4040

4141

4242
def use_linked_inputs(
43-
attributes: Sequence[Dict[str, Any]],
43+
attributes: Iterable[dict[str, Any]],
4444
on_change: Callable[[_Value], None] = lambda value: None,
4545
cast: _CastFunc[_Value] = lambda value: value,
4646
initial_value: str = "",
4747
ignore_empty: bool = True,
48-
) -> List[VdomDict]:
48+
) -> list[VdomDict]:
4949
"""Return a list of linked inputs equal to the number of given attributes.
5050
5151
Parameters:
@@ -67,7 +67,7 @@ def use_linked_inputs(
6767
"""
6868
value, set_value = idom.hooks.use_state(initial_value)
6969

70-
def sync_inputs(event: Dict[str, Any]) -> None:
70+
def sync_inputs(event: dict[str, Any]) -> None:
7171
new_value = event["target"]["value"]
7272
set_value(new_value)
7373
if not new_value and ignore_empty:
@@ -82,7 +82,7 @@ def sync_inputs(event: Dict[str, Any]) -> None:
8282
key = attrs.pop("key", None)
8383
attrs.update({"onChange": sync_inputs, "value": value})
8484

85-
inputs.append(html.input(attrs, key=key))
85+
inputs.append(html.input(key=key, **attrs))
8686

8787
return inputs
8888

tests/test_widgets.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@
1919

2020
async def test_image_from_string(display: DisplayFixture):
2121
src = IMAGE_SRC_BYTES.decode()
22-
await display.show(lambda: idom.widgets.image("svg", src, {"id": "a-circle-1"}))
22+
await display.show(lambda: idom.widgets.image("svg", src, id="a-circle-1"))
2323
client_img = await display.page.wait_for_selector("#a-circle-1")
2424
assert BASE64_IMAGE_SRC in (await client_img.get_attribute("src"))
2525

2626

2727
async def test_image_from_bytes(display: DisplayFixture):
2828
src = IMAGE_SRC_BYTES
29-
await display.show(lambda: idom.widgets.image("svg", src, {"id": "a-circle-1"}))
29+
await display.show(lambda: idom.widgets.image("svg", src, id="a-circle-1"))
3030
client_img = await display.page.wait_for_selector("#a-circle-1")
3131
assert BASE64_IMAGE_SRC in (await client_img.get_attribute("src"))
3232

0 commit comments

Comments
 (0)