in pythonflow/core.py [0:0]
def normalize_operation(self, operation):
"""
Normalize an operation by resolving its name if necessary.
Parameters
----------
operation : Operation or str
Operation instance or name of an operation.
Returns
-------
normalized_operation : Operation
Operation instance.
Raises
------
ValueError
If `operation` is not an `Operation` instance or an operation name.
RuntimeError
If `operation` is an `Operation` instance but does not belong to this graph.
KeyError
If `operation` is an operation name that does not match any operation of this graph.
"""
if isinstance(operation, Operation):
if operation.graph is not self:
raise RuntimeError(f"operation '{operation}' does not belong to this graph")
return operation
if isinstance(operation, str):
return self.operations[operation]
raise ValueError(f"'{operation}' is not an `Operation` instance or operation name")