diff --git a/moto/ec2/models/amis.py b/moto/ec2/models/amis.py index 432568e8a..8579d3c65 100644 --- a/moto/ec2/models/amis.py +++ b/moto/ec2/models/amis.py @@ -1,7 +1,7 @@ import json import re from os import environ -from typing import Any, Dict, List, Iterable, Optional, Set +from typing import Any, Dict, List, Iterable, Optional, Set, cast from moto.utilities.utils import load_resource from ..exceptions import ( InvalidAMIIdError, @@ -21,7 +21,7 @@ from ..utils import ( if "MOTO_AMIS_PATH" in environ: with open(environ["MOTO_AMIS_PATH"], "r", encoding="utf-8") as f: - AMIS = json.load(f) + AMIS: List[Dict[str, Any]] = json.load(f) else: AMIS = load_resource(__name__, "../resources/amis.json") @@ -161,8 +161,11 @@ class AmiBackend: if "MOTO_AMIS_PATH" not in environ: for path in ["latest_amis", "ecs/optimized_amis"]: try: - latest_amis = load_resource( - __name__, f"../resources/{path}/{self.region_name}.json" # type: ignore[attr-defined] + latest_amis = cast( + List[Dict[str, Any]], + load_resource( + __name__, f"../resources/{path}/{self.region_name}.json" # type: ignore[attr-defined] + ), ) for ami in latest_amis: ami_id = ami["ami_id"] diff --git a/moto/utilities/utils.py b/moto/utilities/utils.py index d415b57aa..971346c1d 100644 --- a/moto/utilities/utils.py +++ b/moto/utilities/utils.py @@ -14,7 +14,7 @@ def str2bool(v: Any) -> Optional[bool]: return None -def load_resource(package: str, resource: str) -> Dict[str, Any]: +def load_resource(package: str, resource: str) -> Any: """ Open a file, and return the contents as JSON. Usage: