Skip to content

Commit 0241cc8

Browse files
committed
Fix up typing
- Don't allow `GeneratorType` as a type for children - Now `children` is a more specific type
1 parent c6b048c commit 0241cc8

36 files changed

Lines changed: 135 additions & 108 deletions

plugins/ui/src/deephaven/ui/components/action_button.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@
2121
)
2222

2323
from .basic import component_element
24-
from ..elements import Element
24+
from ..elements import Element, NodeType
2525

2626
ActionButtonElement = Element
2727

2828

2929
def action_button(
30-
*children: Any,
30+
*children: NodeType,
3131
type: ButtonType = "button",
3232
on_press: PressEventCallable | None = None,
3333
on_press_start: PressEventCallable | None = None,

plugins/ui/src/deephaven/ui/components/action_group.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@
1717
Position,
1818
)
1919
from .basic import component_element
20-
from ..elements import Element
20+
from ..elements import Element, NodeType
2121
from ..types import ActionGroupDensity, SelectedKeys, SelectionMode, Key, Selection
2222

2323

2424
def action_group(
25-
*children: Any,
25+
*children: NodeType,
2626
is_emphasized: bool | None = None,
2727
density: ActionGroupDensity | None = "regular",
2828
is_justified: bool | None = None,

plugins/ui/src/deephaven/ui/components/badge.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@
1010
Position,
1111
)
1212
from .basic import component_element
13-
from ..elements import Element
13+
from ..elements import Element, NodeType
1414
from ..types import BadgeVariant
1515

1616

1717
def badge(
18-
*children: Any,
18+
*children: NodeType,
1919
variant: BadgeVariant | None = None,
2020
flex: LayoutFlex | None = None,
2121
flex_grow: float | None = None,
Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,35 @@
11
from __future__ import annotations
22
from typing import Any
3-
from ..elements import BaseElement
3+
from ..elements import BaseElement, NodeType
4+
from ..types import Key
45

56
NAME_PREFIX = "deephaven.ui.components."
67

78

8-
def component_element(name: str, /, *children: Any, **props: Any) -> BaseElement:
9+
def component_element(
10+
name: str,
11+
/,
12+
*children: NodeType,
13+
key: Key | None = None,
14+
_nullable_props: list[str] = [],
15+
**props: Any,
16+
) -> BaseElement:
917
"""
1018
Base class for UI elements.
1119
All names are automatically prefixed with "deephaven.ui.components.", and
1220
all props are automatically camelCased.
21+
22+
Args:
23+
name: The name of the element, e.g. "button", "input", "my_component", etc. The full name of the element will be "deephaven.ui.components.{name}".
24+
children: The children of the element.
25+
key: The key for the element.
26+
_nullable_props: A list of prop names that can be set to None.
27+
props: The props for the element.
1328
"""
14-
return BaseElement(f"{NAME_PREFIX}{name}", *children, **props)
29+
return BaseElement(
30+
f"{NAME_PREFIX}{name}",
31+
*children,
32+
key=key,
33+
_nullable_props=_nullable_props,
34+
**props,
35+
)

plugins/ui/src/deephaven/ui/components/button.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@
2222
Position,
2323
)
2424
from .basic import component_element
25-
from ..elements import Element
25+
from ..elements import Element, NodeType
2626

2727

2828
def button(
29-
*children: Any,
29+
*children: NodeType,
3030
variant: ButtonVariant | None = "accent",
3131
style: ButtonStyle | None = "fill",
3232
static_color: StaticColor | None = None,

plugins/ui/src/deephaven/ui/components/button_group.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@
1313
Position,
1414
)
1515
from .basic import component_element
16-
from ..elements import Element
16+
from ..elements import Element, NodeType
1717

1818
BUTTON_GROUP_NAME = "ButtonGroup"
1919

2020

2121
def button_group(
22-
*children: Any,
22+
*children: NodeType,
2323
is_disabled: bool | None = None,
2424
orientation: Orientation = "horizontal",
2525
align: ButtonGroupAlignment = "start",

plugins/ui/src/deephaven/ui/components/checkbox.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@
1414
Position,
1515
)
1616
from .basic import component_element
17-
from ..elements import Element
17+
from ..elements import Element, NodeType
1818

1919

2020
def checkbox(
21-
*children: Any,
21+
*children: NodeType,
2222
is_emphasized: bool | None = None,
2323
is_indeterminate: bool | None = None,
2424
default_selected: bool | None = None,

plugins/ui/src/deephaven/ui/components/checkbox_group.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@
1616
LabelPosition,
1717
)
1818
from .basic import component_element
19-
from ..elements import Element
19+
from ..elements import Element, NodeType
2020
from ..types import Key, Selection
2121

2222

2323
def checkbox_group(
24-
*children: Any,
24+
*children: NodeType,
2525
orientation: Orientation = "vertical",
2626
is_emphasized: bool | None = None,
2727
value: Selection | None = None,

plugins/ui/src/deephaven/ui/components/color_picker.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
from typing import Any, Callable
33

44
from .basic import component_element
5-
from ..elements import Element
5+
from ..elements import Element, NodeType
66
from ..types import CSSColor
77

88

99
def color_picker(
10-
*children: Any,
10+
*children: NodeType,
1111
label: Any = None,
1212
size: str = "M",
1313
rounding: str = "default",

plugins/ui/src/deephaven/ui/components/column.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

33
from typing import Any
44
from .basic import component_element
5-
from ..elements import Element
5+
from ..elements import Element, NodeType
66

77

88
def column(
9-
*children: Any, width: float | None = None, key: str | None = None
9+
*children: NodeType, width: float | None = None, key: str | None = None
1010
) -> Element:
1111
"""
1212
A column is a container that can be used to group elements.

0 commit comments

Comments
 (0)