Skip to content

Commit

Permalink
[squash] Add docstring for classes and make lines shorter
Browse files Browse the repository at this point in the history
  • Loading branch information
LucaTomasko committed Jan 19, 2024
1 parent e1e27c0 commit 9f6a193
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions scaaml/capture/input_generators/attack_point_itarator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -21,7 +22,7 @@


Check failure on line 23 in scaaml/capture/input_generators/attack_point_itarator.py

View workflow job for this annotation

GitHub Actions / yapf

reformatted
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
Expand All @@ -36,18 +37,19 @@ 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:

Check failure on line 46 in scaaml/capture/input_generators/attack_point_itarator.py

View workflow job for this annotation

GitHub Actions / mypy

Function "collections.namedtuple" is not valid as a type [valid-type]

Check failure on line 46 in scaaml/capture/input_generators/attack_point_itarator.py

View workflow job for this annotation

GitHub Actions / mypy

Perhaps you need "Callable[...]" or a callback protocol?
"""Next iterated element."""
return self._attack_point_iterator_internal.__next__()


class AttackPointIteratorInternalBase(ABC):
"Attack point iterator abstract class."
@abstractmethod
def __len__(self) -> int:
"""Return the number of iterated elements.
Expand All @@ -63,9 +65,10 @@ def __next__(self) -> namedtuple:


class AttackPointIteratorInternalConstants(AttackPointIteratorInternalBase):
"""Attack point iterator class that iterates over a constent."""

Check failure on line 68 in scaaml/capture/input_generators/attack_point_itarator.py

View workflow job for this annotation

GitHub Actions / spellchecking

Unknown word (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")

Check failure on line 71 in scaaml/capture/input_generators/attack_point_itarator.py

View workflow job for this annotation

GitHub Actions / mypy

NamedTuple type as an attribute is not supported [misc]

Check failure on line 71 in scaaml/capture/input_generators/attack_point_itarator.py

View workflow job for this annotation

GitHub Actions / pylint (3.8)

Attribute name "_Valuestuple" doesn't conform to '^_{0,2}[a-z][a-z0-9_]*$' pattern (invalid-name)

Check failure on line 71 in scaaml/capture/input_generators/attack_point_itarator.py

View workflow job for this annotation

GitHub Actions / pylint (3.9)

Attribute name "_Valuestuple" doesn't conform to '^_{0,2}[a-z][a-z0-9_]*$' pattern (invalid-name)

Check failure on line 71 in scaaml/capture/input_generators/attack_point_itarator.py

View workflow job for this annotation

GitHub Actions / spellchecking

Unknown word (Valuestuple)

Check failure on line 71 in scaaml/capture/input_generators/attack_point_itarator.py

View workflow job for this annotation

GitHub Actions / pylint (3.10)

Attribute name "_Valuestuple" doesn't conform to '^_{0,2}[a-z][a-z0-9_]*$' pattern (invalid-name)

Check failure on line 71 in scaaml/capture/input_generators/attack_point_itarator.py

View workflow job for this annotation

GitHub Actions / pylint (3.11)

Attribute name "_Valuestuple" doesn't conform to '^_{0,2}[a-z][a-z0-9_]*$' pattern (invalid-name)
self._values = values
self._index = 0

Expand All @@ -77,7 +80,7 @@ def __iter__(self):

def __next__(self) -> namedtuple:

Check failure on line 81 in scaaml/capture/input_generators/attack_point_itarator.py

View workflow job for this annotation

GitHub Actions / mypy

Function "collections.namedtuple" is not valid as a type [valid-type]

Check failure on line 81 in scaaml/capture/input_generators/attack_point_itarator.py

View workflow job for this annotation

GitHub Actions / mypy

Perhaps you need "Callable[...]" or a callback protocol?
if self._index < self.__len__():
tuple = self.Valuestuple(self._values[self._index])
tuple = self._Valuestuple(self._values[self._index])

Check failure on line 83 in scaaml/capture/input_generators/attack_point_itarator.py

View workflow job for this annotation

GitHub Actions / pylint (3.8)

Redefining built-in 'tuple' (redefined-builtin)

Check failure on line 83 in scaaml/capture/input_generators/attack_point_itarator.py

View workflow job for this annotation

GitHub Actions / pylint (3.9)

Redefining built-in 'tuple' (redefined-builtin)

Check failure on line 83 in scaaml/capture/input_generators/attack_point_itarator.py

View workflow job for this annotation

GitHub Actions / spellchecking

Unknown word (Valuestuple)

Check failure on line 83 in scaaml/capture/input_generators/attack_point_itarator.py

View workflow job for this annotation

GitHub Actions / pylint (3.10)

Redefining built-in 'tuple' (redefined-builtin)

Check failure on line 83 in scaaml/capture/input_generators/attack_point_itarator.py

View workflow job for this annotation

GitHub Actions / pylint (3.11)

Redefining built-in 'tuple' (redefined-builtin)
self._index += 1
return tuple
else:
Expand Down

0 comments on commit 9f6a193

Please sign in to comment.