-
Notifications
You must be signed in to change notification settings - Fork 0
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
Ruttor
wants to merge
19
commits into
main
Choose a base branch
from
2-add-docstrings
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 9 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
609fbf4
small code changes
PythonFZ cb506f8
move examples
PythonFZ 1401165
Added Docstrings to base.py
Ruttor b62b468
Removed empty docstring
Ruttor d17be27
Add Docstrings
Ruttor f405abe
Merge branch 'main' into 2-add-docstrings
Ruttor 426efb3
Add Docstrings
Ruttor 4c1c11f
Add Docstrings
Ruttor 2d8902d
Add Docstrings and eliminate merge conflicts
Ruttor 7f7899f
Eliminate merge conflicts
Ruttor 015d97a
Merge branch 'main' into 2-add-docstrings
Ruttor bfc6d7f
Reduce ruff "D401"-errors
Ruttor 4c0b16d
Finish Docstrings in base
Ruttor 4f98269
Merge branch 'main' into 2-add-docstrings
Ruttor 89bd975
Merge main into branch
Ruttor 5f4076b
Resolve merge conflict
Ruttor f9df8a5
Merge branch 'main' into 2-add-docstrings
Ruttor f95567f
ruff is now happy with base.py, but there is still one TODO
Ruttor d896999
Merge branch '2-add-docstrings' of https://github.com/zincware/ZnFlow…
Ruttor File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
@@ -29,6 +30,12 @@ class Property: | |
""" | ||
|
||
def __init__(self, fget=None, fset=None, fdel=None, doc=None): | ||
"""Init method of the property class. | ||
|
||
References | ||
---------- | ||
Adapted from https://docs.python.org/3/howto/descriptor.html#properties | ||
""" | ||
self.fget = disable_graph()(fget) | ||
self.fset = disable_graph()(fset) | ||
self.fdel = disable_graph()(fdel) | ||
|
@@ -38,36 +45,78 @@ def __init__(self, fget=None, fset=None, fdel=None, doc=None): | |
self._name = "" | ||
|
||
def __set_name__(self, owner, name): | ||
"""Set Name Method of the Property class. | ||
|
||
References | ||
---------- | ||
Adapted from https://docs.python.org/3/howto/descriptor.html#properties | ||
""" | ||
self._name = name | ||
|
||
def __get__(self, obj, objtype=None): | ||
"""Get Method of the Property class. | ||
|
||
References | ||
---------- | ||
Adapted from https://docs.python.org/3/howto/descriptor.html#properties | ||
""" | ||
if obj is None: | ||
return self | ||
if self.fget is None: | ||
raise AttributeError(f"property '{self._name}' has no getter") | ||
return self.fget(obj) | ||
|
||
def __set__(self, obj, value): | ||
"""Set Method of the Property class. | ||
|
||
References | ||
---------- | ||
Adapted from https://docs.python.org/3/howto/descriptor.html#properties | ||
""" | ||
if self.fset is None: | ||
raise AttributeError(f"property '{self._name}' has no setter") | ||
self.fset(obj, value) | ||
|
||
def __delete__(self, obj): | ||
"""Delete Method of the Property class. | ||
|
||
References | ||
---------- | ||
Adapted from https://docs.python.org/3/howto/descriptor.html#properties | ||
""" | ||
if self.fdel is None: | ||
raise AttributeError(f"property '{self._name}' has no deleter") | ||
self.fdel(obj) | ||
|
||
def getter(self, fget): | ||
"""Getter Method of the Property class. | ||
|
||
References | ||
---------- | ||
Adapted from https://docs.python.org/3/howto/descriptor.html#properties | ||
""" | ||
prop = type(self)(fget, self.fset, self.fdel, self.__doc__) | ||
prop._name = self._name | ||
return prop | ||
|
||
def setter(self, fset): | ||
"""Setter Method of the Property class. | ||
|
||
References | ||
---------- | ||
Adapted from https://docs.python.org/3/howto/descriptor.html#properties | ||
""" | ||
prop = type(self)(self.fget, fset, self.fdel, self.__doc__) | ||
prop._name = self._name | ||
return prop | ||
|
||
def deleter(self, fdel): | ||
"""Deleter Method of the Property class. | ||
|
||
References | ||
---------- | ||
Adapted from https://docs.python.org/3/howto/descriptor.html#properties | ||
""" | ||
prop = type(self)(self.fget, self.fset, fdel, self.__doc__) | ||
prop._name = self._name | ||
return prop | ||
|
@@ -98,23 +147,36 @@ 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. | ||
|
||
Raises | ||
------ | ||
ValueError | ||
If a UUID is already set for the current node. | ||
""" | ||
if self._uuid is not None: | ||
raise ValueError("uuid is already set") | ||
self._uuid = value | ||
|
||
def run(self): | ||
"""Run Method of NodeBaseMixin.""" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||
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 | ||
|
||
|
||
|
@@ -132,30 +194,40 @@ 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 | ||
|
||
Instance | ||
-------- | ||
Either a Node or FunctionFuture. | ||
|
||
Attributes | ||
---------- | ||
attribute : Node.attribute | ||
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 | ||
item: any = None | ||
|
||
def __getitem__(self, item): | ||
"""TODO.""" | ||
return dataclasses.replace(self, instance=self, attribute=None, item=item) | ||
|
||
def __post_init__(self): | ||
"""Raises a Valueerror if a private attribute is called.""" | ||
if self.attribute is not None and self.attribute.startswith("_"): | ||
raise ValueError("Private attributes are not allowed.") | ||
|
||
@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: | ||
result = getattr(self.instance, self.attribute) | ||
elif isinstance(self.instance, (FunctionFuture, self.__class__)): | ||
|
@@ -167,6 +239,15 @@ def result(self): | |
|
||
@dataclasses.dataclass | ||
class FunctionFuture(NodeBaseMixin): | ||
"""A class that creates a future object out of a function. | ||
|
||
Attributes | ||
---------- | ||
function : callable | ||
args : tuple | ||
kwargs : dict | ||
""" | ||
|
||
function: typing.Callable | ||
args: typing.Tuple | ||
kwargs: typing.Dict | ||
|
@@ -177,7 +258,12 @@ class FunctionFuture(NodeBaseMixin): | |
_protected_ = NodeBaseMixin._protected_ + ["function", "args", "kwargs"] | ||
|
||
def run(self): | ||
self.result = self.function(*self.args, **self.kwargs) | ||
"""Run Method of the FunctionFuture class. | ||
|
||
Executes the function with the given arguments and saves the result. | ||
""" | ||
self._result = self.function(*self.args, **self.kwargs) | ||
Ruttor marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
def __getitem__(self, item): | ||
"""Gets the object with all the information of the Connection class.""" | ||
return Connection(instance=self, attribute=None, item=item) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
"""The graph module of ZnFlow.""" | ||
import functools | ||
import logging | ||
import typing | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
"""The node module of ZnFlow.""" | ||
from __future__ import annotations | ||
|
||
import functools | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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