Skip to content

Commit

Permalink
📝 update documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
clorton committed Nov 6, 2024
1 parent 02b4c43 commit 4617038
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
29 changes: 29 additions & 0 deletions src/laser_core/propertyset.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,38 @@ def save(self, filename):
return

def __getitem__(self, key):
"""
Retrieve the attribute of the object with the given key (e.g., ``ps[key]``).
Parameters:
key (str): The name of the attribute to retrieve.
Returns:
Any: The value of the attribute with the specified key.
Raises:
AttributeError: If the attribute with the specified key does not exist.
"""

return getattr(self, key)

def __setitem__(self, key, value):
"""
Set the value of an attribute.
This method allows setting an attribute of the instance using the
dictionary-like syntax (e.g., ``ps[key] = value``).
Parameters:
key (str): The name of the attribute to set.
value (any): The value to set for the attribute.
Returns:
None
"""

setattr(self, key, value)

def __add__(self, other):
Expand Down
4 changes: 2 additions & 2 deletions tests/test_propertyset.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ def test_load(self):
assert PropertySet.load(filename) == gb

def test_item_access(self):
"""Test item access in the PropertySet class."""
"""Test item access, e.g., ``ps[key]``, in the PropertySet class."""
gb = PropertySet({"a": 1, "b": 2.7182818285}, {"c": "three", "d": np.uint32(42)})
assert gb["a"] == 1
assert gb["b"] == 2.7182818285
Expand All @@ -176,7 +176,7 @@ def test_item_access(self):
assert gb.ps["e"] == 2.7182818285

def test_item_set(self):
"""Test item set in the PropertySet class."""
"""Test item set, e.g., ``ps[key] = value``, in the PropertySet class."""
gb = PropertySet()
gb["a"] = 1
gb["b"] = 2.7182818285
Expand Down

0 comments on commit 4617038

Please sign in to comment.