Skip to content

Commit

Permalink
Merge branch 'main' into dependabot/pip/eng/pytest-8.3.4
Browse files Browse the repository at this point in the history
  • Loading branch information
iscai-msft authored Jan 22, 2025
2 parents f1f738f + 071976d commit 2230124
Show file tree
Hide file tree
Showing 288 changed files with 10,460 additions and 11,008 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
changeKind: fix
packages:
- "@autorest/python"
- "@azure-tools/typespec-python"
---

Fix sphinx typing for raising documentation
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
changeKind: fix
packages:
- "@autorest/python"
- "@azure-tools/typespec-python"
---

fix typing for class methods in _serialization.py
2 changes: 1 addition & 1 deletion .github/workflows/consistency.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:

- run: pnpm change verify
name: Check changelog
if: ${{ !startsWith(github.head_ref, 'publish/') && !startsWith(github.head_ref, 'dependabot/') && !startsWith(github.head_ref, 'backmerge/') && !startsWith(github.head_ref, 'auto-microsoft-update/') }}
if: ${{ !startsWith(github.head_ref, 'publish/') && !startsWith(github.head_ref, 'dependabot/') && !startsWith(github.head_ref, 'backmerge/') && !startsWith(github.head_ref, 'auto-microsoft-') }}

- run: pnpm check-version-mismatch
name: Check version mismatch
Expand Down
2 changes: 1 addition & 1 deletion packages/autorest.python/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
},
"homepage": "https://github.com/Azure/autorest.python/blob/main/README.md",
"dependencies": {
"@typespec/http-client-python": "~0.6.6",
"@typespec/http-client-python": "~0.6.7",
"@autorest/system-requirements": "~1.0.2",
"fs-extra": "~11.2.0",
"tsx": "~4.19.1"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,7 @@
IO,
Mapping,
Callable,
TypeVar,
MutableMapping,
Type,
List,
)

Expand All @@ -61,13 +59,13 @@
import xml.etree.ElementTree as ET

import isodate # type: ignore
from typing_extensions import Self

from azure.core.exceptions import DeserializationError, SerializationError
from azure.core.serialization import NULL as CoreNull

_BOM = codecs.BOM_UTF8.decode(encoding="utf-8")

ModelType = TypeVar("ModelType", bound="Model")
JSON = MutableMapping[str, Any]


Expand Down Expand Up @@ -384,25 +382,25 @@ def _infer_class_models(cls):
return client_models

@classmethod
def deserialize(cls: Type[ModelType], data: Any, content_type: Optional[str] = None) -> ModelType:
def deserialize(cls, data: Any, content_type: Optional[str] = None) -> Self:
"""Parse a str using the RestAPI syntax and return a model.
:param str data: A str using RestAPI structure. JSON by default.
:param str content_type: JSON by default, set application/xml if XML.
:returns: An instance of this model
:raises: DeserializationError if something went wrong
:rtype: ModelType
:raises DeserializationError: if something went wrong
:rtype: Self
"""
deserializer = Deserializer(cls._infer_class_models())
return deserializer(cls.__name__, data, content_type=content_type) # type: ignore

@classmethod
def from_dict(
cls: Type[ModelType],
cls,
data: Any,
key_extractors: Optional[Callable[[str, Dict[str, Any], Any], Any]] = None,
content_type: Optional[str] = None,
) -> ModelType:
) -> Self:
"""Parse a dict using given key extractor return a model.
By default consider key
Expand All @@ -414,7 +412,7 @@ def from_dict(
:param str content_type: JSON by default, set application/xml if XML.
:returns: An instance of this model
:raises: DeserializationError if something went wrong
:rtype: ModelType
:rtype: Self
"""
deserializer = Deserializer(cls._infer_class_models())
deserializer.key_extractors = ( # type: ignore
Expand Down Expand Up @@ -560,7 +558,7 @@ def _serialize( # pylint: disable=too-many-nested-blocks, too-many-branches, to
:param object target_obj: The data to be serialized.
:param str data_type: The type to be serialized from.
:rtype: str, dict
:raises: SerializationError if serialization fails.
:raises SerializationError: if serialization fails.
:returns: The serialized data.
"""
key_transformer = kwargs.get("key_transformer", self.key_transformer)
Expand Down Expand Up @@ -670,8 +668,8 @@ def body(self, data, data_type, **kwargs):
:param object data: The data to be serialized.
:param str data_type: The type to be serialized from.
:rtype: dict
:raises: SerializationError if serialization fails.
:raises: ValueError if data is None
:raises SerializationError: if serialization fails.
:raises ValueError: if data is None
:returns: The serialized request body
"""

Expand Down Expand Up @@ -715,8 +713,8 @@ def url(self, name, data, data_type, **kwargs):
:param str data_type: The type to be serialized from.
:rtype: str
:returns: The serialized URL path
:raises: TypeError if serialization fails.
:raises: ValueError if data is None
:raises TypeError: if serialization fails.
:raises ValueError: if data is None
"""
try:
output = self.serialize_data(data, data_type, **kwargs)
Expand All @@ -739,8 +737,8 @@ def query(self, name, data, data_type, **kwargs):
:param object data: The data to be serialized.
:param str data_type: The type to be serialized from.
:rtype: str, list
:raises: TypeError if serialization fails.
:raises: ValueError if data is None
:raises TypeError: if serialization fails.
:raises ValueError: if data is None
:returns: The serialized query parameter
"""
try:
Expand Down Expand Up @@ -769,8 +767,8 @@ def header(self, name, data, data_type, **kwargs):
:param object data: The data to be serialized.
:param str data_type: The type to be serialized from.
:rtype: str
:raises: TypeError if serialization fails.
:raises: ValueError if data is None
:raises TypeError: if serialization fails.
:raises ValueError: if data is None
:returns: The serialized header
"""
try:
Expand All @@ -789,9 +787,9 @@ def serialize_data(self, data, data_type, **kwargs):
:param object data: The data to be serialized.
:param str data_type: The type to be serialized from.
:raises: AttributeError if required data is None.
:raises: ValueError if data is None
:raises: SerializationError if serialization fails.
:raises AttributeError: if required data is None.
:raises ValueError: if data is None
:raises SerializationError: if serialization fails.
:returns: The serialized data.
:rtype: str, int, float, bool, dict, list
"""
Expand Down Expand Up @@ -1126,7 +1124,7 @@ def serialize_rfc(attr, **kwargs): # pylint: disable=unused-argument
:param Datetime attr: Object to be serialized.
:rtype: str
:raises: TypeError if format invalid.
:raises TypeError: if format invalid.
:return: serialized rfc
"""
try:
Expand All @@ -1152,7 +1150,7 @@ def serialize_iso(attr, **kwargs): # pylint: disable=unused-argument
:param Datetime attr: Object to be serialized.
:rtype: str
:raises: SerializationError if format invalid.
:raises SerializationError: if format invalid.
:return: serialized iso
"""
if isinstance(attr, str):
Expand Down Expand Up @@ -1185,7 +1183,7 @@ def serialize_unix(attr, **kwargs): # pylint: disable=unused-argument
:param Datetime attr: Object to be serialized.
:rtype: int
:raises: SerializationError if format invalid
:raises SerializationError: if format invalid
:return: serialied unix
"""
if isinstance(attr, int):
Expand Down Expand Up @@ -1422,7 +1420,7 @@ def __call__(self, target_obj, response_data, content_type=None):
:param str target_obj: Target data type to deserialize to.
:param requests.Response response_data: REST response object.
:param str content_type: Swagger "produces" if available.
:raises: DeserializationError if deserialization fails.
:raises DeserializationError: if deserialization fails.
:return: Deserialized object.
:rtype: object
"""
Expand All @@ -1436,7 +1434,7 @@ def _deserialize(self, target_obj, data): # pylint: disable=inconsistent-return
:param str target_obj: Target data type to deserialize to.
:param object data: Object to deserialize.
:raises: DeserializationError if deserialization fails.
:raises DeserializationError: if deserialization fails.
:return: Deserialized object.
:rtype: object
"""
Expand Down Expand Up @@ -1651,7 +1649,7 @@ def deserialize_data(self, data, data_type): # pylint: disable=too-many-return-
:param str data: The response string to be deserialized.
:param str data_type: The type to deserialize to.
:raises: DeserializationError if deserialization fails.
:raises DeserializationError: if deserialization fails.
:return: Deserialized object.
:rtype: object
"""
Expand Down Expand Up @@ -1733,7 +1731,7 @@ def deserialize_object(self, attr, **kwargs): # pylint: disable=too-many-return
:param dict attr: Dictionary to be deserialized.
:return: Deserialized object.
:rtype: dict
:raises: TypeError if non-builtin datatype encountered.
:raises TypeError: if non-builtin datatype encountered.
"""
if attr is None:
return None
Expand Down Expand Up @@ -1779,7 +1777,7 @@ def deserialize_basic(self, attr, data_type): # pylint: disable=too-many-return
:param str data_type: deserialization data type.
:return: Deserialized basic type.
:rtype: str, int, float or bool
:raises: TypeError if string format is not valid.
:raises TypeError: if string format is not valid.
"""
# If we're here, data is supposed to be a basic type.
# If it's still an XML node, take the text
Expand Down Expand Up @@ -1870,7 +1868,7 @@ def deserialize_bytearray(attr):
:param str attr: response string to be deserialized.
:return: Deserialized bytearray
:rtype: bytearray
:raises: TypeError if string format invalid.
:raises TypeError: if string format invalid.
"""
if isinstance(attr, ET.Element):
attr = attr.text
Expand All @@ -1883,7 +1881,7 @@ def deserialize_base64(attr):
:param str attr: response string to be deserialized.
:return: Deserialized base64 string
:rtype: bytearray
:raises: TypeError if string format invalid.
:raises TypeError: if string format invalid.
"""
if isinstance(attr, ET.Element):
attr = attr.text
Expand All @@ -1898,7 +1896,7 @@ def deserialize_decimal(attr):
:param str attr: response string to be deserialized.
:return: Deserialized decimal
:raises: DeserializationError if string format invalid.
:raises DeserializationError: if string format invalid.
:rtype: decimal
"""
if isinstance(attr, ET.Element):
Expand All @@ -1916,7 +1914,7 @@ def deserialize_long(attr):
:param str attr: response string to be deserialized.
:return: Deserialized int
:rtype: long or int
:raises: ValueError if string format invalid.
:raises ValueError: if string format invalid.
"""
if isinstance(attr, ET.Element):
attr = attr.text
Expand All @@ -1929,7 +1927,7 @@ def deserialize_duration(attr):
:param str attr: response string to be deserialized.
:return: Deserialized duration
:rtype: TimeDelta
:raises: DeserializationError if string format invalid.
:raises DeserializationError: if string format invalid.
"""
if isinstance(attr, ET.Element):
attr = attr.text
Expand All @@ -1947,7 +1945,7 @@ def deserialize_date(attr):
:param str attr: response string to be deserialized.
:return: Deserialized date
:rtype: Date
:raises: DeserializationError if string format invalid.
:raises DeserializationError: if string format invalid.
"""
if isinstance(attr, ET.Element):
attr = attr.text
Expand All @@ -1963,7 +1961,7 @@ def deserialize_time(attr):
:param str attr: response string to be deserialized.
:return: Deserialized time
:rtype: datetime.time
:raises: DeserializationError if string format invalid.
:raises DeserializationError: if string format invalid.
"""
if isinstance(attr, ET.Element):
attr = attr.text
Expand All @@ -1978,7 +1976,7 @@ def deserialize_rfc(attr):
:param str attr: response string to be deserialized.
:return: Deserialized RFC datetime
:rtype: Datetime
:raises: DeserializationError if string format invalid.
:raises DeserializationError: if string format invalid.
"""
if isinstance(attr, ET.Element):
attr = attr.text
Expand All @@ -2001,7 +1999,7 @@ def deserialize_iso(attr):
:param str attr: response string to be deserialized.
:return: Deserialized ISO datetime
:rtype: Datetime
:raises: DeserializationError if string format invalid.
:raises DeserializationError: if string format invalid.
"""
if isinstance(attr, ET.Element):
attr = attr.text
Expand Down Expand Up @@ -2039,7 +2037,7 @@ def deserialize_unix(attr):
:param int attr: Object to be serialized.
:return: Deserialized datetime
:rtype: Datetime
:raises: DeserializationError if format invalid
:raises DeserializationError: if format invalid
"""
if isinstance(attr, ET.Element):
attr = int(attr.text) # type: ignore
Expand Down
Loading

0 comments on commit 2230124

Please sign in to comment.