@autorest/python 5.19.0 → 6.0.1

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 (52) hide show
  1. package/ChangeLog.md +61 -2
  2. package/README.md +9 -0
  3. package/autorest/__init__.py +54 -13
  4. package/autorest/black/__init__.py +14 -8
  5. package/autorest/codegen/__init__.py +126 -89
  6. package/autorest/codegen/models/base_builder.py +17 -6
  7. package/autorest/codegen/models/client.py +1 -1
  8. package/autorest/codegen/models/code_model.py +7 -12
  9. package/autorest/codegen/models/lro_operation.py +2 -6
  10. package/autorest/codegen/models/lro_paging_operation.py +3 -9
  11. package/autorest/codegen/models/model_type.py +1 -6
  12. package/autorest/codegen/models/operation.py +6 -37
  13. package/autorest/codegen/models/operation_group.py +4 -7
  14. package/autorest/codegen/models/paging_operation.py +17 -7
  15. package/autorest/codegen/models/parameter.py +3 -7
  16. package/autorest/codegen/models/parameter_list.py +20 -36
  17. package/autorest/codegen/models/request_builder.py +0 -22
  18. package/autorest/codegen/serializers/__init__.py +46 -98
  19. package/autorest/codegen/serializers/builder_serializer.py +53 -36
  20. package/autorest/codegen/serializers/client_serializer.py +20 -31
  21. package/autorest/codegen/serializers/general_serializer.py +2 -7
  22. package/autorest/codegen/serializers/import_serializer.py +11 -22
  23. package/autorest/codegen/serializers/metadata_serializer.py +0 -2
  24. package/autorest/codegen/serializers/{model_base_serializer.py → model_serializer.py} +47 -38
  25. package/autorest/codegen/serializers/operation_groups_serializer.py +0 -7
  26. package/autorest/codegen/serializers/operations_init_serializer.py +2 -23
  27. package/autorest/codegen/serializers/patch_serializer.py +1 -3
  28. package/autorest/codegen/serializers/request_builders_serializer.py +1 -4
  29. package/autorest/codegen/serializers/utils.py +1 -4
  30. package/autorest/codegen/templates/client.py.jinja2 +3 -3
  31. package/autorest/codegen/templates/config.py.jinja2 +2 -2
  32. package/autorest/codegen/templates/metadata.json.jinja2 +4 -4
  33. package/autorest/codegen/templates/model_init.py.jinja2 +5 -12
  34. package/autorest/codegen/templates/operation_group.py.jinja2 +1 -1
  35. package/autorest/codegen/templates/operation_groups_container.py.jinja2 +0 -6
  36. package/autorest/codegen/templates/patch.py.jinja2 +1 -2
  37. package/autorest/codegen/templates/request_builders.py.jinja2 +0 -3
  38. package/autorest/codegen/templates/rest_init.py.jinja2 +3 -8
  39. package/autorest/codegen/templates/serialization.py.jinja2 +3 -3
  40. package/autorest/codegen/templates/setup.py.jinja2 +1 -1
  41. package/autorest/jsonrpc/server.py +7 -7
  42. package/autorest/m2r/__init__.py +7 -2
  43. package/autorest/m4reformatter/__init__.py +13 -5
  44. package/autorest/multiapi/__init__.py +56 -29
  45. package/autorest/multiapi/serializers/__init__.py +26 -31
  46. package/autorest/multiapi/serializers/import_serializer.py +4 -8
  47. package/autorest/multiapi/serializers/multiapi_serializer.py +33 -26
  48. package/autorest/postprocess/__init__.py +14 -11
  49. package/autorest/preprocess/__init__.py +36 -7
  50. package/package.json +2 -2
  51. package/autorest/codegen/serializers/model_generic_serializer.py +0 -32
  52. package/autorest/codegen/serializers/model_python3_serializer.py +0 -72
@@ -11,47 +11,48 @@ from .parameter_serializer import ParameterSerializer, PopKwargType
11
11
 
12
12
 
13
13
  class ClientSerializer:
14
- def __init__(self, code_model: CodeModel, is_python3_file: bool) -> None:
14
+ def __init__(self, code_model: CodeModel) -> None:
15
15
  self.code_model = code_model
16
- self.is_python3_file = is_python3_file
17
16
  self.parameter_serializer = ParameterSerializer()
18
17
 
19
18
  def _init_signature(self, async_mode: bool) -> str:
19
+ pylint_disable = ""
20
+ if not self.code_model.client.parameters.credential:
21
+ pylint_disable = (
22
+ " # pylint: disable=missing-client-constructor-parameter-credential"
23
+ )
20
24
  return self.parameter_serializer.serialize_method(
21
25
  function_def="def",
22
26
  method_name="__init__",
23
27
  need_self_param=True,
24
28
  method_param_signatures=self.code_model.client.parameters.method_signature(
25
- async_mode or self.is_python3_file, async_mode
29
+ async_mode
26
30
  ),
31
+ pylint_disable=pylint_disable,
27
32
  )
28
33
 
29
34
  def init_signature_and_response_type_annotation(self, async_mode: bool) -> str:
30
35
  init_signature = self._init_signature(async_mode)
31
36
  return utils.method_signature_and_response_type_annotation_template(
32
- is_python3_file=async_mode or self.is_python3_file,
33
37
  method_signature=init_signature,
34
38
  response_type_annotation="None",
35
39
  )
36
40
 
37
- def pop_kwargs_from_signature(self, async_mode: bool) -> List[str]:
41
+ def pop_kwargs_from_signature(self) -> List[str]:
38
42
  return self.parameter_serializer.pop_kwargs_from_signature(
39
- self.code_model.client.parameters.kwargs_to_pop(
40
- async_mode or self.is_python3_file,
41
- ),
43
+ self.code_model.client.parameters.kwargs_to_pop,
42
44
  check_kwarg_dict=False,
43
45
  pop_headers_kwarg=PopKwargType.NO,
44
46
  pop_params_kwarg=PopKwargType.NO,
45
47
  )
46
48
 
47
- def class_definition(self, async_mode) -> str:
49
+ @property
50
+ def class_definition(self) -> str:
48
51
  class_name = self.code_model.client.name
49
52
  has_mixin_og = any(og for og in self.code_model.operation_groups if og.is_mixin)
50
53
  base_class = ""
51
54
  if has_mixin_og:
52
55
  base_class = f"{class_name}OperationsMixin"
53
- elif not (async_mode or self.is_python3_file):
54
- base_class = "object"
55
56
  pylint_disable = self.code_model.client.pylint_disable
56
57
  if base_class:
57
58
  return f"class {class_name}({base_class}):{pylint_disable}"
@@ -146,17 +147,10 @@ class ClientSerializer:
146
147
  )
147
148
  return retval
148
149
 
149
- def _send_request_signature(self, async_mode: bool) -> str:
150
- is_python3_file = async_mode or self.code_model.options["python3_only"]
151
- request_signature = [
150
+ def _send_request_signature(self) -> str:
151
+ send_request_signature = [
152
152
  "request: HttpRequest,"
153
- if is_python3_file
154
- else "request, # type: HttpRequest"
155
- ]
156
- send_request_signature = (
157
- request_signature
158
- + self.code_model.client.parameters.method_signature_kwargs(is_python3_file)
159
- )
153
+ ] + self.code_model.client.parameters.method_signature_kwargs
160
154
  return self.parameter_serializer.serialize_method(
161
155
  function_def="def",
162
156
  method_name=self.code_model.client.send_request_name,
@@ -167,9 +161,8 @@ class ClientSerializer:
167
161
  def send_request_signature_and_response_type_annotation(
168
162
  self, async_mode: bool
169
163
  ) -> str:
170
- send_request_signature = self._send_request_signature(async_mode)
164
+ send_request_signature = self._send_request_signature()
171
165
  return utils.method_signature_and_response_type_annotation_template(
172
- is_python3_file=async_mode or self.is_python3_file,
173
166
  method_signature=send_request_signature,
174
167
  response_type_annotation="Awaitable[AsyncHttpResponse]"
175
168
  if async_mode
@@ -255,10 +248,9 @@ class ClientSerializer:
255
248
 
256
249
 
257
250
  class ConfigSerializer:
258
- def __init__(self, code_model: CodeModel, is_python3_file: bool) -> None:
251
+ def __init__(self, code_model: CodeModel) -> None:
259
252
  self.code_model = code_model
260
253
  self.parameter_serializer = ParameterSerializer()
261
- self.is_python3_file = is_python3_file
262
254
 
263
255
  def _init_signature(self, async_mode: bool) -> str:
264
256
  return self.parameter_serializer.serialize_method(
@@ -266,23 +258,20 @@ class ConfigSerializer:
266
258
  method_name="__init__",
267
259
  need_self_param=True,
268
260
  method_param_signatures=self.code_model.config.parameters.method_signature(
269
- async_mode or self.is_python3_file, async_mode
261
+ async_mode
270
262
  ),
271
263
  )
272
264
 
273
265
  def init_signature_and_response_type_annotation(self, async_mode: bool) -> str:
274
266
  init_signature = self._init_signature(async_mode)
275
267
  return utils.method_signature_and_response_type_annotation_template(
276
- is_python3_file=async_mode or self.is_python3_file,
277
268
  method_signature=init_signature,
278
269
  response_type_annotation="None",
279
270
  )
280
271
 
281
- def pop_kwargs_from_signature(self, async_mode: bool) -> List[str]:
272
+ def pop_kwargs_from_signature(self) -> List[str]:
282
273
  return self.parameter_serializer.pop_kwargs_from_signature(
283
- self.code_model.config.parameters.kwargs_to_pop(
284
- async_mode or self.is_python3_file
285
- ),
274
+ self.code_model.config.parameters.kwargs_to_pop,
286
275
  check_kwarg_dict=False,
287
276
  pop_headers_kwarg=PopKwargType.NO,
288
277
  pop_params_kwarg=PopKwargType.NO,
@@ -34,14 +34,12 @@ class GeneralSerializer:
34
34
 
35
35
  template = self.env.get_template("client.py.jinja2")
36
36
 
37
- python3_only = self.code_model.options["python3_only"]
38
37
  return template.render(
39
38
  code_model=self.code_model,
40
39
  async_mode=self.async_mode,
41
- serializer=ClientSerializer(self.code_model, is_python3_file=python3_only),
40
+ serializer=ClientSerializer(self.code_model),
42
41
  imports=FileImportSerializer(
43
42
  self.code_model.client.imports(self.async_mode),
44
- is_python3_file=self.async_mode or python3_only,
45
43
  ),
46
44
  )
47
45
 
@@ -85,7 +83,6 @@ class GeneralSerializer:
85
83
  code_model=self.code_model,
86
84
  imports=FileImportSerializer(
87
85
  file_import,
88
- is_python3_file=self.async_mode,
89
86
  ),
90
87
  async_mode=self.async_mode,
91
88
  )
@@ -99,15 +96,13 @@ class GeneralSerializer:
99
96
  package_name if package_name else self.code_model.client.name.lower()
100
97
  )
101
98
  template = self.env.get_template("config.py.jinja2")
102
- python3_only = self.code_model.options["python3_only"]
103
99
  return template.render(
104
100
  code_model=self.code_model,
105
101
  async_mode=self.async_mode,
106
102
  imports=FileImportSerializer(
107
103
  self.code_model.config.imports(self.async_mode),
108
- is_python3_file=self.async_mode or python3_only,
109
104
  ),
110
- serializer=ConfigSerializer(self.code_model, is_python3_file=python3_only),
105
+ serializer=ConfigSerializer(self.code_model),
111
106
  sdk_moniker=sdk_moniker,
112
107
  )
113
108
 
@@ -58,11 +58,8 @@ def _get_import_clauses(imports: List[ImportModel], delimiter: str) -> List[str]
58
58
 
59
59
 
60
60
  class FileImportSerializer:
61
- def __init__(
62
- self, file_import: FileImport, is_python3_file: bool, async_mode: bool = False
63
- ) -> None:
61
+ def __init__(self, file_import: FileImport, async_mode: bool = False) -> None:
64
62
  self.file_import = file_import
65
- self.is_python3_file = is_python3_file
66
63
  self.async_mode = async_mode
67
64
 
68
65
  def _get_imports_list(
@@ -82,20 +79,14 @@ class FileImportSerializer:
82
79
  return file_import_copy.get_imports_from_section(baseline_typing_section)
83
80
 
84
81
  def _add_type_checking_import(self):
85
- any_typing = any(
86
- self.file_import.get_imports_from_section(TypingSection.TYPING)
87
- )
88
- conditional_and_not_py3 = not self.is_python3_file and any(
89
- self.file_import.get_imports_from_section(TypingSection.CONDITIONAL)
90
- )
91
- if any_typing or conditional_and_not_py3:
82
+ if any(self.file_import.get_imports_from_section(TypingSection.TYPING)):
92
83
  self.file_import.add_submodule_import(
93
84
  "typing", "TYPE_CHECKING", ImportType.STDLIB
94
85
  )
95
86
 
96
87
  def _get_typing_definitions(self) -> str:
97
88
  def declare_defintion(
98
- spacing: str, type_name: str, type_definition: TypeDefinition
89
+ type_name: str, type_definition: TypeDefinition
99
90
  ) -> List[str]:
100
91
  ret: List[str] = []
101
92
  definition_value = (
@@ -112,21 +103,20 @@ class FileImportSerializer:
112
103
  ):
113
104
  if version is not None:
114
105
  ret.append(
115
- "{}{} sys.version_info >= {}:".format(
116
- spacing, "if" if i == 0 else "elif", version
106
+ "{} sys.version_info >= {}:".format(
107
+ "if" if i == 0 else "elif", version
117
108
  )
118
109
  )
119
110
  elif i > 0:
120
- ret.append("{}else:".format(spacing))
111
+ ret.append("else:")
121
112
  for import_clause in _get_import_clauses(
122
113
  [type_definition.version_imports[version]], "\n"
123
114
  ):
124
115
  ret.append(
125
- "{}{}{}".format(
116
+ "{}{}".format(
126
117
  " "
127
118
  if len(versions) > 1 or version is not None
128
119
  else "",
129
- spacing,
130
120
  import_clause,
131
121
  )
132
122
  )
@@ -134,15 +124,14 @@ class FileImportSerializer:
134
124
  ret[
135
125
  -1
136
126
  ] += " # type: ignore # pylint: disable=ungrouped-imports"
137
- ret.append("{}{} = {}".format(spacing, type_name, definition_value))
127
+ ret.append("{} = {}".format(type_name, definition_value))
138
128
  return ret
139
129
 
140
130
  if not self.file_import.type_definitions:
141
131
  return ""
142
- spacing = "" if self.is_python3_file else " "
143
132
  declarations: List[str] = [""]
144
133
  for type_name, value in self.file_import.type_definitions.items():
145
- declarations.extend(declare_defintion(spacing, type_name, value))
134
+ declarations.extend(declare_defintion(type_name, value))
146
135
  return "\n".join(declarations)
147
136
 
148
137
  def __str__(self) -> str:
@@ -150,7 +139,7 @@ class FileImportSerializer:
150
139
  regular_imports = ""
151
140
  regular_imports_list = self._get_imports_list(
152
141
  baseline_typing_section=TypingSection.REGULAR,
153
- add_conditional_typing=self.is_python3_file,
142
+ add_conditional_typing=True,
154
143
  )
155
144
 
156
145
  if regular_imports_list:
@@ -161,7 +150,7 @@ class FileImportSerializer:
161
150
  typing_imports = ""
162
151
  typing_imports_list = self._get_imports_list(
163
152
  baseline_typing_section=TypingSection.TYPING,
164
- add_conditional_typing=not self.is_python3_file,
153
+ add_conditional_typing=False,
165
154
  )
166
155
  if typing_imports_list:
167
156
  typing_imports += "\n\nif TYPE_CHECKING:\n # pylint: disable=unused-import,ungrouped-imports\n "
@@ -143,13 +143,11 @@ class MetadataSerializer:
143
143
  get_operation_serializer,
144
144
  code_model=self.code_model,
145
145
  async_mode=True,
146
- is_python3_file=True,
147
146
  ),
148
147
  get_sync_operation_serializer=functools.partial(
149
148
  get_operation_serializer,
150
149
  code_model=self.code_model,
151
150
  async_mode=False,
152
- is_python3_file=False,
153
151
  ),
154
152
  has_credential=bool(self.code_model.credential),
155
153
  )
@@ -3,7 +3,6 @@
3
3
  # Licensed under the MIT License. See License.txt in the project root for
4
4
  # license information.
5
5
  # --------------------------------------------------------------------------
6
- from abc import abstractmethod
7
6
  from typing import cast, List
8
7
  from jinja2 import Environment
9
8
  from ..models import ModelType, CodeModel, Property
@@ -27,22 +26,17 @@ def _documentation_string(
27
26
  return retval
28
27
 
29
28
 
30
- class ModelBaseSerializer:
31
- def __init__(
32
- self, code_model: CodeModel, env: Environment, is_python3_file: bool
33
- ) -> None:
29
+ class ModelSerializer:
30
+ def __init__(self, code_model: CodeModel, env: Environment) -> None:
34
31
  self.code_model = code_model
35
32
  self.env = env
36
- self.is_python3_file = is_python3_file
37
33
 
38
34
  def serialize(self) -> str:
39
35
  # Generate the models
40
36
  template = self.env.get_template("model_container.py.jinja2")
41
37
  return template.render(
42
38
  code_model=self.code_model,
43
- imports=FileImportSerializer(
44
- self.imports(), is_python3_file=self.is_python3_file
45
- ),
39
+ imports=FileImportSerializer(self.imports()),
46
40
  str=str,
47
41
  serializer=self,
48
42
  )
@@ -54,6 +48,11 @@ class ModelBaseSerializer:
54
48
  )
55
49
  for model in self.code_model.model_types:
56
50
  file_import.merge(model.imports(is_operation_file=False))
51
+ init_line_parameters = [
52
+ p for p in model.properties if not p.readonly and not p.is_discriminator
53
+ ]
54
+ for param in init_line_parameters:
55
+ file_import.merge(param.imports())
57
56
  return file_import
58
57
 
59
58
  @staticmethod
@@ -92,18 +91,12 @@ class ModelBaseSerializer:
92
91
  def variable_documentation_string(prop: Property) -> List[str]:
93
92
  return _documentation_string(prop, "ivar", "vartype")
94
93
 
95
- @abstractmethod
96
- def super_call_template(self, model: ModelType) -> str:
97
- ...
98
-
99
94
  def super_call(self, model: ModelType):
100
- return self.super_call_template(model).format(
101
- self.properties_to_pass_to_super(model)
102
- )
95
+ return f"super().__init__({self.properties_to_pass_to_super(model)})"
103
96
 
104
97
  def initialize_properties(self, model: ModelType) -> List[str]:
105
98
  init_args = []
106
- for prop in ModelBaseSerializer.get_properties_to_initialize(model):
99
+ for prop in self.get_properties_to_initialize(model):
107
100
  if prop.is_discriminator:
108
101
  discriminator_value = (
109
102
  f"'{model.discriminator_value}'"
@@ -120,13 +113,17 @@ class ModelBaseSerializer:
120
113
  elif prop.readonly:
121
114
  init_args.append(f"self.{prop.client_name} = None")
122
115
  elif not prop.constant:
123
- init_args.append(self.initialize_standard_arg(prop))
116
+ init_args.append(f"self.{prop.client_name} = {prop.client_name}")
124
117
  return init_args
125
118
 
126
- def initialize_standard_property(self, prop: Property):
119
+ @staticmethod
120
+ def initialize_standard_property(prop: Property):
127
121
  if not (prop.optional or prop.client_default_value is not None):
128
- return self.required_property_no_default_init(prop)
129
- return self.optional_property_init(prop)
122
+ return f"{prop.client_name}: {prop.type_annotation()},{prop.pylint_disable}"
123
+ return (
124
+ f"{prop.client_name}: {prop.type_annotation()} = "
125
+ f"{prop.client_default_value_declaration},{prop.pylint_disable}"
126
+ )
130
127
 
131
128
  @staticmethod
132
129
  def discriminator_docstring(model: ModelType) -> str:
@@ -135,22 +132,34 @@ class ModelBaseSerializer:
135
132
  f"Known sub-classes are: {', '.join(v.name for v in model.discriminated_subtypes.values())}"
136
133
  )
137
134
 
138
- @abstractmethod
139
135
  def init_line(self, model: ModelType) -> List[str]:
140
- ...
136
+ init_properties_declaration = []
137
+ init_line_parameters = [
138
+ p
139
+ for p in model.properties
140
+ if not p.readonly and not p.is_discriminator and not p.constant
141
+ ]
142
+ init_line_parameters.sort(key=lambda x: x.optional)
143
+ if init_line_parameters:
144
+ init_properties_declaration.append("*,")
145
+ for param in init_line_parameters:
146
+ init_properties_declaration.append(self.initialize_standard_property(param))
147
+
148
+ return init_properties_declaration
141
149
 
142
- @abstractmethod
143
- def properties_to_pass_to_super(self, model: ModelType) -> str:
144
- ...
145
-
146
- @abstractmethod
147
- def required_property_no_default_init(self, prop: Property) -> str:
148
- ...
149
-
150
- @abstractmethod
151
- def optional_property_init(self, prop: Property) -> str:
152
- ...
153
-
154
- @abstractmethod
155
- def initialize_standard_arg(self, prop: Property) -> str:
156
- ...
150
+ @staticmethod
151
+ def properties_to_pass_to_super(model: ModelType) -> str:
152
+ properties_to_pass_to_super = []
153
+ for parent in model.parents:
154
+ for prop in model.properties:
155
+ if (
156
+ prop in parent.properties
157
+ and not prop.is_discriminator
158
+ and not prop.constant
159
+ and not prop.readonly
160
+ ):
161
+ properties_to_pass_to_super.append(
162
+ f"{prop.client_name}={prop.client_name}"
163
+ )
164
+ properties_to_pass_to_super.append("**kwargs")
165
+ return ", ".join(properties_to_pass_to_super)
@@ -22,13 +22,11 @@ class OperationGroupsSerializer:
22
22
  code_model: CodeModel,
23
23
  env: Environment,
24
24
  async_mode: bool,
25
- is_python3_file: bool,
26
25
  operation_group: Optional[OperationGroup] = None,
27
26
  ) -> None:
28
27
  self.code_model = code_model
29
28
  self.env = env
30
29
  self.async_mode = async_mode
31
- self.is_python3_file = is_python3_file
32
30
  self.operation_group = operation_group
33
31
 
34
32
  def serialize(self) -> str:
@@ -42,7 +40,6 @@ class OperationGroupsSerializer:
42
40
  imports.merge(
43
41
  operation_group.imports(
44
42
  async_mode=self.async_mode,
45
- is_python3_file=self.is_python3_file,
46
43
  )
47
44
  )
48
45
 
@@ -54,21 +51,17 @@ class OperationGroupsSerializer:
54
51
  operation_groups=operation_groups,
55
52
  imports=FileImportSerializer(
56
53
  imports,
57
- is_python3_file=self.is_python3_file,
58
54
  async_mode=self.async_mode,
59
55
  ),
60
56
  async_mode=self.async_mode,
61
- is_python3_file=self.is_python3_file,
62
57
  get_operation_serializer=functools.partial(
63
58
  get_operation_serializer,
64
59
  code_model=self.code_model,
65
60
  async_mode=self.async_mode,
66
- is_python3_file=self.is_python3_file,
67
61
  ),
68
62
  request_builder_serializer=RequestBuilderSerializer(
69
63
  self.code_model,
70
64
  async_mode=False,
71
- is_python3_file=self.is_python3_file,
72
65
  ),
73
66
  request_builders=[
74
67
  rb for rb in self.code_model.request_builders if not rb.abstract
@@ -18,40 +18,19 @@ class OperationsInitSerializer:
18
18
  self.env = env
19
19
  self.async_mode = async_mode
20
20
 
21
- def _operation_group_imports_helper(self, filename_suffix: str = "") -> List[str]:
21
+ def operation_group_imports(self) -> List[str]:
22
22
  def _get_filename(operation_group: OperationGroup) -> str:
23
- prefix = (
23
+ return (
24
24
  "_operations"
25
25
  if self.code_model.options["combine_operation_files"]
26
26
  else operation_group.filename
27
27
  )
28
- return prefix + filename_suffix
29
28
 
30
29
  return [
31
30
  f"from .{_get_filename(og)} import {og.class_name}"
32
31
  for og in self.code_model.operation_groups
33
32
  ]
34
33
 
35
- def operation_group_imports(self) -> List[str]:
36
- typed_py3_files = self.code_model.options["add_python3_operation_files"]
37
- py3_only = self.code_model.options["python3_only"]
38
- if typed_py3_files and not py3_only and not self.async_mode:
39
- retval: List[str] = ["try:"]
40
- retval.extend(
41
- [
42
- f" {line}"
43
- for line in self._operation_group_imports_helper(
44
- filename_suffix="_py3"
45
- )
46
- ]
47
- )
48
- retval.append("except (SyntaxError, ImportError):")
49
- retval.extend(
50
- [f" {line}" for line in self._operation_group_imports_helper()]
51
- )
52
- return retval
53
- return self._operation_group_imports_helper()
54
-
55
34
  def serialize(self) -> str:
56
35
  operation_group_init_template = self.env.get_template(
57
36
  "operations_folder_init.py.jinja2"
@@ -19,9 +19,7 @@ class PatchSerializer:
19
19
  imports.add_submodule_import(
20
20
  "typing", "List", ImportType.STDLIB, TypingSection.CONDITIONAL
21
21
  )
22
- is_python3_file = self.code_model.options["python3_only"]
23
22
  return template.render(
24
23
  code_model=self.code_model,
25
- imports=FileImportSerializer(imports, is_python3_file=is_python3_file),
26
- is_python3_file=is_python3_file,
24
+ imports=FileImportSerializer(imports),
27
25
  )
@@ -18,13 +18,11 @@ class RequestBuildersSerializer:
18
18
  code_model: CodeModel,
19
19
  env: Environment,
20
20
  request_builders: List[RequestBuilderType],
21
- is_python3_file: bool,
22
21
  ) -> None:
23
22
  self.code_model = code_model
24
23
  self.env = env
25
24
  self.request_builders = request_builders
26
25
  self.group_name = request_builders[0].group_name
27
- self.is_python3_file = is_python3_file
28
26
 
29
27
  @property
30
28
  def imports(self) -> FileImport:
@@ -49,9 +47,8 @@ class RequestBuildersSerializer:
49
47
  request_builders=[rb for rb in self.request_builders if not rb.abstract],
50
48
  imports=FileImportSerializer(
51
49
  self.imports,
52
- is_python3_file=True,
53
50
  ),
54
51
  request_builder_serializer=RequestBuilderSerializer(
55
- self.code_model, async_mode=False, is_python3_file=self.is_python3_file
52
+ self.code_model, async_mode=False
56
53
  ),
57
54
  )
@@ -7,10 +7,7 @@
7
7
 
8
8
  def method_signature_and_response_type_annotation_template(
9
9
  *,
10
- is_python3_file: bool,
11
10
  method_signature: str,
12
11
  response_type_annotation: str,
13
12
  ) -> str:
14
- if is_python3_file:
15
- return f"{method_signature} -> {response_type_annotation}:"
16
- return f"{method_signature}:\n # type: (...) -> {response_type_annotation}"
13
+ return f"{method_signature} -> {response_type_annotation}:"
@@ -6,7 +6,7 @@
6
6
 
7
7
  {{ imports }}
8
8
 
9
- {{ serializer.class_definition(async_mode) }}
9
+ {{ serializer.class_definition }}
10
10
  """{{ op_tools.wrap_string(code_model.client.description, "\n") | indent }}
11
11
 
12
12
  {{ op_tools.serialize_with_wrap(serializer.property_descriptions(async_mode), "\n ") | indent }}
@@ -14,8 +14,8 @@
14
14
  {% if serializer.should_init_super %}
15
15
  super().__init__()
16
16
  {% endif %}
17
- {% if code_model.client.parameters.kwargs_to_pop(async_mode) %}
18
- {{ op_tools.serialize(serializer.pop_kwargs_from_signature(async_mode)) | indent(8) }}
17
+ {% if code_model.client.parameters.kwargs_to_pop %}
18
+ {{ op_tools.serialize(serializer.pop_kwargs_from_signature()) | indent(8) }}
19
19
  {% endif %}
20
20
  {% if code_model.client.has_parameterized_host %}
21
21
  {{ serializer.host_variable_name }} = {{ keywords.escape_str(code_model.client.url) }}
@@ -22,8 +22,8 @@ class {{ code_model.client.name }}Configuration(Configuration): # pylint: disab
22
22
  {{ op_tools.serialize_with_wrap(serializer.property_descriptions(async_mode), "\n ") | indent }}
23
23
  {{ serializer.init_signature_and_response_type_annotation(async_mode) | indent }}
24
24
  super({{ code_model.client.name }}Configuration, self).__init__(**kwargs)
25
- {% if code_model.config.parameters.kwargs_to_pop(async_mode) %}
26
- {{ op_tools.serialize(serializer.pop_kwargs_from_signature(async_mode)) | indent(8) }}
25
+ {% if code_model.config.parameters.kwargs_to_pop %}
26
+ {{ op_tools.serialize(serializer.pop_kwargs_from_signature()) | indent(8) }}
27
27
  {% endif %}
28
28
  {% if serializer.check_required_parameters() %}
29
29
  {{ op_tools.serialize(serializer.check_required_parameters()) | indent(8) -}}
@@ -20,7 +20,7 @@
20
20
  "sync": {
21
21
  {% for gp in global_parameters.method | rejectattr("client_name", "equalto", "api_version") | rejectattr("is_host") %}
22
22
  {{ gp.client_name | tojson }}: {
23
- "signature": {{ gp.method_signature(is_python3_file=False, async_mode=False) | tojson }},
23
+ "signature": {{ gp.method_signature(async_mode=False) | tojson }},
24
24
  "description": {{ gp.description | tojson }},
25
25
  "docstring_type": {{ gp.docstring_type(async_mode=False) | tojson }},
26
26
  "required": {{ (not gp.optional) | tojson }}
@@ -30,7 +30,7 @@
30
30
  "async": {
31
31
  {% for gp in global_parameters.method | rejectattr("client_name", "equalto", "api_version") | rejectattr("is_host") %}
32
32
  {{ gp.client_name | tojson }}: {
33
- "signature": {{ (gp.method_signature(is_python3_file=True, async_mode=True)) | tojson }},
33
+ "signature": {{ (gp.method_signature(async_mode=True)) | tojson }},
34
34
  "description": {{ gp.description | tojson }},
35
35
  "docstring_type": {{ gp.docstring_type(async_mode=True) | tojson }},
36
36
  "required": {{ (not gp.optional) | tojson }}
@@ -53,7 +53,7 @@
53
53
  },
54
54
  {% if not client.has_parameterized_host %}
55
55
  "base_url": {
56
- "signature": {{ client.parameters.host.method_signature(False, async_mode=False) | tojson }},
56
+ "signature": {{ client.parameters.host.method_signature(async_mode=False) | tojson }},
57
57
  "description": "Service URL",
58
58
  "docstring_type": "str",
59
59
  "required": false
@@ -75,7 +75,7 @@
75
75
  },
76
76
  {% if not client.has_parameterized_host %}
77
77
  "base_url": {
78
- "signature": {{ client.parameters.host.method_signature(True, async_mode=True) | tojson }},
78
+ "signature": {{ client.parameters.host.method_signature(async_mode=True) | tojson }},
79
79
  "description": "Service URL",
80
80
  "docstring_type": "str",
81
81
  "required": false
@@ -3,21 +3,14 @@
3
3
  {{ code_model.options['license_header'] }}
4
4
  {% macro iterate_models_py3() %}
5
5
  {% for schema in schemas %}
6
- from .{{ code_model.get_models_filename(is_python3_file=True) }} import {{ schema }}
6
+ from .{{ code_model.models_filename }} import {{ schema }}
7
7
  {% endfor %}
8
8
  {% endmacro %}
9
-
10
9
  {% if schemas %}
11
- {% if code_model.options["python3_only"] %}
12
- {{ iterate_models_py3() }}
13
- {% else %}
14
- try:
15
- {{ iterate_models_py3() | indent-}}
16
- except (SyntaxError, ImportError):
17
- {% for schema in schemas %}
18
- from .{{ code_model.get_models_filename(is_python3_file=False) }} import {{ schema }} # type: ignore
19
- {% endfor %}
20
- {% endif %}
10
+
11
+ {% for schema in schemas %}
12
+ from .{{ code_model.models_filename }} import {{ schema }}
13
+ {% endfor %}
21
14
  {% endif %}
22
15
  {% if enums %}
23
16
 
@@ -1,5 +1,5 @@
1
1
  {% set disable = " # pylint: disable=too-many-public-methods" if operation_group.operations | length > 20 else "" %}
2
- {% set base_class = ("(" + operation_group.base_class(async_mode) + ")") if operation_group.base_class(async_mode) else "" %}
2
+ {% set base_class = ("(" + operation_group.base_class + ")") if operation_group.base_class else "" %}
3
3
  {% macro check_abstract_methods() %}
4
4
  {% if operation_group.has_abstract_operations %}
5
5
  raise_if_not_implemented(self.__class__, [