@autorest/python 5.12.2 → 5.12.6

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.
Files changed (42) hide show
  1. package/ChangeLog.md +60 -0
  2. package/autorest/black/__init__.py +4 -1
  3. package/autorest/codegen/models/client.py +22 -19
  4. package/autorest/codegen/models/credential_schema.py +3 -3
  5. package/autorest/codegen/models/dictionary_schema.py +1 -1
  6. package/autorest/codegen/models/enum_schema.py +2 -2
  7. package/autorest/codegen/models/imports.py +90 -50
  8. package/autorest/codegen/models/list_schema.py +1 -1
  9. package/autorest/codegen/models/lro_operation.py +15 -9
  10. package/autorest/codegen/models/object_schema.py +2 -2
  11. package/autorest/codegen/models/operation.py +28 -26
  12. package/autorest/codegen/models/operation_group.py +5 -14
  13. package/autorest/codegen/models/paging_operation.py +9 -9
  14. package/autorest/codegen/models/parameter.py +6 -7
  15. package/autorest/codegen/models/parameter_list.py +1 -0
  16. package/autorest/codegen/models/primitive_schemas.py +2 -2
  17. package/autorest/codegen/models/property.py +1 -1
  18. package/autorest/codegen/models/request_builder.py +7 -6
  19. package/autorest/codegen/models/request_builder_parameter.py +0 -2
  20. package/autorest/codegen/models/request_builder_parameter_list.py +1 -0
  21. package/autorest/codegen/models/schema_response.py +1 -1
  22. package/autorest/codegen/serializers/builder_serializer.py +33 -26
  23. package/autorest/codegen/serializers/client_serializer.py +14 -3
  24. package/autorest/codegen/serializers/general_serializer.py +7 -7
  25. package/autorest/codegen/serializers/import_serializer.py +44 -46
  26. package/autorest/codegen/serializers/metadata_serializer.py +12 -10
  27. package/autorest/codegen/serializers/model_base_serializer.py +6 -6
  28. package/autorest/codegen/serializers/utils.py +5 -1
  29. package/autorest/codegen/templates/config.py.jinja2 +2 -7
  30. package/autorest/codegen/templates/lro_operation.py.jinja2 +3 -1
  31. package/autorest/codegen/templates/lro_paging_operation.py.jinja2 +2 -0
  32. package/autorest/codegen/templates/metadata.json.jinja2 +3 -3
  33. package/autorest/codegen/templates/operation.py.jinja2 +8 -2
  34. package/autorest/codegen/templates/operation_group.py.jinja2 +2 -1
  35. package/autorest/codegen/templates/operation_groups_container.py.jinja2 +1 -0
  36. package/autorest/codegen/templates/operation_tools.jinja2 +3 -2
  37. package/autorest/codegen/templates/paging_operation.py.jinja2 +3 -1
  38. package/autorest/codegen/templates/request_builder.py.jinja2 +2 -7
  39. package/autorest/codegen/templates/service_client.py.jinja2 +1 -1
  40. package/autorest/multiapi/models/imports.py +1 -1
  41. package/autorest/multiapi/serializers/import_serializer.py +1 -1
  42. package/package.json +2 -2
@@ -62,7 +62,7 @@ def _mixin_imports(mixin_operation_group: Optional[OperationGroup]) -> Tuple[Opt
62
62
  sync_mixin_imports = mixin_operation_group.imports_for_multiapi(async_mode=False)
63
63
  async_mixin_imports = mixin_operation_group.imports_for_multiapi(async_mode=True)
64
64
 
65
- return _json_serialize_imports(sync_mixin_imports.imports), _json_serialize_imports(async_mixin_imports.imports)
65
+ return _json_serialize_imports(sync_mixin_imports.to_dict()), _json_serialize_imports(async_mixin_imports.to_dict())
66
66
 
67
67
 
68
68
  class MetadataSerializer:
@@ -102,20 +102,22 @@ class MetadataSerializer:
102
102
  file_import = FileImport()
103
103
  for gp in global_parameters:
104
104
  file_import.merge(gp.imports())
105
- file_import.add_from_import("azure.profiles", "KnownProfiles", import_type=ImportType.AZURECORE)
106
- file_import.add_from_import("azure.profiles", "ProfileDefinition", import_type=ImportType.AZURECORE)
107
- file_import.add_from_import(
105
+ file_import.add_submodule_import("azure.profiles", "KnownProfiles", import_type=ImportType.AZURECORE)
106
+ file_import.add_submodule_import("azure.profiles", "ProfileDefinition", import_type=ImportType.AZURECORE)
107
+ file_import.add_submodule_import(
108
108
  "azure.profiles.multiapiclient", "MultiApiClientMixin", import_type=ImportType.AZURECORE
109
109
  )
110
- file_import.add_from_import("._configuration", f"{self.code_model.class_name}Configuration", ImportType.LOCAL)
110
+ file_import.add_submodule_import(
111
+ "._configuration", f"{self.code_model.class_name}Configuration", ImportType.LOCAL
112
+ )
111
113
  # api_version and potentially endpoint require Optional typing
112
- file_import.add_from_import("typing", "Optional", ImportType.STDLIB, TypingSection.CONDITIONAL)
114
+ file_import.add_submodule_import("typing", "Optional", ImportType.STDLIB, TypingSection.CONDITIONAL)
113
115
  if mixin_operation_group:
114
- file_import.add_from_import(
116
+ file_import.add_submodule_import(
115
117
  "._operations_mixin", f"{self.code_model.class_name}OperationsMixin", ImportType.LOCAL
116
118
  )
117
119
  file_import.merge(self.code_model.service_client.imports_for_multiapi(async_mode=async_mode))
118
- return _json_serialize_imports(file_import.imports)
120
+ return _json_serialize_imports(file_import.to_dict())
119
121
 
120
122
  def serialize(self) -> str:
121
123
  def _is_lro(operation):
@@ -179,10 +181,10 @@ class MetadataSerializer:
179
181
  sync_client_imports=sync_client_imports,
180
182
  async_client_imports=async_client_imports,
181
183
  sync_config_imports=_json_serialize_imports(
182
- config_imports(self.code_model, self.code_model.global_parameters, async_mode=False).imports
184
+ config_imports(self.code_model, self.code_model.global_parameters, async_mode=False).to_dict()
183
185
  ),
184
186
  async_config_imports=_json_serialize_imports(
185
- config_imports(self.code_model, async_global_parameters, async_mode=True).imports
187
+ config_imports(self.code_model, async_global_parameters, async_mode=True).to_dict()
186
188
  ),
187
189
  get_async_operation_serializer=functools.partial(
188
190
  get_operation_serializer, code_model=self.code_model, async_mode=True, is_python3_file=True
@@ -52,12 +52,12 @@ class ModelBaseSerializer:
52
52
  @staticmethod
53
53
  def get_properties_to_initialize(model: ObjectSchema) -> List[Property]:
54
54
  if model.base_models:
55
- properties_to_initialize = []
56
- for uncast_base_model in model.base_models:
57
- base_model = cast(ObjectSchema, uncast_base_model)
58
- for prop in model.properties:
59
- if prop not in base_model.properties or prop.is_discriminator or prop.constant:
60
- properties_to_initialize.append(prop)
55
+ properties_to_initialize = list({
56
+ p.name: p
57
+ for bm in model.base_models
58
+ for p in model.properties
59
+ if p not in cast(ObjectSchema, bm).properties or p.is_discriminator or p.constant
60
+ }.values())
61
61
  else:
62
62
  properties_to_initialize = model.properties
63
63
  return properties_to_initialize
@@ -13,9 +13,13 @@ def serialize_method(
13
13
  method_name: str,
14
14
  is_in_class: bool,
15
15
  method_param_signatures: List[str],
16
+ ignore_inconsistent_return_statements: bool = False,
16
17
  ):
17
18
  lines: List[str] = []
18
- lines.append(f"{function_def} {method_name}(")
19
+ first_line = f"{function_def} {method_name}("
20
+ if ignore_inconsistent_return_statements:
21
+ first_line += " # pylint: disable=inconsistent-return-statements"
22
+ lines.append(first_line)
19
23
  if is_in_class:
20
24
  lines.append(" self,")
21
25
  lines.extend([
@@ -11,7 +11,7 @@
11
11
  VERSION = "unknown"
12
12
  {% endif %}
13
13
 
14
- class {{ code_model.class_name }}Configuration(Configuration):
14
+ class {{ code_model.class_name }}Configuration(Configuration): # pylint: disable=too-many-instance-attributes
15
15
  """Configuration for {{ code_model.class_name }}.
16
16
 
17
17
  Note that all parameters used to create this instance are saved as instance
@@ -19,12 +19,7 @@ class {{ code_model.class_name }}Configuration(Configuration):
19
19
  {% if code_model.global_parameters.config_method | first %}
20
20
 
21
21
  {% endif %}
22
- {% for parameter in code_model.global_parameters.config_method %}
23
- :{{ parameter.description_keyword }} {{ parameter.serialized_name }}: {{ parameter.description }}
24
- :{{ parameter.docstring_type_keyword }} {{ parameter.serialized_name }}: {{ parameter.docstring_type }}
25
- {% endfor %}
26
- """
27
-
22
+ {{ op_tools.serialize_with_wrap(serializer.property_descriptions(), "\n ") | indent }}
28
23
  {{ serializer.init_signature_and_response_type_annotation(async_mode) | indent }}
29
24
  super({{ code_model.class_name }}Configuration, self).__init__(**kwargs)
30
25
  {% if code_model.service_client.parameters.config_kwargs_to_pop(async_mode) %}
@@ -13,4 +13,6 @@
13
13
  {{ op_tools.serialize(operation_serializer.get_long_running_output(operation)) | indent }}
14
14
 
15
15
  {{ op_tools.serialize(operation_serializer.return_lro_poller(operation)) | indent }}
16
- {{ operation_serializer.get_metadata_url(operation) }}
16
+ {% if not code_model.options["version_tolerant"] %}
17
+ {{ operation_serializer.get_metadata_url(operation) -}}
18
+ {% endif %}
@@ -15,4 +15,6 @@
15
15
  {{ op_tools.serialize(operation_serializer.initial_call(operation)) | indent }}
16
16
  {{ op_tools.serialize(operation_serializer.get_long_running_output(operation)) | indent }}
17
17
  {{ op_tools.serialize(operation_serializer.return_lro_poller(operation)) | indent }}
18
+ {% if not code_model.options["version_tolerant"] %}
18
19
  {{ operation_serializer.get_metadata_url(operation) }}
20
+ {% endif %}
@@ -18,7 +18,7 @@
18
18
  },
19
19
  "global_parameters": {
20
20
  "sync": {
21
- {% for gp in sync_global_parameters.config_method %}
21
+ {% for gp in sync_global_parameters.config_method | rejectattr("serialized_name", "equalto", "api_version") %}
22
22
  {{ gp.serialized_name | tojson }}: {
23
23
  "signature": {{ gp.method_signature(is_python3_file=False) | tojson }},
24
24
  "description": {{ gp.description | tojson }},
@@ -28,7 +28,7 @@
28
28
  {% endfor %}
29
29
  },
30
30
  "async": {
31
- {% for gp in async_global_parameters.config_method %}
31
+ {% for gp in async_global_parameters.config_method | rejectattr("serialized_name", "equalto", "api_version") %}
32
32
  {{ gp.serialized_name | tojson }}: {
33
33
  "signature": {{ (gp.method_signature(is_python3_file=True)) | tojson }},
34
34
  "description": {{ gp.description | tojson }},
@@ -42,7 +42,7 @@
42
42
  {{ gp.serialized_name | tojson }}: {{ gp.constant_declaration | tojson }}{{ "," if not loop.last else "" }}
43
43
  {% endfor %}
44
44
  },
45
- "call": {{ code_model.global_parameters.config_method | map(attribute="serialized_name") | join(', ') | tojson }},
45
+ "call": {{ code_model.global_parameters.config_method | rejectattr("serialized_name", "equalto", "api_version") | map(attribute="serialized_name") | join(', ') | tojson }},
46
46
  "service_client_specific": {
47
47
  "sync": {
48
48
  "api_version": {
@@ -18,6 +18,12 @@
18
18
  {{ op_tools.serialize(operation_serializer.pop_kwargs_from_signature(operation)) | indent }}
19
19
  {% endif %}
20
20
  {{ op_tools.serialize(operation_serializer.call_request_builder(operation)) | indent }}
21
- pipeline_response = {{ keywords.await }}self._client._pipeline.run(request, {{ stream_request_parameter }}, **kwargs)
21
+ pipeline_response = {{ keywords.await }}self._client._pipeline.run( # pylint: disable=protected-access
22
+ request,
23
+ {{ stream_request_parameter }},
24
+ **kwargs
25
+ )
22
26
  {{ op_tools.serialize(operation_serializer.handle_response(operation)) | indent }}
23
- {{ operation.python_name }}.metadata = {'url': {{ keywords.escape_str(request_builder.url) }}} # type: ignore
27
+ {% if not code_model.options["version_tolerant"] %}
28
+ {{ operation_serializer.get_metadata_url(operation) }}
29
+ {% endif %}
@@ -1,4 +1,5 @@
1
- class {{ operation_group.class_name }}{{ object_base_class }}:
1
+ {% set disable = " # pylint: disable=too-many-public-methods" if operation_group.operations | length > 20 else "" %}
2
+ class {{ operation_group.class_name }}{{ object_base_class }}:{{ disable }}
2
3
  {% if not operation_group.is_empty_operation_group %}
3
4
  """{{ operation_group.class_name }} {{ operations_description }}.
4
5
 
@@ -2,6 +2,7 @@
2
2
  {% set object_base_class = "" if async_mode else "(object)" %}
3
3
  {% set operations_description = "async operations" if async_mode else "operations" %}
4
4
  {% set return_none_type_annotation = " -> None" if async_mode else "" %}
5
+ # pylint: disable=too-many-lines
5
6
  # coding=utf-8
6
7
  {{ code_model.options['license_header'] }}
7
8
  {{ imports }}
@@ -1,4 +1,4 @@
1
- {% macro wrap_string(string, wrapstring) %}{{ string | wordwrap(width=95, break_long_words=False, break_on_hyphens=False, wrapstring=wrapstring)}}{% endmacro %}
1
+ {% macro wrap_string(string, wrapstring, width=95) %}{{ string | wordwrap(width=width, break_long_words=False, break_on_hyphens=False, wrapstring=wrapstring)}}{% endmacro %}
2
2
 
3
3
  {% macro description(builder, serializer) %}
4
4
  {% for description in serializer.description_and_summary(builder) %}
@@ -22,7 +22,8 @@ Example:
22
22
  .. code-block:: python
23
23
  {% for template_line in serializer.get_example_template(builder) %}
24
24
  {% if template_line %}
25
- {{ template_line }}
25
+ {% set wrap_amount = (template_line | length) - (template_line.lstrip() | length) + 10 %}
26
+ {{ wrap_string(template_line, wrapstring='\n' + " " * wrap_amount, width=(95 - wrap_amount)) }}
26
27
  {% else %}
27
28
 
28
29
  {% endif %}
@@ -17,4 +17,6 @@
17
17
  return {{ operation.get_pager(async_mode) }}(
18
18
  get_next, extract_data
19
19
  )
20
- {{ operation.python_name }}.metadata = {'url': '{{ request_builder.url|replace("'", "\\'") }}'} # type: ignore
20
+ {% if not code_model.options["version_tolerant"] %}
21
+ {{ operation_serializer.get_metadata_url(operation) -}}
22
+ {% endif %}
@@ -13,15 +13,10 @@
13
13
  {% endfor %}
14
14
  {% endif %}
15
15
  # Construct URL
16
- {% if code_model.options["version_tolerant"] or code_model.options["low_level_client"] %}
17
- {% set url_value = keywords.escape_str(request_builder.url) %}
18
- {% else %}
19
- {% set url_value = 'kwargs.pop("template_url", ' + keywords.escape_str(request_builder.url) + ')' %}
20
- {% endif %}
21
- url = {{ url_value }}
16
+ {{ request_builder_serializer.construct_url(request_builder) }}
22
17
  {% if request_builder.parameters.path %}
23
18
  {{ op_tools.serialize(request_builder_serializer.serialize_path(request_builder)) | indent }}
24
- url = _format_url_section(url, **path_format_arguments)
19
+ _url = _format_url_section(_url, **path_format_arguments)
25
20
  {% endif %}
26
21
 
27
22
  {% if request_builder.parameters.query %}
@@ -7,7 +7,7 @@
7
7
  {{ imports }}
8
8
 
9
9
  {{ serializer.class_definition(async_mode) }}
10
- """{{ code_model.description }}
10
+ """{{ op_tools.wrap_string(code_model.description, "\n") | indent }}
11
11
 
12
12
  {{ op_tools.serialize_with_wrap(serializer.property_descriptions(async_mode), "\n ") | indent }}
13
13
  {{ serializer.init_signature_and_response_type_annotation(async_mode) | indent }}
@@ -45,7 +45,7 @@ class FileImport:
45
45
  from_section, set()
46
46
  ).add(name_import)
47
47
 
48
- def add_from_import(
48
+ def add_submodule_import(
49
49
  self,
50
50
  from_section: str,
51
51
  name_import: str,
@@ -62,7 +62,7 @@ class FileImportSerializer:
62
62
  self._file_import.imports.get(TypingSection.TYPING) or
63
63
  (not self.is_python3_file and self._file_import.imports.get(TypingSection.CONDITIONAL))
64
64
  ):
65
- self._file_import.add_from_import("typing", "TYPE_CHECKING", ImportType.STDLIB)
65
+ self._file_import.add_submodule_import("typing", "TYPE_CHECKING", ImportType.STDLIB)
66
66
 
67
67
  def __str__(self) -> str:
68
68
  self._add_type_checking_import()
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@autorest/python",
3
- "version": "5.12.2",
3
+ "version": "5.12.6",
4
4
  "description": "The Python extension for generators in AutoRest.",
5
5
  "scripts": {
6
6
  "prepare": "node run-python3.js prepare.py",
@@ -27,7 +27,7 @@
27
27
  "@azure-tools/extension": "~3.2.1"
28
28
  },
29
29
  "devDependencies": {
30
- "@microsoft.azure/autorest.testserver": "^3.1.11"
30
+ "@microsoft.azure/autorest.testserver": "^3.1.13"
31
31
  },
32
32
  "files": [
33
33
  "autorest/**/*.py",