This repository was archived by the owner on Nov 28, 2023. It is now read-only.
Make to/from_dict optional #107
Merged
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.
Writing small custom components is very common in teaching material (tutorials, presentations) and might become even more popular depending how the users will receive the new Pipelines in 2.x. Problem is, having to write a
to_dict
andfrom_dict
every time is cumbersome, even if the implementation is a single line thanks to the default methods provided by canals.The idea is to remove
to_dict
andfrom_dict
from the Component protocol and make them optional. We use the default serialization methods we already have whento_dict
orfrom_dict
are not present in a component class.Caveat: when
to_dict
is not present, we inspect the__init__
signature and see if the init parameters were assigned to an instance variable. If that wasn't the case, we resort to the default value of the parameter. If it doesn't have a default value, we raise an error.ATM all the components have the serialization methods, so I changed
Greet
as an example of how this would look like.