Repository: Avaiga/taipy
File: taipy/core/_entity/submittable.py (Python)

Code before:

    def __get_outputs(self, dag: nx.DiGraph) -> set[DataNode]:
        return {node for node, degree in dict(dag.out_degree).items() if degree == 0 and isinstance(node, DataNode)}

    def get_intermediate(self) -> Set[DataNode]:
        """Return the set of intermediate data nodes of the submittable entity.

        Returns:
            The set of intermediate data nodes.
        """
        dag = self._build_dag()
        all_data_nodes_in_dag = {node for node in dag.nodes if isinstance(node, DataNode)}
        return all_data_nodes_in_dag - self.__get_inputs(dag) - self.__get_outputs(dag)

    def is_ready_to_run(self) -> Reasons:
        """Indicate if the entity is ready to be run.

        Returns:
            A Reason object that can function as a Boolean value.
            which is True if the given entity is ready to be run or there is no reason to be blocked, False otherwise.
        """
        reason = Reasons(self._submittable_id)

        for node in self.get_inputs():
            if node._edit_in_progress:
                reason._add_reason(node.id, DataNodeEditInProgress(node.id))
            if not node._last_edit_date:
                reason._add_reason(node.id, DataNodeIsNotWritten(node.id))

        return reason

    def data_nodes_being_edited(self) -> Set[DataNode]:
        """Return the set of data nodes of the submittable entity that are being edited.

        Returns:
            The set of data nodes that are being edited.
        """
        dag = self._build_dag()
        return {node for node in dag.nodes if isinstance(node, DataNode) and node.edit_in_progress}

    @abc.abstractmethod
    def subscribe(self, callback: Callable[[Submittable, Job], None], params: Optional[List[Any]] = None):
        raise NotImplementedError

    @abc.abstractmethod
    def unsubscribe(self, callback: Callable[[Submittable, Job], None], params: Optional[List[Any]] = None):
        raise NotImplementedError

    @abc.abstractmethod
    def _get_set_of_tasks(self) -> Set[Task]:
        raise NotImplementedError

Review comment (suggestion):
Since the name difference between Reasons and Reason classes is only singular or plural, I would love it if the variables to match the class name to avoid future confusion.

```suggestion
                reasons._add_reason(node.id, DataNodeEditInProgress(node.id))
```

Code after:

    def __get_outputs(self, dag: nx.DiGraph) -> set[DataNode]:
        return {node for node, degree in dict(dag.out_degree).items() if degree == 0 and isinstance(node, DataNode)}

    def get_intermediate(self) -> Set[DataNode]:
        """Return the set of intermediate data nodes of the submittable entity.

        Returns:
            The set of intermediate data nodes.
        """
        dag = self._build_dag()
        all_data_nodes_in_dag = {node for node in dag.nodes if isinstance(node, DataNode)}
        return all_data_nodes_in_dag - self.__get_inputs(dag) - self.__get_outputs(dag)

    def is_ready_to_run(self) -> ReasonCollection:
        """Indicate if the entity is ready to be run.

        Returns:
            A Reason object that can function as a Boolean value.
            which is True if the given entity is ready to be run or there is no reason to be blocked, False otherwise.
        """
        reason_collection = ReasonCollection()

        for node in self.get_inputs():
            if node._edit_in_progress:
                reason_collection._add_reason(node.id, DataNodeEditInProgress(node.id))
            if not node._last_edit_date:
                reason_collection._add_reason(node.id, DataNodeIsNotWritten(node.id))

        return reason_collection

    def data_nodes_being_edited(self) -> Set[DataNode]:
        """Return the set of data nodes of the submittable entity that are being edited.

        Returns:
            The set of data nodes that are being edited.
        """
        dag = self._build_dag()
        return {node for node in dag.nodes if isinstance(node, DataNode) and node.edit_in_progress}

    @abc.abstractmethod
    def subscribe(self, callback: Callable[[Submittable, Job], None], params: Optional[List[Any]] = None):
        raise NotImplementedError

    @abc.abstractmethod
    def unsubscribe(self, callback: Callable[[Submittable, Job], None], params: Optional[List[Any]] = None):
        raise NotImplementedError

    @abc.abstractmethod
    def _get_set_of_tasks(self) -> Set[Task]:
        raise NotImplementedError