@autorest/python 6.4.8 → 6.4.10

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.
@@ -133,7 +133,7 @@ TYPE_TO_OBJECT = {
133
133
  "time": TimeType,
134
134
  "duration": DurationType,
135
135
  "date": DateType,
136
- "byte-array": ByteArraySchema,
136
+ "bytes": ByteArraySchema,
137
137
  "boolean": BooleanType,
138
138
  "combined": CombinedType,
139
139
  "OAuth2": TokenCredentialType,
@@ -205,7 +205,11 @@ class Client(_ClientConfigBase[ClientGlobalParameterList]):
205
205
  if gp.method_location == ParameterMethodLocation.KWARG:
206
206
  continue
207
207
  file_import.merge(
208
- gp.imports(async_mode, relative_path=".." if async_mode else ".")
208
+ gp.imports(
209
+ async_mode,
210
+ relative_path=".." if async_mode else ".",
211
+ operation=True,
212
+ )
209
213
  )
210
214
  file_import.add_submodule_import(
211
215
  "._configuration",
@@ -422,7 +426,9 @@ class Config(_ClientConfigBase[ConfigGlobalParameterList]):
422
426
  continue
423
427
  file_import.merge(
424
428
  gp.imports(
425
- async_mode=async_mode, relative_path=".." if async_mode else "."
429
+ async_mode=async_mode,
430
+ relative_path=".." if async_mode else ".",
431
+ operation=True,
426
432
  )
427
433
  )
428
434
  return file_import
@@ -438,7 +444,9 @@ class Config(_ClientConfigBase[ConfigGlobalParameterList]):
438
444
  continue
439
445
  file_import.merge(
440
446
  gp.imports_for_multiapi(
441
- async_mode=async_mode, relative_path=".." if async_mode else "."
447
+ async_mode=async_mode,
448
+ relative_path=".." if async_mode else ".",
449
+ operation=True,
442
450
  )
443
451
  )
444
452
  return file_import
@@ -173,13 +173,13 @@ class EnumType(BaseType):
173
173
  )
174
174
 
175
175
  def imports(self, **kwargs: Any) -> FileImport:
176
- is_operation_file = kwargs.pop("is_operation_file", False)
176
+ operation = kwargs.pop("operation", False)
177
177
  file_import = FileImport()
178
178
  if self.code_model.options["models_mode"]:
179
179
  file_import.add_submodule_import(
180
180
  "typing", "Union", ImportType.STDLIB, TypingSection.CONDITIONAL
181
181
  )
182
- if not is_operation_file:
182
+ if not operation:
183
183
  file_import.add_submodule_import(
184
184
  "..",
185
185
  "models",
@@ -187,9 +187,7 @@ class EnumType(BaseType):
187
187
  TypingSection.TYPING,
188
188
  alias="_models",
189
189
  )
190
- file_import.merge(
191
- self.value_type.imports(is_operation_file=is_operation_file, **kwargs)
192
- )
190
+ file_import.merge(self.value_type.imports(operation=operation, **kwargs))
193
191
  relative_path = kwargs.pop("relative_path", None)
194
192
  if self.code_model.options["models_mode"] and relative_path:
195
193
  # add import for enums in operations file
@@ -223,7 +223,9 @@ class OperationBase( # pylint: disable=too-many-public-methods
223
223
  )
224
224
 
225
225
  response_types = [
226
- r.type_annotation(async_mode=async_mode) for r in self.responses if r.type
226
+ r.type_annotation(async_mode=async_mode, operation=self)
227
+ for r in self.responses
228
+ if r.type
227
229
  ]
228
230
  if len(set(response_types)) > 1:
229
231
  file_import.add_submodule_import(
@@ -245,17 +247,22 @@ class OperationBase( # pylint: disable=too-many-public-methods
245
247
  file_import.merge(
246
248
  param.imports_for_multiapi(
247
249
  async_mode,
250
+ operation=self,
248
251
  **kwargs,
249
252
  )
250
253
  )
251
254
  for response in self.responses:
252
255
  file_import.merge(
253
- response.imports_for_multiapi(async_mode=async_mode, **kwargs)
256
+ response.imports_for_multiapi(
257
+ async_mode=async_mode, operation=self, **kwargs
258
+ )
254
259
  )
255
260
  if self.code_model.options["models_mode"]:
256
261
  for exception in self.exceptions:
257
262
  file_import.merge(
258
- exception.imports_for_multiapi(async_mode=async_mode, **kwargs)
263
+ exception.imports_for_multiapi(
264
+ async_mode=async_mode, operation=self, **kwargs
265
+ )
259
266
  )
260
267
  return file_import
261
268
 
@@ -323,17 +330,22 @@ class OperationBase( # pylint: disable=too-many-public-methods
323
330
  file_import.merge(
324
331
  param.imports(
325
332
  async_mode,
333
+ operation=self,
326
334
  **kwargs,
327
335
  )
328
336
  )
329
337
  for response in self.responses:
330
- file_import.merge(response.imports(async_mode=async_mode, **kwargs))
338
+ file_import.merge(
339
+ response.imports(async_mode=async_mode, operation=self, **kwargs)
340
+ )
331
341
  if self.code_model.options["models_mode"]:
332
342
  for exception in self.exceptions:
333
343
  file_import.merge(exception.imports(async_mode=async_mode, **kwargs))
334
344
 
335
345
  if self.parameters.has_body and self.parameters.body_parameter.flattened:
336
- file_import.merge(self.parameters.body_parameter.type.imports(**kwargs))
346
+ file_import.merge(
347
+ self.parameters.body_parameter.type.imports(operation=self, **kwargs)
348
+ )
337
349
 
338
350
  # Exceptions
339
351
  errors = [
@@ -182,11 +182,7 @@ class _ParameterBase(
182
182
  file_import = self._imports_shared(async_mode, **kwargs)
183
183
  # special logic for api-version parameter
184
184
  if not self.is_api_version:
185
- file_import.merge(
186
- self.type.imports(
187
- is_operation_file=True, async_mode=async_mode, **kwargs
188
- )
189
- )
185
+ file_import.merge(self.type.imports(async_mode=async_mode, **kwargs))
190
186
  if self.default_to_unset_sentinel:
191
187
  file_import.add_submodule_import("typing", "Any", ImportType.STDLIB)
192
188
  file_import.define_mypy_type(
@@ -198,9 +194,7 @@ class _ParameterBase(
198
194
  def imports_for_multiapi(self, async_mode: bool, **kwargs: Any) -> FileImport:
199
195
  file_import = self._imports_shared(async_mode, **kwargs)
200
196
  file_import.merge(
201
- self.type.imports_for_multiapi(
202
- is_operation_file=True, async_mode=async_mode, **kwargs
203
- )
197
+ self.type.imports_for_multiapi(async_mode=async_mode, **kwargs)
204
198
  )
205
199
  return file_import
206
200
 
@@ -105,13 +105,23 @@ class BinaryType(PrimitiveType):
105
105
  return self.get_declaration(b"bytes")
106
106
 
107
107
  def imports(self, **kwargs: Any) -> FileImport:
108
+ from .combined_type import CombinedType
109
+ from .operation import OperationBase
110
+
108
111
  file_import = FileImport()
109
112
  file_import.add_submodule_import("typing", "IO", ImportType.STDLIB)
113
+ operation = kwargs.get("operation")
114
+ if (
115
+ isinstance(operation, OperationBase)
116
+ and operation.parameters.has_body
117
+ and isinstance(operation.parameters.body_parameter.type, CombinedType)
118
+ ):
119
+ file_import.add_submodule_import("io", "IOBase", ImportType.STDLIB)
110
120
  return file_import
111
121
 
112
122
  @property
113
123
  def instance_check_template(self) -> str:
114
- return "isinstance({}, (IO, bytes))"
124
+ return "isinstance({}, (IOBase, bytes))"
115
125
 
116
126
 
117
127
  class BinaryIteratorType(PrimitiveType):
@@ -346,7 +356,7 @@ class StringType(PrimitiveType):
346
356
  class DatetimeType(PrimitiveType):
347
357
  def __init__(self, yaml_data: Dict[str, Any], code_model: "CodeModel") -> None:
348
358
  super().__init__(yaml_data=yaml_data, code_model=code_model)
349
- self.format = self.Formats(yaml_data["format"])
359
+ self.format = self.Formats(yaml_data.get("format", "date-time"))
350
360
 
351
361
  class Formats(str, Enum):
352
362
  datetime = "date-time"
@@ -578,7 +588,7 @@ class DurationType(PrimitiveType):
578
588
  class ByteArraySchema(PrimitiveType):
579
589
  def __init__(self, yaml_data: Dict[str, Any], code_model: "CodeModel") -> None:
580
590
  super().__init__(yaml_data=yaml_data, code_model=code_model)
581
- self.format = yaml_data["format"]
591
+ self.format = yaml_data.get("format", "bytes")
582
592
 
583
593
  @property
584
594
  def serialization_type(self) -> str:
@@ -130,9 +130,7 @@ class Property(BaseModel): # pylint: disable=too-many-instance-attributes
130
130
  return retval or None
131
131
 
132
132
  def imports(self, **kwargs) -> FileImport:
133
- file_import = self.type.imports(
134
- **kwargs, is_operation_file=False, relative_path="..", model_typing=True
135
- )
133
+ file_import = self.type.imports(**kwargs, relative_path="..", model_typing=True)
136
134
  if self.optional and self.client_default_value is None:
137
135
  file_import.add_submodule_import("typing", "Optional", ImportType.STDLIB)
138
136
  if self.code_model.options["models_mode"] == "dpg":
@@ -88,7 +88,9 @@ class RequestBuilderBase(BaseBuilder[ParameterListType]):
88
88
  return file_import
89
89
  for parameter in self.parameters.method:
90
90
  file_import.merge(
91
- parameter.imports(async_mode=False, relative_path=relative_path)
91
+ parameter.imports(
92
+ async_mode=False, relative_path=relative_path, operation=self
93
+ )
92
94
  )
93
95
 
94
96
  file_import.add_submodule_import(
@@ -103,7 +103,7 @@ class Response(BaseModel):
103
103
  def _imports_shared(self, **kwargs: Any) -> FileImport:
104
104
  file_import = FileImport()
105
105
  if self.type:
106
- file_import.merge(self.type.imports(is_operation_file=True, **kwargs))
106
+ file_import.merge(self.type.imports(**kwargs))
107
107
  if self.nullable:
108
108
  file_import.add_submodule_import("typing", "Optional", ImportType.STDLIB)
109
109
  if isinstance(self.type, CombinedType) and self.type.name:
@@ -20,7 +20,7 @@ import isodate
20
20
  from azure.core.exceptions import DeserializationError
21
21
  from azure.core import CaseInsensitiveEnumMeta
22
22
  from azure.core.pipeline import PipelineResponse
23
- from azure.core.serialization import NULL as AzureCoreNull
23
+ from azure.core.serialization import _Null # pylint: disable=protected-access
24
24
 
25
25
  if sys.version_info >= (3, 9):
26
26
  from collections.abc import MutableMapping
@@ -29,24 +29,9 @@ else:
29
29
 
30
30
  _LOGGER = logging.getLogger(__name__)
31
31
 
32
- __all__ = ["NULL", "AzureJSONEncoder", "Model", "rest_field", "rest_discriminator"]
32
+ __all__ = ["AzureJSONEncoder", "Model", "rest_field", "rest_discriminator"]
33
33
 
34
34
 
35
- class _Null(object):
36
- """To create a Falsy object"""
37
-
38
- def __bool__(self):
39
- return False
40
-
41
- __nonzero__ = __bool__ # Python2 compatibility
42
-
43
-
44
- NULL = _Null()
45
- """
46
- A falsy sentinel object which is supposed to be used to specify attributes
47
- with no data. This gets serialized to `null` on the wire.
48
- """
49
-
50
35
  TZ_UTC = timezone.utc
51
36
 
52
37
  def _timedelta_as_isostr(td: timedelta) -> str:
@@ -162,7 +147,7 @@ class AzureJSONEncoder(JSONEncoder):
162
147
  return {k: v for k, v in o.items() if k not in readonly_props}
163
148
  if isinstance(o, (bytes, bytearray)):
164
149
  return base64.b64encode(o).decode()
165
- if o is AzureCoreNull:
150
+ if isinstance(o, _Null):
166
151
  return None
167
152
  try:
168
153
  return super(AzureJSONEncoder, self).default(o)
@@ -234,7 +234,7 @@ def update_primitive( # pylint: disable=too-many-return-statements
234
234
  base["format"] = yaml_data["format"]
235
235
  return base
236
236
  if type_group == "byte-array":
237
- base = _update_type_base("byte-array", yaml_data)
237
+ base = _update_type_base("bytes", yaml_data)
238
238
  base["format"] = yaml_data["format"]
239
239
  return base
240
240
  return _update_type_base(type_group, yaml_data)
@@ -220,7 +220,7 @@ class PreProcessPlugin(YamlUpdatePlugin): # pylint: disable=abstract-method
220
220
  if type.get("name"):
221
221
  type["name"] = self.pad_reserved_words(type["name"], PadType.MODEL)
222
222
  type["description"] = update_description(
223
- type["description"], type["name"]
223
+ type.get("description", ""), type["name"]
224
224
  )
225
225
  type["snakeCaseName"] = to_snake_case(type["name"])
226
226
  if type.get("values") and not self.version_tolerant:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@autorest/python",
3
- "version": "6.4.8",
3
+ "version": "6.4.10",
4
4
  "description": "The Python extension for generators in AutoRest.",
5
5
  "main": "index.js",
6
6
  "repository": {