@typespec/http-client-python 0.6.6 → 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.
Files changed (30) hide show
  1. package/dist/emitter/emitter.d.ts.map +1 -1
  2. package/dist/emitter/emitter.js +1 -3
  3. package/dist/emitter/emitter.js.map +1 -1
  4. package/dist/emitter/types.d.ts.map +1 -1
  5. package/dist/emitter/types.js +20 -54
  6. package/dist/emitter/types.js.map +1 -1
  7. package/dist/emitter/utils.d.ts.map +1 -1
  8. package/dist/emitter/utils.js +6 -1
  9. package/dist/emitter/utils.js.map +1 -1
  10. package/emitter/src/emitter.ts +1 -4
  11. package/emitter/src/types.ts +25 -57
  12. package/emitter/src/utils.ts +7 -1
  13. package/emitter/temp/tsconfig.tsbuildinfo +1 -1
  14. package/eng/scripts/setup/__pycache__/venvtools.cpython-38.pyc +0 -0
  15. package/generator/build/lib/pygen/codegen/models/code_model.py +1 -1
  16. package/generator/build/lib/pygen/codegen/models/operation.py +1 -1
  17. package/generator/build/lib/pygen/codegen/serializers/__init__.py +9 -4
  18. package/generator/build/lib/pygen/codegen/serializers/builder_serializer.py +9 -2
  19. package/generator/build/lib/pygen/codegen/templates/model_base.py.jinja2 +61 -0
  20. package/generator/build/lib/pygen/codegen/templates/serialization.py.jinja2 +37 -39
  21. package/generator/dist/pygen-0.1.0-py3-none-any.whl +0 -0
  22. package/generator/pygen/codegen/models/code_model.py +1 -1
  23. package/generator/pygen/codegen/models/operation.py +1 -1
  24. package/generator/pygen/codegen/serializers/__init__.py +9 -4
  25. package/generator/pygen/codegen/serializers/builder_serializer.py +9 -2
  26. package/generator/pygen/codegen/templates/model_base.py.jinja2 +61 -0
  27. package/generator/pygen/codegen/templates/serialization.py.jinja2 +37 -39
  28. package/generator/test/azure/tox.ini +3 -3
  29. package/generator/test/unbranded/tox.ini +3 -3
  30. package/package.json +3 -3
@@ -47,9 +47,7 @@ from typing import (
47
47
  IO,
48
48
  Mapping,
49
49
  Callable,
50
- TypeVar,
51
50
  MutableMapping,
52
- Type,
53
51
  List,
54
52
  )
55
53
 
@@ -60,13 +58,13 @@ except ImportError:
60
58
  import xml.etree.ElementTree as ET
61
59
 
62
60
  import isodate # type: ignore
61
+ from typing_extensions import Self
63
62
 
64
63
  from {{ code_model.core_library }}.exceptions import DeserializationError, SerializationError
65
64
  from {{ code_model.core_library }}.serialization import NULL as CoreNull
66
65
 
67
66
  _BOM = codecs.BOM_UTF8.decode(encoding="utf-8")
68
67
 
69
- ModelType = TypeVar("ModelType", bound="Model")
70
68
  JSON = MutableMapping[str, Any]
71
69
 
72
70
 
@@ -383,25 +381,25 @@ class Model:
383
381
  return client_models
384
382
 
385
383
  @classmethod
386
- def deserialize(cls: Type[ModelType], data: Any, content_type: Optional[str] = None) -> ModelType:
384
+ def deserialize(cls, data: Any, content_type: Optional[str] = None) -> Self:
387
385
  """Parse a str using the RestAPI syntax and return a model.
388
386
 
389
387
  :param str data: A str using RestAPI structure. JSON by default.
390
388
  :param str content_type: JSON by default, set application/xml if XML.
391
389
  :returns: An instance of this model
392
- :raises: DeserializationError if something went wrong
393
- :rtype: ModelType
390
+ :raises DeserializationError: if something went wrong
391
+ :rtype: Self
394
392
  """
395
393
  deserializer = Deserializer(cls._infer_class_models())
396
394
  return deserializer(cls.__name__, data, content_type=content_type) # type: ignore
397
395
 
398
396
  @classmethod
399
397
  def from_dict(
400
- cls: Type[ModelType],
398
+ cls,
401
399
  data: Any,
402
400
  key_extractors: Optional[Callable[[str, Dict[str, Any], Any], Any]] = None,
403
401
  content_type: Optional[str] = None,
404
- ) -> ModelType:
402
+ ) -> Self:
405
403
  """Parse a dict using given key extractor return a model.
406
404
 
407
405
  By default consider key
@@ -413,7 +411,7 @@ class Model:
413
411
  :param str content_type: JSON by default, set application/xml if XML.
414
412
  :returns: An instance of this model
415
413
  :raises: DeserializationError if something went wrong
416
- :rtype: ModelType
414
+ :rtype: Self
417
415
  """
418
416
  deserializer = Deserializer(cls._infer_class_models())
419
417
  deserializer.key_extractors = ( # type: ignore
@@ -559,7 +557,7 @@ class Serializer: # pylint: disable=too-many-public-methods
559
557
  :param object target_obj: The data to be serialized.
560
558
  :param str data_type: The type to be serialized from.
561
559
  :rtype: str, dict
562
- :raises: SerializationError if serialization fails.
560
+ :raises SerializationError: if serialization fails.
563
561
  :returns: The serialized data.
564
562
  """
565
563
  key_transformer = kwargs.get("key_transformer", self.key_transformer)
@@ -669,8 +667,8 @@ class Serializer: # pylint: disable=too-many-public-methods
669
667
  :param object data: The data to be serialized.
670
668
  :param str data_type: The type to be serialized from.
671
669
  :rtype: dict
672
- :raises: SerializationError if serialization fails.
673
- :raises: ValueError if data is None
670
+ :raises SerializationError: if serialization fails.
671
+ :raises ValueError: if data is None
674
672
  :returns: The serialized request body
675
673
  """
676
674
 
@@ -714,8 +712,8 @@ class Serializer: # pylint: disable=too-many-public-methods
714
712
  :param str data_type: The type to be serialized from.
715
713
  :rtype: str
716
714
  :returns: The serialized URL path
717
- :raises: TypeError if serialization fails.
718
- :raises: ValueError if data is None
715
+ :raises TypeError: if serialization fails.
716
+ :raises ValueError: if data is None
719
717
  """
720
718
  try:
721
719
  output = self.serialize_data(data, data_type, **kwargs)
@@ -738,8 +736,8 @@ class Serializer: # pylint: disable=too-many-public-methods
738
736
  :param object data: The data to be serialized.
739
737
  :param str data_type: The type to be serialized from.
740
738
  :rtype: str, list
741
- :raises: TypeError if serialization fails.
742
- :raises: ValueError if data is None
739
+ :raises TypeError: if serialization fails.
740
+ :raises ValueError: if data is None
743
741
  :returns: The serialized query parameter
744
742
  """
745
743
  try:
@@ -768,8 +766,8 @@ class Serializer: # pylint: disable=too-many-public-methods
768
766
  :param object data: The data to be serialized.
769
767
  :param str data_type: The type to be serialized from.
770
768
  :rtype: str
771
- :raises: TypeError if serialization fails.
772
- :raises: ValueError if data is None
769
+ :raises TypeError: if serialization fails.
770
+ :raises ValueError: if data is None
773
771
  :returns: The serialized header
774
772
  """
775
773
  try:
@@ -788,9 +786,9 @@ class Serializer: # pylint: disable=too-many-public-methods
788
786
 
789
787
  :param object data: The data to be serialized.
790
788
  :param str data_type: The type to be serialized from.
791
- :raises: AttributeError if required data is None.
792
- :raises: ValueError if data is None
793
- :raises: SerializationError if serialization fails.
789
+ :raises AttributeError: if required data is None.
790
+ :raises ValueError: if data is None
791
+ :raises SerializationError: if serialization fails.
794
792
  :returns: The serialized data.
795
793
  :rtype: str, int, float, bool, dict, list
796
794
  """
@@ -1125,7 +1123,7 @@ class Serializer: # pylint: disable=too-many-public-methods
1125
1123
 
1126
1124
  :param Datetime attr: Object to be serialized.
1127
1125
  :rtype: str
1128
- :raises: TypeError if format invalid.
1126
+ :raises TypeError: if format invalid.
1129
1127
  :return: serialized rfc
1130
1128
  """
1131
1129
  try:
@@ -1151,7 +1149,7 @@ class Serializer: # pylint: disable=too-many-public-methods
1151
1149
 
1152
1150
  :param Datetime attr: Object to be serialized.
1153
1151
  :rtype: str
1154
- :raises: SerializationError if format invalid.
1152
+ :raises SerializationError: if format invalid.
1155
1153
  :return: serialized iso
1156
1154
  """
1157
1155
  if isinstance(attr, str):
@@ -1184,7 +1182,7 @@ class Serializer: # pylint: disable=too-many-public-methods
1184
1182
 
1185
1183
  :param Datetime attr: Object to be serialized.
1186
1184
  :rtype: int
1187
- :raises: SerializationError if format invalid
1185
+ :raises SerializationError: if format invalid
1188
1186
  :return: serialied unix
1189
1187
  """
1190
1188
  if isinstance(attr, int):
@@ -1421,7 +1419,7 @@ class Deserializer:
1421
1419
  :param str target_obj: Target data type to deserialize to.
1422
1420
  :param requests.Response response_data: REST response object.
1423
1421
  :param str content_type: Swagger "produces" if available.
1424
- :raises: DeserializationError if deserialization fails.
1422
+ :raises DeserializationError: if deserialization fails.
1425
1423
  :return: Deserialized object.
1426
1424
  :rtype: object
1427
1425
  """
@@ -1435,7 +1433,7 @@ class Deserializer:
1435
1433
 
1436
1434
  :param str target_obj: Target data type to deserialize to.
1437
1435
  :param object data: Object to deserialize.
1438
- :raises: DeserializationError if deserialization fails.
1436
+ :raises DeserializationError: if deserialization fails.
1439
1437
  :return: Deserialized object.
1440
1438
  :rtype: object
1441
1439
  """
@@ -1650,7 +1648,7 @@ class Deserializer:
1650
1648
 
1651
1649
  :param str data: The response string to be deserialized.
1652
1650
  :param str data_type: The type to deserialize to.
1653
- :raises: DeserializationError if deserialization fails.
1651
+ :raises DeserializationError: if deserialization fails.
1654
1652
  :return: Deserialized object.
1655
1653
  :rtype: object
1656
1654
  """
@@ -1732,7 +1730,7 @@ class Deserializer:
1732
1730
  :param dict attr: Dictionary to be deserialized.
1733
1731
  :return: Deserialized object.
1734
1732
  :rtype: dict
1735
- :raises: TypeError if non-builtin datatype encountered.
1733
+ :raises TypeError: if non-builtin datatype encountered.
1736
1734
  """
1737
1735
  if attr is None:
1738
1736
  return None
@@ -1778,7 +1776,7 @@ class Deserializer:
1778
1776
  :param str data_type: deserialization data type.
1779
1777
  :return: Deserialized basic type.
1780
1778
  :rtype: str, int, float or bool
1781
- :raises: TypeError if string format is not valid.
1779
+ :raises TypeError: if string format is not valid.
1782
1780
  """
1783
1781
  # If we're here, data is supposed to be a basic type.
1784
1782
  # If it's still an XML node, take the text
@@ -1869,7 +1867,7 @@ class Deserializer:
1869
1867
  :param str attr: response string to be deserialized.
1870
1868
  :return: Deserialized bytearray
1871
1869
  :rtype: bytearray
1872
- :raises: TypeError if string format invalid.
1870
+ :raises TypeError: if string format invalid.
1873
1871
  """
1874
1872
  if isinstance(attr, ET.Element):
1875
1873
  attr = attr.text
@@ -1882,7 +1880,7 @@ class Deserializer:
1882
1880
  :param str attr: response string to be deserialized.
1883
1881
  :return: Deserialized base64 string
1884
1882
  :rtype: bytearray
1885
- :raises: TypeError if string format invalid.
1883
+ :raises TypeError: if string format invalid.
1886
1884
  """
1887
1885
  if isinstance(attr, ET.Element):
1888
1886
  attr = attr.text
@@ -1897,7 +1895,7 @@ class Deserializer:
1897
1895
 
1898
1896
  :param str attr: response string to be deserialized.
1899
1897
  :return: Deserialized decimal
1900
- :raises: DeserializationError if string format invalid.
1898
+ :raises DeserializationError: if string format invalid.
1901
1899
  :rtype: decimal
1902
1900
  """
1903
1901
  if isinstance(attr, ET.Element):
@@ -1915,7 +1913,7 @@ class Deserializer:
1915
1913
  :param str attr: response string to be deserialized.
1916
1914
  :return: Deserialized int
1917
1915
  :rtype: long or int
1918
- :raises: ValueError if string format invalid.
1916
+ :raises ValueError: if string format invalid.
1919
1917
  """
1920
1918
  if isinstance(attr, ET.Element):
1921
1919
  attr = attr.text
@@ -1928,7 +1926,7 @@ class Deserializer:
1928
1926
  :param str attr: response string to be deserialized.
1929
1927
  :return: Deserialized duration
1930
1928
  :rtype: TimeDelta
1931
- :raises: DeserializationError if string format invalid.
1929
+ :raises DeserializationError: if string format invalid.
1932
1930
  """
1933
1931
  if isinstance(attr, ET.Element):
1934
1932
  attr = attr.text
@@ -1946,7 +1944,7 @@ class Deserializer:
1946
1944
  :param str attr: response string to be deserialized.
1947
1945
  :return: Deserialized date
1948
1946
  :rtype: Date
1949
- :raises: DeserializationError if string format invalid.
1947
+ :raises DeserializationError: if string format invalid.
1950
1948
  """
1951
1949
  if isinstance(attr, ET.Element):
1952
1950
  attr = attr.text
@@ -1962,7 +1960,7 @@ class Deserializer:
1962
1960
  :param str attr: response string to be deserialized.
1963
1961
  :return: Deserialized time
1964
1962
  :rtype: datetime.time
1965
- :raises: DeserializationError if string format invalid.
1963
+ :raises DeserializationError: if string format invalid.
1966
1964
  """
1967
1965
  if isinstance(attr, ET.Element):
1968
1966
  attr = attr.text
@@ -1977,7 +1975,7 @@ class Deserializer:
1977
1975
  :param str attr: response string to be deserialized.
1978
1976
  :return: Deserialized RFC datetime
1979
1977
  :rtype: Datetime
1980
- :raises: DeserializationError if string format invalid.
1978
+ :raises DeserializationError: if string format invalid.
1981
1979
  """
1982
1980
  if isinstance(attr, ET.Element):
1983
1981
  attr = attr.text
@@ -2000,7 +1998,7 @@ class Deserializer:
2000
1998
  :param str attr: response string to be deserialized.
2001
1999
  :return: Deserialized ISO datetime
2002
2000
  :rtype: Datetime
2003
- :raises: DeserializationError if string format invalid.
2001
+ :raises DeserializationError: if string format invalid.
2004
2002
  """
2005
2003
  if isinstance(attr, ET.Element):
2006
2004
  attr = attr.text
@@ -2038,7 +2036,7 @@ class Deserializer:
2038
2036
  :param int attr: Object to be serialized.
2039
2037
  :return: Deserialized datetime
2040
2038
  :rtype: Datetime
2041
- :raises: DeserializationError if format invalid
2039
+ :raises DeserializationError: if format invalid
2042
2040
  """
2043
2041
  if isinstance(attr, ET.Element):
2044
2042
  attr = int(attr.text) # type: ignore
@@ -20,8 +20,8 @@ commands =
20
20
  python ../../../eng/scripts/ci/run_pyright.py -t azure -s "generated" {posargs}
21
21
 
22
22
  # apiview
23
- ; pip install apiview-stub-generator==0.3.12 --index-url="https://pkgs.dev.azure.com/azure-sdk/public/_packaging/azure-sdk-for-python/pypi/simple/"
24
- ; python ../../../eng/scripts/ci/run_apiview.py -t azure -s "generated" {posargs}
23
+ pip install apiview-stub-generator==0.3.13 --index-url="https://pkgs.dev.azure.com/azure-sdk/public/_packaging/azure-sdk-for-python/pypi/simple/"
24
+ python ../../../eng/scripts/ci/run_apiview.py -t azure -s "generated" {posargs}
25
25
 
26
26
  [testenv:test]
27
27
  deps=
@@ -52,5 +52,5 @@ commands =
52
52
  deps=
53
53
  -r requirements.txt
54
54
  commands =
55
- pip install apiview-stub-generator==0.3.12 --index-url="https://pkgs.dev.azure.com/azure-sdk/public/_packaging/azure-sdk-for-python/pypi/simple/"
55
+ pip install apiview-stub-generator==0.3.13 --index-url="https://pkgs.dev.azure.com/azure-sdk/public/_packaging/azure-sdk-for-python/pypi/simple/"
56
56
  python ../../../eng/scripts/ci/run_apiview.py -t azure -s "generated" {posargs}
@@ -20,8 +20,8 @@ commands =
20
20
  python ../../../eng/scripts/ci/run_pyright.py -t unbranded -s "generated" {posargs}
21
21
 
22
22
  # apiview
23
- ; pip install apiview-stub-generator==0.3.12 --index-url="https://pkgs.dev.azure.com/azure-sdk/public/_packaging/azure-sdk-for-python/pypi/simple/"
24
- ; python ../../../eng/scripts/ci/run_apiview.py -t unbranded -s "generated" {posargs}
23
+ pip install apiview-stub-generator==0.3.13 --index-url="https://pkgs.dev.azure.com/azure-sdk/public/_packaging/azure-sdk-for-python/pypi/simple/"
24
+ python ../../../eng/scripts/ci/run_apiview.py -t unbranded -s "generated" {posargs}
25
25
 
26
26
  [testenv:test]
27
27
  deps=
@@ -52,5 +52,5 @@ commands =
52
52
  deps=
53
53
  -r requirements.txt
54
54
  commands =
55
- pip install apiview-stub-generator==0.3.12 --index-url="https://pkgs.dev.azure.com/azure-sdk/public/_packaging/azure-sdk-for-python/pypi/simple/"
55
+ pip install apiview-stub-generator==0.3.13 --index-url="https://pkgs.dev.azure.com/azure-sdk/public/_packaging/azure-sdk-for-python/pypi/simple/"
56
56
  python ../../../eng/scripts/ci/run_apiview.py -t unbranded -s "generated" {posargs}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@typespec/http-client-python",
3
- "version": "0.6.6",
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",