Exceptions typing in bastd module

This commit is contained in:
Roman Trapeznikov 2020-05-21 19:01:50 +03:00
parent 5b5aee6faf
commit 9143415308
No known key found for this signature in database
GPG Key ID: 827DD41DACE1E018
6 changed files with 43 additions and 41 deletions

View File

@ -149,7 +149,7 @@ class CoopScoreScreen(ba.Activity[ba.Player, ba.Team]):
self._score_order: str self._score_order: str
if 'score_order' in settings: if 'score_order' in settings:
if not settings['score_order'] in ['increasing', 'decreasing']: if not settings['score_order'] in ['increasing', 'decreasing']:
raise Exception('Invalid score order: ' + raise ValueError('Invalid score order: ' +
settings['score_order']) settings['score_order'])
self._score_order = settings['score_order'] self._score_order = settings['score_order']
else: else:
@ -159,7 +159,7 @@ class CoopScoreScreen(ba.Activity[ba.Player, ba.Team]):
self._score_type: str self._score_type: str
if 'score_type' in settings: if 'score_type' in settings:
if not settings['score_type'] in ['points', 'time']: if not settings['score_type'] in ['points', 'time']:
raise Exception('Invalid score type: ' + raise ValueError('Invalid score type: ' +
settings['score_type']) settings['score_type'])
self._score_type = settings['score_type'] self._score_type = settings['score_type']
else: else:
@ -387,7 +387,8 @@ class CoopScoreScreen(ba.Activity[ba.Player, ba.Team]):
label=ba.Lstr(resource='tournamentStandingsText') label=ba.Lstr(resource='tournamentStandingsText')
if self.session.tournament_id is not None else ba.Lstr( if self.session.tournament_id is not None else ba.Lstr(
resource='worldsBestScoresText') if self._score_type resource='worldsBestScoresText') if self._score_type
== 'points' else ba.Lstr(resource='worldsBestTimesText'), == 'points' else ba.Lstr(
resource='worldsBestTimesText'),
autoselect=True, autoselect=True,
on_activate_call=ba.WeakCall(self._ui_worlds_best), on_activate_call=ba.WeakCall(self._ui_worlds_best),
transition_delay=delay + 1.9, transition_delay=delay + 1.9,
@ -728,7 +729,8 @@ class CoopScoreScreen(ba.Activity[ba.Player, ba.Team]):
txt = Text(ba.Lstr(resource='tournamentStandingsText') txt = Text(ba.Lstr(resource='tournamentStandingsText')
if self.session.tournament_id is not None else ba.Lstr( if self.session.tournament_id is not None else ba.Lstr(
resource='worldsBestScoresText') if self._score_type resource='worldsBestScoresText') if self._score_type
== 'points' else ba.Lstr(resource='worldsBestTimesText'), == 'points' else ba.Lstr(
resource='worldsBestTimesText'),
maxwidth=210, maxwidth=210,
position=(ts_h_offs - 10, ts_height / 2 + 25 + v_offs + 20), position=(ts_h_offs - 10, ts_height / 2 + 25 + v_offs + 20),
transition=Text.Transition.IN_LEFT, transition=Text.Transition.IN_LEFT,
@ -764,7 +766,8 @@ class CoopScoreScreen(ba.Activity[ba.Player, ba.Team]):
ts_h_offs = -480 ts_h_offs = -480
v_offs = 40 v_offs = 40
Text(ba.Lstr(resource='yourBestScoresText') if self._score_type Text(ba.Lstr(resource='yourBestScoresText') if self._score_type
== 'points' else ba.Lstr(resource='yourBestTimesText'), == 'points' else ba.Lstr(
resource='yourBestTimesText'),
maxwidth=210, maxwidth=210,
position=(ts_h_offs - 10, ts_height / 2 + 25 + v_offs + 20), position=(ts_h_offs - 10, ts_height / 2 + 25 + v_offs + 20),
transition=Text.Transition.IN_RIGHT, transition=Text.Transition.IN_RIGHT,

View File

@ -665,7 +665,7 @@ class Bomb(ba.Actor):
if bomb_type not in ('ice', 'impact', 'land_mine', 'normal', 'sticky', if bomb_type not in ('ice', 'impact', 'land_mine', 'normal', 'sticky',
'tnt'): 'tnt'):
raise Exception('invalid bomb type: ' + bomb_type) raise ValueError('invalid bomb type: ' + bomb_type)
self.bomb_type = bomb_type self.bomb_type = bomb_type
self._exploded = False self._exploded = False

View File

@ -95,7 +95,7 @@ class OnScreenTimer(ba.Actor):
assert isinstance(endtime, int) assert isinstance(endtime, int)
endtime_ms = endtime endtime_ms = endtime
else: else:
raise Exception(f'invalid timeformat: {timeformat}') raise ValueError(f'invalid timeformat: {timeformat}')
self.inputnode.timemax = endtime_ms - self._starttime self.inputnode.timemax = endtime_ms - self._starttime
@ -119,7 +119,7 @@ class OnScreenTimer(ba.Actor):
return 0.001 * val_ms return 0.001 * val_ms
if timeformat is ba.TimeFormat.MILLISECONDS: if timeformat is ba.TimeFormat.MILLISECONDS:
return val_ms return val_ms
raise Exception(f'invalid timeformat: {timeformat}') raise ValueError(f'invalid timeformat: {timeformat}')
def handlemessage(self, msg: Any) -> Any: def handlemessage(self, msg: Any) -> Any:
# if we're asked to die, just kill our node/timer # if we're asked to die, just kill our node/timer

View File

@ -187,7 +187,7 @@ def get_factory() -> PowerupBoxFactory:
"""Return a shared ba.PowerupBoxFactory object, creating if necessary.""" """Return a shared ba.PowerupBoxFactory object, creating if necessary."""
activity = ba.getactivity() activity = ba.getactivity()
if activity is None: if activity is None:
raise Exception('no current activity') raise RuntimeError('no current activity')
try: try:
# FIXME: et better way to store stuff with activity # FIXME: et better way to store stuff with activity
# pylint: disable=protected-access # pylint: disable=protected-access
@ -252,10 +252,10 @@ class PowerupBox(ba.Actor):
elif poweruptype == 'curse': elif poweruptype == 'curse':
tex = factory.tex_curse tex = factory.tex_curse
else: else:
raise Exception('invalid poweruptype: ' + str(poweruptype)) raise ValueError('invalid poweruptype: ' + str(poweruptype))
if len(position) != 3: if len(position) != 3:
raise Exception('expected 3 floats for position') raise ValueError('expected 3 floats for position')
self.node = ba.newnode( self.node = ba.newnode(
'prop', 'prop',

View File

@ -1384,7 +1384,7 @@ class Spaz(ba.Actor):
return bomb_factory.tex_ice_bombs return bomb_factory.tex_ice_bombs
if self.bomb_type == 'impact': if self.bomb_type == 'impact':
return bomb_factory.tex_impact_bombs return bomb_factory.tex_impact_bombs
raise Exception() raise ValueError('invalid bomb type')
def _flash_billboard(self, tex: ba.Texture) -> None: def _flash_billboard(self, tex: ba.Texture) -> None:
assert self.node assert self.node

View File

@ -1110,7 +1110,6 @@ class RunaroundGame(ba.CoopGameActivity[Player, Team]):
if ((ba.is_point_in_box(pos, boxes['b8']) if ((ba.is_point_in_box(pos, boxes['b8'])
and not ba.is_point_in_box(pos, boxes['b9'])) and not ba.is_point_in_box(pos, boxes['b9']))
or pos == (0.0, 0.0, 0.0)): or pos == (0.0, 0.0, 0.0)):
# Default to walking right if we're still in the walking area. # Default to walking right if we're still in the walking area.
bot.node.move_left_right = speed bot.node.move_left_right = speed
bot.node.move_up_down = 0 bot.node.move_up_down = 0
@ -1177,7 +1176,7 @@ class RunaroundGame(ba.CoopGameActivity[Player, Team]):
def _get_bot_speed(self, bot_type: Type[spazbot.SpazBot]) -> float: def _get_bot_speed(self, bot_type: Type[spazbot.SpazBot]) -> float:
speed = self._bot_speed_map.get(bot_type) speed = self._bot_speed_map.get(bot_type)
if speed is None: if speed is None:
raise Exception('Invalid bot type to _get_bot_speed(): ' + raise TypeError('Invalid bot type to _get_bot_speed(): ' +
str(bot_type)) str(bot_type))
return speed return speed