Skip to content

Commit e49324f

Browse files
authored
Add DictMixin to easy AML SDK classes (#26365)
* copy ADO branch changes into GH branch * sync with closed source comments * fix merge issues * continue to fix changelog file merge issues * move CL entry to correct section
1 parent 215e829 commit e49324f

File tree

5 files changed

+15
-4
lines changed

5 files changed

+15
-4
lines changed

sdk/ml/azure-ai-ml/CHANGELOG.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
## 0.2.0 (Unreleased)
44

55
### Features Added
6-
6+
- Most configuration classes from the entity package now implement the standard mapping protocol.
77
### Breaking Changes
88

99
### Bugs Fixed
@@ -15,7 +15,7 @@
1515
- Dropped support for Python 3.6. The Python versions supported for this release are 3.7-3.10.
1616

1717
### Features Added
18-
18+
1919
### Breaking Changes
2020
- OnlineDeploymentOperations.delete has been renamed to begin_delete.
2121
- Datastore credentials are switched to use unified credential configuration classes.

sdk/ml/azure-ai-ml/azure/ai/ml/entities/_compute/compute_instance.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
from azure.ai.ml.constants._common import BASE_PATH_CONTEXT_KEY, TYPE
2121
from azure.ai.ml.constants._compute import ComputeDefaults, ComputeType
2222
from azure.ai.ml.entities._compute.compute import Compute, NetworkSettings
23+
from azure.ai.ml.entities._mixins import DictMixin
2324
from azure.ai.ml.entities._util import load_from_dict
2425
from azure.ai.ml.exceptions import ErrorCategory, ErrorTarget, ValidationException
2526
from azure.ai.ml.entities._credentials import IdentityConfiguration
@@ -70,7 +71,7 @@ def ssh_port(self) -> str:
7071
return self._ssh_port
7172

7273

73-
class AssignedUserConfiguration:
74+
class AssignedUserConfiguration(DictMixin):
7475
"""Settings to create a compute on behalf of another user."""
7576

7677
def __init__(self, *, user_tenant_id: str, user_object_id: str):

sdk/ml/azure-ai-ml/azure/ai/ml/entities/_deployment/code_configuration.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,13 @@
66

77
from azure.ai.ml._restclient.v2021_10_01.models import CodeConfiguration as RestCodeConfiguration
88
from azure.ai.ml.entities._assets import Code
9+
from azure.ai.ml.entities._mixins import DictMixin
910
from azure.ai.ml.exceptions import ErrorCategory, ErrorTarget, ValidationException
1011

1112
module_logger = logging.getLogger(__name__)
1213

1314

14-
class CodeConfiguration:
15+
class CodeConfiguration(DictMixin):
1516
"""CodeConfiguration.
1617
1718
:param code: Code entity, defaults to None

sdk/ml/azure-ai-ml/azure/ai/ml/entities/_job/pipeline/_io.py

+3
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,9 @@ def _data_binding(self) -> str:
172172
"""Return data binding string representation for this input/output."""
173173
raise NotImplementedError()
174174

175+
# Why did we have this function? It prevents the DictMixin from being applied.
176+
# Unclear if we explicitly do NOT want the mapping protocol to be applied to this, or it this was just
177+
# confirmation that it didn't at the time.
175178
def keys(self):
176179
# This property is introduced to raise catchable Exception in marshmallow mapping validation trial.
177180
raise TypeError(f"'{type(self).__name__}' object is not a mapping")

sdk/ml/azure-ai-ml/azure/ai/ml/entities/_mixins.py

+6
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@ def _from_rest_object(cls, obj: Any) -> Any:
1717

1818

1919
class DictMixin(object):
20+
def __contains__(self, item):
21+
return self.__dict__.__contains__(item)
22+
23+
def __iter__(self):
24+
return self.__dict__.__iter__()
25+
2026
def __setitem__(self, key, item):
2127
# type: (Any, Any) -> None
2228
self.__dict__[key] = item

0 commit comments

Comments
 (0)