@autorest/python 6.12.0 → 6.12.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.
- package/autorest/codegen/models/client.py +5 -0
- package/autorest/codegen/models/code_model.py +11 -18
- package/autorest/codegen/models/constant_type.py +4 -2
- package/autorest/codegen/models/enum_type.py +3 -1
- package/autorest/codegen/models/imports.py +0 -17
- package/autorest/codegen/models/operation_group.py +18 -1
- package/autorest/codegen/templates/enum.py.jinja2 +1 -1
- package/autorest/codegen/templates/model_base.py.jinja2 +1 -8
- package/autorest/codegen/templates/packaging_templates/setup.py.jinja2 +0 -3
- package/package.json +1 -1
|
@@ -304,6 +304,11 @@ class Client(_ClientConfigBase[ClientGlobalParameterList]):
|
|
|
304
304
|
"""Whether there is abstract operation in any operation group."""
|
|
305
305
|
return any(og.has_abstract_operations for og in self.operation_groups)
|
|
306
306
|
|
|
307
|
+
@property
|
|
308
|
+
def has_non_abstract_operations(self) -> bool:
|
|
309
|
+
"""Whether there is non-abstract operation in any operation group."""
|
|
310
|
+
return any(og.has_non_abstract_operations for og in self.operation_groups)
|
|
311
|
+
|
|
307
312
|
def imports(self, async_mode: bool) -> FileImport:
|
|
308
313
|
file_import = self._imports_shared(async_mode)
|
|
309
314
|
if async_mode:
|
|
@@ -79,12 +79,11 @@ class CodeModel: # pylint: disable=too-many-public-methods, disable=too-many-in
|
|
|
79
79
|
|
|
80
80
|
@property
|
|
81
81
|
def has_form_data(self) -> bool:
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
return False
|
|
82
|
+
return any(
|
|
83
|
+
og.has_form_data_body
|
|
84
|
+
for client in self.clients
|
|
85
|
+
for og in client.operation_groups
|
|
86
|
+
)
|
|
88
87
|
|
|
89
88
|
@property
|
|
90
89
|
def has_etag(self) -> bool:
|
|
@@ -103,18 +102,12 @@ class CodeModel: # pylint: disable=too-many-public-methods, disable=too-many-in
|
|
|
103
102
|
|
|
104
103
|
@property
|
|
105
104
|
def has_non_abstract_operations(self) -> bool:
|
|
106
|
-
for
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
for client in clients:
|
|
113
|
-
for operation_group in client.operation_groups:
|
|
114
|
-
for operation in operation_group.operations:
|
|
115
|
-
if not operation.abstract:
|
|
116
|
-
return True
|
|
117
|
-
return False
|
|
105
|
+
return any(c for c in self.clients if c.has_non_abstract_operations) or any(
|
|
106
|
+
c
|
|
107
|
+
for cs in self.subnamespace_to_clients.values()
|
|
108
|
+
for c in cs
|
|
109
|
+
if c.has_non_abstract_operations
|
|
110
|
+
)
|
|
118
111
|
|
|
119
112
|
def lookup_request_builder(
|
|
120
113
|
self, request_builder_id: int
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
import logging
|
|
7
7
|
from typing import Dict, Any, Optional, TYPE_CHECKING
|
|
8
8
|
from .base import BaseType
|
|
9
|
-
from .imports import FileImport
|
|
9
|
+
from .imports import FileImport, ImportType, TypingSection
|
|
10
10
|
from .primitive_types import IntegerType, BinaryType, StringType, BooleanType
|
|
11
11
|
from .utils import add_to_description
|
|
12
12
|
|
|
@@ -134,7 +134,9 @@ class ConstantType(BaseType):
|
|
|
134
134
|
def imports(self, **kwargs: Any) -> FileImport:
|
|
135
135
|
file_import = self._imports_shared(**kwargs)
|
|
136
136
|
if self._is_literal:
|
|
137
|
-
file_import.
|
|
137
|
+
file_import.add_submodule_import(
|
|
138
|
+
"typing", "Literal", ImportType.STDLIB, TypingSection.REGULAR
|
|
139
|
+
)
|
|
138
140
|
return file_import
|
|
139
141
|
|
|
140
142
|
@property
|
|
@@ -78,7 +78,9 @@ class EnumValue(BaseType):
|
|
|
78
78
|
def imports(self, **kwargs: Any) -> FileImport:
|
|
79
79
|
file_import = FileImport(self.code_model)
|
|
80
80
|
file_import.merge(self.value_type.imports(**kwargs))
|
|
81
|
-
file_import.
|
|
81
|
+
file_import.add_submodule_import(
|
|
82
|
+
"typing", "Literal", ImportType.STDLIB, TypingSection.REGULAR
|
|
83
|
+
)
|
|
82
84
|
file_import.add_submodule_import(
|
|
83
85
|
"._enums", self.enum_type.name, ImportType.LOCAL, TypingSection.REGULAR
|
|
84
86
|
)
|
|
@@ -204,23 +204,6 @@ class FileImport:
|
|
|
204
204
|
)
|
|
205
205
|
self.add_submodule_import("typing", "Any", ImportType.STDLIB)
|
|
206
206
|
|
|
207
|
-
def add_literal_import(self) -> None:
|
|
208
|
-
self.add_import("sys", ImportType.STDLIB)
|
|
209
|
-
self.add_submodule_import(
|
|
210
|
-
"typing_extensions",
|
|
211
|
-
"Literal",
|
|
212
|
-
ImportType.BYVERSION,
|
|
213
|
-
TypingSection.REGULAR,
|
|
214
|
-
None,
|
|
215
|
-
(
|
|
216
|
-
(
|
|
217
|
-
(3, 8),
|
|
218
|
-
"typing",
|
|
219
|
-
"pylint: disable=no-name-in-module, ungrouped-imports",
|
|
220
|
-
),
|
|
221
|
-
),
|
|
222
|
-
)
|
|
223
|
-
|
|
224
207
|
def to_dict(
|
|
225
208
|
self,
|
|
226
209
|
) -> Dict[
|
|
@@ -48,7 +48,17 @@ class OperationGroup(BaseModel):
|
|
|
48
48
|
|
|
49
49
|
@property
|
|
50
50
|
def has_abstract_operations(self) -> bool:
|
|
51
|
-
return any(o for o in self.operations if o.abstract)
|
|
51
|
+
return any(o for o in self.operations if o.abstract) or any(
|
|
52
|
+
operation_group.has_abstract_operations
|
|
53
|
+
for operation_group in self.operation_groups
|
|
54
|
+
)
|
|
55
|
+
|
|
56
|
+
@property
|
|
57
|
+
def has_non_abstract_operations(self) -> bool:
|
|
58
|
+
return any(o for o in self.operations if not o.abstract) or any(
|
|
59
|
+
operation_group.has_non_abstract_operations
|
|
60
|
+
for operation_group in self.operation_groups
|
|
61
|
+
)
|
|
52
62
|
|
|
53
63
|
@property
|
|
54
64
|
def base_class(self) -> str:
|
|
@@ -183,6 +193,13 @@ class OperationGroup(BaseModel):
|
|
|
183
193
|
operation_group.has_operations for operation_group in self.operation_groups
|
|
184
194
|
) or bool(self.operations)
|
|
185
195
|
|
|
196
|
+
@property
|
|
197
|
+
def has_form_data_body(self) -> bool:
|
|
198
|
+
operations = self.operations + [
|
|
199
|
+
o for og in self.operation_groups for o in og.operations
|
|
200
|
+
]
|
|
201
|
+
return any(operation.has_form_data_body for operation in operations)
|
|
202
|
+
|
|
186
203
|
@classmethod
|
|
187
204
|
def from_yaml(
|
|
188
205
|
cls,
|
|
@@ -8,6 +8,6 @@ class {{ enum.name }}({{ enum.value_type.type_annotation(is_operation_file=False
|
|
|
8
8
|
{% for value in enum.values %}
|
|
9
9
|
{{ value.name }} = {{ enum.value_type.get_declaration(value.value) }}
|
|
10
10
|
{% if value.description(is_operation_file=False) %}
|
|
11
|
-
"""{{ value.description(is_operation_file=False) | wordwrap(width=95, break_long_words=False, break_on_hyphens=False, wrapstring='\n
|
|
11
|
+
"""{{ value.description(is_operation_file=False) | wordwrap(width=95, break_long_words=False, break_on_hyphens=False, wrapstring='\n ') }}"""
|
|
12
12
|
{% endif %}
|
|
13
13
|
{% endfor %}
|
|
@@ -625,14 +625,7 @@ def _get_deserialize_callable_from_annotation( # pylint: disable=R0911, R0915,
|
|
|
625
625
|
|
|
626
626
|
# is it a literal?
|
|
627
627
|
try:
|
|
628
|
-
if
|
|
629
|
-
from typing import (
|
|
630
|
-
Literal,
|
|
631
|
-
) # pylint: disable=no-name-in-module, ungrouped-imports
|
|
632
|
-
else:
|
|
633
|
-
from typing_extensions import Literal # type: ignore # pylint: disable=ungrouped-imports
|
|
634
|
-
|
|
635
|
-
if annotation.__origin__ == Literal:
|
|
628
|
+
if annotation.__origin__ == typing.Literal:
|
|
636
629
|
return None
|
|
637
630
|
except AttributeError:
|
|
638
631
|
pass
|