I'm working to extend some functionality of the SSG I maintain to be able to render arbitrary serializable objects as JSON, TOML, or other standardized formats.
class DataObject(BaseObject):
"""Class to store a data object"""
data_object: Any = None # The data object
output_file: str | Path = Path('data_object.json')
serializer: Callable = json.dumps
serializer_args: dict | None = None
def render(self, *args, **kwargs):
"""
Renders the data_object to the file at output_file
"""
path = Path(site.output_path) / Path(self.output_file)
path.parent.mkdir(parents=True, exist_ok=True)
serialized = self.serializer(self.data_object)
path.write_text(serialized)
For some reason, self.serializer is being treated like a method of the class and I am getting:
File "/Users/brass75/src/render-engine/src/render_engine/data_object.py", line 41, in render
serialized = self.serializer(data_object)
TypeError: dumps() takes 1 positional argument but 2 were given
Does anyone know what I need to do to maintain this Callable attribute as a function, and not as a method of DataObject?