From 299ed88f09d506df1a10e5454b237263e5cbeeab Mon Sep 17 00:00:00 2001 From: Dan Albert Date: Wed, 7 Jul 2021 15:10:02 -0700 Subject: [PATCH] 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. --- gen/flights/flightplan.py | 6 +----- gen/flights/loadouts.py | 6 +++++- mypy.ini | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/gen/flights/flightplan.py b/gen/flights/flightplan.py index 80a7f6e1..07498342 100644 --- a/gen/flights/flightplan.py +++ b/gen/flights/flightplan.py @@ -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() diff --git a/gen/flights/loadouts.py b/gen/flights/loadouts.py index 5906315e..8b34f9ef 100644 --- a/gen/flights/loadouts.py +++ b/gen/flights/loadouts.py @@ -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 diff --git a/mypy.ini b/mypy.ini index b63df6a9..f4888eca 100644 --- a/mypy.ini +++ b/mypy.ini @@ -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.*]