@@ -503,7 +503,7 @@ def set_finished_dependency(self, finished_task: TTask) -> None:
503
503
self ._declared_finished .add (task_id )
504
504
# note that this task is intentionally *not* added to self._unready
505
505
506
- def register_tasks (self , tasks : Tuple [TTask , ...]) -> None :
506
+ def register_tasks (self , tasks : Tuple [TTask , ...], ignore_duplicates : bool = False ) -> None :
507
507
"""
508
508
Initiate a task into tracking. By default, each task must be registered
509
509
*after* its dependency has been registered.
@@ -512,23 +512,25 @@ def register_tasks(self, tasks: Tuple[TTask, ...]) -> None:
512
512
initialize this intance with: ``accept_dangling_tasks=True``.
513
513
514
514
:param tasks: the tasks to register, in iteration order
515
+ :param ignore_duplicates: any tasks that have already been registered will be ignored,
516
+ whether ready or not
515
517
"""
516
- task_meta_info = tuple (
517
- (self ._prereq_tracker (task ), self ._id_of (task ), self ._dependency_of (task ))
518
- for task in tasks
519
- )
520
-
521
- duplicates = tuple (
522
- tracker .task for tracker , task_id , _ in task_meta_info
523
- if task_id in self ._tasks
524
- )
518
+ identified_tasks = tuple ((self ._id_of (task ), task ) for task in tasks )
519
+ duplicates = tuple (task for task_id , task in identified_tasks if task_id in self ._tasks )
525
520
526
- if duplicates :
521
+ if duplicates and not ignore_duplicates :
527
522
raise DuplicateTasks (
528
523
f"Cannot re-register tasks: { duplicates !r} for completion" ,
529
524
duplicates ,
530
525
)
531
526
527
+ task_meta_info = tuple (
528
+ (self ._prereq_tracker (task ), task_id , self ._dependency_of (task ))
529
+ for task_id , task in identified_tasks
530
+ # when ignoring duplicates, must not try to re-add them
531
+ if task_id not in self ._tasks
532
+ )
533
+
532
534
for prereq_tracker , task_id , dependency_id in task_meta_info :
533
535
if not self ._accept_dangling_tasks and dependency_id not in self ._tasks :
534
536
raise MissingDependency (
0 commit comments