some more docstring fixes (#7527)

This commit is contained in:
David S. Batista 2024-04-11 09:42:06 +02:00 committed by GitHub
parent b1760add56
commit b90a005b85
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 18 additions and 8 deletions

View File

@ -17,6 +17,7 @@ logger = logging.getLogger(__name__)
def _prepare_for_drawing(graph: networkx.MultiDiGraph) -> networkx.MultiDiGraph:
"""
Add some extra nodes to show the inputs and outputs of the pipeline.
Also adds labels to edges.
"""
# Label the edges
@ -99,8 +100,10 @@ def _to_mermaid_image(graph: networkx.MultiDiGraph):
def _to_mermaid_text(graph: networkx.MultiDiGraph) -> str:
"""
Converts a Networkx graph into Mermaid syntax. The output of this function can be used in the documentation
with `mermaid` codeblocks and it will be automatically rendered.
Converts a Networkx graph into Mermaid syntax.
The output of this function can be used in the documentation with `mermaid` codeblocks, and it will
be automatically rendered.
"""
# Copy the graph to avoid modifying the original
graph = _prepare_for_drawing(graph.copy())

View File

@ -31,8 +31,9 @@ class DeserializationCallbacks:
def component_to_dict(obj: Any) -> Dict[str, Any]:
"""
Converts a component instance into a dictionary. If a `to_dict` method is present in the
component instance, that will be used instead of the default method.
Converts a component instance into a dictionary.
If a `to_dict` method is present in the component instance, that will be used instead of the default method.
:param obj:
The component to be serialized.
@ -85,8 +86,9 @@ def component_from_dict(
cls: Type[object], data: Dict[str, Any], name: str, callbacks: Optional[DeserializationCallbacks] = None
) -> Any:
"""
Creates a component instance from a dictionary. If a `from_dict` method is present in the
component class, that will be used instead of the default method.
Creates a component instance from a dictionary.
If a `from_dict` method is present in the component class, that will be used instead of the default method.
:param cls:
The class to be used for deserialization.
@ -121,7 +123,8 @@ def component_from_dict(
def default_to_dict(obj: Any, **init_parameters) -> Dict[str, Any]:
"""
Utility function to serialize an object to a dictionary.
This is mostly necessary for Components but it can be used by any object.
This is mostly necessary for Components, but it can be used by any object.
`init_parameters` are parameters passed to the object class `__init__`.
They must be defined explicitly as they'll be used when creating a new
@ -162,7 +165,8 @@ def default_to_dict(obj: Any, **init_parameters) -> Dict[str, Any]:
def default_from_dict(cls: Type[object], data: Dict[str, Any]) -> Any:
"""
Utility function to deserialize a dictionary to an object.
This is mostly necessary for Components but it can be used by any object.
This is mostly necessary for Components but, it can be used by any object.
The function will raise a `DeserializationError` if the `type` field in `data` is
missing or it doesn't match the type of `cls`.

View File

@ -57,6 +57,7 @@ def _types_are_compatible(sender, receiver): # pylint: disable=too-many-return-
def _type_name(type_):
"""
Util methods to get a nice readable representation of a type.
Handles Optional and Literal in a special way to make it more readable.
"""
# Literal args are strings, so we wrap them in quotes to make it clear

View File

@ -8,6 +8,8 @@ class SparseEmbedding:
def __init__(self, indices: List[int], values: List[float]):
"""
Initialize a sparse embedding.
:param indices: List of indices of non-zero elements in the embedding.
:param values: List of values of non-zero elements in the embedding.