Type check the contents of untyped functions.

By default mypy doesn't type check the code within an untyped function.
This enables that and fixes typing errors to accomodate it.

This did uncover a very old bug:
https://github.com/dcs-liberation/dcs_liberation/issues/1417
This commit is contained in:
Dan Albert 2021-07-07 15:47:19 -07:00
parent 299ed88f09
commit fc32b98341
5 changed files with 15 additions and 20 deletions

View File

@ -323,7 +323,7 @@ class ControlPoint(MissionTarget, ABC):
self.target_position: Optional[Point] = None self.target_position: Optional[Point] = None
def __repr__(self): def __repr__(self):
return f"<{__class__}: {self.name}>" return f"<{self.__class__}: {self.name}>"
@property @property
def ground_objects(self) -> List[TheaterGroundObject]: def ground_objects(self) -> List[TheaterGroundObject]:

View File

@ -136,6 +136,7 @@ class GroundConflictGenerator:
position = Conflict.frontline_position( position = Conflict.frontline_position(
self.conflict.front_line, self.game.theater self.conflict.front_line, self.game.theater
) )
frontline_vector = Conflict.frontline_vector( frontline_vector = Conflict.frontline_vector(
self.conflict.front_line, self.game.theater self.conflict.front_line, self.game.theater
) )
@ -150,6 +151,13 @@ class GroundConflictGenerator:
self.enemy_planned_combat_groups, frontline_vector, False self.enemy_planned_combat_groups, frontline_vector, False
) )
# TODO: Differentiate AirConflict and GroundConflict classes.
if self.conflict.heading is None:
raise RuntimeError(
"Cannot generate ground units for non-ground conflict. Ground unit "
"conflicts cannot have the heading `None`."
)
# Plan combat actions for groups # Plan combat actions for groups
self.plan_action_for_groups( self.plan_action_for_groups(
self.player_stance, self.player_stance,
@ -174,7 +182,7 @@ class GroundConflictGenerator:
code = 1688 - len(self.jtacs) code = 1688 - len(self.jtacs)
utype = self.game.player_faction.jtac_unit utype = self.game.player_faction.jtac_unit
if self.game.player_faction.jtac_unit is None: if utype is None:
utype = AircraftType.named("MQ-9 Reaper") utype = AircraftType.named("MQ-9 Reaper")
jtac = self.mission.flight_group( jtac = self.mission.flight_group(

View File

@ -52,7 +52,6 @@ class CombatGroup:
self.unit_type = unit_type self.unit_type = unit_type
self.size = size self.size = size
self.role = role self.role = role
self.assigned_enemy_cp = None
self.start_position = None self.start_position = None
def __str__(self): def __str__(self):
@ -89,11 +88,9 @@ class GroundPlanner:
remaining_available_frontline_units = ground_unit_limit remaining_available_frontline_units = ground_unit_limit
if hasattr(self.cp, "stance"): # TODO: Fix to handle the per-front stances.
group_size_choice = GROUP_SIZES_BY_COMBAT_STANCE[self.cp.stance] # https://github.com/dcs-liberation/dcs_liberation/issues/1417
else: group_size_choice = GROUP_SIZES_BY_COMBAT_STANCE[CombatStance.DEFENSIVE]
self.cp.stance = CombatStance.DEFENSIVE
group_size_choice = GROUP_SIZES_BY_COMBAT_STANCE[CombatStance.DEFENSIVE]
# Create combat groups and assign them randomly to each enemy CP # Create combat groups and assign them randomly to each enemy CP
for unit_type in self.cp.base.armor: for unit_type in self.cp.base.armor:
@ -152,20 +149,9 @@ class GroundPlanner:
if len(self.connected_enemy_cp) > 0: if len(self.connected_enemy_cp) > 0:
enemy_cp = random.choice(self.connected_enemy_cp).id enemy_cp = random.choice(self.connected_enemy_cp).id
self.units_per_cp[enemy_cp].append(group) self.units_per_cp[enemy_cp].append(group)
group.assigned_enemy_cp = enemy_cp
else: else:
self.reserve.append(group) self.reserve.append(group)
group.assigned_enemy_cp = "__reserve__"
collection.append(group) collection.append(group)
if remaining_available_frontline_units == 0: if remaining_available_frontline_units == 0:
break break
print("------------------")
print("Ground Planner : ")
print(self.cp.name)
print("------------------")
for unit_type in self.units_per_cp.keys():
print("For : #" + str(unit_type))
for group in self.units_per_cp[unit_type]:
print(str(group))

View File

@ -637,6 +637,7 @@ class GroundObjectsGenerator:
).generate() ).generate()
for ground_object in cp.ground_objects: for ground_object in cp.ground_objects:
generator: GenericGroundObjectGenerator
if isinstance(ground_object, FactoryGroundObject): if isinstance(ground_object, FactoryGroundObject):
generator = FactoryGenerator( generator = FactoryGenerator(
ground_object, country, self.game, self.m, self.unit_map ground_object, country, self.game, self.m, self.unit_map

View File

@ -1,6 +1,6 @@
[mypy] [mypy]
# TODO: Cleanup so we can enable the checks commented out here. # TODO: Cleanup so we can enable the checks commented out here.
# check_untyped_defs = True check_untyped_defs = True
# disallow_any_decorated = True # disallow_any_decorated = True
# disallow_any_expr = True # disallow_any_expr = True
# disallow_any_generics = True # disallow_any_generics = True