Skip to content

Commit

Permalink
Command: Check block parameter for correct type
Browse files Browse the repository at this point in the history
  • Loading branch information
sanssecours committed Sep 30, 2024
1 parent 5a8f5c2 commit 944a215
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion mytoolit/can/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,21 @@ def __init__(self, block: Block | str | int):
try:
if isinstance(block, str):
self.number = self.block_number[block]
else:
elif isinstance(block, int):
assert isinstance(block, int)
if block < 0 or block > 2**6:
raise ValueError(
"Block number is too "
f"{'small' if block < 0 else 'large'}"
)
self.number = block
elif isinstance(block, Block):
self.number = block.number
else:
raise ValueError(
"Incorrect type for block parameter:"
f" {type(block).__name__}"
)
except KeyError as error:
raise ValueError(f"Unknown block: {block}") from error

Expand Down

0 comments on commit 944a215

Please sign in to comment.