@autorest/python 6.13.4 → 6.13.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -33,7 +33,7 @@ class PrimitiveType(BaseType): # pylint: disable=abstract-method
|
|
|
33
33
|
return self.docstring_type(**kwargs)
|
|
34
34
|
|
|
35
35
|
def docstring_text(self, **kwargs: Any) -> str:
|
|
36
|
-
return self.docstring_type()
|
|
36
|
+
return self.docstring_type(**kwargs)
|
|
37
37
|
|
|
38
38
|
def get_json_template_representation(
|
|
39
39
|
self,
|
|
@@ -125,35 +125,36 @@ class BinaryType(PrimitiveType):
|
|
|
125
125
|
|
|
126
126
|
|
|
127
127
|
class BinaryIteratorType(PrimitiveType):
|
|
128
|
-
|
|
128
|
+
def _iterator_name(self, **kwargs: Any) -> str:
|
|
129
|
+
return "AsyncIterator" if kwargs.pop("async_mode") else "Iterator"
|
|
129
130
|
|
|
130
131
|
@property
|
|
131
132
|
def serialization_type(self) -> str:
|
|
132
133
|
return "IO"
|
|
133
134
|
|
|
134
135
|
def docstring_type(self, **kwargs: Any) -> str:
|
|
135
|
-
return "
|
|
136
|
+
return f"{self._iterator_name(**kwargs)}[bytes]"
|
|
136
137
|
|
|
137
138
|
def type_annotation(self, **kwargs: Any) -> str:
|
|
138
|
-
return self.
|
|
139
|
+
return f"{self._iterator_name(**kwargs)}[bytes]"
|
|
139
140
|
|
|
140
141
|
def docstring_text(self, **kwargs: Any) -> str:
|
|
141
|
-
|
|
142
|
-
return f"{iterator} of the response bytes"
|
|
142
|
+
return f"{self._iterator_name(**kwargs)}[bytes]"
|
|
143
143
|
|
|
144
144
|
@property
|
|
145
145
|
def default_template_representation_declaration(self) -> str:
|
|
146
|
-
return self.get_declaration("
|
|
146
|
+
return self.get_declaration(b"bytes")
|
|
147
147
|
|
|
148
148
|
def imports(self, **kwargs: Any) -> FileImport:
|
|
149
149
|
file_import = FileImport(self.code_model)
|
|
150
|
-
|
|
151
|
-
|
|
150
|
+
file_import.add_submodule_import(
|
|
151
|
+
"typing", self._iterator_name(**kwargs), ImportType.STDLIB
|
|
152
|
+
)
|
|
152
153
|
return file_import
|
|
153
154
|
|
|
154
155
|
@property
|
|
155
156
|
def instance_check_template(self) -> str:
|
|
156
|
-
return "
|
|
157
|
+
return "getattr({}, '__aiter__', None) is not None or getattr({}, '__iter__', None) is not None"
|
|
157
158
|
|
|
158
159
|
|
|
159
160
|
class AnyType(PrimitiveType):
|
|
@@ -155,7 +155,11 @@ class Response(BaseModel):
|
|
|
155
155
|
else None
|
|
156
156
|
)
|
|
157
157
|
# use ByteIteratorType if we are returning a binary type
|
|
158
|
-
|
|
158
|
+
default_content_type = yaml_data.get("defaultContentType", "application/json")
|
|
159
|
+
if isinstance(type, BinaryType) or (
|
|
160
|
+
isinstance(type, ByteArraySchema)
|
|
161
|
+
and default_content_type != "application/json"
|
|
162
|
+
):
|
|
159
163
|
type = BinaryIteratorType(type.yaml_data, type.code_model)
|
|
160
164
|
return cls(
|
|
161
165
|
yaml_data=yaml_data,
|
|
@@ -361,7 +361,9 @@ class _BuilderBaseSerializer(Generic[BuilderType]): # pylint: disable=abstract-
|
|
|
361
361
|
"\n"
|
|
362
362
|
)
|
|
363
363
|
)
|
|
364
|
-
docstring_type = param.docstring_type(
|
|
364
|
+
docstring_type = param.docstring_type(
|
|
365
|
+
async_mode=self.async_mode,
|
|
366
|
+
)
|
|
365
367
|
description_list.append(
|
|
366
368
|
f":{param.docstring_type_keyword} {param.client_name}: {docstring_type}"
|
|
367
369
|
)
|
|
@@ -1112,12 +1114,12 @@ class _OperationSerializer(
|
|
|
1112
1114
|
if response.headers:
|
|
1113
1115
|
retval.append("")
|
|
1114
1116
|
deserialize_code: List[str] = []
|
|
1115
|
-
|
|
1117
|
+
stream_logic = True
|
|
1116
1118
|
if builder.has_stream_response:
|
|
1117
1119
|
if isinstance(response.type, ByteArraySchema):
|
|
1118
1120
|
deserialized = f"{'await ' if self.async_mode else ''}response.read()"
|
|
1119
1121
|
else:
|
|
1120
|
-
|
|
1122
|
+
stream_logic = False
|
|
1121
1123
|
if self.code_model.options["version_tolerant"]:
|
|
1122
1124
|
deserialized = "response.iter_bytes()"
|
|
1123
1125
|
else:
|
|
@@ -1171,7 +1173,7 @@ class _OperationSerializer(
|
|
|
1171
1173
|
deserialize_code.append("else:")
|
|
1172
1174
|
deserialize_code.append(" deserialized = None")
|
|
1173
1175
|
if len(deserialize_code) > 0:
|
|
1174
|
-
if builder.expose_stream_keyword and
|
|
1176
|
+
if builder.expose_stream_keyword and stream_logic:
|
|
1175
1177
|
retval.append("if _stream:")
|
|
1176
1178
|
retval.append(" deserialized = response.iter_bytes()")
|
|
1177
1179
|
retval.append("else:")
|