null_node.py 774 B

12345678910111213141516171819202122232425
  1. import functools
  2. from symtable import Function
  3. from typing import List, Callable, Generator
  4. from api.od import ODAPI
  5. from .singleton import Singleton
  6. from .exec_node import ExecNode
  7. class NullNode(ExecNode, metaclass=Singleton):
  8. def __init__(self):
  9. ExecNode.__init__(self, out_connections=0)
  10. def execute(self, od: ODAPI) -> Generator | None:
  11. raise Exception('Null node should already have terminated the schedule')
  12. @staticmethod
  13. def terminate(od: ODAPI):
  14. return None
  15. yield # verrrry important line, dont remove this unreachable code
  16. def generate_dot(self, nodes: List[str], edges: List[str], visited: set[int]) -> None:
  17. if self.id in visited:
  18. return
  19. nodes.append(f"{self.id}[label=Null]")