From 837d4e8592c53375c7d9aa6df8b134c23cdeb487 Mon Sep 17 00:00:00 2001 From: kdestin <101366538+kdestin@users.noreply.github.com> Date: Tue, 9 Jul 2024 21:05:48 -0400 Subject: [PATCH] fix: Resolve `azd` crash when using the `ai.endpoint` service host with Python 3.8 (#4092) * fix: Use typing.List instead of subscripting list Support for using builtin types as generics (i.e. `list[int]` or `dict[str, str]`) was only added in Python 3.9. Before this commit, running `ml_client.py` on Python3.8 would crash azd. See PEP 385: https://peps.python.org/pep-0585/ * style: Run isort on ml_client.py --- cli/azd/resources/ai-python/ml_client.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/cli/azd/resources/ai-python/ml_client.py b/cli/azd/resources/ai-python/ml_client.py index 35fdd600e8b..b7629c3d318 100644 --- a/cli/azd/resources/ai-python/ml_client.py +++ b/cli/azd/resources/ai-python/ml_client.py @@ -2,22 +2,25 @@ # coding: utf-8 import argparse +from typing import List + +from azure.ai.ml import MLClient, load_environment, load_model, load_online_deployment, load_online_endpoint from azure.identity import AzureDeveloperCliCredential -from azure.ai.ml import MLClient, load_environment, load_model, load_online_endpoint, load_online_deployment -def create_or_update_environment(client: MLClient, file_path: str, overrides: list[dict]): + +def create_or_update_environment(client: MLClient, file_path: str, overrides: List[dict]): environment = load_environment(source=file_path, params_override=overrides) client.environments.create_or_update(environment) -def create_or_update_model(client: MLClient, file_path: str, overrides: list[dict]): +def create_or_update_model(client: MLClient, file_path: str, overrides: List[dict]): model = load_model(source=file_path, params_override=overrides) client.models.create_or_update(model) -def create_or_update_online_endpoint(client: MLClient, file_path: str, overrides: list[dict]): +def create_or_update_online_endpoint(client: MLClient, file_path: str, overrides: List[dict]): online_endpoint = load_online_endpoint(source=file_path, params_override=overrides) client.online_endpoints.begin_create_or_update(online_endpoint) -def create_or_update_online_deployment(client: MLClient, file_path: str, overrides: list[dict]): +def create_or_update_online_deployment(client: MLClient, file_path: str, overrides: List[dict]): deployment = load_online_deployment(source=file_path, params_override=overrides) client.online_deployments.begin_create_or_update(deployment)