Skip to content

Commit

Permalink
Classes w/o proper edsl version added
Browse files Browse the repository at this point in the history
  • Loading branch information
johnjosephhorton committed May 11, 2024
1 parent 8c8893f commit 0a5bcef
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
6 changes: 6 additions & 0 deletions edsl/agents/AgentList.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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]}
Expand All @@ -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.
Expand Down
7 changes: 7 additions & 0 deletions edsl/data/Cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand Down Expand Up @@ -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()}
Expand All @@ -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()}
Expand Down
6 changes: 6 additions & 0 deletions edsl/scenarios/Scenario.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down Expand Up @@ -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.
Expand All @@ -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.
Expand Down

0 comments on commit 0a5bcef

Please sign in to comment.