1
+ from typing import Union , Sequence
2
+
1
3
from dash .development .base_component import Component
2
4
3
5
from ._validate import validate_callback
4
6
from ._grouping import flatten_grouping , make_grouping_by_index
5
7
from ._utils import stringify_id
6
8
7
9
10
+ ComponentIdType = Union [str , Component , dict ]
11
+
12
+
8
13
class _Wildcard : # pylint: disable=too-few-public-methods
9
- def __init__ (self , name ):
14
+ def __init__ (self , name : str ):
10
15
self ._name = name
11
16
12
17
def __str__ (self ):
@@ -15,7 +20,7 @@ def __str__(self):
15
20
def __repr__ (self ):
16
21
return f"<{ self } >"
17
22
18
- def to_json (self ):
23
+ def to_json (self ) -> str :
19
24
# used in serializing wildcards - arrays are not allowed as
20
25
# id values, so make the wildcards look like length-1 arrays.
21
26
return f'["{ self ._name } "]'
@@ -27,7 +32,12 @@ def to_json(self):
27
32
28
33
29
34
class DashDependency : # pylint: disable=too-few-public-methods
30
- def __init__ (self , component_id , component_property ):
35
+ component_id : ComponentIdType
36
+ allow_duplicate : bool
37
+ component_property : str
38
+ allowed_wildcards : Sequence [_Wildcard ]
39
+
40
+ def __init__ (self , component_id : ComponentIdType , component_property : str ):
31
41
32
42
if isinstance (component_id , Component ):
33
43
self .component_id = component_id ._set_random_id ()
@@ -43,10 +53,10 @@ def __str__(self):
43
53
def __repr__ (self ):
44
54
return f"<{ self .__class__ .__name__ } `{ self } `>"
45
55
46
- def component_id_str (self ):
56
+ def component_id_str (self ) -> str :
47
57
return stringify_id (self .component_id )
48
58
49
- def to_dict (self ):
59
+ def to_dict (self ) -> dict :
50
60
return {"id" : self .component_id_str (), "property" : self .component_property }
51
61
52
62
def __eq__ (self , other ):
@@ -61,7 +71,7 @@ def __eq__(self, other):
61
71
and self ._id_matches (other )
62
72
)
63
73
64
- def _id_matches (self , other ):
74
+ def _id_matches (self , other ) -> bool :
65
75
my_id = self .component_id
66
76
other_id = other .component_id
67
77
self_dict = isinstance (my_id , dict )
@@ -96,7 +106,7 @@ def _id_matches(self, other):
96
106
def __hash__ (self ):
97
107
return hash (str (self ))
98
108
99
- def has_wildcard (self ):
109
+ def has_wildcard (self ) -> bool :
100
110
"""
101
111
Return true if id contains a wildcard (MATCH, ALL, or ALLSMALLER)
102
112
"""
@@ -112,7 +122,12 @@ class Output(DashDependency): # pylint: disable=too-few-public-methods
112
122
113
123
allowed_wildcards = (MATCH , ALL )
114
124
115
- def __init__ (self , component_id , component_property , allow_duplicate = False ):
125
+ def __init__ (
126
+ self ,
127
+ component_id : ComponentIdType ,
128
+ component_property : str ,
129
+ allow_duplicate : bool = False ,
130
+ ):
116
131
super ().__init__ (component_id , component_property )
117
132
self .allow_duplicate = allow_duplicate
118
133
@@ -130,7 +145,7 @@ class State(DashDependency): # pylint: disable=too-few-public-methods
130
145
131
146
132
147
class ClientsideFunction : # pylint: disable=too-few-public-methods
133
- def __init__ (self , namespace = None , function_name = None ):
148
+ def __init__ (self , namespace : str , function_name : str ):
134
149
135
150
if namespace .startswith ("_dashprivate_" ):
136
151
raise ValueError ("Namespaces cannot start with '_dashprivate_'." )
0 commit comments