Skip to content

Commit

Permalink
Add additional docstrings to dict_parsing.py
Browse files Browse the repository at this point in the history
  • Loading branch information
shape-warrior-t committed Dec 7, 2023
1 parent 058988f commit 4843312
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions src/astra/data/dict_parsing.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ def add(self, element: int | str) -> 'Path':
return Path(self.base, self.elements + [element])

def __str__(self):
"""
Format this path in a human-readable way.
Current format looks something like: base[index0].key0[index1][index2].key1.key2
"""
return self.base + ''.join(
(f'[{element}]' if isinstance(element, int) else f'.{element}')
for element in self.elements
Expand Down Expand Up @@ -102,6 +107,17 @@ class PathedList:
_list: list

def __init__(self, path: Path, value: object):
"""
Construct a PathedList.
:param path:
The path for the PathedList.
:param value:
The underlying list for the PathedList, validated as a list during runtime.
:raise ParsingError:
If value is not a list.
"""
self._path = path
self._list = _check_type(path, value, list)

Expand Down Expand Up @@ -166,6 +182,17 @@ class PathedDict:
_dict: dict

def __init__(self, path: Path, value: object):
"""
Construct a PathedDict.
:param path:
The path for the PathedDict.
:param value:
The underlying dict for the PathedDict, validated as a dict during runtime.
:raise ParsingError:
If value is not a dict.
"""
self._path = path
self._dict = _check_type(path, value, dict)

Expand Down

0 comments on commit 4843312

Please sign in to comment.