Replace some isinstance calls with TypeGuard.

These aren't as ergonomic as I'd hoped because of
https://www.python.org/dev/peps/pep-0647/#narrowing-of-implicit-self-and-cls-parameters.

I added a decorator `@self_type_guard` so we can avoid needing to import
the descendent types in the typeguard implementation (which wouldn't fix
any circular imports, just move them).
This commit is contained in:
Dan Albert
2022-02-12 14:57:33 -08:00
parent 85e7b1762d
commit 2e901f3586
5 changed files with 57 additions and 7 deletions

View File

@@ -10,7 +10,6 @@ from game.ato import FlightType
from game.ato.flightstate import InFlight
from game.threatzones import ThreatPoly
from game.utils import Distance, Speed, dcs_to_shapely_point
from gen.flights.flightplan import PatrollingFlightPlan
if TYPE_CHECKING:
from game.ato.flight import Flight
@@ -19,7 +18,7 @@ if TYPE_CHECKING:
class RaceTrack(InFlight):
def __init__(self, flight: Flight, settings: Settings, waypoint_index: int) -> None:
assert isinstance(flight.flight_plan, PatrollingFlightPlan)
assert flight.flight_plan.is_patrol(flight.flight_plan)
self.patrol_duration = flight.flight_plan.patrol_duration
super().__init__(flight, settings, waypoint_index)
self.commit_region = LineString(