@typespec/http-client-python 0.3.2 → 0.3.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.
@@ -17,7 +17,7 @@ enable=useless-suppression
17
17
  # too-many-arguments: Due to the nature of the CLI many commands have large arguments set which reflect in large arguments set in corresponding methods.
18
18
  # too-many-lines: Due to code generation many files end up with too many lines.
19
19
  # Let's black deal with bad-continuation
20
- disable=useless-object-inheritance,missing-docstring,locally-disabled,fixme,cyclic-import,too-many-arguments,invalid-name,duplicate-code,too-few-public-methods,consider-using-f-string,super-with-arguments,redefined-builtin,import-outside-toplevel,client-suffix-needed,unnecessary-dunder-call,unnecessary-ellipsis,disallowed-name,consider-using-max-builtin,too-many-lines,parse-error,useless-suppression,unknown-option-value
20
+ disable=useless-object-inheritance,missing-docstring,locally-disabled,fixme,cyclic-import,too-many-arguments,invalid-name,duplicate-code,too-few-public-methods,consider-using-f-string,super-with-arguments,redefined-builtin,import-outside-toplevel,client-suffix-needed,unnecessary-dunder-call,unnecessary-ellipsis,disallowed-name,consider-using-max-builtin
21
21
 
22
22
  [FORMAT]
23
23
  max-line-length=120
@@ -37,6 +37,8 @@ def _single_dir_pylint(mod):
37
37
  "--evaluation=(max(0, 0 if fatal else 10.0 - ((float(5 * error + warning + refactor + convention + info)/ statement) * 10)))",
38
38
  "--load-plugins=pylint_guidelines_checker",
39
39
  "--output-format=parseable",
40
+ "--recursive=y",
41
+ "--py-version=3.8",
40
42
  str(inner_class.absolute()),
41
43
  ]
42
44
  )
@@ -47,4 +49,8 @@ def _single_dir_pylint(mod):
47
49
 
48
50
 
49
51
  if __name__ == "__main__":
52
+ if os.name == "nt":
53
+ # Before https://github.com/microsoft/typespec/issues/4759 fixed, skip running Pylint for now on Windows
54
+ logging.info("Skip running Pylint on Windows for now")
55
+ sys.exit(0)
50
56
  run_check("pylint", _single_dir_pylint, "Pylint")
@@ -59,10 +59,9 @@ class BlackScriptPlugin(Plugin):
59
59
  except:
60
60
  _LOGGER.error("Error: failed to format %s", file)
61
61
  raise
62
- else:
63
- if len(file_content.splitlines()) > 1000:
64
- file_content = "# pylint: disable=too-many-lines\n" + file_content
65
- self.write_file(file, file_content)
62
+ if len(file_content.splitlines()) > 1000:
63
+ file_content = "# pylint: disable=too-many-lines\n" + file_content
64
+ self.write_file(file, file_content)
66
65
 
67
66
 
68
67
  if __name__ == "__main__":
@@ -354,7 +354,7 @@ class Config(_ClientConfigBase[ConfigGlobalParameterList]):
354
354
  """Model representing our Config type."""
355
355
 
356
356
  def pylint_disable(self) -> str:
357
- retval = add_to_pylint_disable("", "too-many-instance-attributes")
357
+ retval = add_to_pylint_disable("", "too-many-instance-attributes") if self.code_model.is_azure_flavor else ""
358
358
  if len(self.name) > NAME_LENGTH_LIMIT:
359
359
  retval = add_to_pylint_disable(retval, "name-too-long")
360
360
  return retval
@@ -236,8 +236,6 @@ class ModelType(BaseType): # pylint: disable=too-many-instance-attributes, too-
236
236
 
237
237
  def pylint_disable(self) -> str:
238
238
  retval: str = ""
239
- if len(self.properties) > 10:
240
- retval = add_to_pylint_disable(retval, "too-many-instance-attributes")
241
239
  if len(self.name) > NAME_LENGTH_LIMIT:
242
240
  retval = add_to_pylint_disable(retval, "name-too-long")
243
241
  return retval
@@ -142,11 +142,6 @@ class OperationBase( # pylint: disable=too-many-public-methods,too-many-instanc
142
142
  if not async_mode and not self.is_overload and self.response_type_annotation(async_mode=False) == "None":
143
143
  # doesn't matter if it's async or not
144
144
  retval = add_to_pylint_disable(retval, "inconsistent-return-statements")
145
- try:
146
- if any(is_internal(r.type) for r in self.responses) or is_internal(self.parameters.body_parameter.type):
147
- retval = add_to_pylint_disable(retval, "protected-access")
148
- except ValueError:
149
- pass
150
145
  if len(self.name) > NAME_LENGTH_LIMIT:
151
146
  retval = add_to_pylint_disable(retval, "name-too-long")
152
147
  return retval
@@ -553,11 +553,12 @@ class _OperationSerializer(_BuilderBaseSerializer[OperationType]):
553
553
  type_ignore = self.async_mode and builder.group_name == "" # is in a mixin
554
554
  if builder.stream_value is True and not self.code_model.options["version_tolerant"]:
555
555
  retval.append("_decompress = kwargs.pop('decompress', True)")
556
+ pylint_disable = " # pylint: disable=protected-access" if self.code_model.is_azure_flavor else ""
556
557
  retval.extend(
557
558
  [
558
559
  f"_stream = {builder.stream_value}",
559
560
  f"pipeline_response: PipelineResponse = {self._call_method}self._client.{self.pipeline_name}.run( "
560
- + f"{'# type: ignore' if type_ignore else ''} # pylint: disable=protected-access",
561
+ + f"{'# type: ignore' if type_ignore else ''}{pylint_disable}",
561
562
  " _request,",
562
563
  " stream=_stream,",
563
564
  " **kwargs",
@@ -599,7 +600,7 @@ class _OperationSerializer(_BuilderBaseSerializer[OperationType]):
599
600
  retval.append(f" params_added_on={dict(params_added_on)},")
600
601
  if retval:
601
602
  retval_str = "\n".join(retval)
602
- return f"@api_version_validation(\n{retval_str}\n){builder.pylint_disable(self.async_mode)}"
603
+ return f"@api_version_validation(\n{retval_str}\n)"
603
604
  return ""
604
605
 
605
606
  def pop_kwargs_from_signature(self, builder: OperationType) -> List[str]:
@@ -110,16 +110,22 @@ class _ModelSerializer(BaseSerializer, ABC):
110
110
  def need_init(self, model: ModelType) -> bool:
111
111
  return (not model.internal) and bool(self.init_line(model) or model.discriminator)
112
112
 
113
- def pylint_disable(self, model: ModelType) -> str:
113
+ def pylint_disable_items(self, model: ModelType) -> List[str]:
114
114
  if model.flattened_property or self.initialize_properties(model):
115
- return ""
115
+ return [""]
116
116
  if any(p for p in model.properties if p.is_discriminator and model.discriminator_value):
117
- return ""
117
+ return [""]
118
118
  if model.parents and any(
119
119
  "=" in prop for parent in model.parents for prop in self.init_line(parent) if self.need_init(parent)
120
120
  ):
121
- return ""
122
- return " # pylint: disable=useless-super-delegation"
121
+ return [""]
122
+ return ["useless-super-delegation"]
123
+
124
+ def pylint_disable(self, model: ModelType) -> str:
125
+ return " # pylint: disable=" + ", ".join(self.pylint_disable_items(model))
126
+
127
+ def global_pylint_disables(self) -> str:
128
+ return ""
123
129
 
124
130
 
125
131
  class MsrestModelSerializer(_ModelSerializer):
@@ -315,3 +321,15 @@ class DpgModelSerializer(_ModelSerializer):
315
321
  properties_to_pass_to_super.append(f"{prop.client_name}={prop.get_declaration()}")
316
322
  properties_to_pass_to_super.append("**kwargs")
317
323
  return ", ".join(properties_to_pass_to_super)
324
+
325
+ def global_pylint_disables(self) -> str:
326
+ result = []
327
+ for model in self.code_model.model_types:
328
+ if self.need_init(model):
329
+ for item in self.pylint_disable_items(model):
330
+ if item:
331
+ result.append(item)
332
+ final_result = set(result)
333
+ if final_result:
334
+ return "# pylint: disable=" + ", ".join(final_result)
335
+ return ""
@@ -11,7 +11,7 @@
11
11
  try:
12
12
  {% endif %}
13
13
  {{ indentation }}from ._patch import __all__ as _patch_all
14
- {{ indentation }}from ._patch import * # pylint: disable=unused-wildcard-import
14
+ {{ indentation }}from ._patch import *
15
15
  {% if try_except %}
16
16
  except ImportError:
17
17
  _patch_all = []
@@ -4,7 +4,7 @@
4
4
  # Licensed under the MIT License. See License.txt in the project root for
5
5
  # license information.
6
6
  # --------------------------------------------------------------------------
7
- # pylint: disable=protected-access, arguments-differ, signature-differs, broad-except, too-many-lines
7
+ # pylint: disable=protected-access, broad-except
8
8
 
9
9
  import copy
10
10
  import calendar
@@ -573,7 +573,7 @@ class Model(_MyMutableMapping):
573
573
  def copy(self) -> "Model":
574
574
  return Model(self.__dict__)
575
575
 
576
- def __new__(cls, *args: typing.Any, **kwargs: typing.Any) -> Self: # pylint: disable=unused-argument
576
+ def __new__(cls, *args: typing.Any, **kwargs: typing.Any) -> Self:
577
577
  if f"{cls.__module__}.{cls.__qualname__}" not in cls._calculated:
578
578
  # we know the last nine classes in mro are going to be 'Model', '_MyMutableMapping', 'MutableMapping',
579
579
  # 'Mapping', 'Collection', 'Sized', 'Iterable', 'Container' and 'object'
@@ -584,8 +584,8 @@ class Model(_MyMutableMapping):
584
584
  annotations = {
585
585
  k: v
586
586
  for mro_class in mros
587
- if hasattr(mro_class, "__annotations__") # pylint: disable=no-member
588
- for k, v in mro_class.__annotations__.items() # pylint: disable=no-member
587
+ if hasattr(mro_class, "__annotations__")
588
+ for k, v in mro_class.__annotations__.items()
589
589
  }
590
590
  for attr, rf in attr_to_rest_field.items():
591
591
  rf._module = cls.__module__
@@ -600,8 +600,8 @@ class Model(_MyMutableMapping):
600
600
 
601
601
  def __init_subclass__(cls, discriminator: typing.Optional[str] = None) -> None:
602
602
  for base in cls.__bases__:
603
- if hasattr(base, "__mapping__"): # pylint: disable=no-member
604
- base.__mapping__[discriminator or cls.__name__] = cls # type: ignore # pylint: disable=no-member
603
+ if hasattr(base, "__mapping__"):
604
+ base.__mapping__[discriminator or cls.__name__] = cls # type: ignore
605
605
 
606
606
  @classmethod
607
607
  def _get_discriminator(cls, exist_discriminators) -> typing.Optional["_RestField"]:
@@ -612,7 +612,7 @@ class Model(_MyMutableMapping):
612
612
 
613
613
  @classmethod
614
614
  def _deserialize(cls, data, exist_discriminators):
615
- if not hasattr(cls, "__mapping__"): # pylint: disable=no-member
615
+ if not hasattr(cls, "__mapping__"):
616
616
  return cls(data)
617
617
  discriminator = cls._get_discriminator(exist_discriminators)
618
618
  if discriminator is None:
@@ -632,7 +632,7 @@ class Model(_MyMutableMapping):
632
632
  discriminator_value = data.find(xml_name).text # pyright: ignore
633
633
  else:
634
634
  discriminator_value = data.get(discriminator._rest_name)
635
- mapped_cls = cls.__mapping__.get(discriminator_value, cls) # pyright: ignore # pylint: disable=no-member
635
+ mapped_cls = cls.__mapping__.get(discriminator_value, cls) # pyright: ignore
636
636
  return mapped_cls._deserialize(data, exist_discriminators)
637
637
 
638
638
  def as_dict(self, *, exclude_readonly: bool = False) -> typing.Dict[str, typing.Any]:
@@ -1,6 +1,9 @@
1
1
  {% import 'operation_tools.jinja2' as op_tools %}
2
2
  # coding=utf-8
3
3
  {{ code_model.options['license_header'] }}
4
+ {% if serializer.global_pylint_disables() %}
5
+ {{ serializer.global_pylint_disables() }}
6
+ {% endif %}
4
7
 
5
8
  {{ imports }}
6
9
  {% for model in code_model.model_types %}
@@ -70,7 +70,7 @@
70
70
  {% endif %}
71
71
  {% set initialize_properties = serializer.initialize_properties(model) %}
72
72
  {% if serializer.need_init(model) or initialize_properties %}
73
- def __init__(self, *args: Any, **kwargs: Any) -> None:{{ '# pylint: disable=useless-super-delegation' if not initialize_properties else '' }}
73
+ def __init__(self, *args: Any, **kwargs: Any) -> None:
74
74
  {% for line in serializer.super_call(model) %}
75
75
  {{ line }}
76
76
  {% endfor %}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@typespec/http-client-python",
3
- "version": "0.3.2",
3
+ "version": "0.3.3",
4
4
  "author": "Microsoft Corporation",
5
5
  "description": "TypeSpec emitter for Python SDKs",
6
6
  "homepage": "https://typespec.io",