-
Notifications
You must be signed in to change notification settings - Fork 129
Expand file tree
/
Copy pathbase.py
More file actions
32 lines (26 loc) · 1.07 KB
/
base.py
File metadata and controls
32 lines (26 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
from abc import ABC
from databricks_cli.sdk import ApiClient
from pydantic.v1 import BaseModel
from dbx.models.workflow.common.flexible import FlexibleModel
class ApiClientMixin(ABC):
def __init__(self, api_client: ApiClient):
self.api_client = api_client
class ElementSetterMixin:
@classmethod
def set_element_at_parent(cls, element, parent, index) -> None:
"""
Sets the element value for various types of parent
:param element: New element value
:param parent: A nested structure where element should be placed
:param index: Position (or pointer) where element should be provided
:return: None
"""
if isinstance(parent, (dict, list)):
parent[index] = element
elif isinstance(parent, (BaseModel, FlexibleModel)):
setattr(parent, index, element)
else:
raise ValueError(
"Cannot apply reference to the parent structure."
f"Please create a GitHub issue providing the following parent object type: {type(parent)}"
)