Skip to content

Commit

Permalink
Check if unit /and/ output number are non-negative.
Browse files Browse the repository at this point in the history
  • Loading branch information
zuckerruebe authored Nov 3, 2023
1 parent 6ee8b0a commit b570cdd
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/trnsys_dck_parser/parse/expression/parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,18 +101,18 @@ def _argument_list(self) -> _tp.Sequence[_exp.ExpressionOrNumber]:
def _unit_and_output_number(self) -> _tp.Tuple[int, int]:
self._expect(_tok.Tokens.INTEGER)
unit_number = int(self._current_token.value)
self._check_non_negative(unit_number)
self._check_non_negative(unit_number, "Unit number")

self._expect(_tok.Tokens.COMMA)

self._expect(_tok.Tokens.INTEGER)
output_number = int(self._current_token.value)
self._check_non_negative(unit_number)
self._check_non_negative(output_number, "Output number")

return unit_number, output_number

def _check_non_negative(self, integer):
def _check_non_negative(self, integer: int, what: str) -> None:
if integer >= 0:
return

self._raise_parsing_error("Unit numbers must be non-negative.")
self._raise_parsing_error(f"{what} numbers must be non-negative.")

0 comments on commit b570cdd

Please sign in to comment.