From e2c3733b7ce45fa08399b164add1d0977b0f5c07 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Pol=C3=A1=C4=8Dek?= Date: Fri, 12 Dec 2025 13:17:53 +0100 Subject: [PATCH 1/4] feat: expose ComponentSingleType --- dash/development/base_component.py | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/dash/development/base_component.py b/dash/development/base_component.py index 63ccc4ee20..02579ff2e2 100644 --- a/dash/development/base_component.py +++ b/dash/development/base_component.py @@ -454,14 +454,11 @@ def _validate_deprecation(self): warnings.warn(DeprecationWarning(textwrap.dedent(deprecation_message))) +ComponentSingleType = typing.Union[str, int, float, Component, None] # Renderable node type. ComponentType = typing.Union[ - str, - int, - float, - Component, - None, - typing.Sequence[typing.Union[str, int, float, Component, None]], + ComponentSingleType, + typing.Sequence[ComponentSingleType], ] ComponentTemplate = typing.TypeVar("ComponentTemplate") From 3020edc99d2296217eb300aeb8801645f7b5e12a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Pol=C3=A1=C4=8Dek?= Date: Fri, 12 Dec 2025 13:33:45 +0100 Subject: [PATCH 2/4] feat: expose Wildcard type --- dash/dependencies.py | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/dash/dependencies.py b/dash/dependencies.py index 0b5dbe6867..aa4c1aa1db 100644 --- a/dash/dependencies.py +++ b/dash/dependencies.py @@ -1,3 +1,4 @@ +from enum import Enum from typing import Union, Sequence, Any from .development.base_component import Component @@ -9,32 +10,33 @@ ComponentIdType = Union[str, Component, dict] -class _Wildcard: # pylint: disable=too-few-public-methods - def __init__(self, name: str): - self._name = name +class Wildcard(Enum): + MATCH = "MATCH" + ALL = "ALL" + ALLSMALLER = "ALLSMALLER" def __str__(self): - return self._name + return self.value def __repr__(self): - return f"<{self}>" + return f"<{self.value}>" def to_json(self) -> str: # used in serializing wildcards - arrays are not allowed as # id values, so make the wildcards look like length-1 arrays. - return f'["{self._name}"]' + return f'["{self.value}"]' -MATCH = _Wildcard("MATCH") -ALL = _Wildcard("ALL") -ALLSMALLER = _Wildcard("ALLSMALLER") +MATCH = Wildcard.MATCH +ALL = Wildcard.ALL +ALLSMALLER = Wildcard.ALLSMALLER class DashDependency: # pylint: disable=too-few-public-methods component_id: ComponentIdType allow_duplicate: bool component_property: str - allowed_wildcards: Sequence[_Wildcard] + allowed_wildcards: Sequence[Wildcard] allow_optional: bool def __init__(self, component_id: ComponentIdType, component_property: str): @@ -95,8 +97,8 @@ def _id_matches(self, other) -> bool: other_v = other_id[k] if v == other_v: continue - v_wild = isinstance(v, _Wildcard) - other_wild = isinstance(other_v, _Wildcard) + v_wild = isinstance(v, Wildcard) + other_wild = isinstance(other_v, Wildcard) if v_wild or other_wild: if not (v_wild and other_wild): continue # one wild, one not @@ -120,7 +122,7 @@ def has_wildcard(self) -> bool: """ if isinstance(self.component_id, dict): for v in self.component_id.values(): - if isinstance(v, _Wildcard): + if isinstance(v, Wildcard): return True return False From 46720fef966ce850772482169705e1be7825e548 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Pol=C3=A1=C4=8Dek?= Date: Fri, 12 Dec 2025 16:58:50 +0100 Subject: [PATCH 3/4] fix: also replace ComponentType in p components generation --- dash/development/_py_components_generation.py | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/dash/development/_py_components_generation.py b/dash/development/_py_components_generation.py index c6f3ae6c90..492864fb5f 100644 --- a/dash/development/_py_components_generation.py +++ b/dash/development/_py_components_generation.py @@ -24,15 +24,8 @@ import typing # noqa: F401 from typing_extensions import TypedDict, NotRequired, Literal # noqa: F401 from dash.development.base_component import Component, _explicitize_args +from dash.development.base_component import ComponentType # noqa: F401 {custom_imports} -ComponentType = typing.Union[ - str, - int, - float, - Component, - None, - typing.Sequence[typing.Union[str, int, float, Component, None]], -] NumberType = typing.Union[ typing.SupportsFloat, typing.SupportsInt, typing.SupportsComplex From 5090e51b19d32189e1ec41258bcf81669d6e1c4b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Pol=C3=A1=C4=8Dek?= Date: Tue, 16 Dec 2025 15:35:11 +0100 Subject: [PATCH 4/4] fix: preserve backward compatibility --- dash/development/_py_components_generation.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/dash/development/_py_components_generation.py b/dash/development/_py_components_generation.py index 492864fb5f..2d3bef1366 100644 --- a/dash/development/_py_components_generation.py +++ b/dash/development/_py_components_generation.py @@ -24,8 +24,12 @@ import typing # noqa: F401 from typing_extensions import TypedDict, NotRequired, Literal # noqa: F401 from dash.development.base_component import Component, _explicitize_args -from dash.development.base_component import ComponentType # noqa: F401 {custom_imports} +ComponentSingleType = typing.Union[str, int, float, Component, None] +ComponentType = typing.Union[ + ComponentSingleType, + typing.Sequence[ComponentSingleType], +] NumberType = typing.Union[ typing.SupportsFloat, typing.SupportsInt, typing.SupportsComplex