1919from datetime import datetime , timedelta
2020from functools import partial
2121from pathlib import Path
22+ from typing import Any
2223
2324import websockets
2425import yaml
2829from .bundle import BundleHandler , get_charm_series , is_local_charm
2930from .charmhub import CharmHub
3031from .client import client , connector
32+ from .client .connection import Connection
3133from .client .overrides import Caveat , Macaroon
3234from .constraints import parse as parse_constraints
3335from .controller import ConnectedController , Controller
@@ -257,7 +259,9 @@ def get_entity(self, entity_type, entity_id, history_index=-1, connected=True):
257259class ModelEntity :
258260 """An object in the Model tree"""
259261
260- def __init__ (self , entity_id , model , history_index = - 1 , connected = True ):
262+ entity_id : str
263+
264+ def __init__ (self , entity_id : str , model : Model , history_index = - 1 , connected = True ):
261265 """Initialize a new entity
262266
263267 :param entity_id str: The unique id of the object in the model
@@ -279,7 +283,7 @@ def __init__(self, entity_id, model, history_index=-1, connected=True):
279283 def __repr__ (self ):
280284 return f'<{ type (self ).__name__ } entity_id="{ self .entity_id } ">'
281285
282- def __getattr__ (self , name ) :
286+ def __getattr__ (self , name : str ) -> Any :
283287 """Fetch object attributes from the underlying data dict held in the
284288 model.
285289
@@ -615,7 +619,7 @@ def is_connected(self):
615619 """Reports whether the Model is currently connected."""
616620 return self ._connector .is_connected ()
617621
618- def connection (self ):
622+ def connection (self ) -> Connection :
619623 """Return the current Connection object. It raises an exception
620624 if the Model is disconnected
621625 """
@@ -3227,16 +3231,16 @@ def make_archive(self, path):
32273231 zf .close ()
32283232 return path
32293233
3230- def _check_type (self , path ) :
3234+ def _check_type (self , path : str ) -> str :
32313235 """Check the path"""
3232- s = os .stat (str ( path ) )
3236+ s = os .stat (path )
32333237 if stat .S_ISDIR (s .st_mode ) or stat .S_ISREG (s .st_mode ):
32343238 return path
32353239 raise ValueError (
32363240 "Invalid Charm at %s %s" % (path , "Invalid file type for a charm" )
32373241 )
32383242
3239- def _check_link (self , path ) :
3243+ def _check_link (self , path : str ) -> None :
32403244 link_path = os .readlink (path )
32413245 if link_path [0 ] == "/" :
32423246 raise ValueError (
@@ -3249,7 +3253,9 @@ def _check_link(self, path):
32493253 "Invalid charm at %s %s" % (path , "Only internal symlinks are allowed" )
32503254 )
32513255
3252- def _write_symlink (self , zf , link_target , link_path ):
3256+ def _write_symlink (
3257+ self , zf : zipfile .ZipFile , link_target : str , link_path : str
3258+ ) -> None :
32533259 """Package symlinks with appropriate zipfile metadata."""
32543260 info = zipfile .ZipInfo ()
32553261 info .filename = link_path
@@ -3259,11 +3265,8 @@ def _write_symlink(self, zf, link_target, link_path):
32593265 info .external_attr = 2716663808
32603266 zf .writestr (info , link_target )
32613267
3262- def _ignore (self , path ):
3263- if path == "build" or path .startswith ("build/" ):
3264- return True
3265- if path .startswith ("." ):
3266- return True
3268+ def _ignore (self , path : str ) -> bool :
3269+ return path == "build" or path .startswith ("build/" ) or path .startswith ("." )
32673270
32683271
32693272class ModelInfo (ModelEntity ):
0 commit comments