@autorest/python 6.2.2 → 6.2.4

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.
@@ -172,10 +172,7 @@ class Client(_ClientConfigBase[ClientGlobalParameterList]):
172
172
  )
173
173
 
174
174
  for gp in self.parameters:
175
- if (
176
- gp.method_location == ParameterMethodLocation.KWARG
177
- and gp not in self.parameters.kwargs_to_pop
178
- ):
175
+ if gp.method_location == ParameterMethodLocation.KWARG:
179
176
  continue
180
177
  file_import.merge(gp.imports(async_mode))
181
178
  file_import.add_submodule_import(
@@ -393,6 +393,15 @@ class _RequestBuilderParameterList(
393
393
  p for p in super().path if p.location != ParameterLocation.ENDPOINT_PATH
394
394
  ]
395
395
 
396
+ @property
397
+ def constant(
398
+ self,
399
+ ) -> List[Union[RequestBuilderParameter, RequestBuilderBodyParameterType]]:
400
+ """All constant parameters"""
401
+ return [
402
+ p for p in super().constant if p.location != ParameterLocation.ENDPOINT_PATH
403
+ ]
404
+
396
405
 
397
406
  class RequestBuilderParameterList(_RequestBuilderParameterList):
398
407
  """Parameter list for Request Builder"""
@@ -463,15 +472,6 @@ class ClientGlobalParameterList(_ClientGlobalParameterList[ClientParameter]):
463
472
  except StopIteration:
464
473
  return None
465
474
 
466
- @property
467
- def kwargs_to_pop(self) -> List[Union[ClientParameter, BodyParameter]]:
468
- """We only want to pass base url path parameters in the client"""
469
- return [
470
- k
471
- for k in super().kwargs_to_pop
472
- if k.location == ParameterLocation.ENDPOINT_PATH
473
- ]
474
-
475
475
 
476
476
  class ConfigGlobalParameterList(_ClientGlobalParameterList[ConfigParameter]):
477
477
  """Parameter list for config"""
@@ -248,10 +248,9 @@ class DpgModelSerializer(_ModelSerializer):
248
248
 
249
249
  @staticmethod
250
250
  def declare_property(prop: Property) -> List[str]:
251
- attribute_key = _ModelSerializer.escape_dot(prop.rest_api_name)
252
251
  args = []
253
- if prop.client_name != attribute_key or prop.is_discriminator:
254
- args.append(f'name="{attribute_key}"')
252
+ if prop.client_name != prop.rest_api_name or prop.is_discriminator:
253
+ args.append(f'name="{prop.rest_api_name}"')
255
254
  if prop.readonly:
256
255
  args.append("readonly=True")
257
256
  if prop.client_default_value is not None:
@@ -87,6 +87,15 @@ class SampleSerializer:
87
87
 
88
88
  return client_params
89
89
 
90
+ @staticmethod
91
+ def handle_param(param: Any) -> str:
92
+ if isinstance(param, str):
93
+ if any(i in param for i in '\r\n"'):
94
+ return f'"""{param}"""'
95
+ return f'"{param}"'
96
+
97
+ return str(param)
98
+
90
99
  # prepare operation parameters
91
100
  def _operation_params(self) -> Dict[str, Any]:
92
101
  params_positional = [
@@ -94,7 +103,6 @@ class SampleSerializer:
94
103
  for p in self.operation.parameters.positional
95
104
  if not p.client_default_value
96
105
  ]
97
- cls = lambda x: f'"{x}"' if isinstance(x, str) else str(x)
98
106
  failure_info = "fail to find required param named {} in example file {}"
99
107
  operation_params = {}
100
108
  for param in params_positional:
@@ -103,7 +111,7 @@ class SampleSerializer:
103
111
  if not param.optional:
104
112
  if not param_value:
105
113
  raise Exception(failure_info.format(name, self.sample_origin_name))
106
- operation_params[param.client_name] = cls(param_value)
114
+ operation_params[param.client_name] = self.handle_param(param_value)
107
115
  return operation_params
108
116
 
109
117
  def _operation_group_name(self) -> str:
@@ -5,9 +5,6 @@
5
5
  {{ serializer.init_signature_and_response_type_annotation(async_mode) | indent }}
6
6
  {% if serializer.should_init_super %}
7
7
  super().__init__()
8
- {% endif %}
9
- {% if client.parameters.kwargs_to_pop %}
10
- {{ op_tools.serialize(serializer.pop_kwargs_from_signature()) | indent(8) }}
11
8
  {% endif %}
12
9
  {% if client.has_parameterized_host %}
13
10
  {{ serializer.host_variable_name }} = {{ keywords.escape_str(client.url) }}
@@ -92,7 +92,7 @@ setup(
92
92
  "azure-core<2.0.0,>=1.24.0",
93
93
  {% endif %}
94
94
  {% if code_model.need_typing_extensions %}
95
- "typing_extensions>=4.3.0; python_version<'3.8.0'",
95
+ "typing-extensions>=4.3.0; python_version<'3.8.0'",
96
96
  {% endif %}
97
97
  ],
98
98
  {% if package_mode %}
@@ -4,6 +4,7 @@
4
4
  # license information.
5
5
  # --------------------------------------------------------------------------
6
6
  from typing import Any, Dict
7
+ import re
7
8
  from .python_mappings import PadType, RESERVED_WORDS, REDEFINED_BUILTINS
8
9
 
9
10
 
@@ -12,6 +13,7 @@ def pad_reserved_words(name: str, pad_type: PadType):
12
13
  if not name:
13
14
  # we'll pass in empty operation groups sometime etc.
14
15
  return name
16
+ name = pad_special_chars(name)
15
17
  name_prefix = "_" if name[0] == "_" else ""
16
18
  name = name[1:] if name[0] == "_" else name
17
19
  if name.lower() in RESERVED_WORDS[pad_type]:
@@ -22,3 +24,7 @@ def pad_reserved_words(name: str, pad_type: PadType):
22
24
  def add_redefined_builtin_info(name: str, yaml_data: Dict[str, Any]) -> None:
23
25
  if name in REDEFINED_BUILTINS:
24
26
  yaml_data["pylintDisable"] = "redefined-builtin"
27
+
28
+
29
+ def pad_special_chars(name: str) -> str:
30
+ return re.sub(r"[^A-z0-9_]", "_", name)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@autorest/python",
3
- "version": "6.2.2",
3
+ "version": "6.2.4",
4
4
  "description": "The Python extension for generators in AutoRest.",
5
5
  "repository": {
6
6
  "type": "git",