Adjusted "cargo shipping" example (singledispatch uses typing annotation).
Needed to stop using 'from __future__ import annotations' so that annotations
are actual types when registering methods. Hence need to use '"Cargo"'.
-from __future__ import annotations
-
from datetime import datetime, timedelta
from enum import Enum
from typing import Dict, List, Optional, Tuple, Union, cast
@@ -190,7 +188,7 @@ class Cargo(Aggregate):
origin: Location,
destination: Location,
arrival_deadline: datetime,
- ) -> Cargo:
+ ) -> "Cargo":
return cls._create(
event_class=cls.BookingStarted,
id=uuid4(),
@@ -223,7 +221,7 @@ class Cargo(Aggregate):
class DestinationChanged(Event):
destination: Location
- @when.register(DestinationChanged)
+ @when.register
def destination_changed(self, event: DestinationChanged) -> None:
self._destination = event.destination
@@ -233,7 +231,7 @@ class Cargo(Aggregate):
class RouteAssigned(Event):
route: Itinerary
- @when.register(RouteAssigned)
+ @when.register
def route_assigned(self, event: RouteAssigned) -> None:
self._route = event.route
self._routing_status = "ROUTED"
@@ -264,7 +262,7 @@ class Cargo(Aggregate):
location: Location
handling_activity: str
- @when.register(HandlingEventRegistered)
+ @when.register
def handling_event_registered(self, event: HandlingEventRegistered) -> None:
assert self.route is not None
if event.handling_activity == HandlingActivity.RECEIVE:
