@autorest/python 6.7.1 → 6.7.3

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.
@@ -52,6 +52,9 @@ class BlackScriptPlugin(Plugin): # pylint: disable=abstract-method
52
52
  )
53
53
  except NothingChanged:
54
54
  pass
55
+ except: # pylint: disable=bare-except
56
+ _LOGGER.error("Error: failed to format %s", file)
57
+ raise
55
58
  self.write_file(file, file_content)
56
59
 
57
60
 
@@ -8,7 +8,7 @@ from typing import Any, Dict, TYPE_CHECKING, TypeVar, Generic, Union, List, Opti
8
8
  from .base import BaseModel
9
9
  from .parameter_list import ClientGlobalParameterList, ConfigGlobalParameterList
10
10
  from .imports import FileImport, ImportType, TypingSection, MsrestImportType
11
- from .utils import add_to_pylint_disable
11
+ from .utils import add_to_pylint_disable, NAME_LENGTH_LIMIT
12
12
  from .operation_group import OperationGroup
13
13
  from .request_builder import (
14
14
  RequestBuilder,
@@ -148,6 +148,8 @@ class Client(_ClientConfigBase[ClientGlobalParameterList]):
148
148
  retval = add_to_pylint_disable("", "client-accepts-api-version-keyword")
149
149
  if len(self.operation_groups) > 6:
150
150
  retval = add_to_pylint_disable(retval, "too-many-instance-attributes")
151
+ if len(self.name) > NAME_LENGTH_LIMIT:
152
+ retval = add_to_pylint_disable(retval, "name-too-long")
151
153
  return retval
152
154
 
153
155
  @property
@@ -371,6 +373,13 @@ class Client(_ClientConfigBase[ClientGlobalParameterList]):
371
373
  class Config(_ClientConfigBase[ConfigGlobalParameterList]):
372
374
  """Model representing our Config type."""
373
375
 
376
+ @property
377
+ def pylint_disable(self) -> str:
378
+ retval = add_to_pylint_disable("", "too-many-instance-attributes")
379
+ if len(self.name) + len("Configuration") > NAME_LENGTH_LIMIT:
380
+ retval = add_to_pylint_disable(retval, "name-too-long")
381
+ return retval
382
+
374
383
  @property
375
384
  def description(self) -> str:
376
385
  return (
@@ -133,7 +133,7 @@ class CodeModel: # pylint: disable=too-many-public-methods, disable=too-many-in
133
133
  return True
134
134
  if async_mode:
135
135
  return self.need_mixin_abc
136
- return self.need_request_converter or self.need_mixin_abc
136
+ return self.need_request_converter or self.need_mixin_abc or self.has_etag
137
137
 
138
138
  @property
139
139
  def need_request_converter(self) -> bool:
@@ -18,7 +18,7 @@ from typing import (
18
18
 
19
19
  from .request_builder_parameter import RequestBuilderParameter
20
20
 
21
- from .utils import OrderedSet, add_to_pylint_disable
21
+ from .utils import OrderedSet, add_to_pylint_disable, NAME_LENGTH_LIMIT
22
22
  from .base_builder import BaseBuilder
23
23
  from .imports import FileImport, ImportType, TypingSection
24
24
  from .response import (
@@ -143,6 +143,8 @@ class OperationBase( # pylint: disable=too-many-public-methods
143
143
  retval = add_to_pylint_disable(retval, "protected-access")
144
144
  except ValueError:
145
145
  pass
146
+ if len(self.name) > NAME_LENGTH_LIMIT:
147
+ retval = add_to_pylint_disable(retval, "name-too-long")
146
148
  return retval
147
149
 
148
150
  def cls_type_annotation(self, *, async_mode: bool) -> str:
@@ -10,7 +10,7 @@ from autorest.codegen.models.utils import OrderedSet
10
10
  from .base import BaseModel
11
11
  from .operation import get_operation
12
12
  from .imports import FileImport, ImportType, TypingSection
13
- from .utils import add_to_pylint_disable
13
+ from .utils import add_to_pylint_disable, NAME_LENGTH_LIMIT
14
14
 
15
15
  if TYPE_CHECKING:
16
16
  from .code_model import CodeModel
@@ -67,6 +67,10 @@ class OperationGroup(BaseModel):
67
67
  retval: str = ""
68
68
  if self.has_abstract_operations:
69
69
  retval = add_to_pylint_disable(retval, "abstract-class-instantiated")
70
+ if len(self.operations) > 20:
71
+ retval = add_to_pylint_disable(retval, "too-many-public-methods")
72
+ if len(self.class_name) > NAME_LENGTH_LIMIT:
73
+ retval = add_to_pylint_disable(retval, "name-too-long")
70
74
  return retval
71
75
 
72
76
  @property
@@ -80,7 +80,7 @@ class PagingOperationBase(OperationBase[PagingResponseType]):
80
80
 
81
81
  @property
82
82
  def continuation_token_name(self) -> Optional[str]:
83
- wire_name = self.yaml_data["continuationTokenName"]
83
+ wire_name = self.yaml_data.get("continuationTokenName")
84
84
  if not wire_name:
85
85
  # That's an ok scenario, it just means no next page possible
86
86
  return None
@@ -358,6 +358,7 @@ class DatetimeType(PrimitiveType):
358
358
  self.format = (
359
359
  "rfc3339"
360
360
  if yaml_data.get("format", "date-time") == "date-time"
361
+ or yaml_data.get("format", "date-time") == "rfc3339"
361
362
  else "rfc7231"
362
363
  )
363
364
 
@@ -16,6 +16,7 @@ from typing import (
16
16
  from abc import abstractmethod
17
17
 
18
18
  from .base_builder import BaseBuilder
19
+ from .utils import add_to_pylint_disable, NAME_LENGTH_LIMIT
19
20
  from .parameter_list import (
20
21
  RequestBuilderParameterList,
21
22
  OverloadedRequestBuilderParameterList,
@@ -56,6 +57,12 @@ class RequestBuilderBase(BaseBuilder[ParameterListType]):
56
57
  self.method: str = yaml_data["method"]
57
58
  self.want_tracing = False
58
59
 
60
+ @property
61
+ def pylint_disable(self) -> str:
62
+ if len(self.name) > NAME_LENGTH_LIMIT:
63
+ return add_to_pylint_disable("", "name-too-long")
64
+ return ""
65
+
59
66
  def response_type_annotation(self, **kwargs) -> str:
60
67
  return "HttpRequest"
61
68
 
@@ -8,6 +8,8 @@ from typing import TypeVar, Dict
8
8
  T = TypeVar("T")
9
9
  OrderedSet = Dict[T, None]
10
10
 
11
+ NAME_LENGTH_LIMIT = 40
12
+
11
13
 
12
14
  def add_to_description(description: str, entry: str) -> str:
13
15
  if description:
@@ -164,7 +164,7 @@ class ClientSerializer:
164
164
  api_version = ""
165
165
  retval.extend(
166
166
  [
167
- f"self.{og.property_name} = {og.class_name}({og.pylint_disable}",
167
+ f"self.{og.property_name} = {og.class_name}(",
168
168
  f" self._client, self._config, self._serialize, self._deserialize{api_version}",
169
169
  ")",
170
170
  ]
@@ -125,7 +125,9 @@ class SampleSerializer:
125
125
  param_value = self.sample_params.get(name)
126
126
  if not param.optional:
127
127
  if not param_value:
128
- raise Exception(failure_info.format(name))
128
+ raise Exception( # pylint: disable=broad-exception-raised
129
+ failure_info.format(name)
130
+ )
129
131
  operation_params[param.client_name] = self.handle_param(
130
132
  param, param_value
131
133
  )
@@ -1,4 +1,6 @@
1
- class {{ client.name }}Configuration(Configuration): # pylint: disable=too-many-instance-attributes
1
+ class {{ client.name }}Configuration( {{ client.config.pylint_disable }}
2
+ Configuration
3
+ ):
2
4
  """Configuration for {{ client.name }}.
3
5
 
4
6
  Note that all parameters used to create this instance are saved as instance
@@ -1,4 +1,3 @@
1
- {% set disable = " # pylint: disable=too-many-public-methods" if operation_group.operations | length > 20 else "" %}
2
1
  {% set base_class = ("(" + operation_group.base_class + ")") if operation_group.base_class else "" %}
3
2
  {% macro check_abstract_methods() %}
4
3
  {% if operation_group.has_abstract_operations %}
@@ -9,7 +8,13 @@
9
8
  ])
10
9
  {% endif %}
11
10
  {% endmacro %}
12
- class {{ operation_group.class_name }}{{ base_class }}:{{ disable }}
11
+ {% if operation_group.base_class %}
12
+ class {{ operation_group.class_name }}( {{ operation_group.pylint_disable }}
13
+ {{ operation_group.base_class }}
14
+ ):
15
+ {% else %}
16
+ class {{ operation_group.class_name }}: {{ operation_group.pylint_disable }}
17
+ {% endif %}
13
18
  {% if not operation_group.is_mixin %}
14
19
  """
15
20
  .. warning::
@@ -732,6 +732,8 @@ class Serializer(object):
732
732
 
733
733
  if kwargs.get("skip_quote") is True:
734
734
  output = str(output)
735
+ # https://github.com/Azure/autorest.python/issues/2063
736
+ output = output.replace("{", quote("{")).replace("}", quote("}"))
735
737
  else:
736
738
  output = quote(str(output), safe="")
737
739
  except SerializationError:
@@ -13,8 +13,10 @@ def _convert_request(request, files=None):
13
13
  {% endif %}
14
14
  {% if code_model.need_mixin_abc %}
15
15
  {% for client in clients | selectattr("has_mixin") %}
16
-
17
- class {{ client.name }}MixinABC(ABC):
16
+ {% set pylint_disable = "# pylint: disable=name-too-long" if (client.name | length) + ("MixinABC" | length) > 40 else "" %}
17
+ class {{ client.name }}MixinABC( {{ pylint_disable }}
18
+ ABC
19
+ ):
18
20
  """DO NOT use this class. It is for internal typing use only."""
19
21
  _client: "{{ keywords.async_class }}PipelineClient"
20
22
  _config: {{ client.name }}Configuration
@@ -6,7 +6,6 @@
6
6
  import sys
7
7
  import logging
8
8
  import json
9
- import shutil
10
9
 
11
10
  from collections import defaultdict
12
11
  from pathlib import Path
@@ -174,10 +173,6 @@ class MultiAPI(ReaderAndWriter): # pylint: disable=abstract-method
174
173
  user_specified_default_api=self.user_specified_default_api,
175
174
  )
176
175
 
177
- # In case we are transitioning from a single api generation, clean old folders
178
- shutil.rmtree(str(self.output_folder / "operations"), ignore_errors=True)
179
- shutil.rmtree(str(self.output_folder / "models"), ignore_errors=True)
180
-
181
176
  multiapi_serializer = self.serializer
182
177
  multiapi_serializer.serialize(code_model, self.no_async)
183
178
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@autorest/python",
3
- "version": "6.7.1",
3
+ "version": "6.7.3",
4
4
  "description": "The Python extension for generators in AutoRest.",
5
5
  "main": "index.js",
6
6
  "repository": {