@@ -169,38 +169,43 @@ def __attrs_post_init__(self) -> None:
169
169
self , "has_properties_without_templates" , any (prop .template is None for prop in self .inner_properties )
170
170
)
171
171
172
- def _get_inner_prop_string (self , json : bool = False ) -> str :
172
+ def _get_inner_type_strings (self , json : bool = False ) -> List [ str ] :
173
173
inner_types = [p .get_type_string (no_optional = True , json = json ) for p in self .inner_properties ]
174
174
unique_inner_types = list (dict .fromkeys (inner_types ))
175
- return ", " . join ( unique_inner_types )
175
+ return unique_inner_types
176
176
177
177
def get_base_type_string (self , json : bool = False ) -> str :
178
- return f"Union[{ self ._get_inner_prop_string (json = json )} ]"
178
+ return f"Union[{ ', ' . join ( self ._get_inner_type_strings (json = json ) )} ]"
179
179
180
- def get_type_string (self , no_optional : bool = False , query_parameter : bool = False , json : bool = False ) -> str :
181
- """
182
- Get a string representation of type that should be used when declaring this property.
183
-
184
- This implementation differs slightly from `Property.get_type_string` in order to collapse
185
- nested union types.
186
- """
187
- type_string = self .get_base_type_string (json = json )
180
+ def get_type_strings_in_union (self , no_optional : bool = False , query_parameter : bool = False , json : bool = False ) -> List [str ]:
181
+ type_strings = self ._get_inner_type_strings (json = json )
188
182
if no_optional :
189
- return type_string
183
+ return type_strings
190
184
if self .required :
191
185
if self .nullable :
192
- return f"Union[ None, { self . _get_inner_prop_string ( json = json ) } ]"
186
+ return [ " None" ] + type_strings
193
187
else :
194
- return type_string
188
+ return type_strings
195
189
else :
196
190
if self .nullable :
197
- return f"Union[ Unset, None, { self . _get_inner_prop_string ( json = json ) } ]"
191
+ return [ " Unset" , " None" ] + type_strings
198
192
else :
199
193
if query_parameter :
200
194
# For query parameters, None has the same meaning as Unset
201
- return f"Union[ Unset, None, { self . _get_inner_prop_string ( json = json ) } ]"
195
+ return [ " Unset" , " None" ] + type_strings
202
196
else :
203
- return f"Union[Unset, { self ._get_inner_prop_string (json = json )} ]"
197
+ return ["Unset" ] + type_strings
198
+
199
+ def get_type_string (self , no_optional : bool = False , query_parameter : bool = False , json : bool = False ) -> str :
200
+ """
201
+ Get a string representation of type that should be used when declaring this property.
202
+
203
+ This implementation differs slightly from `Property.get_type_string` in order to collapse
204
+ nested union types.
205
+ """
206
+ return (
207
+ f"Union[{ ', ' .join (self .get_type_strings_in_union (no_optional = no_optional , query_parameter = query_parameter , json = json ))} ]"
208
+ )
204
209
205
210
def get_imports (self , * , prefix : str ) -> Set [str ]:
206
211
"""
0 commit comments