1919from datetime import datetime , timedelta
2020from functools import partial
2121from pathlib import Path
22- from typing import Any
22+ from typing import TYPE_CHECKING , Any , Literal , Mapping , overload
2323
2424import websockets
2525import yaml
5858from .url import URL , Schema
5959from .version import DEFAULT_ARCHITECTURE
6060
61+ if TYPE_CHECKING :
62+ from .application import Application
63+ from .machine import Machine
64+ from .relation import Relation
65+ from .remoteapplication import ApplicationOffer , RemoteApplication
66+ from .unit import Unit
67+
6168log = logging .getLogger (__name__ )
6269
6370
@@ -134,7 +141,35 @@ def __init__(self, model):
134141 self .model = model
135142 self .state = dict ()
136143
137- def _live_entity_map (self , entity_type ):
144+ @overload
145+ def _live_entity_map (
146+ self , entity_type : Literal ["application" ]
147+ ) -> dict [str , Application ]: ...
148+
149+ @overload
150+ def _live_entity_map (
151+ self , entity_type : Literal ["applicationOffer" ]
152+ ) -> dict [str , ApplicationOffer ]: ...
153+
154+ @overload
155+ def _live_entity_map (
156+ self , entity_type : Literal ["machine" ]
157+ ) -> dict [str , Machine ]: ...
158+
159+ @overload
160+ def _live_entity_map (
161+ self , entity_type : Literal ["relation" ]
162+ ) -> dict [str , Relation ]: ...
163+
164+ @overload
165+ def _live_entity_map (
166+ self , entity_type : Literal ["remoteApplication" ]
167+ ) -> dict [str , RemoteApplication ]: ...
168+
169+ @overload
170+ def _live_entity_map (self , entity_type : Literal ["unit" ]) -> dict [str , Unit ]: ...
171+
172+ def _live_entity_map (self , entity_type : str ) -> Mapping [str , ModelEntity ]:
138173 """Return an id:Entity map of all the living entities of
139174 type ``entity_type``.
140175
@@ -146,51 +181,51 @@ def _live_entity_map(self, entity_type):
146181 }
147182
148183 @property
149- def applications (self ):
184+ def applications (self ) -> dict [ str , Application ] :
150185 """Return a map of application-name:Application for all applications
151186 currently in the model.
152187
153188 """
154189 return self ._live_entity_map ("application" )
155190
156191 @property
157- def remote_applications (self ):
192+ def remote_applications (self ) -> dict [ str , RemoteApplication ] :
158193 """Return a map of application-name:Application for all remote
159194 applications currently in the model.
160195
161196 """
162197 return self ._live_entity_map ("remoteApplication" )
163198
164199 @property
165- def application_offers (self ):
200+ def application_offers (self ) -> dict [ str , ApplicationOffer ] :
166201 """Return a map of application-name:Application for all applications
167202 offers currently in the model.
168203 """
169204 return self ._live_entity_map ("applicationOffer" )
170205
171206 @property
172- def machines (self ):
207+ def machines (self ) -> dict [ str , Machine ] :
173208 """Return a map of machine-id:Machine for all machines currently in
174209 the model.
175210
176211 """
177212 return self ._live_entity_map ("machine" )
178213
179214 @property
180- def units (self ):
215+ def units (self ) -> dict [ str , Unit ] :
181216 """Return a map of unit-id:Unit for all units currently in
182217 the model.
183218
184219 """
185220 return self ._live_entity_map ("unit" )
186221
187222 @property
188- def subordinate_units (self ):
223+ def subordinate_units (self ) -> dict [ str , Unit ] :
189224 """Return a map of unit-id:Unit for all subordinate units"""
190225 return {u_name : u for u_name , u in self .units .items () if u .is_subordinate }
191226
192227 @property
193- def relations (self ):
228+ def relations (self ) -> dict [ str , Relation ] :
194229 """Return a map of relation-id:Relation for all relations currently in
195230 the model.
196231
@@ -1110,54 +1145,54 @@ def tag(self):
11101145 return tag .model (self .uuid )
11111146
11121147 @property
1113- def applications (self ):
1148+ def applications (self ) -> dict [ str , Application ] :
11141149 """Return a map of application-name:Application for all applications
11151150 currently in the model.
11161151
11171152 """
11181153 return self .state .applications
11191154
11201155 @property
1121- def remote_applications (self ):
1156+ def remote_applications (self ) -> dict [ str , RemoteApplication ] :
11221157 """Return a map of application-name:Application for all remote
11231158 applications currently in the model.
11241159
11251160 """
11261161 return self .state .remote_applications
11271162
11281163 @property
1129- def application_offers (self ):
1164+ def application_offers (self ) -> dict [ str , ApplicationOffer ] :
11301165 """Return a map of application-name:Application for all applications
11311166 offers currently in the model.
11321167 """
11331168 return self .state .application_offers
11341169
11351170 @property
1136- def machines (self ):
1171+ def machines (self ) -> dict [ str , Machine ] :
11371172 """Return a map of machine-id:Machine for all machines currently in
11381173 the model.
11391174
11401175 """
11411176 return self .state .machines
11421177
11431178 @property
1144- def units (self ):
1179+ def units (self ) -> dict [ str , Unit ] :
11451180 """Return a map of unit-id:Unit for all units currently in
11461181 the model.
11471182
11481183 """
11491184 return self .state .units
11501185
11511186 @property
1152- def subordinate_units (self ):
1187+ def subordinate_units (self ) -> dict [ str , Unit ] :
11531188 """Return a map of unit-id:Unit for all subordiante units currently in
11541189 the model.
11551190
11561191 """
11571192 return self .state .subordinate_units
11581193
11591194 @property
1160- def relations (self ):
1195+ def relations (self ) -> list [ Relation ] :
11611196 """Return a list of all Relations currently in the model."""
11621197 return list (self .state .relations .values ())
11631198
0 commit comments