Skip to content

Commit

Permalink
Remove redundant validation
Browse files Browse the repository at this point in the history
There was some residual validation in ModController.move to ensure
from_index and to_index were integers. Since this function receives the
proper types from the UI, remove this validation.
  • Loading branch information
cyberrumor committed Nov 4, 2023
1 parent 43b6ae8 commit 85582c7
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 10 deletions.
15 changes: 6 additions & 9 deletions ammo/mod_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -607,18 +607,15 @@ def move(self, component: ComponentEnum, from_index: int, to_index: int):
components = self._get_validated_components(component)
# Since this operation it not atomic, validation must be performed
# before anything is attempted to ensure nothing can become mangled.
old_ind = int(from_index)
new_ind = int(to_index)
if old_ind == new_ind:
# no op
if from_index == to_index:
return
if new_ind > len(components) - 1:
if to_index > len(components) - 1:
# Auto correct astronomical <to index> to max.
new_ind = len(components) - 1
if old_ind > len(components) - 1:
to_index = len(components) - 1
if from_index > len(components) - 1:
raise Warning("Index out of range.")
comp = components.pop(old_ind)
components.insert(new_ind, comp)
comp = components.pop(from_index)
components.insert(to_index, comp)
self.changes = True

def commit(self):
Expand Down
2 changes: 1 addition & 1 deletion ammo/ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ def repl(self):
expected_arg = expected_args.pop(0)

except (ValueError, KeyError) as e:
print(e)
print(f"arg was unexpected type: {e}")
input("[Enter]")
continue

Expand Down

0 comments on commit 85582c7

Please sign in to comment.