streambricks 0.2.12__tar.gz → 0.2.13__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {streambricks-0.2.12 → streambricks-0.2.13}/PKG-INFO +1 -1
- {streambricks-0.2.12 → streambricks-0.2.13}/src/streambricks/__init__.py +1 -1
- {streambricks-0.2.12 → streambricks-0.2.13}/src/streambricks/widgets/model_widget/main.py +38 -5
- {streambricks-0.2.12 → streambricks-0.2.13}/src/streambricks/widgets/type_helpers.py +8 -1
- {streambricks-0.2.12 → streambricks-0.2.13}/.copier-answers.yml +0 -0
- {streambricks-0.2.12 → streambricks-0.2.13}/.github/FUNDING.yml +0 -0
- {streambricks-0.2.12 → streambricks-0.2.13}/.github/copilot-instructions.md +0 -0
- {streambricks-0.2.12 → streambricks-0.2.13}/.github/dependabot.yml +0 -0
- {streambricks-0.2.12 → streambricks-0.2.13}/.github/workflows/build.yml +0 -0
- {streambricks-0.2.12 → streambricks-0.2.13}/.github/workflows/documentation.yml +0 -0
- {streambricks-0.2.12 → streambricks-0.2.13}/.gitignore +0 -0
- {streambricks-0.2.12 → streambricks-0.2.13}/.pre-commit-config.yaml +0 -0
- {streambricks-0.2.12 → streambricks-0.2.13}/LICENSE +0 -0
- {streambricks-0.2.12 → streambricks-0.2.13}/README.md +0 -0
- {streambricks-0.2.12 → streambricks-0.2.13}/docs/.empty +0 -0
- {streambricks-0.2.12 → streambricks-0.2.13}/duties.py +0 -0
- {streambricks-0.2.12 → streambricks-0.2.13}/mkdocs.yml +0 -0
- {streambricks-0.2.12 → streambricks-0.2.13}/overrides/_dummy.txt +0 -0
- {streambricks-0.2.12 → streambricks-0.2.13}/pyproject.toml +0 -0
- {streambricks-0.2.12 → streambricks-0.2.13}/src/streambricks/helpers.py +0 -0
- {streambricks-0.2.12 → streambricks-0.2.13}/src/streambricks/py.typed +0 -0
- {streambricks-0.2.12 → streambricks-0.2.13}/src/streambricks/state.py +0 -0
- {streambricks-0.2.12 → streambricks-0.2.13}/src/streambricks/widgets/__init__.py +0 -0
- {streambricks-0.2.12 → streambricks-0.2.13}/src/streambricks/widgets/bind_kwargs.py +0 -0
- {streambricks-0.2.12 → streambricks-0.2.13}/src/streambricks/widgets/model_selector.py +0 -0
- {streambricks-0.2.12 → streambricks-0.2.13}/src/streambricks/widgets/model_widget/__init__.py +0 -0
- {streambricks-0.2.12 → streambricks-0.2.13}/src/streambricks/widgets/model_widget/field_metadata_renderers.py +0 -0
- {streambricks-0.2.12 → streambricks-0.2.13}/src/streambricks/widgets/model_widget/type_renderers.py +0 -0
- {streambricks-0.2.12 → streambricks-0.2.13}/src/streambricks/widgets/multi_select.py +0 -0
- {streambricks-0.2.12 → streambricks-0.2.13}/tests/__init__.py +0 -0
- {streambricks-0.2.12 → streambricks-0.2.13}/tests/conftest.py +0 -0
- {streambricks-0.2.12 → streambricks-0.2.13}/tests/test_widgets.py +0 -0
|
@@ -38,6 +38,7 @@ from streambricks.widgets.type_helpers import (
|
|
|
38
38
|
is_sequence_type,
|
|
39
39
|
is_set_type,
|
|
40
40
|
is_union_type,
|
|
41
|
+
unpack_annotated,
|
|
41
42
|
)
|
|
42
43
|
|
|
43
44
|
|
|
@@ -465,7 +466,7 @@ def render_model_instance_field(
|
|
|
465
466
|
value: Any = None,
|
|
466
467
|
label: str | None = None,
|
|
467
468
|
disabled: bool = False,
|
|
468
|
-
help: str | None = None, # noqa: A002
|
|
469
|
+
help: str | None = None, # noqa: A002
|
|
469
470
|
**field_info: Any,
|
|
470
471
|
) -> Any:
|
|
471
472
|
"""Render a nested model instance field."""
|
|
@@ -474,8 +475,32 @@ def render_model_instance_field(
|
|
|
474
475
|
error_msg = f"Model class not provided for field {key}"
|
|
475
476
|
raise ValueError(error_msg)
|
|
476
477
|
|
|
477
|
-
#
|
|
478
|
-
if
|
|
478
|
+
# Handle Union types (including Python 3.10+ pipe syntax)
|
|
479
|
+
if is_union_type(model_class) or hasattr(model_class, "__or__"):
|
|
480
|
+
model_type_name = getattr(
|
|
481
|
+
model_class,
|
|
482
|
+
"__name__",
|
|
483
|
+
"Union[" + ", ".join(str(t) for t in get_args(model_class)) + "]",
|
|
484
|
+
)
|
|
485
|
+
|
|
486
|
+
# Initialize value if none
|
|
487
|
+
if value is None:
|
|
488
|
+
# For Union types, try to create an instance of the first model type
|
|
489
|
+
possible_types = get_args(model_class)
|
|
490
|
+
for possible_type in possible_types:
|
|
491
|
+
if is_dataclass_like(possible_type):
|
|
492
|
+
try:
|
|
493
|
+
value = try_create_default_instance(possible_type)
|
|
494
|
+
if value is not None:
|
|
495
|
+
break
|
|
496
|
+
except Exception: # noqa: BLE001
|
|
497
|
+
continue
|
|
498
|
+
|
|
499
|
+
if value is None:
|
|
500
|
+
st.error(f"Could not create instance of any type in {model_type_name}")
|
|
501
|
+
return None
|
|
502
|
+
# Initialize value if none for non-union types
|
|
503
|
+
elif value is None:
|
|
479
504
|
value = try_create_default_instance(model_class)
|
|
480
505
|
if value is None: # If creation failed
|
|
481
506
|
try:
|
|
@@ -492,7 +517,9 @@ def render_model_instance_field(
|
|
|
492
517
|
with st.expander("Edit", expanded=True):
|
|
493
518
|
updated_value = {}
|
|
494
519
|
try:
|
|
495
|
-
|
|
520
|
+
# Use the actual class of the value instance, not the field type
|
|
521
|
+
actual_class = value.__class__
|
|
522
|
+
for field in fieldz.fields(actual_class):
|
|
496
523
|
field_name = field.name
|
|
497
524
|
field_value = get_with_default(value, field_name, field)
|
|
498
525
|
field_help = get_description(field)
|
|
@@ -519,6 +546,10 @@ def render_model_instance_field(
|
|
|
519
546
|
def get_field_renderer(field_info: dict[str, Any]) -> WidgetFunc[Any]: # noqa: PLR0911
|
|
520
547
|
"""Get the appropriate renderer for a field based on its type and constraints."""
|
|
521
548
|
annotation = field_info.get("type") or field_info.get("annotation")
|
|
549
|
+
if (ann := unpack_annotated(annotation)) != annotation:
|
|
550
|
+
annotation = ann
|
|
551
|
+
field_info["type"] = annotation
|
|
552
|
+
|
|
522
553
|
json_schema_extra = field_info.get("json_schema_extra", {})
|
|
523
554
|
if (
|
|
524
555
|
json_schema_extra
|
|
@@ -690,7 +721,9 @@ def render_model_field(model_class, field_name, value=None, container=st):
|
|
|
690
721
|
raise ValueError(error_msg)
|
|
691
722
|
field_info = {"name": field.name, "type": field.type, "default": field.default}
|
|
692
723
|
if hasattr(field.native_field, "json_schema_extra"):
|
|
693
|
-
|
|
724
|
+
dct = field.native_field.json_schema_extra or {} # type: ignore
|
|
725
|
+
field_info.update(dct)
|
|
726
|
+
field_info["json_schema_extra"] = dct
|
|
694
727
|
label = field_name.replace("_", " ").title()
|
|
695
728
|
help_text = get_description(field)
|
|
696
729
|
if help_text:
|
|
@@ -3,11 +3,18 @@
|
|
|
3
3
|
from __future__ import annotations
|
|
4
4
|
|
|
5
5
|
from collections.abc import Sequence
|
|
6
|
-
from typing import Any, Literal, get_args, get_origin
|
|
6
|
+
from typing import Annotated, Any, Literal, get_args, get_origin
|
|
7
7
|
|
|
8
8
|
import fieldz
|
|
9
9
|
|
|
10
10
|
|
|
11
|
+
def unpack_annotated(annotation: Any) -> Any:
|
|
12
|
+
"""Unpack an Annotated type annotation to its base type."""
|
|
13
|
+
if get_origin(annotation) is Annotated and (args := get_args(annotation)):
|
|
14
|
+
return args[0]
|
|
15
|
+
return annotation
|
|
16
|
+
|
|
17
|
+
|
|
11
18
|
def is_literal_type(annotation: Any) -> bool:
|
|
12
19
|
"""Check if a type annotation is a Literal type."""
|
|
13
20
|
# Check directly against the origin or special attribute
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{streambricks-0.2.12 → streambricks-0.2.13}/src/streambricks/widgets/model_widget/__init__.py
RENAMED
|
File without changes
|
|
File without changes
|
{streambricks-0.2.12 → streambricks-0.2.13}/src/streambricks/widgets/model_widget/type_renderers.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|