@typespec/http-client-python 0.6.7 → 0.6.8

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.
@@ -372,15 +372,34 @@ class _MyMutableMapping(MutableMapping[str, typing.Any]): # pylint: disable=uns
372
372
  return not self.__eq__(other)
373
373
 
374
374
  def keys(self) -> typing.KeysView[str]:
375
+ """
376
+ :returns: a set-like object providing a view on D's keys
377
+ :rtype: ~typing.KeysView
378
+ """
375
379
  return self._data.keys()
376
380
 
377
381
  def values(self) -> typing.ValuesView[typing.Any]:
382
+ """
383
+ :returns: an object providing a view on D's values
384
+ :rtype: ~typing.ValuesView
385
+ """
378
386
  return self._data.values()
379
387
 
380
388
  def items(self) -> typing.ItemsView[str, typing.Any]:
389
+ """
390
+ :returns: set-like object providing a view on D's items
391
+ :rtype: ~typing.ItemsView
392
+ """
381
393
  return self._data.items()
382
394
 
383
395
  def get(self, key: str, default: typing.Any = None) -> typing.Any:
396
+ """
397
+ Get the value for key if key is in the dictionary, else default.
398
+ :param str key: The key to look up.
399
+ :param any default: The value to return if key is not in the dictionary. Defaults to None
400
+ :returns: D[k] if k in D, else d.
401
+ :rtype: any
402
+ """
384
403
  try:
385
404
  return self[key]
386
405
  except KeyError:
@@ -396,17 +415,38 @@ class _MyMutableMapping(MutableMapping[str, typing.Any]): # pylint: disable=uns
396
415
  def pop(self, key: str, default: typing.Any) -> typing.Any: ...
397
416
 
398
417
  def pop(self, key: str, default: typing.Any = _UNSET) -> typing.Any:
418
+ """
419
+ Removes specified key and return the corresponding value.
420
+ :param str key: The key to pop.
421
+ :param any default: The value to return if key is not in the dictionary
422
+ :returns: The value corresponding to the key.
423
+ :rtype: any
424
+ :raises KeyError: If key is not found and default is not given.
425
+ """
399
426
  if default is _UNSET:
400
427
  return self._data.pop(key)
401
428
  return self._data.pop(key, default)
402
429
 
403
430
  def popitem(self) -> typing.Tuple[str, typing.Any]:
431
+ """
432
+ Removes and returns some (key, value) pair
433
+ :returns: The (key, value) pair.
434
+ :rtype: tuple
435
+ :raises KeyError: if D is empty.
436
+ """
404
437
  return self._data.popitem()
405
438
 
406
439
  def clear(self) -> None:
440
+ """
441
+ Remove all items from D.
442
+ """
407
443
  self._data.clear()
408
444
 
409
445
  def update(self, *args: typing.Any, **kwargs: typing.Any) -> None:
446
+ """
447
+ Updates D from mapping/iterable E and F.
448
+ :param any args: Either a mapping object or an iterable of key-value pairs.
449
+ """
410
450
  self._data.update(*args, **kwargs)
411
451
 
412
452
  @typing.overload
@@ -416,6 +456,13 @@ class _MyMutableMapping(MutableMapping[str, typing.Any]): # pylint: disable=uns
416
456
  def setdefault(self, key: str, default: typing.Any) -> typing.Any: ...
417
457
 
418
458
  def setdefault(self, key: str, default: typing.Any = _UNSET) -> typing.Any:
459
+ """
460
+ Same as calling D.get(k, d), and setting D[k]=d if k not found
461
+ :param str key: The key to look up.
462
+ :param any default: The value to set if key is not in the dictionary
463
+ :returns: D[k] if k in D, else d.
464
+ :rtype: any
465
+ """
419
466
  if default is _UNSET:
420
467
  return self._data.setdefault(key)
421
468
  return self._data.setdefault(key, default)
@@ -909,6 +956,20 @@ def _failsafe_deserialize(
909
956
  return None
910
957
 
911
958
 
959
+ def _failsafe_deserialize_xml(
960
+ deserializer: typing.Any,
961
+ value: typing.Any,
962
+ ) -> typing.Any:
963
+ try:
964
+ return _deserialize_xml(deserializer, value)
965
+ except DeserializationError:
966
+ _LOGGER.warning(
967
+ "Ran into a deserialization error. Ignoring since this is failsafe deserialization",
968
+ exc_info=True
969
+ )
970
+ return None
971
+
972
+
912
973
  class _RestField:
913
974
  def __init__(
914
975
  self,
@@ -456,7 +456,7 @@ class OperationBase( # pylint: disable=too-many-public-methods,too-many-instanc
456
456
  ImportType.LOCAL,
457
457
  )
458
458
  file_import.add_import("json", ImportType.STDLIB)
459
- if any(xml_serializable(str(r.default_content_type)) for r in self.responses):
459
+ if any(xml_serializable(str(r.default_content_type)) for r in self.responses + self.exceptions):
460
460
  file_import.add_submodule_import(relative_path, "_deserialize_xml", ImportType.LOCAL)
461
461
  elif self.need_deserialize:
462
462
  file_import.add_submodule_import(relative_path, "_deserialize", ImportType.LOCAL)
@@ -130,10 +130,10 @@ class JinjaSerializer(ReaderAndWriter):
130
130
  if self.code_model.options["package_mode"]:
131
131
  self._serialize_and_write_package_files(client_namespace)
132
132
 
133
- # write apiview_mapping_python.json
133
+ # write apiview-properties.json
134
134
  if self.code_model.options.get("emit_cross_language_definition_file"):
135
135
  self.write_file(
136
- exec_path / Path("apiview_mapping_python.json"),
136
+ exec_path / Path("apiview-properties.json"),
137
137
  general_serializer.serialize_cross_language_definition_file(),
138
138
  )
139
139
 
@@ -479,7 +479,12 @@ class JinjaSerializer(ReaderAndWriter):
479
479
  else Path(".")
480
480
  )
481
481
 
482
+ def exec_path_for_test_sample(self, namespace: str) -> Path:
483
+ return self.exec_path_compensation / Path(*namespace.split("."))
484
+
482
485
  def exec_path(self, namespace: str) -> Path:
486
+ if self.code_model.options["no_namespace_folders"] and not self.code_model.options["multiapi"]:
487
+ return Path(".")
483
488
  return self.exec_path_compensation / Path(*namespace.split("."))
484
489
 
485
490
  @property
@@ -492,7 +497,7 @@ class JinjaSerializer(ReaderAndWriter):
492
497
  return Path("")
493
498
 
494
499
  def _serialize_and_write_sample(self, env: Environment, namespace: str):
495
- out_path = self.exec_path(namespace) / Path("generated_samples")
500
+ out_path = self.exec_path_for_test_sample(namespace) / Path("generated_samples")
496
501
  for client in self.code_model.clients:
497
502
  for op_group in client.operation_groups:
498
503
  for operation in op_group.operations:
@@ -526,7 +531,7 @@ class JinjaSerializer(ReaderAndWriter):
526
531
 
527
532
  def _serialize_and_write_test(self, env: Environment, namespace: str):
528
533
  self.code_model.for_test = True
529
- out_path = self.exec_path(namespace) / Path("generated_tests")
534
+ out_path = self.exec_path_for_test_sample(namespace) / Path("generated_tests")
530
535
  general_serializer = TestGeneralSerializer(code_model=self.code_model, env=env)
531
536
  self.write_file(out_path / "conftest.py", general_serializer.serialize_conftest())
532
537
  if not self.code_model.options["azure_arm"]:
@@ -1005,7 +1005,7 @@ class _OperationSerializer(_BuilderBaseSerializer[OperationType]):
1005
1005
  retval.extend(deserialize_code)
1006
1006
  return retval
1007
1007
 
1008
- def handle_error_response(self, builder: OperationType) -> List[str]:
1008
+ def handle_error_response(self, builder: OperationType) -> List[str]: # pylint: disable=too-many-statements, too-many-branches
1009
1009
  async_await = "await " if self.async_mode else ""
1010
1010
  retval = [f"if response.status_code not in {str(builder.success_status_codes)}:"]
1011
1011
  response_read = [
@@ -1079,7 +1079,14 @@ class _OperationSerializer(_BuilderBaseSerializer[OperationType]):
1079
1079
  is_operation_file=True, skip_quote=True, serialize_namespace=self.serialize_namespace
1080
1080
  )
1081
1081
  if self.code_model.options["models_mode"] == "dpg":
1082
- retval.append(f" error = _failsafe_deserialize({type_annotation}, response.json())")
1082
+ if xml_serializable(str(e.default_content_type)):
1083
+ retval.append(
1084
+ f" error = _failsafe_deserialize_xml({type_annotation}, response.text())"
1085
+ )
1086
+ else:
1087
+ retval.append(
1088
+ f" error = _failsafe_deserialize({type_annotation}, response.json())"
1089
+ )
1083
1090
  else:
1084
1091
  retval.append(
1085
1092
  f" error = self._deserialize.failsafe_deserialize({type_annotation}, "
@@ -372,15 +372,34 @@ class _MyMutableMapping(MutableMapping[str, typing.Any]): # pylint: disable=uns
372
372
  return not self.__eq__(other)
373
373
 
374
374
  def keys(self) -> typing.KeysView[str]:
375
+ """
376
+ :returns: a set-like object providing a view on D's keys
377
+ :rtype: ~typing.KeysView
378
+ """
375
379
  return self._data.keys()
376
380
 
377
381
  def values(self) -> typing.ValuesView[typing.Any]:
382
+ """
383
+ :returns: an object providing a view on D's values
384
+ :rtype: ~typing.ValuesView
385
+ """
378
386
  return self._data.values()
379
387
 
380
388
  def items(self) -> typing.ItemsView[str, typing.Any]:
389
+ """
390
+ :returns: set-like object providing a view on D's items
391
+ :rtype: ~typing.ItemsView
392
+ """
381
393
  return self._data.items()
382
394
 
383
395
  def get(self, key: str, default: typing.Any = None) -> typing.Any:
396
+ """
397
+ Get the value for key if key is in the dictionary, else default.
398
+ :param str key: The key to look up.
399
+ :param any default: The value to return if key is not in the dictionary. Defaults to None
400
+ :returns: D[k] if k in D, else d.
401
+ :rtype: any
402
+ """
384
403
  try:
385
404
  return self[key]
386
405
  except KeyError:
@@ -396,17 +415,38 @@ class _MyMutableMapping(MutableMapping[str, typing.Any]): # pylint: disable=uns
396
415
  def pop(self, key: str, default: typing.Any) -> typing.Any: ...
397
416
 
398
417
  def pop(self, key: str, default: typing.Any = _UNSET) -> typing.Any:
418
+ """
419
+ Removes specified key and return the corresponding value.
420
+ :param str key: The key to pop.
421
+ :param any default: The value to return if key is not in the dictionary
422
+ :returns: The value corresponding to the key.
423
+ :rtype: any
424
+ :raises KeyError: If key is not found and default is not given.
425
+ """
399
426
  if default is _UNSET:
400
427
  return self._data.pop(key)
401
428
  return self._data.pop(key, default)
402
429
 
403
430
  def popitem(self) -> typing.Tuple[str, typing.Any]:
431
+ """
432
+ Removes and returns some (key, value) pair
433
+ :returns: The (key, value) pair.
434
+ :rtype: tuple
435
+ :raises KeyError: if D is empty.
436
+ """
404
437
  return self._data.popitem()
405
438
 
406
439
  def clear(self) -> None:
440
+ """
441
+ Remove all items from D.
442
+ """
407
443
  self._data.clear()
408
444
 
409
445
  def update(self, *args: typing.Any, **kwargs: typing.Any) -> None:
446
+ """
447
+ Updates D from mapping/iterable E and F.
448
+ :param any args: Either a mapping object or an iterable of key-value pairs.
449
+ """
410
450
  self._data.update(*args, **kwargs)
411
451
 
412
452
  @typing.overload
@@ -416,6 +456,13 @@ class _MyMutableMapping(MutableMapping[str, typing.Any]): # pylint: disable=uns
416
456
  def setdefault(self, key: str, default: typing.Any) -> typing.Any: ...
417
457
 
418
458
  def setdefault(self, key: str, default: typing.Any = _UNSET) -> typing.Any:
459
+ """
460
+ Same as calling D.get(k, d), and setting D[k]=d if k not found
461
+ :param str key: The key to look up.
462
+ :param any default: The value to set if key is not in the dictionary
463
+ :returns: D[k] if k in D, else d.
464
+ :rtype: any
465
+ """
419
466
  if default is _UNSET:
420
467
  return self._data.setdefault(key)
421
468
  return self._data.setdefault(key, default)
@@ -909,6 +956,20 @@ def _failsafe_deserialize(
909
956
  return None
910
957
 
911
958
 
959
+ def _failsafe_deserialize_xml(
960
+ deserializer: typing.Any,
961
+ value: typing.Any,
962
+ ) -> typing.Any:
963
+ try:
964
+ return _deserialize_xml(deserializer, value)
965
+ except DeserializationError:
966
+ _LOGGER.warning(
967
+ "Ran into a deserialization error. Ignoring since this is failsafe deserialization",
968
+ exc_info=True
969
+ )
970
+ return None
971
+
972
+
912
973
  class _RestField:
913
974
  def __init__(
914
975
  self,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@typespec/http-client-python",
3
- "version": "0.6.7",
3
+ "version": "0.6.8",
4
4
  "author": "Microsoft Corporation",
5
5
  "description": "TypeSpec emitter for Python SDKs",
6
6
  "homepage": "https://typespec.io",
@@ -60,7 +60,7 @@
60
60
  "@azure-tools/typespec-azure-resource-manager": ">=0.50.0 <1.0.0",
61
61
  "@azure-tools/typespec-autorest": ">=0.50.0 <1.0.0",
62
62
  "@azure-tools/typespec-azure-rulesets": ">=0.50.0 <3.0.0",
63
- "@azure-tools/typespec-client-generator-core": ">=0.50.0 <1.0.0"
63
+ "@azure-tools/typespec-client-generator-core": ">=0.50.2 <1.0.0"
64
64
  },
65
65
  "dependencies": {
66
66
  "js-yaml": "~4.1.0",
@@ -78,7 +78,7 @@
78
78
  "@azure-tools/typespec-azure-core": "~0.50.0",
79
79
  "@azure-tools/typespec-azure-rulesets": "~0.50.0",
80
80
  "@azure-tools/typespec-azure-resource-manager": "~0.50.0",
81
- "@azure-tools/typespec-client-generator-core": "~0.50.0",
81
+ "@azure-tools/typespec-client-generator-core": "~0.50.2",
82
82
  "@azure-tools/azure-http-specs": "0.1.0-alpha.5",
83
83
  "@typespec/http-specs": "0.1.0-alpha.7",
84
84
  "@types/js-yaml": "~4.0.5",