From 9f6a193f82a9cfbf55258cdf86797cdf92499e5f Mon Sep 17 00:00:00 2001 From: Luca Tomasko Date: Fri, 19 Jan 2024 14:34:16 +0000 Subject: [PATCH] [squash] Add docstring for classes and make lines shorter --- .../input_generators/attack_point_itarator.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/scaaml/capture/input_generators/attack_point_itarator.py b/scaaml/capture/input_generators/attack_point_itarator.py index 35fad7f2..d357971d 100644 --- a/scaaml/capture/input_generators/attack_point_itarator.py +++ b/scaaml/capture/input_generators/attack_point_itarator.py @@ -12,7 +12,8 @@ # See the License for the specific language governing permissions and # limitations under the License. """ -An Itarator that itarates through attack points and can be used with config files. +An Iterator that iterates through attack points +and can be used with config files. """ from abc import ABC, abstractmethod @@ -21,7 +22,7 @@ class AttackPointIterator: - + """Attack point iterator class that iterates with different configs.""" def __init__(self, configuration) -> None: """Initialize a new iterator.""" self._attack_point_iterator_internal: AttackPointIteratorInternalBase @@ -36,11 +37,11 @@ def __init__(self, configuration) -> None: def __len__(self) -> int: """Return the number of iterated elements. """ - return self._attack_point_iterator_internal.__len__() + return len(self._attack_point_iterator_internal) def __iter__(self): """Start iterating.""" - return self._attack_point_iterator_internal.__iter__() + return iter(self._attack_point_iterator_internal) def __next__(self) -> namedtuple: """Next iterated element.""" @@ -48,6 +49,7 @@ def __next__(self) -> namedtuple: class AttackPointIteratorInternalBase(ABC): + "Attack point iterator abstract class." @abstractmethod def __len__(self) -> int: """Return the number of iterated elements. @@ -63,9 +65,10 @@ def __next__(self) -> namedtuple: class AttackPointIteratorInternalConstants(AttackPointIteratorInternalBase): + """Attack point iterator class that iterates over a constent.""" def __init__(self, name: str, values: List[List[int]]) -> None: """Initialize the constants to iterate.""" - self.Valuestuple = namedtuple(typename=name, field_names="value") + self._Valuestuple = namedtuple(typename=name, field_names="value") self._values = values self._index = 0 @@ -77,7 +80,7 @@ def __iter__(self): def __next__(self) -> namedtuple: if self._index < self.__len__(): - tuple = self.Valuestuple(self._values[self._index]) + tuple = self._Valuestuple(self._values[self._index]) self._index += 1 return tuple else: