Skip to content

Commit 678e790

Browse files
ViicosArk-kun
authored andcommitted
feat: Use TypeAliasType to define aliases
1 parent 598c931 commit 678e790

File tree

2 files changed

+39
-24
lines changed

2 files changed

+39
-24
lines changed

setup.py

+1
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@
123123

124124
genai_requires = (
125125
"pydantic < 3",
126+
"typing_extensions > 4.6.0",
126127
"docstring_parser < 1",
127128
)
128129

vertexai/generative_models/_generative_models.py

+38-24
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
overload,
3939
TYPE_CHECKING,
4040
)
41+
from typing_extensions import TypeAliasType
4142

4243
from google.cloud.aiplatform import initializer as aiplatform_initializer
4344
from google.cloud.aiplatform import utils as aiplatform_utils
@@ -85,36 +86,49 @@
8586

8687

8788
# These type defnitions are expanded to help the user see all the types
88-
PartsType = Union[
89-
str,
90-
"Image",
91-
"Part",
92-
List[Union[str, "Image", "Part"]],
93-
]
89+
PartsType = TypeAliasType(
90+
"PartsType",
91+
Union[
92+
str,
93+
"Image",
94+
"Part",
95+
List[Union[str, "Image", "Part"]],
96+
],
97+
)
98+
9499

95100
ContentDict = Dict[str, Any]
96-
ContentsType = Union[
97-
List["Content"],
98-
List[ContentDict],
99-
str,
100-
"Image",
101-
"Part",
102-
List[Union[str, "Image", "Part"]],
103-
]
101+
ContentsType = TypeAliasType(
102+
"ContentsType",
103+
Union[
104+
List["Content"],
105+
List[ContentDict],
106+
str,
107+
"Image",
108+
"Part",
109+
List[Union[str, "Image", "Part"]],
110+
],
111+
)
104112

105113
GenerationConfigDict = Dict[str, Any]
106-
GenerationConfigType = Union[
107-
"GenerationConfig",
108-
GenerationConfigDict,
109-
]
114+
GenerationConfigType = TypeAliasType(
115+
"GenerationConfigType",
116+
Union[
117+
"GenerationConfig",
118+
GenerationConfigDict,
119+
],
120+
)
110121

111-
SafetySettingsType = Union[
112-
List["SafetySetting"],
113-
Dict[
114-
gapic_content_types.HarmCategory,
115-
gapic_content_types.SafetySetting.HarmBlockThreshold,
122+
SafetySettingsType = TypeAliasType(
123+
"SafetySettingsType",
124+
Union[
125+
List["SafetySetting"],
126+
Dict[
127+
gapic_content_types.HarmCategory,
128+
gapic_content_types.SafetySetting.HarmBlockThreshold,
129+
],
116130
],
117-
]
131+
)
118132

119133

120134
def _reconcile_model_name(model_name: str, project: str, location: str) -> str:

0 commit comments

Comments
 (0)