@autorest/python 6.10.0 → 6.10.2

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.
@@ -3,15 +3,14 @@
3
3
  # Licensed under the MIT License. See License.txt in the project root for
4
4
  # license information.
5
5
  # --------------------------------------------------------------------------
6
- from typing import Any, Dict, List, Optional, TYPE_CHECKING
6
+ from typing import Any, Dict, List, Optional, TYPE_CHECKING, Type, Tuple, Union
7
7
  import re
8
8
  from autorest.codegen.models.imports import FileImport, ImportType, TypingSection
9
9
  from .base import BaseType
10
- from .model_type import JSONModelType
10
+ from .model_type import ModelType
11
11
 
12
12
  if TYPE_CHECKING:
13
13
  from .code_model import CodeModel
14
- from .model_type import ModelType
15
14
 
16
15
 
17
16
  class CombinedType(BaseType):
@@ -129,19 +128,14 @@ class CombinedType(BaseType):
129
128
  [build_type(t, code_model) for t in yaml_data["types"]],
130
129
  )
131
130
 
132
- @staticmethod
133
- def _get_json_model_type(t: BaseType) -> Optional[JSONModelType]:
134
- if isinstance(t, JSONModelType):
135
- return t
136
- if isinstance(t, CombinedType):
137
- try:
138
- return next(
139
- CombinedType._get_json_model_type(sub_t) for sub_t in t.types
140
- )
141
- except StopIteration:
142
- pass
131
+ def target_model_subtype(
132
+ self,
133
+ target_types: Union[
134
+ Tuple[Type[ModelType]],
135
+ Tuple[Type[ModelType], Type[ModelType]],
136
+ ],
137
+ ) -> Optional[ModelType]:
138
+ for sub_t in self.types:
139
+ if isinstance(sub_t, target_types):
140
+ return sub_t # type: ignore
143
141
  return None
144
-
145
- @property
146
- def json_subtype(self) -> Optional[JSONModelType]:
147
- return CombinedType._get_json_model_type(self)
@@ -271,7 +271,7 @@ class BodyParameter(_ParameterBase):
271
271
  @property
272
272
  def has_json_model_type(self) -> bool:
273
273
  if isinstance(self.type, CombinedType):
274
- return self.type.json_subtype is not None
274
+ return self.type.target_model_subtype((JSONModelType,)) is not None
275
275
  return isinstance(self.type, JSONModelType)
276
276
 
277
277
  @classmethod
@@ -92,13 +92,13 @@ class BinaryType(PrimitiveType):
92
92
  return self.type
93
93
 
94
94
  def docstring_type(self, **kwargs: Any) -> str:
95
- return self.type
95
+ return f"{self.type}[bytes]"
96
96
 
97
97
  def type_annotation(self, **kwargs: Any) -> str:
98
- return self.docstring_type(**kwargs)
98
+ return f"{self.type}[bytes]"
99
99
 
100
100
  def docstring_text(self, **kwargs: Any) -> str:
101
- return "IO"
101
+ return f"{self.type}[bytes]"
102
102
 
103
103
  @property
104
104
  def default_template_representation_declaration(self) -> str:
@@ -30,6 +30,8 @@ from ..models import (
30
30
  Property,
31
31
  RequestBuilderType,
32
32
  CombinedType,
33
+ JSONModelType,
34
+ DPGModelType,
33
35
  ParameterListType,
34
36
  ByteArraySchema,
35
37
  )
@@ -181,8 +183,10 @@ def _serialize_json_model_body(
181
183
  for property_name, parameter_name in body_parameter.property_to_parameter_name.items()
182
184
  )
183
185
  model_type = cast(ModelType, body_parameter.type)
184
- if isinstance(model_type, CombinedType) and model_type.json_subtype:
185
- model_type = model_type.json_subtype
186
+ if isinstance(model_type, CombinedType) and model_type.target_model_subtype(
187
+ (JSONModelType,)
188
+ ):
189
+ model_type = model_type.target_model_subtype((JSONModelType,))
186
190
  retval.append(f" {body_parameter.client_name} = {{{parameter_string}}}")
187
191
  retval.append(f" {body_parameter.client_name} = {{")
188
192
  retval.append(
@@ -320,6 +324,10 @@ class _BuilderBaseSerializer(Generic[BuilderType]): # pylint: disable=abstract-
320
324
  description_list.append("")
321
325
  return description_list
322
326
 
327
+ @staticmethod
328
+ def line_too_long(docs: List[str]) -> bool:
329
+ return any(len(line) > 120 for line in docs)
330
+
323
331
  def example_template(self, builder: BuilderType) -> List[str]:
324
332
  template = []
325
333
  if builder.abstract:
@@ -376,18 +384,21 @@ class _BuilderBaseSerializer(Generic[BuilderType]): # pylint: disable=abstract-
376
384
 
377
385
  if (
378
386
  isinstance(body_param.type, (ListType, DictionaryType))
379
- and self.code_model.options["models_mode"]
387
+ and self.code_model.options["models_mode"] == "msrest"
380
388
  ):
381
389
  return template
382
390
 
383
- if isinstance(body_param.type, ModelType) and body_param.type.base != "json":
391
+ if isinstance(body_param.type, ModelType) and body_param.type.base == "msrest":
384
392
  return template
385
393
 
386
394
  json_type = body_param.type
387
395
  if isinstance(body_param.type, CombinedType):
388
- if body_param.type.json_subtype is None:
396
+ target_model_type = body_param.type.target_model_subtype(
397
+ (JSONModelType, DPGModelType)
398
+ )
399
+ if target_model_type is None:
389
400
  return template
390
- json_type = body_param.type.json_subtype
401
+ json_type = target_model_type
391
402
 
392
403
  polymorphic_subtypes: List[ModelType] = []
393
404
  json_type.get_polymorphic_subtypes(polymorphic_subtypes)
@@ -597,7 +608,7 @@ class _OperationSerializer(
597
608
 
598
609
  def example_template(self, builder: OperationType) -> List[str]:
599
610
  retval = super().example_template(builder)
600
- if self.code_model.options["models_mode"]:
611
+ if self.code_model.options["models_mode"] == "msrest":
601
612
  return retval
602
613
  for response in builder.responses:
603
614
  polymorphic_subtypes: List[ModelType] = []
@@ -1,7 +1,7 @@
1
1
  {% import 'operation_tools.jinja2' as op_tools %}
2
2
  {% set operations_description = "async operations" if async_mode else "operations" %}
3
3
  {% set return_none_type_annotation = " -> None" if async_mode else "" %}
4
- # pylint: disable=too-many-lines
4
+ # pylint: disable=too-many-lines,too-many-statements
5
5
  # coding=utf-8
6
6
  {{ code_model.options['license_header'] }}
7
7
  {{ imports }}
@@ -1,9 +1,13 @@
1
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
+ {% set example_template = serializer.example_template(builder) %}
4
5
  {% for description in serializer.description_and_summary(builder) %}
5
6
  {% if description %}
6
7
  {% set description = wrap_string(description, wrapstring='\n') %}
8
+ {% if serializer.line_too_long(example_template) and loop.first %}
9
+ # pylint: disable=line-too-long
10
+ {% endif %}
7
11
  {{ '"""' + description if loop.first else description }}
8
12
  {% else %}
9
13
 
@@ -16,11 +20,11 @@
16
20
 
17
21
  {% endif %}
18
22
  {% endfor %}
19
- {% if serializer.example_template(builder) %}
23
+ {% if example_template %}
20
24
 
21
25
  Example:
22
26
  .. code-block:: python
23
- {% for template_line in serializer.example_template(builder) %}
27
+ {% for template_line in example_template %}
24
28
  {% if template_line %}
25
29
  {% set wrap_amount = (template_line | length) - (template_line.lstrip() | length) + 10 %}
26
30
  {{ wrap_string(template_line, wrapstring='\n' + " " * wrap_amount, width=(95 - wrap_amount)) }}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@autorest/python",
3
- "version": "6.10.0",
3
+ "version": "6.10.2",
4
4
  "description": "The Python extension for generators in AutoRest.",
5
5
  "main": "index.js",
6
6
  "repository": {
package/requirements.txt CHANGED
@@ -10,3 +10,4 @@ pathspec==0.11.1
10
10
  platformdirs==3.2.0
11
11
  PyYAML==6.0.1
12
12
  tomli==2.0.1
13
+ setuptools==58.3.0