1414# You should have received a copy of the GNU General Public License
1515# along with this program. If not, see <http://www.gnu.org/licenses/>.
1616
17- from typing import TYPE_CHECKING , Tuple
17+ from typing import (
18+ TYPE_CHECKING ,
19+ Optional ,
20+ Tuple ,
21+ )
1822
1923from cylc .flow .cycling .loader import (
2024 get_interval ,
@@ -38,21 +42,28 @@ class TaskTrigger:
3842 """Class representing an upstream dependency.
3943
4044 Args:
41- task_name (str) : The name of the upstream task.
42- cycle_point_offset (str) : String representing the offset of the
45+ task_name: The name of the upstream task.
46+ cycle_point_offset: String representing the offset of the
4347 upstream task (e.g. -P1D) if this dependency is not an absolute
4448 one. Else None.
45- output (str) : The task state / output for this trigger e.g. succeeded.
49+ output: The task state / output for this trigger e.g. succeeded.
4650
4751 """
4852
4953 __slots__ = ['task_name' , 'cycle_point_offset' , 'output' ,
5054 'offset_is_irregular' , 'offset_is_absolute' ,
5155 'offset_is_from_icp' , 'initial_point' ]
5256
53- def __init__ (self , task_name , cycle_point_offset , output ,
54- offset_is_irregular = False , offset_is_absolute = False ,
55- offset_is_from_icp = False , initial_point = None ):
57+ def __init__ (
58+ self ,
59+ task_name : str ,
60+ cycle_point_offset : Optional [str ],
61+ output : str ,
62+ offset_is_irregular : bool = False ,
63+ offset_is_absolute : bool = False ,
64+ offset_is_from_icp : bool = False ,
65+ initial_point : 'Optional[PointBase]' = None ,
66+ ):
5667 self .task_name = task_name
5768 self .cycle_point_offset = cycle_point_offset
5869 self .output = output
@@ -64,9 +75,10 @@ def __init__(self, task_name, cycle_point_offset, output,
6475 # 2000, 20000101T0600Z, 2000-01-01T06:00+00:00, ...
6576 # AND NON-ABSOLUTE IRREGULAR:
6677 # -PT6H+P1D, T00, ...
67- if (self .offset_is_irregular and any (
68- self .cycle_point_offset .startswith (c )
69- for c in ['P' , '+' , '-' , 'T' ])):
78+ if self .offset_is_irregular and any (
79+ self .cycle_point_offset .startswith (c ) # type: ignore[union-attr]
80+ for c in ['P' , '+' , '-' , 'T' ]
81+ ):
7082 self .offset_is_absolute = False
7183
7284 def get_parent_point (self , from_point ):
@@ -147,7 +159,28 @@ def __str__(self):
147159 else :
148160 return '%s:%s' % (self .task_name , self .output )
149161
150- __repr__ = __str__
162+ def __repr__ (self ) -> str :
163+ """
164+ >>> TaskTrigger('', '', '')
165+ <TaskTrigger ...>
166+ """
167+ return f"<{ type (self ).__name__ } { self } >"
168+
169+ def __hash__ (self ) -> int :
170+ return hash ((
171+ self .task_name ,
172+ self .cycle_point_offset ,
173+ self .output ,
174+ self .offset_is_irregular ,
175+ self .offset_is_from_icp ,
176+ self .offset_is_absolute ,
177+ self .initial_point ,
178+ ))
179+
180+ def __eq__ (self , other : object ) -> bool :
181+ if not isinstance (other , TaskTrigger ):
182+ return NotImplemented
183+ return hash (self ) == hash (other )
151184
152185 @staticmethod
153186 def standardise_name (name ):
0 commit comments