Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Docstrings to base.py #35

Open
wants to merge 19 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,10 @@ multi_line_output = 3

[tool.ruff]
line-length = 90
select = ["E", "F"] #, "D"] #, "N", "C", "ANN"]
select = ["E", "F", "D"] #] #, "N", "C", "ANN"]
exclude = [
"tests",
]
extend-ignore = [
"D213", "D203"
]
17 changes: 16 additions & 1 deletion znflow/base.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
"""The base module of znflow."""
from __future__ import annotations

import contextlib
Expand Down Expand Up @@ -43,23 +44,31 @@ class NodeBaseMixin:

@property
def uuid(self):
"""A method that generates a UUID to create a hashable object for each node."""
return self._uuid

@uuid.setter
def uuid(self, value):
"""A method that checks for an existing UUID.

If no UUID exists, it sets the previously defined UUID for the node.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a Raises section

"""
if self._uuid is not None:
raise ValueError("uuid is already set")
self._uuid = value

def run(self):
"""Run Method of NodeBaseMixin."""
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The run method is a really important abstract method. It's the method that is executed upon the graph run call.

raise NotImplementedError


def get_graph():
"""Gets Graph from the NodeBaseMixin class."""
return NodeBaseMixin._graph_


def set_graph(value):
"""Sets a value for the NodeBaseMixin graph."""
NodeBaseMixin._graph_ = value


Expand All @@ -77,29 +86,35 @@ def get_attribute(obj, name, default=_get_attribute_none):
@dataclasses.dataclass(frozen=True)
class Connection:
"""A Connector for Nodes.

instance: either a Node or FunctionFuture
attribute:
Node.attribute
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know, this is on me, but could you change this to numpy docstrings format?

or FunctionFuture.result
or None if the class is passed and not an attribute
or None if the class is passed and not an attribute.
"""

instance: any
attribute: any

@property
def uuid(self):
"""Gets value of the UUID."""
return self.instance.uuid

@property
def result(self):
"""Returns the instance and if available, also the attribute."""
if self.attribute is None:
return self.instance
return getattr(self.instance, self.attribute)


@dataclasses.dataclass
class FunctionFuture(NodeBaseMixin):
"""

"""

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please provide proper docstring, or remove entirely

function: typing.Callable
args: typing.Tuple
kwargs: typing.Dict
Expand Down