@autorest/python 6.17.0 → 6.18.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.
@@ -55,7 +55,7 @@ class BaseType(BaseModel, ABC): # pylint: disable=too-many-public-methods
55
55
  return self.imports(**kwargs)
56
56
 
57
57
  def imports_for_sample(self) -> FileImport:
58
- return self.imports()
58
+ return FileImport(self.code_model)
59
59
 
60
60
  @staticmethod
61
61
  def serialize_sample_value(value: Any) -> str:
@@ -495,7 +495,9 @@ class Operation(OperationBase[Response]):
495
495
  relative_path = "..." if async_mode else ".."
496
496
  if self.code_model.options["models_mode"] == "dpg":
497
497
  if self.parameters.has_body:
498
- if not self.has_form_data_body:
498
+ if self.has_form_data_body:
499
+ file_import.add_submodule_import(relative_path, "_model_base", ImportType.LOCAL)
500
+ else:
499
501
  file_import.add_submodule_import(
500
502
  f"{relative_path}_model_base",
501
503
  "SdkJSONEncoder",
@@ -114,7 +114,7 @@ class OperationGroup(BaseModel):
114
114
  and not self.is_mixin
115
115
  ):
116
116
  file_import.add_submodule_import(relative_path, "models", ImportType.LOCAL, alias="_models")
117
- if self.code_model.need_mixin_abc:
117
+ if self.is_mixin:
118
118
  file_import.add_submodule_import(".._vendor", f"{self.client.name}MixinABC", ImportType.LOCAL)
119
119
  if self.has_abstract_operations:
120
120
  file_import.add_submodule_import(".._vendor", "raise_if_not_implemented", ImportType.LOCAL)
@@ -381,6 +381,12 @@ class ClientParameter(Parameter):
381
381
  ):
382
382
  # this means i am the base url
383
383
  return ParameterMethodLocation.KEYWORD_ONLY
384
+ if (
385
+ self.client_default_value is not None
386
+ and self.code_model.options["from_typespec"]
387
+ and not self.code_model.options["azure_arm"]
388
+ ):
389
+ return ParameterMethodLocation.KEYWORD_ONLY
384
390
  return ParameterMethodLocation.POSITIONAL
385
391
 
386
392
 
@@ -516,7 +516,7 @@ class JinjaSerializer(ReaderAndWriter): # pylint: disable=abstract-method
516
516
  and operation.api_versions[0] != self.code_model.options["default_api_version"]
517
517
  ):
518
518
  continue
519
- samples = operation.yaml_data["samples"]
519
+ samples = operation.yaml_data.get("samples")
520
520
  if not samples or operation.name.startswith("_"):
521
521
  continue
522
522
  for value in samples.values():
@@ -105,11 +105,12 @@ class GeneralSerializer(BaseSerializer):
105
105
  typing_section=TypingSection.TYPING,
106
106
  )
107
107
  for client in clients:
108
- file_import.add_submodule_import(
109
- "._configuration",
110
- f"{client.name}Configuration",
111
- ImportType.LOCAL,
112
- )
108
+ if client.has_mixin:
109
+ file_import.add_submodule_import(
110
+ "._configuration",
111
+ f"{client.name}Configuration",
112
+ ImportType.LOCAL,
113
+ )
113
114
  if self.code_model.has_etag:
114
115
  file_import.add_submodule_import("typing", "Optional", ImportType.STDLIB)
115
116
  file_import.add_submodule_import(
@@ -45,7 +45,8 @@
45
45
  __flattened_items = ["{{ model.flattened_items|join('\", \"') }}"]
46
46
  {% endif %}
47
47
 
48
- {% if not model.internal and serializer.init_line(model) %}
48
+ {% set need_init = (not model.internal) and (serializer.init_line(model) or model.discriminator)%}
49
+ {% if need_init %}
49
50
  @overload
50
51
  def __init__(
51
52
  self,
@@ -64,7 +65,7 @@
64
65
 
65
66
  {% endif %}
66
67
  {% set initialize_properties = serializer.initialize_properties(model) %}
67
- {% if not model.internal and serializer.init_line(model) or initialize_properties %}
68
+ {% if need_init or initialize_properties %}
68
69
  def __init__(self, *args: Any, **kwargs: Any) -> None:{{ '# pylint: disable=useless-super-delegation' if not initialize_properties else '' }}
69
70
  {% for line in serializer.super_call(model) %}
70
71
  {{ line }}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@autorest/python",
3
- "version": "6.17.0",
3
+ "version": "6.18.0",
4
4
  "description": "The Python extension for generators in AutoRest.",
5
5
  "main": "index.js",
6
6
  "repository": {
@@ -25,7 +25,7 @@
25
25
  "devDependencies": {
26
26
  "@microsoft.azure/autorest.testserver": "^3.3.46",
27
27
  "typescript": "~5.1.3",
28
- "@azure-tools/typespec-python": "^0.27.0"
28
+ "@azure-tools/typespec-python": "^0.28.0"
29
29
  },
30
30
  "files": [
31
31
  "autorest/**/*.py",