From 0a5bcefcca9da416120cf751e76d8f68ca28c6fb Mon Sep 17 00:00:00 2001 From: John Horton Date: Sat, 11 May 2024 17:31:48 -0400 Subject: [PATCH] Classes w/o proper edsl version added --- edsl/agents/AgentList.py | 6 ++++++ edsl/data/Cache.py | 7 +++++++ edsl/scenarios/Scenario.py | 6 ++++++ 3 files changed, 19 insertions(+) diff --git a/edsl/agents/AgentList.py b/edsl/agents/AgentList.py index 64aa4f13..c55670d3 100644 --- a/edsl/agents/AgentList.py +++ b/edsl/agents/AgentList.py @@ -18,6 +18,10 @@ from edsl.Base import Base from edsl.agents import Agent +from edsl.utilities.decorators import ( + add_edsl_version, + remove_edsl_version, +) class AgentList(UserList, Base): @@ -33,6 +37,7 @@ def __init__(self, data: Optional[list[Agent]] = None): else: super().__init__() + @add_edsl_version def to_dict(self): """Return dictionary of AgentList to serialization.""" return {"agent_list": [agent.to_dict() for agent in self.data]} @@ -51,6 +56,7 @@ def _repr_html_(self): return data_to_html(self.to_dict()["agent_list"]) @classmethod + @remove_edsl_version def from_dict(cls, data: dict) -> "AgentList": """Deserialize the dictionary back to an AgentList object. diff --git a/edsl/data/Cache.py b/edsl/data/Cache.py index 23d4ee60..afd70df6 100644 --- a/edsl/data/Cache.py +++ b/edsl/data/Cache.py @@ -12,6 +12,11 @@ from edsl.data.SQLiteDict import SQLiteDict from edsl.Base import Base +from edsl.utilities.decorators import ( + add_edsl_version, + remove_edsl_version, +) + class Cache(Base): """ @@ -308,6 +313,7 @@ def __exit__(self, exc_type, exc_value, traceback): #################### # DUNDER / USEFUL #################### + @add_edsl_version def to_dict(self) -> dict: """Return the Cache as a dictionary.""" return {k: v.to_dict() for k, v in self.data.items()} @@ -318,6 +324,7 @@ def _repr_html_(self): return data_to_html(self.to_dict()) @classmethod + @remove_edsl_version def from_dict(cls, data) -> Cache: """Construct a Cache from a dictionary.""" newdata = {k: CacheEntry.from_dict(v) for k, v in data.items()} diff --git a/edsl/scenarios/Scenario.py b/edsl/scenarios/Scenario.py index 7daa66c9..3dffa4f6 100644 --- a/edsl/scenarios/Scenario.py +++ b/edsl/scenarios/Scenario.py @@ -5,6 +5,10 @@ from typing import Union, List from edsl.Base import Base +from edsl.utilities.decorators import ( + add_edsl_version, + remove_edsl_version, +) class Scenario(Base, UserDict): """A Scenario is a dictionary of keys/values for parameterizing questions.""" @@ -64,6 +68,7 @@ def rename(self, replacement_dict: dict) -> "Scenario": new_scenario[key] = value return new_scenario + @add_edsl_version def to_dict(self) -> dict: """Convert a scenario to a dictionary. @@ -88,6 +93,7 @@ def _repr_html_(self): return data_to_html(self.to_dict()) @classmethod + @remove_edsl_version def from_dict(cls, d: dict) -> "Scenario": """Convert a dictionary to a scenario.