-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add AddFixedValue to_dict and from_dict (#88)
Co-authored-by: Massimiliano Pippi <[email protected]>
- Loading branch information
1 parent
f2e1aee
commit db846c6
Showing
2 changed files
with
31 additions
and
5 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,27 @@ | ||
# SPDX-FileCopyrightText: 2022-present deepset GmbH <[email protected]> | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
from typing import Optional | ||
from typing import Optional, Dict, Any | ||
|
||
from canals import component | ||
from canals.serialization import default_to_dict, default_from_dict | ||
|
||
|
||
@component | ||
class AddFixedValue: # pylint: disable=too-few-public-methods | ||
class AddFixedValue: | ||
""" | ||
Adds two values together. | ||
""" | ||
|
||
def __init__(self, add: int = 1): | ||
self.add = add | ||
self.init_parameters = {"add": add} | ||
|
||
def to_dict(self) -> Dict[str, Any]: # pylint: disable=missing-function-docstring | ||
return default_to_dict(self, add=self.add) | ||
|
||
@classmethod | ||
def from_dict(cls, data: Dict[str, Any]) -> "AddFixedValue": # pylint: disable=missing-function-docstring | ||
return default_from_dict(cls, data) | ||
|
||
@component.output_types(result=int) | ||
def run(self, value: int, add: Optional[int] = None): | ||
|
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