Techdebt: add typing to AMIS (#6063)

This commit is contained in:
Oliver Mannion 2023-03-16 10:38:20 +11:00 committed by GitHub
parent 6da5855dcf
commit 30a3df58f7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 5 deletions

View File

@ -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"]

View File

@ -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: