Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 15 additions & 13 deletions dash/dependencies.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from enum import Enum
from typing import Union, Sequence, Any

from .development.base_component import Component
Expand All @@ -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):
Expand Down Expand Up @@ -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
Expand All @@ -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

Expand Down
9 changes: 1 addition & 8 deletions dash/development/_py_components_generation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 3 additions & 6 deletions dash/development/base_component.py
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Comment on lines +457 to +461
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This type is also duplicated on generate components for backward compatibility. The template is here:

ComponentType = typing.Union[
str,
int,
float,
Component,
None,
typing.Sequence[typing.Union[str, int, float, Component, None]],
]

]

ComponentTemplate = typing.TypeVar("ComponentTemplate")
Expand Down