@autorest/python 6.9.2 → 6.9.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.
Files changed (40) hide show
  1. package/autorest/_utils.py +48 -20
  2. package/autorest/codegen/__init__.py +8 -1
  3. package/autorest/codegen/models/__init__.py +17 -2
  4. package/autorest/codegen/models/base.py +3 -4
  5. package/autorest/codegen/models/client.py +5 -6
  6. package/autorest/codegen/models/combined_type.py +1 -1
  7. package/autorest/codegen/models/constant_type.py +3 -17
  8. package/autorest/codegen/models/credential_types.py +2 -2
  9. package/autorest/codegen/models/dictionary_type.py +1 -1
  10. package/autorest/codegen/models/enum_type.py +78 -23
  11. package/autorest/codegen/models/imports.py +23 -5
  12. package/autorest/codegen/models/list_type.py +1 -1
  13. package/autorest/codegen/models/lro_operation.py +3 -0
  14. package/autorest/codegen/models/model_type.py +1 -1
  15. package/autorest/codegen/models/operation.py +4 -4
  16. package/autorest/codegen/models/operation_group.py +2 -2
  17. package/autorest/codegen/models/paging_operation.py +1 -1
  18. package/autorest/codegen/models/parameter.py +6 -3
  19. package/autorest/codegen/models/primitive_types.py +20 -25
  20. package/autorest/codegen/models/property.py +25 -4
  21. package/autorest/codegen/models/request_builder.py +4 -5
  22. package/autorest/codegen/models/response.py +1 -1
  23. package/autorest/codegen/serializers/builder_serializer.py +23 -41
  24. package/autorest/codegen/serializers/client_serializer.py +1 -1
  25. package/autorest/codegen/serializers/general_serializer.py +6 -7
  26. package/autorest/codegen/serializers/model_serializer.py +10 -9
  27. package/autorest/codegen/serializers/operation_groups_serializer.py +1 -1
  28. package/autorest/codegen/serializers/patch_serializer.py +1 -1
  29. package/autorest/codegen/serializers/request_builders_serializer.py +1 -1
  30. package/autorest/codegen/serializers/sample_serializer.py +1 -1
  31. package/autorest/codegen/serializers/types_serializer.py +1 -1
  32. package/autorest/codegen/templates/client.py.jinja2 +1 -1
  33. package/autorest/codegen/templates/enum.py.jinja2 +3 -3
  34. package/autorest/codegen/templates/model_base.py.jinja2 +1 -1
  35. package/autorest/codegen/templates/serialization.py.jinja2 +5 -5
  36. package/autorest/jsonrpc/server.py +5 -1
  37. package/autorest/m4reformatter/__init__.py +11 -9
  38. package/autorest/multiapi/models/imports.py +17 -15
  39. package/autorest/preprocess/__init__.py +7 -6
  40. package/package.json +1 -1
@@ -295,7 +295,7 @@ class Model(object):
295
295
  _validation: Dict[str, Dict[str, Any]] = {}
296
296
 
297
297
  def __init__(self, **kwargs: Any) -> None:
298
- self.additional_properties: Dict[str, Any] = {}
298
+ self.additional_properties: Optional[Dict[str, Any]] = {}
299
299
  for k in kwargs:
300
300
  if k not in self._attribute_map:
301
301
  _LOGGER.warning("%s is not a known attribute of class %s and will be ignored", k, self.__class__)
@@ -351,7 +351,7 @@ class Model(object):
351
351
  :rtype: dict
352
352
  """
353
353
  serializer = Serializer(self._infer_class_models())
354
- return serializer._serialize(self, keep_readonly=keep_readonly, **kwargs)
354
+ return serializer._serialize(self, keep_readonly=keep_readonly, **kwargs) # type: ignore
355
355
 
356
356
  def as_dict(
357
357
  self,
@@ -392,7 +392,7 @@ class Model(object):
392
392
  :rtype: dict
393
393
  """
394
394
  serializer = Serializer(self._infer_class_models())
395
- return serializer._serialize(self, key_transformer=key_transformer, keep_readonly=keep_readonly, **kwargs)
395
+ return serializer._serialize(self, key_transformer=key_transformer, keep_readonly=keep_readonly, **kwargs) # type: ignore
396
396
 
397
397
  @classmethod
398
398
  def _infer_class_models(cls):
@@ -417,7 +417,7 @@ class Model(object):
417
417
  :raises: DeserializationError if something went wrong
418
418
  """
419
419
  deserializer = Deserializer(cls._infer_class_models())
420
- return deserializer(cls.__name__, data, content_type=content_type)
420
+ return deserializer(cls.__name__, data, content_type=content_type) # type: ignore
421
421
 
422
422
  @classmethod
423
423
  def from_dict(
@@ -447,7 +447,7 @@ class Model(object):
447
447
  if key_extractors is None
448
448
  else key_extractors
449
449
  )
450
- return deserializer(cls.__name__, data, content_type=content_type)
450
+ return deserializer(cls.__name__, data, content_type=content_type) # type: ignore
451
451
 
452
452
  @classmethod
453
453
  def _flatten_subtype(cls, key, objects):
@@ -3,12 +3,14 @@
3
3
  # Licensed under the MIT License. See License.txt in the project root for
4
4
  # license information.
5
5
  # --------------------------------------------------------------------------
6
+ import typing
6
7
  import contextlib
7
8
  import os
8
9
  import sys
9
10
  import logging
10
11
 
11
12
  from jsonrpc import dispatcher, JSONRPCResponseManager
13
+ from jsonrpc.jsonrpc2 import JSONRPC20Response
12
14
 
13
15
  from .stdstream import read_message, write_message
14
16
 
@@ -99,7 +101,9 @@ def main() -> None:
99
101
  _LOGGER.debug("Trying to read")
100
102
  message = read_message()
101
103
 
102
- response = JSONRPCResponseManager.handle(message, dispatcher).json
104
+ response = typing.cast(
105
+ JSONRPC20Response, JSONRPCResponseManager.handle(message, dispatcher)
106
+ ).json
103
107
  _LOGGER.debug("Produced: %s", response)
104
108
  write_message(response)
105
109
  _LOGGER.debug("Message processed")
@@ -16,6 +16,7 @@ from .._utils import (
16
16
  KNOWN_TYPES,
17
17
  get_body_type_for_description,
18
18
  JSON_REGEXP,
19
+ update_enum_value,
19
20
  )
20
21
  from .. import YamlUpdatePluginAutorest
21
22
 
@@ -88,24 +89,25 @@ def update_constant(yaml_data: Dict[str, Any]) -> Dict[str, Any]:
88
89
  return base
89
90
 
90
91
 
91
- def update_enum_value(yaml_data: Dict[str, Any]) -> Dict[str, Any]:
92
- return {
93
- "name": yaml_data["language"]["default"]["name"],
94
- "value": yaml_data["value"],
95
- "description": yaml_data["language"]["default"]["description"],
96
- }
97
-
98
-
99
92
  def update_enum(yaml_data: Dict[str, Any]) -> Dict[str, Any]:
100
93
  base = _update_type_base("enum", yaml_data)
101
94
  base.update(
102
95
  {
103
96
  "name": yaml_data["language"]["default"]["name"],
104
97
  "valueType": update_type(yaml_data["choiceType"]),
105
- "values": [update_enum_value(v) for v in yaml_data["choices"]],
98
+ "values": [],
106
99
  "description": yaml_data["language"]["default"]["description"],
107
100
  }
108
101
  )
102
+ for v in yaml_data["choices"]:
103
+ base["values"].append(
104
+ update_enum_value(
105
+ name=v["language"]["default"]["name"],
106
+ value=v["value"],
107
+ description=v["language"]["default"]["description"],
108
+ enum_type=base,
109
+ )
110
+ )
109
111
  return base
110
112
 
111
113
 
@@ -4,7 +4,7 @@
4
4
  # license information.
5
5
  # --------------------------------------------------------------------------
6
6
  from enum import Enum
7
- from typing import Dict, Optional, Set, Union, Tuple
7
+ from typing import Dict, Optional, Set, Union, Tuple, cast
8
8
  from ..utils import convert_list_to_tuple
9
9
 
10
10
 
@@ -108,21 +108,23 @@ class FileImport:
108
108
  ] = None,
109
109
  typing_section: TypingSection = TypingSection.REGULAR,
110
110
  ) -> None:
111
- name_input: Optional[
112
- Union[
113
- str,
114
- Tuple[
111
+ name_input = cast(
112
+ Optional[
113
+ Union[
115
114
  str,
116
- str,
117
- ],
118
- Tuple[
119
- str,
120
- Optional[str],
121
- Tuple[Tuple[Tuple[int, int], str, Optional[str]]],
122
- ],
123
- ]
124
- ] = None
125
- name_input = convert_list_to_tuple(name_import)
115
+ Tuple[
116
+ str,
117
+ str,
118
+ ],
119
+ Tuple[
120
+ str,
121
+ Optional[str],
122
+ Tuple[Tuple[Tuple[int, int], str, Optional[str]]],
123
+ ],
124
+ ]
125
+ ],
126
+ convert_list_to_tuple(name_import),
127
+ )
126
128
  self._imports.setdefault(typing_section, {}).setdefault(
127
129
  import_type, {}
128
130
  ).setdefault(from_section, set()).add(name_input)
@@ -8,7 +8,7 @@
8
8
  import copy
9
9
  from typing import Callable, Dict, Any, List, Optional
10
10
 
11
- from .._utils import to_snake_case
11
+ from .._utils import to_snake_case, update_enum_value
12
12
  from .helpers import (
13
13
  add_redefined_builtin_info,
14
14
  pad_builtin_namespaces,
@@ -264,11 +264,12 @@ class PreProcessPlugin(YamlUpdatePlugin): # pylint: disable=abstract-method
264
264
  ).upper()
265
265
  if value["name"] != padded_name:
266
266
  values_to_add.append(
267
- {
268
- "description": value["description"],
269
- "name": padded_name,
270
- "value": value["value"],
271
- }
267
+ update_enum_value(
268
+ name=padded_name,
269
+ value=value["value"],
270
+ description=value["description"],
271
+ enum_type=value["enumType"],
272
+ )
272
273
  )
273
274
  type["values"].extend(values_to_add)
274
275
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@autorest/python",
3
- "version": "6.9.2",
3
+ "version": "6.9.4",
4
4
  "description": "The Python extension for generators in AutoRest.",
5
5
  "main": "index.js",
6
6
  "repository": {