Fix unreachable code issues, enable checking.

The loadout case actually could (and previously did) hide bugs from the
type checker, since mypy was smart enough to see that we were removing
None from the input it assumed that the member was non-optional, but
later modifications could cause null values, and since those came from
the UI mypy couldn't reason about this. This meant that mypy assumed the
type could not be optional and wouldn't check that case.

(cherry picked from commit 299ed88f09d506df1a10e5454b237263e5cbeeab)
This commit is contained in:
Dan Albert 2021-07-07 15:10:02 -07:00
parent f9c20d729b
commit 7015b3a40d
3 changed files with 7 additions and 7 deletions

View File

@ -219,11 +219,7 @@ class FlightPlan:
tot_waypoint = self.tot_waypoint
if tot_waypoint is None:
return None
time = self.tot
if time is None:
return None
return time - self._travel_time_to_waypoint(tot_waypoint)
return self.tot - self._travel_time_to_waypoint(tot_waypoint)
def startup_time(self) -> Optional[timedelta]:
takeoff_time = self.takeoff_time()

View File

@ -19,7 +19,11 @@ class Loadout:
is_custom: bool = False,
) -> None:
self.name = name
self.pylons = {k: v for k, v in pylons.items() if v is not None}
# We clear unused pylon entries on initialization, but UI actions can still
# cause a pylon to be emptied, so make the optional type explicit.
self.pylons: Mapping[int, Optional[Weapon]] = {
k: v for k, v in pylons.items() if v is not None
}
self.date = date
self.is_custom = is_custom

View File

@ -13,7 +13,7 @@ namespace_packages = True
no_implicit_optional = True
warn_redundant_casts = True
# warn_return_any = True
# warn_unreachable = True
warn_unreachable = True
warn_unused_ignores = True
[mypy-dcs.*]