1+ from enum import Enum
12from typing import Union , Sequence , Any
23
34from .development .base_component import Component
910ComponentIdType = Union [str , Component , dict ]
1011
1112
12- class _Wildcard : # pylint: disable=too-few-public-methods
13- def __init__ (self , name : str ):
14- self ._name = name
13+ class Wildcard (Enum ):
14+ MATCH = "MATCH"
15+ ALL = "ALL"
16+ ALLSMALLER = "ALLSMALLER"
1517
1618 def __str__ (self ):
17- return self ._name
19+ return self .value
1820
1921 def __repr__ (self ):
20- return f"<{ self } >"
22+ return f"<{ self . value } >"
2123
2224 def to_json (self ) -> str :
2325 # used in serializing wildcards - arrays are not allowed as
2426 # id values, so make the wildcards look like length-1 arrays.
25- return f'["{ self ._name } "]'
27+ return f'["{ self .value } "]'
2628
2729
28- MATCH = _Wildcard ( " MATCH" )
29- ALL = _Wildcard ( " ALL" )
30- ALLSMALLER = _Wildcard ( " ALLSMALLER" )
30+ MATCH = Wildcard . MATCH
31+ ALL = Wildcard . ALL
32+ ALLSMALLER = Wildcard . ALLSMALLER
3133
3234
3335class DashDependency : # pylint: disable=too-few-public-methods
3436 component_id : ComponentIdType
3537 allow_duplicate : bool
3638 component_property : str
37- allowed_wildcards : Sequence [_Wildcard ]
39+ allowed_wildcards : Sequence [Wildcard ]
3840 allow_optional : bool
3941
4042 def __init__ (self , component_id : ComponentIdType , component_property : str ):
@@ -95,8 +97,8 @@ def _id_matches(self, other) -> bool:
9597 other_v = other_id [k ]
9698 if v == other_v :
9799 continue
98- v_wild = isinstance (v , _Wildcard )
99- other_wild = isinstance (other_v , _Wildcard )
100+ v_wild = isinstance (v , Wildcard )
101+ other_wild = isinstance (other_v , Wildcard )
100102 if v_wild or other_wild :
101103 if not (v_wild and other_wild ):
102104 continue # one wild, one not
@@ -120,7 +122,7 @@ def has_wildcard(self) -> bool:
120122 """
121123 if isinstance (self .component_id , dict ):
122124 for v in self .component_id .values ():
123- if isinstance (v , _Wildcard ):
125+ if isinstance (v , Wildcard ):
124126 return True
125127 return False
126128
0 commit comments