@autorest/python 6.39.0 → 6.40.0

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.
@@ -69,9 +69,9 @@ class BlackScriptPlugin(Plugin):
69
69
  pylint_disables.append("too-many-lines")
70
70
  if pylint_disables:
71
71
  file_content = (
72
- "\n".join([lines[0] + ",".join([""] + pylint_disables)] + lines[1:])
72
+ os.linesep.join([lines[0] + ",".join([""] + pylint_disables)] + lines[1:])
73
73
  if "pylint: disable=" in lines[0]
74
- else f"# pylint: disable={','.join(pylint_disables)}\n" + file_content
74
+ else f"# pylint: disable={','.join(pylint_disables)}{os.linesep}" + file_content
75
75
  )
76
76
  self.write_file(file, file_content)
77
77
 
@@ -484,3 +484,7 @@ class CodeModel: # pylint: disable=too-many-public-methods, disable=too-many-in
484
484
 
485
485
  # No generation-subdir specified, use the namespace path directly
486
486
  return Path(*namespace.split("."))
487
+
488
+ @property
489
+ def has_operation_named_list(self) -> bool:
490
+ return any(o.name.lower() == "list" for c in self.clients for og in c.operation_groups for o in og.operations)
@@ -40,13 +40,9 @@ class ListType(BaseType):
40
40
  ):
41
41
  # this means we're version tolerant XML, we just return the XML element
42
42
  return self.element_type.type_annotation(**kwargs)
43
- has_operation_named_list = any(
44
- o.name.lower() == "list"
45
- for c in self.code_model.clients
46
- for og in c.operation_groups
47
- for o in og.operations
48
- )
49
- list_type = "List" if has_operation_named_list and kwargs.get("is_operation_file") else "list"
43
+
44
+ # if there is a function named `list` we have to make sure there's no conflict with the built-in `list`
45
+ list_type = "List" if self.code_model.has_operation_named_list and kwargs.get("is_operation_file") else "list"
50
46
  return f"{list_type}[{self.element_type.type_annotation(**kwargs)}]"
51
47
 
52
48
  def description(self, *, is_operation_file: bool) -> str:
@@ -404,10 +404,6 @@ class OperationBase( # pylint: disable=too-many-public-methods,too-many-instanc
404
404
  file_import.merge(self.get_request_builder_import(self.request_builder, async_mode, serialize_namespace))
405
405
  if self.overloads:
406
406
  file_import.add_submodule_import("typing", "overload", ImportType.STDLIB)
407
- if self.name == "list":
408
- # if there is a function named `list` we have to make sure there's no conflict with the built-in `list`
409
- # not doing for dict or set yet, though we might have to later
410
- file_import.define_mypy_type("List", "list")
411
407
  if self.code_model.options["models-mode"] == "dpg":
412
408
  relative_path = self.code_model.get_relative_import_path(
413
409
  serialize_namespace, module_name="_utils.model_base"
@@ -158,6 +158,16 @@ class MsrestModelSerializer(_ModelSerializer):
158
158
  called_by_property=True,
159
159
  )
160
160
  )
161
+ for prop in model.properties:
162
+ if prop.readonly:
163
+ # it will be defined in the __init__ so we need to import it
164
+ file_import.merge(
165
+ prop.imports(
166
+ serialize_namespace=self.serialize_namespace,
167
+ serialize_namespace_type=NamespaceType.MODEL,
168
+ called_by_property=True,
169
+ )
170
+ )
161
171
 
162
172
  return file_import
163
173
 
@@ -224,7 +234,16 @@ class DpgModelSerializer(_ModelSerializer):
224
234
  "for k, v in _flattened_input.items():",
225
235
  " setattr(self, k, v)",
226
236
  ]
227
- return [super_call]
237
+ discriminator_value_setter = []
238
+ for prop in self.get_properties_to_declare(model):
239
+ if (
240
+ prop.is_discriminator
241
+ and isinstance(prop.type, (ConstantType, EnumValue))
242
+ and prop.type.value is not None
243
+ ):
244
+ discriminator_value_setter.append(f"self.{prop.client_name}={prop.get_declaration()} # type: ignore")
245
+
246
+ return [super_call, *discriminator_value_setter]
228
247
 
229
248
  def imports(self) -> FileImport:
230
249
  file_import = FileImport(self.code_model)
@@ -343,17 +362,7 @@ class DpgModelSerializer(_ModelSerializer):
343
362
 
344
363
  @staticmethod
345
364
  def properties_to_pass_to_super(model: ModelType) -> str:
346
- properties_to_pass_to_super = ["*args"]
347
- for parent in model.parents:
348
- for prop in model.properties:
349
- if (
350
- prop.client_name in [prop.client_name for prop in parent.properties if prop.is_base_discriminator]
351
- and prop.is_discriminator
352
- and not prop.constant
353
- and not prop.readonly
354
- ):
355
- properties_to_pass_to_super.append(f"{prop.client_name}={prop.get_declaration()}")
356
- properties_to_pass_to_super.append("**kwargs")
365
+ properties_to_pass_to_super = ["*args", "**kwargs"]
357
366
  return ", ".join(properties_to_pass_to_super)
358
367
 
359
368
  def global_pylint_disables(self) -> str:
@@ -66,6 +66,11 @@ class OperationGroupsSerializer(BaseSerializer):
66
66
  serialize_namespace_type=NamespaceType.OPERATION,
67
67
  )
68
68
  )
69
+ # put here since one operation file only need one self-defined list type
70
+ if self.code_model.has_operation_named_list:
71
+ # if there is a function named `list` we have to make sure there's no conflict with the built-in `list`
72
+ # not doing for dict or set yet, though we might have to later
73
+ imports.define_mypy_type("List", "list")
69
74
 
70
75
  template = self.env.get_or_select_template("operation_groups_container.py.jinja2")
71
76
 
@@ -43,7 +43,7 @@ dependencies = [
43
43
  {% else %}
44
44
  "isodate>={{ VERSION_MAP['isodate'] }}",
45
45
  {% endif %}
46
- {% if options.get('azure_arm') %}
46
+ {% if options.get('azure-arm') %}
47
47
  "azure-mgmt-core>={{ VERSION_MAP['azure-mgmt-core'] }}",
48
48
  {% elif code_model.is_azure_flavor %}
49
49
  "azure-core>={{ VERSION_MAP['azure-core'] }}",
@@ -69,9 +69,9 @@ class BlackScriptPlugin(Plugin):
69
69
  pylint_disables.append("too-many-lines")
70
70
  if pylint_disables:
71
71
  file_content = (
72
- "\n".join([lines[0] + ",".join([""] + pylint_disables)] + lines[1:])
72
+ os.linesep.join([lines[0] + ",".join([""] + pylint_disables)] + lines[1:])
73
73
  if "pylint: disable=" in lines[0]
74
- else f"# pylint: disable={','.join(pylint_disables)}\n" + file_content
74
+ else f"# pylint: disable={','.join(pylint_disables)}{os.linesep}" + file_content
75
75
  )
76
76
  self.write_file(file, file_content)
77
77
 
@@ -484,3 +484,7 @@ class CodeModel: # pylint: disable=too-many-public-methods, disable=too-many-in
484
484
 
485
485
  # No generation-subdir specified, use the namespace path directly
486
486
  return Path(*namespace.split("."))
487
+
488
+ @property
489
+ def has_operation_named_list(self) -> bool:
490
+ return any(o.name.lower() == "list" for c in self.clients for og in c.operation_groups for o in og.operations)
@@ -40,13 +40,9 @@ class ListType(BaseType):
40
40
  ):
41
41
  # this means we're version tolerant XML, we just return the XML element
42
42
  return self.element_type.type_annotation(**kwargs)
43
- has_operation_named_list = any(
44
- o.name.lower() == "list"
45
- for c in self.code_model.clients
46
- for og in c.operation_groups
47
- for o in og.operations
48
- )
49
- list_type = "List" if has_operation_named_list and kwargs.get("is_operation_file") else "list"
43
+
44
+ # if there is a function named `list` we have to make sure there's no conflict with the built-in `list`
45
+ list_type = "List" if self.code_model.has_operation_named_list and kwargs.get("is_operation_file") else "list"
50
46
  return f"{list_type}[{self.element_type.type_annotation(**kwargs)}]"
51
47
 
52
48
  def description(self, *, is_operation_file: bool) -> str:
@@ -404,10 +404,6 @@ class OperationBase( # pylint: disable=too-many-public-methods,too-many-instanc
404
404
  file_import.merge(self.get_request_builder_import(self.request_builder, async_mode, serialize_namespace))
405
405
  if self.overloads:
406
406
  file_import.add_submodule_import("typing", "overload", ImportType.STDLIB)
407
- if self.name == "list":
408
- # if there is a function named `list` we have to make sure there's no conflict with the built-in `list`
409
- # not doing for dict or set yet, though we might have to later
410
- file_import.define_mypy_type("List", "list")
411
407
  if self.code_model.options["models-mode"] == "dpg":
412
408
  relative_path = self.code_model.get_relative_import_path(
413
409
  serialize_namespace, module_name="_utils.model_base"
@@ -158,6 +158,16 @@ class MsrestModelSerializer(_ModelSerializer):
158
158
  called_by_property=True,
159
159
  )
160
160
  )
161
+ for prop in model.properties:
162
+ if prop.readonly:
163
+ # it will be defined in the __init__ so we need to import it
164
+ file_import.merge(
165
+ prop.imports(
166
+ serialize_namespace=self.serialize_namespace,
167
+ serialize_namespace_type=NamespaceType.MODEL,
168
+ called_by_property=True,
169
+ )
170
+ )
161
171
 
162
172
  return file_import
163
173
 
@@ -224,7 +234,16 @@ class DpgModelSerializer(_ModelSerializer):
224
234
  "for k, v in _flattened_input.items():",
225
235
  " setattr(self, k, v)",
226
236
  ]
227
- return [super_call]
237
+ discriminator_value_setter = []
238
+ for prop in self.get_properties_to_declare(model):
239
+ if (
240
+ prop.is_discriminator
241
+ and isinstance(prop.type, (ConstantType, EnumValue))
242
+ and prop.type.value is not None
243
+ ):
244
+ discriminator_value_setter.append(f"self.{prop.client_name}={prop.get_declaration()} # type: ignore")
245
+
246
+ return [super_call, *discriminator_value_setter]
228
247
 
229
248
  def imports(self) -> FileImport:
230
249
  file_import = FileImport(self.code_model)
@@ -343,17 +362,7 @@ class DpgModelSerializer(_ModelSerializer):
343
362
 
344
363
  @staticmethod
345
364
  def properties_to_pass_to_super(model: ModelType) -> str:
346
- properties_to_pass_to_super = ["*args"]
347
- for parent in model.parents:
348
- for prop in model.properties:
349
- if (
350
- prop.client_name in [prop.client_name for prop in parent.properties if prop.is_base_discriminator]
351
- and prop.is_discriminator
352
- and not prop.constant
353
- and not prop.readonly
354
- ):
355
- properties_to_pass_to_super.append(f"{prop.client_name}={prop.get_declaration()}")
356
- properties_to_pass_to_super.append("**kwargs")
365
+ properties_to_pass_to_super = ["*args", "**kwargs"]
357
366
  return ", ".join(properties_to_pass_to_super)
358
367
 
359
368
  def global_pylint_disables(self) -> str:
@@ -66,6 +66,11 @@ class OperationGroupsSerializer(BaseSerializer):
66
66
  serialize_namespace_type=NamespaceType.OPERATION,
67
67
  )
68
68
  )
69
+ # put here since one operation file only need one self-defined list type
70
+ if self.code_model.has_operation_named_list:
71
+ # if there is a function named `list` we have to make sure there's no conflict with the built-in `list`
72
+ # not doing for dict or set yet, though we might have to later
73
+ imports.define_mypy_type("List", "list")
69
74
 
70
75
  template = self.env.get_or_select_template("operation_groups_container.py.jinja2")
71
76
 
@@ -43,7 +43,7 @@ dependencies = [
43
43
  {% else %}
44
44
  "isodate>={{ VERSION_MAP['isodate'] }}",
45
45
  {% endif %}
46
- {% if options.get('azure_arm') %}
46
+ {% if options.get('azure-arm') %}
47
47
  "azure-mgmt-core>={{ VERSION_MAP['azure-mgmt-core'] }}",
48
48
  {% elif code_model.is_azure_flavor %}
49
49
  "azure-core>={{ VERSION_MAP['azure-core'] }}",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@autorest/python",
3
- "version": "6.39.0",
3
+ "version": "6.40.0",
4
4
  "description": "The Python extension for generators in AutoRest.",
5
5
  "main": "index.js",
6
6
  "repository": {
@@ -19,7 +19,7 @@
19
19
  },
20
20
  "homepage": "https://github.com/Azure/autorest.python/blob/main/README.md",
21
21
  "dependencies": {
22
- "@typespec/http-client-python": "~0.16.0",
22
+ "@typespec/http-client-python": "~0.17.0",
23
23
  "@autorest/system-requirements": "~1.0.2",
24
24
  "fs-extra": "~11.2.0",
25
25
  "tsx": "~4.19.1"