diff --git a/.chronus/changes/copilot-add-xml-deserialization-test-2026-03-04-05-46-13.md b/.chronus/changes/copilot-add-xml-deserialization-test-2026-03-04-05-46-13.md new file mode 100644 index 00000000000..37af6e0c2b9 --- /dev/null +++ b/.chronus/changes/copilot-add-xml-deserialization-test-2026-03-04-05-46-13.md @@ -0,0 +1,7 @@ +--- +changeKind: fix +packages: + - "@autorest/python" + - "@azure-tools/typespec-python" +--- +Return empty list instead of None for non-optional unwrapped XML list fields during deserialization diff --git a/.chronus/changes/http-client-python-xml-enumeration-results-test-2026-2-23-22-33-2.md b/.chronus/changes/http-client-python-xml-enumeration-results-test-2026-2-23-22-33-2.md new file mode 100644 index 00000000000..96d3569cd86 --- /dev/null +++ b/.chronus/changes/http-client-python-xml-enumeration-results-test-2026-2-23-22-33-2.md @@ -0,0 +1,8 @@ +--- +changeKind: internal +packages: + - "@autorest/python" + - "@azure-tools/typespec-python" +--- + +Add unit test for deserializing Azure Blob Storage EnumerationResults XML payload with attributes, empty list element, and empty string element. diff --git a/.chronus/changes/python-removeEnumPadding-2026-1-27-12-23-22.md b/.chronus/changes/python-removeEnumPadding-2026-1-27-12-23-22.md new file mode 100644 index 00000000000..0405e59db2a --- /dev/null +++ b/.chronus/changes/python-removeEnumPadding-2026-1-27-12-23-22.md @@ -0,0 +1,8 @@ +--- +changeKind: feature +packages: + - "@autorest/python" + - "@azure-tools/typespec-python" +--- + +Remove enum value padding because we generate our enum value names with upper case so there is no need diff --git a/packages/autorest.python/package.json b/packages/autorest.python/package.json index 682b2520f7a..cce86752ae8 100644 --- a/packages/autorest.python/package.json +++ b/packages/autorest.python/package.json @@ -29,7 +29,7 @@ }, "homepage": "https://github.com/Azure/autorest.python/blob/main/README.md", "dependencies": { - "@typespec/http-client-python": "https://artprodcus3.artifacts.visualstudio.com/A0fb41ef4-5012-48a9-bf39-4ee3de03ee35/29ec6040-b234-4e31-b139-33dc4287b756/_apis/artifact/cGlwZWxpbmVhcnRpZmFjdDovL2F6dXJlLXNkay9wcm9qZWN0SWQvMjllYzYwNDAtYjIzNC00ZTMxLWIxMzktMzNkYzQyODdiNzU2L2J1aWxkSWQvNTk1Mzk0MS9hcnRpZmFjdE5hbWUvYnVpbGRfYXJ0aWZhY3RzX3B5dGhvbg2/content?format=file&subPath=%2Fpackages%2Ftypespec-http-client-python-0.27.2.tgz", + "@typespec/http-client-python": "https://artprodcus3.artifacts.visualstudio.com/A0fb41ef4-5012-48a9-bf39-4ee3de03ee35/29ec6040-b234-4e31-b139-33dc4287b756/_apis/artifact/cGlwZWxpbmVhcnRpZmFjdDovL2F6dXJlLXNkay9wcm9qZWN0SWQvMjllYzYwNDAtYjIzNC00ZTMxLWIxMzktMzNkYzQyODdiNzU2L2J1aWxkSWQvNTk3MDY3MS9hcnRpZmFjdE5hbWUvYnVpbGRfYXJ0aWZhY3RzX3B5dGhvbg2/content?format=file&subPath=%2Fpackages%2Ftypespec-http-client-python-0.27.2.tgz", "@autorest/system-requirements": "~1.0.2", "fs-extra": "~11.2.0", "tsx": "^4.21.0" diff --git a/packages/autorest.python/test/vanilla/legacy/AcceptanceTests/asynctests/test_reserved_words.py b/packages/autorest.python/test/vanilla/legacy/AcceptanceTests/asynctests/test_reserved_words.py index 8c362e6323f..11cd3c9bf8d 100644 --- a/packages/autorest.python/test/vanilla/legacy/AcceptanceTests/asynctests/test_reserved_words.py +++ b/packages/autorest.python/test/vanilla/legacy/AcceptanceTests/asynctests/test_reserved_words.py @@ -66,4 +66,3 @@ async def test_operation_with_url(client): @pytest.mark.asyncio async def test_operation_with_enum(client): await client.reserved_enum(models.MyEnum.IMPORT) - await client.reserved_enum(models.MyEnum.IMPORT_ENUM) diff --git a/packages/autorest.python/test/vanilla/legacy/AcceptanceTests/test_reserved_words.py b/packages/autorest.python/test/vanilla/legacy/AcceptanceTests/test_reserved_words.py index fbfceb2fe25..228abeae9e2 100644 --- a/packages/autorest.python/test/vanilla/legacy/AcceptanceTests/test_reserved_words.py +++ b/packages/autorest.python/test/vanilla/legacy/AcceptanceTests/test_reserved_words.py @@ -59,4 +59,3 @@ def test_operation_with_url(client): def test_operation_with_enum(client): client.reserved_enum(models.MyEnum.IMPORT) - client.reserved_enum(models.MyEnum.IMPORT_ENUM) diff --git a/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/ReservedWords/reservedwords/aio/operations/_reserved_words_client_operations.py b/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/ReservedWords/reservedwords/aio/operations/_reserved_words_client_operations.py index f686a798f3f..37c3fed7bdc 100644 --- a/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/ReservedWords/reservedwords/aio/operations/_reserved_words_client_operations.py +++ b/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/ReservedWords/reservedwords/aio/operations/_reserved_words_client_operations.py @@ -329,8 +329,8 @@ async def operation_with_url( async def reserved_enum(self, enum_parameter: Union[str, _models.MyEnum], **kwargs: Any) -> JSON: """Operation that accepts a reserved enum value. - :param enum_parameter: Pass in MyEnum.IMPORT to pass. Known values are: "import", "other", and - "import". Required. + :param enum_parameter: Pass in MyEnum.IMPORT to pass. Known values are: "import" and "other". + Required. :type enum_parameter: str or ~reservedwords.models.MyEnum :return: JSON or the result of cls(response) :rtype: JSON diff --git a/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/ReservedWords/reservedwords/models/_reserved_words_client_enums.py b/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/ReservedWords/reservedwords/models/_reserved_words_client_enums.py index 4dbf78eda21..abc0ee6e1d3 100644 --- a/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/ReservedWords/reservedwords/models/_reserved_words_client_enums.py +++ b/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/ReservedWords/reservedwords/models/_reserved_words_client_enums.py @@ -15,4 +15,3 @@ class MyEnum(str, Enum, metaclass=CaseInsensitiveEnumMeta): IMPORT = "import" OTHER = "other" - IMPORT_ENUM = "import" diff --git a/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/ReservedWords/reservedwords/operations/_reserved_words_client_operations.py b/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/ReservedWords/reservedwords/operations/_reserved_words_client_operations.py index be8f1ee1179..45f357ab03b 100644 --- a/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/ReservedWords/reservedwords/operations/_reserved_words_client_operations.py +++ b/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/ReservedWords/reservedwords/operations/_reserved_words_client_operations.py @@ -434,8 +434,8 @@ def operation_with_url( def reserved_enum(self, enum_parameter: Union[str, _models.MyEnum], **kwargs: Any) -> JSON: """Operation that accepts a reserved enum value. - :param enum_parameter: Pass in MyEnum.IMPORT to pass. Known values are: "import", "other", and - "import". Required. + :param enum_parameter: Pass in MyEnum.IMPORT to pass. Known values are: "import" and "other". + Required. :type enum_parameter: str or ~reservedwords.models.MyEnum :return: JSON or the result of cls(response) :rtype: JSON diff --git a/packages/typespec-python/package.json b/packages/typespec-python/package.json index 021db766aea..3c32a0ffb8b 100644 --- a/packages/typespec-python/package.json +++ b/packages/typespec-python/package.json @@ -67,7 +67,7 @@ "js-yaml": "~4.1.0", "semver": "~7.6.2", "tsx": "^4.21.0", - "@typespec/http-client-python": "https://artprodcus3.artifacts.visualstudio.com/A0fb41ef4-5012-48a9-bf39-4ee3de03ee35/29ec6040-b234-4e31-b139-33dc4287b756/_apis/artifact/cGlwZWxpbmVhcnRpZmFjdDovL2F6dXJlLXNkay9wcm9qZWN0SWQvMjllYzYwNDAtYjIzNC00ZTMxLWIxMzktMzNkYzQyODdiNzU2L2J1aWxkSWQvNTk1Mzk0MS9hcnRpZmFjdE5hbWUvYnVpbGRfYXJ0aWZhY3RzX3B5dGhvbg2/content?format=file&subPath=%2Fpackages%2Ftypespec-http-client-python-0.27.2.tgz", + "@typespec/http-client-python": "https://artprodcus3.artifacts.visualstudio.com/A0fb41ef4-5012-48a9-bf39-4ee3de03ee35/29ec6040-b234-4e31-b139-33dc4287b756/_apis/artifact/cGlwZWxpbmVhcnRpZmFjdDovL2F6dXJlLXNkay9wcm9qZWN0SWQvMjllYzYwNDAtYjIzNC00ZTMxLWIxMzktMzNkYzQyODdiNzU2L2J1aWxkSWQvNTk3MDY3MS9hcnRpZmFjdE5hbWUvYnVpbGRfYXJ0aWZhY3RzX3B5dGhvbg2/content?format=file&subPath=%2Fpackages%2Ftypespec-http-client-python-0.27.2.tgz", "fs-extra": "~11.2.0" }, "devDependencies": { diff --git a/packages/typespec-python/test/azure/generated/authentication-api-key/authentication/apikey/_utils/model_base.py b/packages/typespec-python/test/azure/generated/authentication-api-key/authentication/apikey/_utils/model_base.py index b4433021b4e..7b7f8ba67b5 100644 --- a/packages/typespec-python/test/azure/generated/authentication-api-key/authentication/apikey/_utils/model_base.py +++ b/packages/typespec-python/test/azure/generated/authentication-api-key/authentication/apikey/_utils/model_base.py @@ -630,6 +630,9 @@ def __init__(self, *args: typing.Any, **kwargs: typing.Any) -> None: if len(items) > 0: existed_attr_keys.append(xml_name) dict_to_pass[rf._rest_name] = _deserialize(rf._type, items) + elif not rf._is_optional: + existed_attr_keys.append(xml_name) + dict_to_pass[rf._rest_name] = [] continue # text element is primitive type @@ -891,6 +894,8 @@ def _get_deserialize_callable_from_annotation( # pylint: disable=too-many-retur # is it optional? try: if any(a is _NONE_TYPE for a in annotation.__args__): # pyright: ignore + if rf: + rf._is_optional = True if len(annotation.__args__) <= 2: # pyright: ignore if_obj_deserializer = _get_deserialize_callable_from_annotation( next(a for a in annotation.__args__ if a is not _NONE_TYPE), module, rf # pyright: ignore @@ -1049,6 +1054,7 @@ def _failsafe_deserialize_xml( return None +# pylint: disable=too-many-instance-attributes class _RestField: def __init__( self, @@ -1068,6 +1074,7 @@ def __init__( self._is_discriminator = is_discriminator self._visibility = visibility self._is_model = False + self._is_optional = False self._default = default self._format = format self._is_multipart_file_input = is_multipart_file_input diff --git a/packages/typespec-python/test/azure/generated/authentication-http-custom/authentication/http/custom/_utils/model_base.py b/packages/typespec-python/test/azure/generated/authentication-http-custom/authentication/http/custom/_utils/model_base.py index b4433021b4e..7b7f8ba67b5 100644 --- a/packages/typespec-python/test/azure/generated/authentication-http-custom/authentication/http/custom/_utils/model_base.py +++ b/packages/typespec-python/test/azure/generated/authentication-http-custom/authentication/http/custom/_utils/model_base.py @@ -630,6 +630,9 @@ def __init__(self, *args: typing.Any, **kwargs: typing.Any) -> None: if len(items) > 0: existed_attr_keys.append(xml_name) dict_to_pass[rf._rest_name] = _deserialize(rf._type, items) + elif not rf._is_optional: + existed_attr_keys.append(xml_name) + dict_to_pass[rf._rest_name] = [] continue # text element is primitive type @@ -891,6 +894,8 @@ def _get_deserialize_callable_from_annotation( # pylint: disable=too-many-retur # is it optional? try: if any(a is _NONE_TYPE for a in annotation.__args__): # pyright: ignore + if rf: + rf._is_optional = True if len(annotation.__args__) <= 2: # pyright: ignore if_obj_deserializer = _get_deserialize_callable_from_annotation( next(a for a in annotation.__args__ if a is not _NONE_TYPE), module, rf # pyright: ignore @@ -1049,6 +1054,7 @@ def _failsafe_deserialize_xml( return None +# pylint: disable=too-many-instance-attributes class _RestField: def __init__( self, @@ -1068,6 +1074,7 @@ def __init__( self._is_discriminator = is_discriminator self._visibility = visibility self._is_model = False + self._is_optional = False self._default = default self._format = format self._is_multipart_file_input = is_multipart_file_input diff --git a/packages/typespec-python/test/azure/generated/authentication-noauth-union/authentication/noauth/union/_utils/model_base.py b/packages/typespec-python/test/azure/generated/authentication-noauth-union/authentication/noauth/union/_utils/model_base.py index b4433021b4e..7b7f8ba67b5 100644 --- a/packages/typespec-python/test/azure/generated/authentication-noauth-union/authentication/noauth/union/_utils/model_base.py +++ b/packages/typespec-python/test/azure/generated/authentication-noauth-union/authentication/noauth/union/_utils/model_base.py @@ -630,6 +630,9 @@ def __init__(self, *args: typing.Any, **kwargs: typing.Any) -> None: if len(items) > 0: existed_attr_keys.append(xml_name) dict_to_pass[rf._rest_name] = _deserialize(rf._type, items) + elif not rf._is_optional: + existed_attr_keys.append(xml_name) + dict_to_pass[rf._rest_name] = [] continue # text element is primitive type @@ -891,6 +894,8 @@ def _get_deserialize_callable_from_annotation( # pylint: disable=too-many-retur # is it optional? try: if any(a is _NONE_TYPE for a in annotation.__args__): # pyright: ignore + if rf: + rf._is_optional = True if len(annotation.__args__) <= 2: # pyright: ignore if_obj_deserializer = _get_deserialize_callable_from_annotation( next(a for a in annotation.__args__ if a is not _NONE_TYPE), module, rf # pyright: ignore @@ -1049,6 +1054,7 @@ def _failsafe_deserialize_xml( return None +# pylint: disable=too-many-instance-attributes class _RestField: def __init__( self, @@ -1068,6 +1074,7 @@ def __init__( self._is_discriminator = is_discriminator self._visibility = visibility self._is_model = False + self._is_optional = False self._default = default self._format = format self._is_multipart_file_input = is_multipart_file_input diff --git a/packages/typespec-python/test/azure/generated/authentication-oauth2/authentication/oauth2/_utils/model_base.py b/packages/typespec-python/test/azure/generated/authentication-oauth2/authentication/oauth2/_utils/model_base.py index b4433021b4e..7b7f8ba67b5 100644 --- a/packages/typespec-python/test/azure/generated/authentication-oauth2/authentication/oauth2/_utils/model_base.py +++ b/packages/typespec-python/test/azure/generated/authentication-oauth2/authentication/oauth2/_utils/model_base.py @@ -630,6 +630,9 @@ def __init__(self, *args: typing.Any, **kwargs: typing.Any) -> None: if len(items) > 0: existed_attr_keys.append(xml_name) dict_to_pass[rf._rest_name] = _deserialize(rf._type, items) + elif not rf._is_optional: + existed_attr_keys.append(xml_name) + dict_to_pass[rf._rest_name] = [] continue # text element is primitive type @@ -891,6 +894,8 @@ def _get_deserialize_callable_from_annotation( # pylint: disable=too-many-retur # is it optional? try: if any(a is _NONE_TYPE for a in annotation.__args__): # pyright: ignore + if rf: + rf._is_optional = True if len(annotation.__args__) <= 2: # pyright: ignore if_obj_deserializer = _get_deserialize_callable_from_annotation( next(a for a in annotation.__args__ if a is not _NONE_TYPE), module, rf # pyright: ignore @@ -1049,6 +1054,7 @@ def _failsafe_deserialize_xml( return None +# pylint: disable=too-many-instance-attributes class _RestField: def __init__( self, @@ -1068,6 +1074,7 @@ def __init__( self._is_discriminator = is_discriminator self._visibility = visibility self._is_model = False + self._is_optional = False self._default = default self._format = format self._is_multipart_file_input = is_multipart_file_input diff --git a/packages/typespec-python/test/azure/generated/authentication-union/authentication/union/_utils/model_base.py b/packages/typespec-python/test/azure/generated/authentication-union/authentication/union/_utils/model_base.py index b4433021b4e..7b7f8ba67b5 100644 --- a/packages/typespec-python/test/azure/generated/authentication-union/authentication/union/_utils/model_base.py +++ b/packages/typespec-python/test/azure/generated/authentication-union/authentication/union/_utils/model_base.py @@ -630,6 +630,9 @@ def __init__(self, *args: typing.Any, **kwargs: typing.Any) -> None: if len(items) > 0: existed_attr_keys.append(xml_name) dict_to_pass[rf._rest_name] = _deserialize(rf._type, items) + elif not rf._is_optional: + existed_attr_keys.append(xml_name) + dict_to_pass[rf._rest_name] = [] continue # text element is primitive type @@ -891,6 +894,8 @@ def _get_deserialize_callable_from_annotation( # pylint: disable=too-many-retur # is it optional? try: if any(a is _NONE_TYPE for a in annotation.__args__): # pyright: ignore + if rf: + rf._is_optional = True if len(annotation.__args__) <= 2: # pyright: ignore if_obj_deserializer = _get_deserialize_callable_from_annotation( next(a for a in annotation.__args__ if a is not _NONE_TYPE), module, rf # pyright: ignore @@ -1049,6 +1054,7 @@ def _failsafe_deserialize_xml( return None +# pylint: disable=too-many-instance-attributes class _RestField: def __init__( self, @@ -1068,6 +1074,7 @@ def __init__( self._is_discriminator = is_discriminator self._visibility = visibility self._is_model = False + self._is_optional = False self._default = default self._format = format self._is_multipart_file_input = is_multipart_file_input diff --git a/packages/typespec-python/test/azure/generated/azure-client-generator-core-access/specs/azure/clientgenerator/core/access/_utils/model_base.py b/packages/typespec-python/test/azure/generated/azure-client-generator-core-access/specs/azure/clientgenerator/core/access/_utils/model_base.py index b4433021b4e..7b7f8ba67b5 100644 --- a/packages/typespec-python/test/azure/generated/azure-client-generator-core-access/specs/azure/clientgenerator/core/access/_utils/model_base.py +++ b/packages/typespec-python/test/azure/generated/azure-client-generator-core-access/specs/azure/clientgenerator/core/access/_utils/model_base.py @@ -630,6 +630,9 @@ def __init__(self, *args: typing.Any, **kwargs: typing.Any) -> None: if len(items) > 0: existed_attr_keys.append(xml_name) dict_to_pass[rf._rest_name] = _deserialize(rf._type, items) + elif not rf._is_optional: + existed_attr_keys.append(xml_name) + dict_to_pass[rf._rest_name] = [] continue # text element is primitive type @@ -891,6 +894,8 @@ def _get_deserialize_callable_from_annotation( # pylint: disable=too-many-retur # is it optional? try: if any(a is _NONE_TYPE for a in annotation.__args__): # pyright: ignore + if rf: + rf._is_optional = True if len(annotation.__args__) <= 2: # pyright: ignore if_obj_deserializer = _get_deserialize_callable_from_annotation( next(a for a in annotation.__args__ if a is not _NONE_TYPE), module, rf # pyright: ignore @@ -1049,6 +1054,7 @@ def _failsafe_deserialize_xml( return None +# pylint: disable=too-many-instance-attributes class _RestField: def __init__( self, @@ -1068,6 +1074,7 @@ def __init__( self._is_discriminator = is_discriminator self._visibility = visibility self._is_model = False + self._is_optional = False self._default = default self._format = format self._is_multipart_file_input = is_multipart_file_input diff --git a/packages/typespec-python/test/azure/generated/azure-client-generator-core-alternate-type/specs/azure/clientgenerator/core/alternatetype/_utils/model_base.py b/packages/typespec-python/test/azure/generated/azure-client-generator-core-alternate-type/specs/azure/clientgenerator/core/alternatetype/_utils/model_base.py index 4d538cc06ba..0ba7447ba6d 100644 --- a/packages/typespec-python/test/azure/generated/azure-client-generator-core-alternate-type/specs/azure/clientgenerator/core/alternatetype/_utils/model_base.py +++ b/packages/typespec-python/test/azure/generated/azure-client-generator-core-alternate-type/specs/azure/clientgenerator/core/alternatetype/_utils/model_base.py @@ -644,6 +644,9 @@ def __init__(self, *args: typing.Any, **kwargs: typing.Any) -> None: if len(items) > 0: existed_attr_keys.append(xml_name) dict_to_pass[rf._rest_name] = _deserialize(rf._type, items) + elif not rf._is_optional: + existed_attr_keys.append(xml_name) + dict_to_pass[rf._rest_name] = [] continue # text element is primitive type @@ -905,6 +908,8 @@ def _get_deserialize_callable_from_annotation( # pylint: disable=too-many-retur # is it optional? try: if any(a is _NONE_TYPE for a in annotation.__args__): # pyright: ignore + if rf: + rf._is_optional = True if len(annotation.__args__) <= 2: # pyright: ignore if_obj_deserializer = _get_deserialize_callable_from_annotation( next(a for a in annotation.__args__ if a is not _NONE_TYPE), module, rf # pyright: ignore @@ -1063,6 +1068,7 @@ def _failsafe_deserialize_xml( return None +# pylint: disable=too-many-instance-attributes class _RestField: def __init__( self, @@ -1082,6 +1088,7 @@ def __init__( self._is_discriminator = is_discriminator self._visibility = visibility self._is_model = False + self._is_optional = False self._default = default self._format = format self._is_multipart_file_input = is_multipart_file_input diff --git a/packages/typespec-python/test/azure/generated/azure-client-generator-core-api-version-header/client/alternateapiversion/service/header/_utils/model_base.py b/packages/typespec-python/test/azure/generated/azure-client-generator-core-api-version-header/client/alternateapiversion/service/header/_utils/model_base.py index b4433021b4e..7b7f8ba67b5 100644 --- a/packages/typespec-python/test/azure/generated/azure-client-generator-core-api-version-header/client/alternateapiversion/service/header/_utils/model_base.py +++ b/packages/typespec-python/test/azure/generated/azure-client-generator-core-api-version-header/client/alternateapiversion/service/header/_utils/model_base.py @@ -630,6 +630,9 @@ def __init__(self, *args: typing.Any, **kwargs: typing.Any) -> None: if len(items) > 0: existed_attr_keys.append(xml_name) dict_to_pass[rf._rest_name] = _deserialize(rf._type, items) + elif not rf._is_optional: + existed_attr_keys.append(xml_name) + dict_to_pass[rf._rest_name] = [] continue # text element is primitive type @@ -891,6 +894,8 @@ def _get_deserialize_callable_from_annotation( # pylint: disable=too-many-retur # is it optional? try: if any(a is _NONE_TYPE for a in annotation.__args__): # pyright: ignore + if rf: + rf._is_optional = True if len(annotation.__args__) <= 2: # pyright: ignore if_obj_deserializer = _get_deserialize_callable_from_annotation( next(a for a in annotation.__args__ if a is not _NONE_TYPE), module, rf # pyright: ignore @@ -1049,6 +1054,7 @@ def _failsafe_deserialize_xml( return None +# pylint: disable=too-many-instance-attributes class _RestField: def __init__( self, @@ -1068,6 +1074,7 @@ def __init__( self._is_discriminator = is_discriminator self._visibility = visibility self._is_model = False + self._is_optional = False self._default = default self._format = format self._is_multipart_file_input = is_multipart_file_input diff --git a/packages/typespec-python/test/azure/generated/azure-client-generator-core-api-version-path/client/alternateapiversion/service/path/_utils/model_base.py b/packages/typespec-python/test/azure/generated/azure-client-generator-core-api-version-path/client/alternateapiversion/service/path/_utils/model_base.py index b4433021b4e..7b7f8ba67b5 100644 --- a/packages/typespec-python/test/azure/generated/azure-client-generator-core-api-version-path/client/alternateapiversion/service/path/_utils/model_base.py +++ b/packages/typespec-python/test/azure/generated/azure-client-generator-core-api-version-path/client/alternateapiversion/service/path/_utils/model_base.py @@ -630,6 +630,9 @@ def __init__(self, *args: typing.Any, **kwargs: typing.Any) -> None: if len(items) > 0: existed_attr_keys.append(xml_name) dict_to_pass[rf._rest_name] = _deserialize(rf._type, items) + elif not rf._is_optional: + existed_attr_keys.append(xml_name) + dict_to_pass[rf._rest_name] = [] continue # text element is primitive type @@ -891,6 +894,8 @@ def _get_deserialize_callable_from_annotation( # pylint: disable=too-many-retur # is it optional? try: if any(a is _NONE_TYPE for a in annotation.__args__): # pyright: ignore + if rf: + rf._is_optional = True if len(annotation.__args__) <= 2: # pyright: ignore if_obj_deserializer = _get_deserialize_callable_from_annotation( next(a for a in annotation.__args__ if a is not _NONE_TYPE), module, rf # pyright: ignore @@ -1049,6 +1054,7 @@ def _failsafe_deserialize_xml( return None +# pylint: disable=too-many-instance-attributes class _RestField: def __init__( self, @@ -1068,6 +1074,7 @@ def __init__( self._is_discriminator = is_discriminator self._visibility = visibility self._is_model = False + self._is_optional = False self._default = default self._format = format self._is_multipart_file_input = is_multipart_file_input diff --git a/packages/typespec-python/test/azure/generated/azure-client-generator-core-api-version-query/client/alternateapiversion/service/query/_utils/model_base.py b/packages/typespec-python/test/azure/generated/azure-client-generator-core-api-version-query/client/alternateapiversion/service/query/_utils/model_base.py index b4433021b4e..7b7f8ba67b5 100644 --- a/packages/typespec-python/test/azure/generated/azure-client-generator-core-api-version-query/client/alternateapiversion/service/query/_utils/model_base.py +++ b/packages/typespec-python/test/azure/generated/azure-client-generator-core-api-version-query/client/alternateapiversion/service/query/_utils/model_base.py @@ -630,6 +630,9 @@ def __init__(self, *args: typing.Any, **kwargs: typing.Any) -> None: if len(items) > 0: existed_attr_keys.append(xml_name) dict_to_pass[rf._rest_name] = _deserialize(rf._type, items) + elif not rf._is_optional: + existed_attr_keys.append(xml_name) + dict_to_pass[rf._rest_name] = [] continue # text element is primitive type @@ -891,6 +894,8 @@ def _get_deserialize_callable_from_annotation( # pylint: disable=too-many-retur # is it optional? try: if any(a is _NONE_TYPE for a in annotation.__args__): # pyright: ignore + if rf: + rf._is_optional = True if len(annotation.__args__) <= 2: # pyright: ignore if_obj_deserializer = _get_deserialize_callable_from_annotation( next(a for a in annotation.__args__ if a is not _NONE_TYPE), module, rf # pyright: ignore @@ -1049,6 +1054,7 @@ def _failsafe_deserialize_xml( return None +# pylint: disable=too-many-instance-attributes class _RestField: def __init__( self, @@ -1068,6 +1074,7 @@ def __init__( self._is_discriminator = is_discriminator self._visibility = visibility self._is_model = False + self._is_optional = False self._default = default self._format = format self._is_multipart_file_input = is_multipart_file_input diff --git a/packages/typespec-python/test/azure/generated/azure-client-generator-core-client-default-value/specs/azure/clientgenerator/core/clientdefaultvalue/_utils/model_base.py b/packages/typespec-python/test/azure/generated/azure-client-generator-core-client-default-value/specs/azure/clientgenerator/core/clientdefaultvalue/_utils/model_base.py index b4433021b4e..7b7f8ba67b5 100644 --- a/packages/typespec-python/test/azure/generated/azure-client-generator-core-client-default-value/specs/azure/clientgenerator/core/clientdefaultvalue/_utils/model_base.py +++ b/packages/typespec-python/test/azure/generated/azure-client-generator-core-client-default-value/specs/azure/clientgenerator/core/clientdefaultvalue/_utils/model_base.py @@ -630,6 +630,9 @@ def __init__(self, *args: typing.Any, **kwargs: typing.Any) -> None: if len(items) > 0: existed_attr_keys.append(xml_name) dict_to_pass[rf._rest_name] = _deserialize(rf._type, items) + elif not rf._is_optional: + existed_attr_keys.append(xml_name) + dict_to_pass[rf._rest_name] = [] continue # text element is primitive type @@ -891,6 +894,8 @@ def _get_deserialize_callable_from_annotation( # pylint: disable=too-many-retur # is it optional? try: if any(a is _NONE_TYPE for a in annotation.__args__): # pyright: ignore + if rf: + rf._is_optional = True if len(annotation.__args__) <= 2: # pyright: ignore if_obj_deserializer = _get_deserialize_callable_from_annotation( next(a for a in annotation.__args__ if a is not _NONE_TYPE), module, rf # pyright: ignore @@ -1049,6 +1054,7 @@ def _failsafe_deserialize_xml( return None +# pylint: disable=too-many-instance-attributes class _RestField: def __init__( self, @@ -1068,6 +1074,7 @@ def __init__( self._is_discriminator = is_discriminator self._visibility = visibility self._is_model = False + self._is_optional = False self._default = default self._format = format self._is_multipart_file_input = is_multipart_file_input diff --git a/packages/typespec-python/test/azure/generated/azure-client-generator-core-client-initialization-default/specs/azure/clientgenerator/core/clientinitialization/default/_utils/model_base.py b/packages/typespec-python/test/azure/generated/azure-client-generator-core-client-initialization-default/specs/azure/clientgenerator/core/clientinitialization/default/_utils/model_base.py index b4433021b4e..7b7f8ba67b5 100644 --- a/packages/typespec-python/test/azure/generated/azure-client-generator-core-client-initialization-default/specs/azure/clientgenerator/core/clientinitialization/default/_utils/model_base.py +++ b/packages/typespec-python/test/azure/generated/azure-client-generator-core-client-initialization-default/specs/azure/clientgenerator/core/clientinitialization/default/_utils/model_base.py @@ -630,6 +630,9 @@ def __init__(self, *args: typing.Any, **kwargs: typing.Any) -> None: if len(items) > 0: existed_attr_keys.append(xml_name) dict_to_pass[rf._rest_name] = _deserialize(rf._type, items) + elif not rf._is_optional: + existed_attr_keys.append(xml_name) + dict_to_pass[rf._rest_name] = [] continue # text element is primitive type @@ -891,6 +894,8 @@ def _get_deserialize_callable_from_annotation( # pylint: disable=too-many-retur # is it optional? try: if any(a is _NONE_TYPE for a in annotation.__args__): # pyright: ignore + if rf: + rf._is_optional = True if len(annotation.__args__) <= 2: # pyright: ignore if_obj_deserializer = _get_deserialize_callable_from_annotation( next(a for a in annotation.__args__ if a is not _NONE_TYPE), module, rf # pyright: ignore @@ -1049,6 +1054,7 @@ def _failsafe_deserialize_xml( return None +# pylint: disable=too-many-instance-attributes class _RestField: def __init__( self, @@ -1068,6 +1074,7 @@ def __init__( self._is_discriminator = is_discriminator self._visibility = visibility self._is_model = False + self._is_optional = False self._default = default self._format = format self._is_multipart_file_input = is_multipart_file_input diff --git a/packages/typespec-python/test/azure/generated/azure-client-generator-core-client-initialization-individually/specs/azure/clientgenerator/core/clientinitialization/individually/_utils/model_base.py b/packages/typespec-python/test/azure/generated/azure-client-generator-core-client-initialization-individually/specs/azure/clientgenerator/core/clientinitialization/individually/_utils/model_base.py index b4433021b4e..7b7f8ba67b5 100644 --- a/packages/typespec-python/test/azure/generated/azure-client-generator-core-client-initialization-individually/specs/azure/clientgenerator/core/clientinitialization/individually/_utils/model_base.py +++ b/packages/typespec-python/test/azure/generated/azure-client-generator-core-client-initialization-individually/specs/azure/clientgenerator/core/clientinitialization/individually/_utils/model_base.py @@ -630,6 +630,9 @@ def __init__(self, *args: typing.Any, **kwargs: typing.Any) -> None: if len(items) > 0: existed_attr_keys.append(xml_name) dict_to_pass[rf._rest_name] = _deserialize(rf._type, items) + elif not rf._is_optional: + existed_attr_keys.append(xml_name) + dict_to_pass[rf._rest_name] = [] continue # text element is primitive type @@ -891,6 +894,8 @@ def _get_deserialize_callable_from_annotation( # pylint: disable=too-many-retur # is it optional? try: if any(a is _NONE_TYPE for a in annotation.__args__): # pyright: ignore + if rf: + rf._is_optional = True if len(annotation.__args__) <= 2: # pyright: ignore if_obj_deserializer = _get_deserialize_callable_from_annotation( next(a for a in annotation.__args__ if a is not _NONE_TYPE), module, rf # pyright: ignore @@ -1049,6 +1054,7 @@ def _failsafe_deserialize_xml( return None +# pylint: disable=too-many-instance-attributes class _RestField: def __init__( self, @@ -1068,6 +1074,7 @@ def __init__( self._is_discriminator = is_discriminator self._visibility = visibility self._is_model = False + self._is_optional = False self._default = default self._format = format self._is_multipart_file_input = is_multipart_file_input diff --git a/packages/typespec-python/test/azure/generated/azure-client-generator-core-client-initialization-individuallyparent/specs/azure/clientgenerator/core/clientinitialization/individuallyparent/_utils/model_base.py b/packages/typespec-python/test/azure/generated/azure-client-generator-core-client-initialization-individuallyparent/specs/azure/clientgenerator/core/clientinitialization/individuallyparent/_utils/model_base.py index b4433021b4e..7b7f8ba67b5 100644 --- a/packages/typespec-python/test/azure/generated/azure-client-generator-core-client-initialization-individuallyparent/specs/azure/clientgenerator/core/clientinitialization/individuallyparent/_utils/model_base.py +++ b/packages/typespec-python/test/azure/generated/azure-client-generator-core-client-initialization-individuallyparent/specs/azure/clientgenerator/core/clientinitialization/individuallyparent/_utils/model_base.py @@ -630,6 +630,9 @@ def __init__(self, *args: typing.Any, **kwargs: typing.Any) -> None: if len(items) > 0: existed_attr_keys.append(xml_name) dict_to_pass[rf._rest_name] = _deserialize(rf._type, items) + elif not rf._is_optional: + existed_attr_keys.append(xml_name) + dict_to_pass[rf._rest_name] = [] continue # text element is primitive type @@ -891,6 +894,8 @@ def _get_deserialize_callable_from_annotation( # pylint: disable=too-many-retur # is it optional? try: if any(a is _NONE_TYPE for a in annotation.__args__): # pyright: ignore + if rf: + rf._is_optional = True if len(annotation.__args__) <= 2: # pyright: ignore if_obj_deserializer = _get_deserialize_callable_from_annotation( next(a for a in annotation.__args__ if a is not _NONE_TYPE), module, rf # pyright: ignore @@ -1049,6 +1054,7 @@ def _failsafe_deserialize_xml( return None +# pylint: disable=too-many-instance-attributes class _RestField: def __init__( self, @@ -1068,6 +1074,7 @@ def __init__( self._is_discriminator = is_discriminator self._visibility = visibility self._is_model = False + self._is_optional = False self._default = default self._format = format self._is_multipart_file_input = is_multipart_file_input diff --git a/packages/typespec-python/test/azure/generated/azure-client-generator-core-client-location-move-method-parameter-to-client/specs/azure/clientgenerator/core/clientlocation/parameter/_utils/model_base.py b/packages/typespec-python/test/azure/generated/azure-client-generator-core-client-location-move-method-parameter-to-client/specs/azure/clientgenerator/core/clientlocation/parameter/_utils/model_base.py index b4433021b4e..7b7f8ba67b5 100644 --- a/packages/typespec-python/test/azure/generated/azure-client-generator-core-client-location-move-method-parameter-to-client/specs/azure/clientgenerator/core/clientlocation/parameter/_utils/model_base.py +++ b/packages/typespec-python/test/azure/generated/azure-client-generator-core-client-location-move-method-parameter-to-client/specs/azure/clientgenerator/core/clientlocation/parameter/_utils/model_base.py @@ -630,6 +630,9 @@ def __init__(self, *args: typing.Any, **kwargs: typing.Any) -> None: if len(items) > 0: existed_attr_keys.append(xml_name) dict_to_pass[rf._rest_name] = _deserialize(rf._type, items) + elif not rf._is_optional: + existed_attr_keys.append(xml_name) + dict_to_pass[rf._rest_name] = [] continue # text element is primitive type @@ -891,6 +894,8 @@ def _get_deserialize_callable_from_annotation( # pylint: disable=too-many-retur # is it optional? try: if any(a is _NONE_TYPE for a in annotation.__args__): # pyright: ignore + if rf: + rf._is_optional = True if len(annotation.__args__) <= 2: # pyright: ignore if_obj_deserializer = _get_deserialize_callable_from_annotation( next(a for a in annotation.__args__ if a is not _NONE_TYPE), module, rf # pyright: ignore @@ -1049,6 +1054,7 @@ def _failsafe_deserialize_xml( return None +# pylint: disable=too-many-instance-attributes class _RestField: def __init__( self, @@ -1068,6 +1074,7 @@ def __init__( self._is_discriminator = is_discriminator self._visibility = visibility self._is_model = False + self._is_optional = False self._default = default self._format = format self._is_multipart_file_input = is_multipart_file_input diff --git a/packages/typespec-python/test/azure/generated/azure-client-generator-core-client-location-move-to-existing-sub-client/specs/azure/clientgenerator/core/clientlocation/subclient/_utils/model_base.py b/packages/typespec-python/test/azure/generated/azure-client-generator-core-client-location-move-to-existing-sub-client/specs/azure/clientgenerator/core/clientlocation/subclient/_utils/model_base.py index b4433021b4e..7b7f8ba67b5 100644 --- a/packages/typespec-python/test/azure/generated/azure-client-generator-core-client-location-move-to-existing-sub-client/specs/azure/clientgenerator/core/clientlocation/subclient/_utils/model_base.py +++ b/packages/typespec-python/test/azure/generated/azure-client-generator-core-client-location-move-to-existing-sub-client/specs/azure/clientgenerator/core/clientlocation/subclient/_utils/model_base.py @@ -630,6 +630,9 @@ def __init__(self, *args: typing.Any, **kwargs: typing.Any) -> None: if len(items) > 0: existed_attr_keys.append(xml_name) dict_to_pass[rf._rest_name] = _deserialize(rf._type, items) + elif not rf._is_optional: + existed_attr_keys.append(xml_name) + dict_to_pass[rf._rest_name] = [] continue # text element is primitive type @@ -891,6 +894,8 @@ def _get_deserialize_callable_from_annotation( # pylint: disable=too-many-retur # is it optional? try: if any(a is _NONE_TYPE for a in annotation.__args__): # pyright: ignore + if rf: + rf._is_optional = True if len(annotation.__args__) <= 2: # pyright: ignore if_obj_deserializer = _get_deserialize_callable_from_annotation( next(a for a in annotation.__args__ if a is not _NONE_TYPE), module, rf # pyright: ignore @@ -1049,6 +1054,7 @@ def _failsafe_deserialize_xml( return None +# pylint: disable=too-many-instance-attributes class _RestField: def __init__( self, @@ -1068,6 +1074,7 @@ def __init__( self._is_discriminator = is_discriminator self._visibility = visibility self._is_model = False + self._is_optional = False self._default = default self._format = format self._is_multipart_file_input = is_multipart_file_input diff --git a/packages/typespec-python/test/azure/generated/azure-client-generator-core-client-location-move-to-new-sub-client/specs/azure/clientgenerator/core/clientlocation/newsubclient/_utils/model_base.py b/packages/typespec-python/test/azure/generated/azure-client-generator-core-client-location-move-to-new-sub-client/specs/azure/clientgenerator/core/clientlocation/newsubclient/_utils/model_base.py index b4433021b4e..7b7f8ba67b5 100644 --- a/packages/typespec-python/test/azure/generated/azure-client-generator-core-client-location-move-to-new-sub-client/specs/azure/clientgenerator/core/clientlocation/newsubclient/_utils/model_base.py +++ b/packages/typespec-python/test/azure/generated/azure-client-generator-core-client-location-move-to-new-sub-client/specs/azure/clientgenerator/core/clientlocation/newsubclient/_utils/model_base.py @@ -630,6 +630,9 @@ def __init__(self, *args: typing.Any, **kwargs: typing.Any) -> None: if len(items) > 0: existed_attr_keys.append(xml_name) dict_to_pass[rf._rest_name] = _deserialize(rf._type, items) + elif not rf._is_optional: + existed_attr_keys.append(xml_name) + dict_to_pass[rf._rest_name] = [] continue # text element is primitive type @@ -891,6 +894,8 @@ def _get_deserialize_callable_from_annotation( # pylint: disable=too-many-retur # is it optional? try: if any(a is _NONE_TYPE for a in annotation.__args__): # pyright: ignore + if rf: + rf._is_optional = True if len(annotation.__args__) <= 2: # pyright: ignore if_obj_deserializer = _get_deserialize_callable_from_annotation( next(a for a in annotation.__args__ if a is not _NONE_TYPE), module, rf # pyright: ignore @@ -1049,6 +1054,7 @@ def _failsafe_deserialize_xml( return None +# pylint: disable=too-many-instance-attributes class _RestField: def __init__( self, @@ -1068,6 +1074,7 @@ def __init__( self._is_discriminator = is_discriminator self._visibility = visibility self._is_model = False + self._is_optional = False self._default = default self._format = format self._is_multipart_file_input = is_multipart_file_input diff --git a/packages/typespec-python/test/azure/generated/azure-client-generator-core-client-location-move-to-root-client/specs/azure/clientgenerator/core/clientlocation/rootclient/_utils/model_base.py b/packages/typespec-python/test/azure/generated/azure-client-generator-core-client-location-move-to-root-client/specs/azure/clientgenerator/core/clientlocation/rootclient/_utils/model_base.py index b4433021b4e..7b7f8ba67b5 100644 --- a/packages/typespec-python/test/azure/generated/azure-client-generator-core-client-location-move-to-root-client/specs/azure/clientgenerator/core/clientlocation/rootclient/_utils/model_base.py +++ b/packages/typespec-python/test/azure/generated/azure-client-generator-core-client-location-move-to-root-client/specs/azure/clientgenerator/core/clientlocation/rootclient/_utils/model_base.py @@ -630,6 +630,9 @@ def __init__(self, *args: typing.Any, **kwargs: typing.Any) -> None: if len(items) > 0: existed_attr_keys.append(xml_name) dict_to_pass[rf._rest_name] = _deserialize(rf._type, items) + elif not rf._is_optional: + existed_attr_keys.append(xml_name) + dict_to_pass[rf._rest_name] = [] continue # text element is primitive type @@ -891,6 +894,8 @@ def _get_deserialize_callable_from_annotation( # pylint: disable=too-many-retur # is it optional? try: if any(a is _NONE_TYPE for a in annotation.__args__): # pyright: ignore + if rf: + rf._is_optional = True if len(annotation.__args__) <= 2: # pyright: ignore if_obj_deserializer = _get_deserialize_callable_from_annotation( next(a for a in annotation.__args__ if a is not _NONE_TYPE), module, rf # pyright: ignore @@ -1049,6 +1054,7 @@ def _failsafe_deserialize_xml( return None +# pylint: disable=too-many-instance-attributes class _RestField: def __init__( self, @@ -1068,6 +1074,7 @@ def __init__( self._is_discriminator = is_discriminator self._visibility = visibility self._is_model = False + self._is_optional = False self._default = default self._format = format self._is_multipart_file_input = is_multipart_file_input diff --git a/packages/typespec-python/test/azure/generated/azure-client-generator-core-deserialize-empty-string-as-null/specs/azure/clientgenerator/core/emptystring/_utils/model_base.py b/packages/typespec-python/test/azure/generated/azure-client-generator-core-deserialize-empty-string-as-null/specs/azure/clientgenerator/core/emptystring/_utils/model_base.py index b4433021b4e..7b7f8ba67b5 100644 --- a/packages/typespec-python/test/azure/generated/azure-client-generator-core-deserialize-empty-string-as-null/specs/azure/clientgenerator/core/emptystring/_utils/model_base.py +++ b/packages/typespec-python/test/azure/generated/azure-client-generator-core-deserialize-empty-string-as-null/specs/azure/clientgenerator/core/emptystring/_utils/model_base.py @@ -630,6 +630,9 @@ def __init__(self, *args: typing.Any, **kwargs: typing.Any) -> None: if len(items) > 0: existed_attr_keys.append(xml_name) dict_to_pass[rf._rest_name] = _deserialize(rf._type, items) + elif not rf._is_optional: + existed_attr_keys.append(xml_name) + dict_to_pass[rf._rest_name] = [] continue # text element is primitive type @@ -891,6 +894,8 @@ def _get_deserialize_callable_from_annotation( # pylint: disable=too-many-retur # is it optional? try: if any(a is _NONE_TYPE for a in annotation.__args__): # pyright: ignore + if rf: + rf._is_optional = True if len(annotation.__args__) <= 2: # pyright: ignore if_obj_deserializer = _get_deserialize_callable_from_annotation( next(a for a in annotation.__args__ if a is not _NONE_TYPE), module, rf # pyright: ignore @@ -1049,6 +1054,7 @@ def _failsafe_deserialize_xml( return None +# pylint: disable=too-many-instance-attributes class _RestField: def __init__( self, @@ -1068,6 +1074,7 @@ def __init__( self._is_discriminator = is_discriminator self._visibility = visibility self._is_model = False + self._is_optional = False self._default = default self._format = format self._is_multipart_file_input = is_multipart_file_input diff --git a/packages/typespec-python/test/azure/generated/azure-client-generator-core-flatten-property/specs/azure/clientgenerator/core/flattenproperty/_utils/model_base.py b/packages/typespec-python/test/azure/generated/azure-client-generator-core-flatten-property/specs/azure/clientgenerator/core/flattenproperty/_utils/model_base.py index b4433021b4e..7b7f8ba67b5 100644 --- a/packages/typespec-python/test/azure/generated/azure-client-generator-core-flatten-property/specs/azure/clientgenerator/core/flattenproperty/_utils/model_base.py +++ b/packages/typespec-python/test/azure/generated/azure-client-generator-core-flatten-property/specs/azure/clientgenerator/core/flattenproperty/_utils/model_base.py @@ -630,6 +630,9 @@ def __init__(self, *args: typing.Any, **kwargs: typing.Any) -> None: if len(items) > 0: existed_attr_keys.append(xml_name) dict_to_pass[rf._rest_name] = _deserialize(rf._type, items) + elif not rf._is_optional: + existed_attr_keys.append(xml_name) + dict_to_pass[rf._rest_name] = [] continue # text element is primitive type @@ -891,6 +894,8 @@ def _get_deserialize_callable_from_annotation( # pylint: disable=too-many-retur # is it optional? try: if any(a is _NONE_TYPE for a in annotation.__args__): # pyright: ignore + if rf: + rf._is_optional = True if len(annotation.__args__) <= 2: # pyright: ignore if_obj_deserializer = _get_deserialize_callable_from_annotation( next(a for a in annotation.__args__ if a is not _NONE_TYPE), module, rf # pyright: ignore @@ -1049,6 +1054,7 @@ def _failsafe_deserialize_xml( return None +# pylint: disable=too-many-instance-attributes class _RestField: def __init__( self, @@ -1068,6 +1074,7 @@ def __init__( self._is_discriminator = is_discriminator self._visibility = visibility self._is_model = False + self._is_optional = False self._default = default self._format = format self._is_multipart_file_input = is_multipart_file_input diff --git a/packages/typespec-python/test/azure/generated/azure-client-generator-core-hierarchy-building/specs/azure/clientgenerator/core/hierarchybuilding/_utils/model_base.py b/packages/typespec-python/test/azure/generated/azure-client-generator-core-hierarchy-building/specs/azure/clientgenerator/core/hierarchybuilding/_utils/model_base.py index b4433021b4e..7b7f8ba67b5 100644 --- a/packages/typespec-python/test/azure/generated/azure-client-generator-core-hierarchy-building/specs/azure/clientgenerator/core/hierarchybuilding/_utils/model_base.py +++ b/packages/typespec-python/test/azure/generated/azure-client-generator-core-hierarchy-building/specs/azure/clientgenerator/core/hierarchybuilding/_utils/model_base.py @@ -630,6 +630,9 @@ def __init__(self, *args: typing.Any, **kwargs: typing.Any) -> None: if len(items) > 0: existed_attr_keys.append(xml_name) dict_to_pass[rf._rest_name] = _deserialize(rf._type, items) + elif not rf._is_optional: + existed_attr_keys.append(xml_name) + dict_to_pass[rf._rest_name] = [] continue # text element is primitive type @@ -891,6 +894,8 @@ def _get_deserialize_callable_from_annotation( # pylint: disable=too-many-retur # is it optional? try: if any(a is _NONE_TYPE for a in annotation.__args__): # pyright: ignore + if rf: + rf._is_optional = True if len(annotation.__args__) <= 2: # pyright: ignore if_obj_deserializer = _get_deserialize_callable_from_annotation( next(a for a in annotation.__args__ if a is not _NONE_TYPE), module, rf # pyright: ignore @@ -1049,6 +1054,7 @@ def _failsafe_deserialize_xml( return None +# pylint: disable=too-many-instance-attributes class _RestField: def __init__( self, @@ -1068,6 +1074,7 @@ def __init__( self._is_discriminator = is_discriminator self._visibility = visibility self._is_model = False + self._is_optional = False self._default = default self._format = format self._is_multipart_file_input = is_multipart_file_input diff --git a/packages/typespec-python/test/azure/generated/azure-client-generator-core-next-link-verb/specs/azure/clientgenerator/core/nextlinkverb/_utils/model_base.py b/packages/typespec-python/test/azure/generated/azure-client-generator-core-next-link-verb/specs/azure/clientgenerator/core/nextlinkverb/_utils/model_base.py index b4433021b4e..7b7f8ba67b5 100644 --- a/packages/typespec-python/test/azure/generated/azure-client-generator-core-next-link-verb/specs/azure/clientgenerator/core/nextlinkverb/_utils/model_base.py +++ b/packages/typespec-python/test/azure/generated/azure-client-generator-core-next-link-verb/specs/azure/clientgenerator/core/nextlinkverb/_utils/model_base.py @@ -630,6 +630,9 @@ def __init__(self, *args: typing.Any, **kwargs: typing.Any) -> None: if len(items) > 0: existed_attr_keys.append(xml_name) dict_to_pass[rf._rest_name] = _deserialize(rf._type, items) + elif not rf._is_optional: + existed_attr_keys.append(xml_name) + dict_to_pass[rf._rest_name] = [] continue # text element is primitive type @@ -891,6 +894,8 @@ def _get_deserialize_callable_from_annotation( # pylint: disable=too-many-retur # is it optional? try: if any(a is _NONE_TYPE for a in annotation.__args__): # pyright: ignore + if rf: + rf._is_optional = True if len(annotation.__args__) <= 2: # pyright: ignore if_obj_deserializer = _get_deserialize_callable_from_annotation( next(a for a in annotation.__args__ if a is not _NONE_TYPE), module, rf # pyright: ignore @@ -1049,6 +1054,7 @@ def _failsafe_deserialize_xml( return None +# pylint: disable=too-many-instance-attributes class _RestField: def __init__( self, @@ -1068,6 +1074,7 @@ def __init__( self._is_discriminator = is_discriminator self._visibility = visibility self._is_model = False + self._is_optional = False self._default = default self._format = format self._is_multipart_file_input = is_multipart_file_input diff --git a/packages/typespec-python/test/azure/generated/azure-client-generator-core-override/specs/azure/clientgenerator/core/override/_utils/model_base.py b/packages/typespec-python/test/azure/generated/azure-client-generator-core-override/specs/azure/clientgenerator/core/override/_utils/model_base.py index b4433021b4e..7b7f8ba67b5 100644 --- a/packages/typespec-python/test/azure/generated/azure-client-generator-core-override/specs/azure/clientgenerator/core/override/_utils/model_base.py +++ b/packages/typespec-python/test/azure/generated/azure-client-generator-core-override/specs/azure/clientgenerator/core/override/_utils/model_base.py @@ -630,6 +630,9 @@ def __init__(self, *args: typing.Any, **kwargs: typing.Any) -> None: if len(items) > 0: existed_attr_keys.append(xml_name) dict_to_pass[rf._rest_name] = _deserialize(rf._type, items) + elif not rf._is_optional: + existed_attr_keys.append(xml_name) + dict_to_pass[rf._rest_name] = [] continue # text element is primitive type @@ -891,6 +894,8 @@ def _get_deserialize_callable_from_annotation( # pylint: disable=too-many-retur # is it optional? try: if any(a is _NONE_TYPE for a in annotation.__args__): # pyright: ignore + if rf: + rf._is_optional = True if len(annotation.__args__) <= 2: # pyright: ignore if_obj_deserializer = _get_deserialize_callable_from_annotation( next(a for a in annotation.__args__ if a is not _NONE_TYPE), module, rf # pyright: ignore @@ -1049,6 +1054,7 @@ def _failsafe_deserialize_xml( return None +# pylint: disable=too-many-instance-attributes class _RestField: def __init__( self, @@ -1068,6 +1074,7 @@ def __init__( self._is_discriminator = is_discriminator self._visibility = visibility self._is_model = False + self._is_optional = False self._default = default self._format = format self._is_multipart_file_input = is_multipart_file_input diff --git a/packages/typespec-python/test/azure/generated/azure-client-generator-core-usage/specs/azure/clientgenerator/core/usage/_utils/model_base.py b/packages/typespec-python/test/azure/generated/azure-client-generator-core-usage/specs/azure/clientgenerator/core/usage/_utils/model_base.py index b4433021b4e..7b7f8ba67b5 100644 --- a/packages/typespec-python/test/azure/generated/azure-client-generator-core-usage/specs/azure/clientgenerator/core/usage/_utils/model_base.py +++ b/packages/typespec-python/test/azure/generated/azure-client-generator-core-usage/specs/azure/clientgenerator/core/usage/_utils/model_base.py @@ -630,6 +630,9 @@ def __init__(self, *args: typing.Any, **kwargs: typing.Any) -> None: if len(items) > 0: existed_attr_keys.append(xml_name) dict_to_pass[rf._rest_name] = _deserialize(rf._type, items) + elif not rf._is_optional: + existed_attr_keys.append(xml_name) + dict_to_pass[rf._rest_name] = [] continue # text element is primitive type @@ -891,6 +894,8 @@ def _get_deserialize_callable_from_annotation( # pylint: disable=too-many-retur # is it optional? try: if any(a is _NONE_TYPE for a in annotation.__args__): # pyright: ignore + if rf: + rf._is_optional = True if len(annotation.__args__) <= 2: # pyright: ignore if_obj_deserializer = _get_deserialize_callable_from_annotation( next(a for a in annotation.__args__ if a is not _NONE_TYPE), module, rf # pyright: ignore @@ -1049,6 +1054,7 @@ def _failsafe_deserialize_xml( return None +# pylint: disable=too-many-instance-attributes class _RestField: def __init__( self, @@ -1068,6 +1074,7 @@ def __init__( self._is_discriminator = is_discriminator self._visibility = visibility self._is_model = False + self._is_optional = False self._default = default self._format = format self._is_multipart_file_input = is_multipart_file_input diff --git a/packages/typespec-python/test/azure/generated/azure-core-basic/specs/azure/core/basic/_utils/model_base.py b/packages/typespec-python/test/azure/generated/azure-core-basic/specs/azure/core/basic/_utils/model_base.py index b4433021b4e..7b7f8ba67b5 100644 --- a/packages/typespec-python/test/azure/generated/azure-core-basic/specs/azure/core/basic/_utils/model_base.py +++ b/packages/typespec-python/test/azure/generated/azure-core-basic/specs/azure/core/basic/_utils/model_base.py @@ -630,6 +630,9 @@ def __init__(self, *args: typing.Any, **kwargs: typing.Any) -> None: if len(items) > 0: existed_attr_keys.append(xml_name) dict_to_pass[rf._rest_name] = _deserialize(rf._type, items) + elif not rf._is_optional: + existed_attr_keys.append(xml_name) + dict_to_pass[rf._rest_name] = [] continue # text element is primitive type @@ -891,6 +894,8 @@ def _get_deserialize_callable_from_annotation( # pylint: disable=too-many-retur # is it optional? try: if any(a is _NONE_TYPE for a in annotation.__args__): # pyright: ignore + if rf: + rf._is_optional = True if len(annotation.__args__) <= 2: # pyright: ignore if_obj_deserializer = _get_deserialize_callable_from_annotation( next(a for a in annotation.__args__ if a is not _NONE_TYPE), module, rf # pyright: ignore @@ -1049,6 +1054,7 @@ def _failsafe_deserialize_xml( return None +# pylint: disable=too-many-instance-attributes class _RestField: def __init__( self, @@ -1068,6 +1074,7 @@ def __init__( self._is_discriminator = is_discriminator self._visibility = visibility self._is_model = False + self._is_optional = False self._default = default self._format = format self._is_multipart_file_input = is_multipart_file_input diff --git a/packages/typespec-python/test/azure/generated/azure-core-lro-rpc/specs/azure/core/lro/rpc/_utils/model_base.py b/packages/typespec-python/test/azure/generated/azure-core-lro-rpc/specs/azure/core/lro/rpc/_utils/model_base.py index b4433021b4e..7b7f8ba67b5 100644 --- a/packages/typespec-python/test/azure/generated/azure-core-lro-rpc/specs/azure/core/lro/rpc/_utils/model_base.py +++ b/packages/typespec-python/test/azure/generated/azure-core-lro-rpc/specs/azure/core/lro/rpc/_utils/model_base.py @@ -630,6 +630,9 @@ def __init__(self, *args: typing.Any, **kwargs: typing.Any) -> None: if len(items) > 0: existed_attr_keys.append(xml_name) dict_to_pass[rf._rest_name] = _deserialize(rf._type, items) + elif not rf._is_optional: + existed_attr_keys.append(xml_name) + dict_to_pass[rf._rest_name] = [] continue # text element is primitive type @@ -891,6 +894,8 @@ def _get_deserialize_callable_from_annotation( # pylint: disable=too-many-retur # is it optional? try: if any(a is _NONE_TYPE for a in annotation.__args__): # pyright: ignore + if rf: + rf._is_optional = True if len(annotation.__args__) <= 2: # pyright: ignore if_obj_deserializer = _get_deserialize_callable_from_annotation( next(a for a in annotation.__args__ if a is not _NONE_TYPE), module, rf # pyright: ignore @@ -1049,6 +1054,7 @@ def _failsafe_deserialize_xml( return None +# pylint: disable=too-many-instance-attributes class _RestField: def __init__( self, @@ -1068,6 +1074,7 @@ def __init__( self._is_discriminator = is_discriminator self._visibility = visibility self._is_model = False + self._is_optional = False self._default = default self._format = format self._is_multipart_file_input = is_multipart_file_input diff --git a/packages/typespec-python/test/azure/generated/azure-core-lro-standard/specs/azure/core/lro/standard/_utils/model_base.py b/packages/typespec-python/test/azure/generated/azure-core-lro-standard/specs/azure/core/lro/standard/_utils/model_base.py index b4433021b4e..7b7f8ba67b5 100644 --- a/packages/typespec-python/test/azure/generated/azure-core-lro-standard/specs/azure/core/lro/standard/_utils/model_base.py +++ b/packages/typespec-python/test/azure/generated/azure-core-lro-standard/specs/azure/core/lro/standard/_utils/model_base.py @@ -630,6 +630,9 @@ def __init__(self, *args: typing.Any, **kwargs: typing.Any) -> None: if len(items) > 0: existed_attr_keys.append(xml_name) dict_to_pass[rf._rest_name] = _deserialize(rf._type, items) + elif not rf._is_optional: + existed_attr_keys.append(xml_name) + dict_to_pass[rf._rest_name] = [] continue # text element is primitive type @@ -891,6 +894,8 @@ def _get_deserialize_callable_from_annotation( # pylint: disable=too-many-retur # is it optional? try: if any(a is _NONE_TYPE for a in annotation.__args__): # pyright: ignore + if rf: + rf._is_optional = True if len(annotation.__args__) <= 2: # pyright: ignore if_obj_deserializer = _get_deserialize_callable_from_annotation( next(a for a in annotation.__args__ if a is not _NONE_TYPE), module, rf # pyright: ignore @@ -1049,6 +1054,7 @@ def _failsafe_deserialize_xml( return None +# pylint: disable=too-many-instance-attributes class _RestField: def __init__( self, @@ -1068,6 +1074,7 @@ def __init__( self._is_discriminator = is_discriminator self._visibility = visibility self._is_model = False + self._is_optional = False self._default = default self._format = format self._is_multipart_file_input = is_multipart_file_input diff --git a/packages/typespec-python/test/azure/generated/azure-core-model/specs/azure/core/model/_utils/model_base.py b/packages/typespec-python/test/azure/generated/azure-core-model/specs/azure/core/model/_utils/model_base.py index b4433021b4e..7b7f8ba67b5 100644 --- a/packages/typespec-python/test/azure/generated/azure-core-model/specs/azure/core/model/_utils/model_base.py +++ b/packages/typespec-python/test/azure/generated/azure-core-model/specs/azure/core/model/_utils/model_base.py @@ -630,6 +630,9 @@ def __init__(self, *args: typing.Any, **kwargs: typing.Any) -> None: if len(items) > 0: existed_attr_keys.append(xml_name) dict_to_pass[rf._rest_name] = _deserialize(rf._type, items) + elif not rf._is_optional: + existed_attr_keys.append(xml_name) + dict_to_pass[rf._rest_name] = [] continue # text element is primitive type @@ -891,6 +894,8 @@ def _get_deserialize_callable_from_annotation( # pylint: disable=too-many-retur # is it optional? try: if any(a is _NONE_TYPE for a in annotation.__args__): # pyright: ignore + if rf: + rf._is_optional = True if len(annotation.__args__) <= 2: # pyright: ignore if_obj_deserializer = _get_deserialize_callable_from_annotation( next(a for a in annotation.__args__ if a is not _NONE_TYPE), module, rf # pyright: ignore @@ -1049,6 +1054,7 @@ def _failsafe_deserialize_xml( return None +# pylint: disable=too-many-instance-attributes class _RestField: def __init__( self, @@ -1068,6 +1074,7 @@ def __init__( self._is_discriminator = is_discriminator self._visibility = visibility self._is_model = False + self._is_optional = False self._default = default self._format = format self._is_multipart_file_input = is_multipart_file_input diff --git a/packages/typespec-python/test/azure/generated/azure-core-page/specs/azure/core/page/_utils/model_base.py b/packages/typespec-python/test/azure/generated/azure-core-page/specs/azure/core/page/_utils/model_base.py index b4433021b4e..7b7f8ba67b5 100644 --- a/packages/typespec-python/test/azure/generated/azure-core-page/specs/azure/core/page/_utils/model_base.py +++ b/packages/typespec-python/test/azure/generated/azure-core-page/specs/azure/core/page/_utils/model_base.py @@ -630,6 +630,9 @@ def __init__(self, *args: typing.Any, **kwargs: typing.Any) -> None: if len(items) > 0: existed_attr_keys.append(xml_name) dict_to_pass[rf._rest_name] = _deserialize(rf._type, items) + elif not rf._is_optional: + existed_attr_keys.append(xml_name) + dict_to_pass[rf._rest_name] = [] continue # text element is primitive type @@ -891,6 +894,8 @@ def _get_deserialize_callable_from_annotation( # pylint: disable=too-many-retur # is it optional? try: if any(a is _NONE_TYPE for a in annotation.__args__): # pyright: ignore + if rf: + rf._is_optional = True if len(annotation.__args__) <= 2: # pyright: ignore if_obj_deserializer = _get_deserialize_callable_from_annotation( next(a for a in annotation.__args__ if a is not _NONE_TYPE), module, rf # pyright: ignore @@ -1049,6 +1054,7 @@ def _failsafe_deserialize_xml( return None +# pylint: disable=too-many-instance-attributes class _RestField: def __init__( self, @@ -1068,6 +1074,7 @@ def __init__( self._is_discriminator = is_discriminator self._visibility = visibility self._is_model = False + self._is_optional = False self._default = default self._format = format self._is_multipart_file_input = is_multipart_file_input diff --git a/packages/typespec-python/test/azure/generated/azure-core-scalar/specs/azure/core/scalar/_utils/model_base.py b/packages/typespec-python/test/azure/generated/azure-core-scalar/specs/azure/core/scalar/_utils/model_base.py index b4433021b4e..7b7f8ba67b5 100644 --- a/packages/typespec-python/test/azure/generated/azure-core-scalar/specs/azure/core/scalar/_utils/model_base.py +++ b/packages/typespec-python/test/azure/generated/azure-core-scalar/specs/azure/core/scalar/_utils/model_base.py @@ -630,6 +630,9 @@ def __init__(self, *args: typing.Any, **kwargs: typing.Any) -> None: if len(items) > 0: existed_attr_keys.append(xml_name) dict_to_pass[rf._rest_name] = _deserialize(rf._type, items) + elif not rf._is_optional: + existed_attr_keys.append(xml_name) + dict_to_pass[rf._rest_name] = [] continue # text element is primitive type @@ -891,6 +894,8 @@ def _get_deserialize_callable_from_annotation( # pylint: disable=too-many-retur # is it optional? try: if any(a is _NONE_TYPE for a in annotation.__args__): # pyright: ignore + if rf: + rf._is_optional = True if len(annotation.__args__) <= 2: # pyright: ignore if_obj_deserializer = _get_deserialize_callable_from_annotation( next(a for a in annotation.__args__ if a is not _NONE_TYPE), module, rf # pyright: ignore @@ -1049,6 +1054,7 @@ def _failsafe_deserialize_xml( return None +# pylint: disable=too-many-instance-attributes class _RestField: def __init__( self, @@ -1068,6 +1074,7 @@ def __init__( self._is_discriminator = is_discriminator self._visibility = visibility self._is_model = False + self._is_optional = False self._default = default self._format = format self._is_multipart_file_input = is_multipart_file_input diff --git a/packages/typespec-python/test/azure/generated/azure-core-traits/specs/azure/core/traits/_utils/model_base.py b/packages/typespec-python/test/azure/generated/azure-core-traits/specs/azure/core/traits/_utils/model_base.py index b4433021b4e..7b7f8ba67b5 100644 --- a/packages/typespec-python/test/azure/generated/azure-core-traits/specs/azure/core/traits/_utils/model_base.py +++ b/packages/typespec-python/test/azure/generated/azure-core-traits/specs/azure/core/traits/_utils/model_base.py @@ -630,6 +630,9 @@ def __init__(self, *args: typing.Any, **kwargs: typing.Any) -> None: if len(items) > 0: existed_attr_keys.append(xml_name) dict_to_pass[rf._rest_name] = _deserialize(rf._type, items) + elif not rf._is_optional: + existed_attr_keys.append(xml_name) + dict_to_pass[rf._rest_name] = [] continue # text element is primitive type @@ -891,6 +894,8 @@ def _get_deserialize_callable_from_annotation( # pylint: disable=too-many-retur # is it optional? try: if any(a is _NONE_TYPE for a in annotation.__args__): # pyright: ignore + if rf: + rf._is_optional = True if len(annotation.__args__) <= 2: # pyright: ignore if_obj_deserializer = _get_deserialize_callable_from_annotation( next(a for a in annotation.__args__ if a is not _NONE_TYPE), module, rf # pyright: ignore @@ -1049,6 +1054,7 @@ def _failsafe_deserialize_xml( return None +# pylint: disable=too-many-instance-attributes class _RestField: def __init__( self, @@ -1068,6 +1074,7 @@ def __init__( self._is_discriminator = is_discriminator self._visibility = visibility self._is_model = False + self._is_optional = False self._default = default self._format = format self._is_multipart_file_input = is_multipart_file_input diff --git a/packages/typespec-python/test/azure/generated/azure-encode-duration/specs/azure/encode/duration/_utils/model_base.py b/packages/typespec-python/test/azure/generated/azure-encode-duration/specs/azure/encode/duration/_utils/model_base.py index b4433021b4e..7b7f8ba67b5 100644 --- a/packages/typespec-python/test/azure/generated/azure-encode-duration/specs/azure/encode/duration/_utils/model_base.py +++ b/packages/typespec-python/test/azure/generated/azure-encode-duration/specs/azure/encode/duration/_utils/model_base.py @@ -630,6 +630,9 @@ def __init__(self, *args: typing.Any, **kwargs: typing.Any) -> None: if len(items) > 0: existed_attr_keys.append(xml_name) dict_to_pass[rf._rest_name] = _deserialize(rf._type, items) + elif not rf._is_optional: + existed_attr_keys.append(xml_name) + dict_to_pass[rf._rest_name] = [] continue # text element is primitive type @@ -891,6 +894,8 @@ def _get_deserialize_callable_from_annotation( # pylint: disable=too-many-retur # is it optional? try: if any(a is _NONE_TYPE for a in annotation.__args__): # pyright: ignore + if rf: + rf._is_optional = True if len(annotation.__args__) <= 2: # pyright: ignore if_obj_deserializer = _get_deserialize_callable_from_annotation( next(a for a in annotation.__args__ if a is not _NONE_TYPE), module, rf # pyright: ignore @@ -1049,6 +1054,7 @@ def _failsafe_deserialize_xml( return None +# pylint: disable=too-many-instance-attributes class _RestField: def __init__( self, @@ -1068,6 +1074,7 @@ def __init__( self._is_discriminator = is_discriminator self._visibility = visibility self._is_model = False + self._is_optional = False self._default = default self._format = format self._is_multipart_file_input = is_multipart_file_input diff --git a/packages/typespec-python/test/azure/generated/azure-example-basic/specs/azure/example/basic/_utils/model_base.py b/packages/typespec-python/test/azure/generated/azure-example-basic/specs/azure/example/basic/_utils/model_base.py index b4433021b4e..7b7f8ba67b5 100644 --- a/packages/typespec-python/test/azure/generated/azure-example-basic/specs/azure/example/basic/_utils/model_base.py +++ b/packages/typespec-python/test/azure/generated/azure-example-basic/specs/azure/example/basic/_utils/model_base.py @@ -630,6 +630,9 @@ def __init__(self, *args: typing.Any, **kwargs: typing.Any) -> None: if len(items) > 0: existed_attr_keys.append(xml_name) dict_to_pass[rf._rest_name] = _deserialize(rf._type, items) + elif not rf._is_optional: + existed_attr_keys.append(xml_name) + dict_to_pass[rf._rest_name] = [] continue # text element is primitive type @@ -891,6 +894,8 @@ def _get_deserialize_callable_from_annotation( # pylint: disable=too-many-retur # is it optional? try: if any(a is _NONE_TYPE for a in annotation.__args__): # pyright: ignore + if rf: + rf._is_optional = True if len(annotation.__args__) <= 2: # pyright: ignore if_obj_deserializer = _get_deserialize_callable_from_annotation( next(a for a in annotation.__args__ if a is not _NONE_TYPE), module, rf # pyright: ignore @@ -1049,6 +1054,7 @@ def _failsafe_deserialize_xml( return None +# pylint: disable=too-many-instance-attributes class _RestField: def __init__( self, @@ -1068,6 +1074,7 @@ def __init__( self._is_discriminator = is_discriminator self._visibility = visibility self._is_model = False + self._is_optional = False self._default = default self._format = format self._is_multipart_file_input = is_multipart_file_input diff --git a/packages/typespec-python/test/azure/generated/azure-payload-pageable/specs/azure/payload/pageable/_utils/model_base.py b/packages/typespec-python/test/azure/generated/azure-payload-pageable/specs/azure/payload/pageable/_utils/model_base.py index b4433021b4e..7b7f8ba67b5 100644 --- a/packages/typespec-python/test/azure/generated/azure-payload-pageable/specs/azure/payload/pageable/_utils/model_base.py +++ b/packages/typespec-python/test/azure/generated/azure-payload-pageable/specs/azure/payload/pageable/_utils/model_base.py @@ -630,6 +630,9 @@ def __init__(self, *args: typing.Any, **kwargs: typing.Any) -> None: if len(items) > 0: existed_attr_keys.append(xml_name) dict_to_pass[rf._rest_name] = _deserialize(rf._type, items) + elif not rf._is_optional: + existed_attr_keys.append(xml_name) + dict_to_pass[rf._rest_name] = [] continue # text element is primitive type @@ -891,6 +894,8 @@ def _get_deserialize_callable_from_annotation( # pylint: disable=too-many-retur # is it optional? try: if any(a is _NONE_TYPE for a in annotation.__args__): # pyright: ignore + if rf: + rf._is_optional = True if len(annotation.__args__) <= 2: # pyright: ignore if_obj_deserializer = _get_deserialize_callable_from_annotation( next(a for a in annotation.__args__ if a is not _NONE_TYPE), module, rf # pyright: ignore @@ -1049,6 +1054,7 @@ def _failsafe_deserialize_xml( return None +# pylint: disable=too-many-instance-attributes class _RestField: def __init__( self, @@ -1068,6 +1074,7 @@ def __init__( self._is_discriminator = is_discriminator self._visibility = visibility self._is_model = False + self._is_optional = False self._default = default self._format = format self._is_multipart_file_input = is_multipart_file_input diff --git a/packages/typespec-python/test/azure/generated/azure-resource-manager-common-properties/azure/resourcemanager/commonproperties/_utils/model_base.py b/packages/typespec-python/test/azure/generated/azure-resource-manager-common-properties/azure/resourcemanager/commonproperties/_utils/model_base.py index b4433021b4e..7b7f8ba67b5 100644 --- a/packages/typespec-python/test/azure/generated/azure-resource-manager-common-properties/azure/resourcemanager/commonproperties/_utils/model_base.py +++ b/packages/typespec-python/test/azure/generated/azure-resource-manager-common-properties/azure/resourcemanager/commonproperties/_utils/model_base.py @@ -630,6 +630,9 @@ def __init__(self, *args: typing.Any, **kwargs: typing.Any) -> None: if len(items) > 0: existed_attr_keys.append(xml_name) dict_to_pass[rf._rest_name] = _deserialize(rf._type, items) + elif not rf._is_optional: + existed_attr_keys.append(xml_name) + dict_to_pass[rf._rest_name] = [] continue # text element is primitive type @@ -891,6 +894,8 @@ def _get_deserialize_callable_from_annotation( # pylint: disable=too-many-retur # is it optional? try: if any(a is _NONE_TYPE for a in annotation.__args__): # pyright: ignore + if rf: + rf._is_optional = True if len(annotation.__args__) <= 2: # pyright: ignore if_obj_deserializer = _get_deserialize_callable_from_annotation( next(a for a in annotation.__args__ if a is not _NONE_TYPE), module, rf # pyright: ignore @@ -1049,6 +1054,7 @@ def _failsafe_deserialize_xml( return None +# pylint: disable=too-many-instance-attributes class _RestField: def __init__( self, @@ -1068,6 +1074,7 @@ def __init__( self._is_discriminator = is_discriminator self._visibility = visibility self._is_model = False + self._is_optional = False self._default = default self._format = format self._is_multipart_file_input = is_multipart_file_input diff --git a/packages/typespec-python/test/azure/generated/azure-resource-manager-large-header/azure/resourcemanager/largeheader/_utils/model_base.py b/packages/typespec-python/test/azure/generated/azure-resource-manager-large-header/azure/resourcemanager/largeheader/_utils/model_base.py index b4433021b4e..7b7f8ba67b5 100644 --- a/packages/typespec-python/test/azure/generated/azure-resource-manager-large-header/azure/resourcemanager/largeheader/_utils/model_base.py +++ b/packages/typespec-python/test/azure/generated/azure-resource-manager-large-header/azure/resourcemanager/largeheader/_utils/model_base.py @@ -630,6 +630,9 @@ def __init__(self, *args: typing.Any, **kwargs: typing.Any) -> None: if len(items) > 0: existed_attr_keys.append(xml_name) dict_to_pass[rf._rest_name] = _deserialize(rf._type, items) + elif not rf._is_optional: + existed_attr_keys.append(xml_name) + dict_to_pass[rf._rest_name] = [] continue # text element is primitive type @@ -891,6 +894,8 @@ def _get_deserialize_callable_from_annotation( # pylint: disable=too-many-retur # is it optional? try: if any(a is _NONE_TYPE for a in annotation.__args__): # pyright: ignore + if rf: + rf._is_optional = True if len(annotation.__args__) <= 2: # pyright: ignore if_obj_deserializer = _get_deserialize_callable_from_annotation( next(a for a in annotation.__args__ if a is not _NONE_TYPE), module, rf # pyright: ignore @@ -1049,6 +1054,7 @@ def _failsafe_deserialize_xml( return None +# pylint: disable=too-many-instance-attributes class _RestField: def __init__( self, @@ -1068,6 +1074,7 @@ def __init__( self._is_discriminator = is_discriminator self._visibility = visibility self._is_model = False + self._is_optional = False self._default = default self._format = format self._is_multipart_file_input = is_multipart_file_input diff --git a/packages/typespec-python/test/azure/generated/azure-resource-manager-method-subscription-id/azure/resourcemanager/methodsubscriptionid/_utils/model_base.py b/packages/typespec-python/test/azure/generated/azure-resource-manager-method-subscription-id/azure/resourcemanager/methodsubscriptionid/_utils/model_base.py index b4433021b4e..7b7f8ba67b5 100644 --- a/packages/typespec-python/test/azure/generated/azure-resource-manager-method-subscription-id/azure/resourcemanager/methodsubscriptionid/_utils/model_base.py +++ b/packages/typespec-python/test/azure/generated/azure-resource-manager-method-subscription-id/azure/resourcemanager/methodsubscriptionid/_utils/model_base.py @@ -630,6 +630,9 @@ def __init__(self, *args: typing.Any, **kwargs: typing.Any) -> None: if len(items) > 0: existed_attr_keys.append(xml_name) dict_to_pass[rf._rest_name] = _deserialize(rf._type, items) + elif not rf._is_optional: + existed_attr_keys.append(xml_name) + dict_to_pass[rf._rest_name] = [] continue # text element is primitive type @@ -891,6 +894,8 @@ def _get_deserialize_callable_from_annotation( # pylint: disable=too-many-retur # is it optional? try: if any(a is _NONE_TYPE for a in annotation.__args__): # pyright: ignore + if rf: + rf._is_optional = True if len(annotation.__args__) <= 2: # pyright: ignore if_obj_deserializer = _get_deserialize_callable_from_annotation( next(a for a in annotation.__args__ if a is not _NONE_TYPE), module, rf # pyright: ignore @@ -1049,6 +1054,7 @@ def _failsafe_deserialize_xml( return None +# pylint: disable=too-many-instance-attributes class _RestField: def __init__( self, @@ -1068,6 +1074,7 @@ def __init__( self._is_discriminator = is_discriminator self._visibility = visibility self._is_model = False + self._is_optional = False self._default = default self._format = format self._is_multipart_file_input = is_multipart_file_input diff --git a/packages/typespec-python/test/azure/generated/azure-resource-manager-multi-service-older-versions/azure/resourcemanager/multiserviceolderversions/combined/_utils/model_base.py b/packages/typespec-python/test/azure/generated/azure-resource-manager-multi-service-older-versions/azure/resourcemanager/multiserviceolderversions/combined/_utils/model_base.py index b4433021b4e..7b7f8ba67b5 100644 --- a/packages/typespec-python/test/azure/generated/azure-resource-manager-multi-service-older-versions/azure/resourcemanager/multiserviceolderversions/combined/_utils/model_base.py +++ b/packages/typespec-python/test/azure/generated/azure-resource-manager-multi-service-older-versions/azure/resourcemanager/multiserviceolderversions/combined/_utils/model_base.py @@ -630,6 +630,9 @@ def __init__(self, *args: typing.Any, **kwargs: typing.Any) -> None: if len(items) > 0: existed_attr_keys.append(xml_name) dict_to_pass[rf._rest_name] = _deserialize(rf._type, items) + elif not rf._is_optional: + existed_attr_keys.append(xml_name) + dict_to_pass[rf._rest_name] = [] continue # text element is primitive type @@ -891,6 +894,8 @@ def _get_deserialize_callable_from_annotation( # pylint: disable=too-many-retur # is it optional? try: if any(a is _NONE_TYPE for a in annotation.__args__): # pyright: ignore + if rf: + rf._is_optional = True if len(annotation.__args__) <= 2: # pyright: ignore if_obj_deserializer = _get_deserialize_callable_from_annotation( next(a for a in annotation.__args__ if a is not _NONE_TYPE), module, rf # pyright: ignore @@ -1049,6 +1054,7 @@ def _failsafe_deserialize_xml( return None +# pylint: disable=too-many-instance-attributes class _RestField: def __init__( self, @@ -1068,6 +1074,7 @@ def __init__( self._is_discriminator = is_discriminator self._visibility = visibility self._is_model = False + self._is_optional = False self._default = default self._format = format self._is_multipart_file_input = is_multipart_file_input diff --git a/packages/typespec-python/test/azure/generated/azure-resource-manager-multi-service-shared-models/azure/resourcemanager/multiservicesharedmodels/combined/_utils/model_base.py b/packages/typespec-python/test/azure/generated/azure-resource-manager-multi-service-shared-models/azure/resourcemanager/multiservicesharedmodels/combined/_utils/model_base.py index b4433021b4e..7b7f8ba67b5 100644 --- a/packages/typespec-python/test/azure/generated/azure-resource-manager-multi-service-shared-models/azure/resourcemanager/multiservicesharedmodels/combined/_utils/model_base.py +++ b/packages/typespec-python/test/azure/generated/azure-resource-manager-multi-service-shared-models/azure/resourcemanager/multiservicesharedmodels/combined/_utils/model_base.py @@ -630,6 +630,9 @@ def __init__(self, *args: typing.Any, **kwargs: typing.Any) -> None: if len(items) > 0: existed_attr_keys.append(xml_name) dict_to_pass[rf._rest_name] = _deserialize(rf._type, items) + elif not rf._is_optional: + existed_attr_keys.append(xml_name) + dict_to_pass[rf._rest_name] = [] continue # text element is primitive type @@ -891,6 +894,8 @@ def _get_deserialize_callable_from_annotation( # pylint: disable=too-many-retur # is it optional? try: if any(a is _NONE_TYPE for a in annotation.__args__): # pyright: ignore + if rf: + rf._is_optional = True if len(annotation.__args__) <= 2: # pyright: ignore if_obj_deserializer = _get_deserialize_callable_from_annotation( next(a for a in annotation.__args__ if a is not _NONE_TYPE), module, rf # pyright: ignore @@ -1049,6 +1054,7 @@ def _failsafe_deserialize_xml( return None +# pylint: disable=too-many-instance-attributes class _RestField: def __init__( self, @@ -1068,6 +1074,7 @@ def __init__( self._is_discriminator = is_discriminator self._visibility = visibility self._is_model = False + self._is_optional = False self._default = default self._format = format self._is_multipart_file_input = is_multipart_file_input diff --git a/packages/typespec-python/test/azure/generated/azure-resource-manager-multi-service/azure/resourcemanager/multiservice/combined/_utils/model_base.py b/packages/typespec-python/test/azure/generated/azure-resource-manager-multi-service/azure/resourcemanager/multiservice/combined/_utils/model_base.py index b4433021b4e..7b7f8ba67b5 100644 --- a/packages/typespec-python/test/azure/generated/azure-resource-manager-multi-service/azure/resourcemanager/multiservice/combined/_utils/model_base.py +++ b/packages/typespec-python/test/azure/generated/azure-resource-manager-multi-service/azure/resourcemanager/multiservice/combined/_utils/model_base.py @@ -630,6 +630,9 @@ def __init__(self, *args: typing.Any, **kwargs: typing.Any) -> None: if len(items) > 0: existed_attr_keys.append(xml_name) dict_to_pass[rf._rest_name] = _deserialize(rf._type, items) + elif not rf._is_optional: + existed_attr_keys.append(xml_name) + dict_to_pass[rf._rest_name] = [] continue # text element is primitive type @@ -891,6 +894,8 @@ def _get_deserialize_callable_from_annotation( # pylint: disable=too-many-retur # is it optional? try: if any(a is _NONE_TYPE for a in annotation.__args__): # pyright: ignore + if rf: + rf._is_optional = True if len(annotation.__args__) <= 2: # pyright: ignore if_obj_deserializer = _get_deserialize_callable_from_annotation( next(a for a in annotation.__args__ if a is not _NONE_TYPE), module, rf # pyright: ignore @@ -1049,6 +1054,7 @@ def _failsafe_deserialize_xml( return None +# pylint: disable=too-many-instance-attributes class _RestField: def __init__( self, @@ -1068,6 +1074,7 @@ def __init__( self._is_discriminator = is_discriminator self._visibility = visibility self._is_model = False + self._is_optional = False self._default = default self._format = format self._is_multipart_file_input = is_multipart_file_input diff --git a/packages/typespec-python/test/azure/generated/azure-resource-manager-non-resource/azure/resourcemanager/nonresource/_utils/model_base.py b/packages/typespec-python/test/azure/generated/azure-resource-manager-non-resource/azure/resourcemanager/nonresource/_utils/model_base.py index b4433021b4e..7b7f8ba67b5 100644 --- a/packages/typespec-python/test/azure/generated/azure-resource-manager-non-resource/azure/resourcemanager/nonresource/_utils/model_base.py +++ b/packages/typespec-python/test/azure/generated/azure-resource-manager-non-resource/azure/resourcemanager/nonresource/_utils/model_base.py @@ -630,6 +630,9 @@ def __init__(self, *args: typing.Any, **kwargs: typing.Any) -> None: if len(items) > 0: existed_attr_keys.append(xml_name) dict_to_pass[rf._rest_name] = _deserialize(rf._type, items) + elif not rf._is_optional: + existed_attr_keys.append(xml_name) + dict_to_pass[rf._rest_name] = [] continue # text element is primitive type @@ -891,6 +894,8 @@ def _get_deserialize_callable_from_annotation( # pylint: disable=too-many-retur # is it optional? try: if any(a is _NONE_TYPE for a in annotation.__args__): # pyright: ignore + if rf: + rf._is_optional = True if len(annotation.__args__) <= 2: # pyright: ignore if_obj_deserializer = _get_deserialize_callable_from_annotation( next(a for a in annotation.__args__ if a is not _NONE_TYPE), module, rf # pyright: ignore @@ -1049,6 +1054,7 @@ def _failsafe_deserialize_xml( return None +# pylint: disable=too-many-instance-attributes class _RestField: def __init__( self, @@ -1068,6 +1074,7 @@ def __init__( self._is_discriminator = is_discriminator self._visibility = visibility self._is_model = False + self._is_optional = False self._default = default self._format = format self._is_multipart_file_input = is_multipart_file_input diff --git a/packages/typespec-python/test/azure/generated/azure-resource-manager-operation-templates/azure/resourcemanager/operationtemplates/_utils/model_base.py b/packages/typespec-python/test/azure/generated/azure-resource-manager-operation-templates/azure/resourcemanager/operationtemplates/_utils/model_base.py index b4433021b4e..7b7f8ba67b5 100644 --- a/packages/typespec-python/test/azure/generated/azure-resource-manager-operation-templates/azure/resourcemanager/operationtemplates/_utils/model_base.py +++ b/packages/typespec-python/test/azure/generated/azure-resource-manager-operation-templates/azure/resourcemanager/operationtemplates/_utils/model_base.py @@ -630,6 +630,9 @@ def __init__(self, *args: typing.Any, **kwargs: typing.Any) -> None: if len(items) > 0: existed_attr_keys.append(xml_name) dict_to_pass[rf._rest_name] = _deserialize(rf._type, items) + elif not rf._is_optional: + existed_attr_keys.append(xml_name) + dict_to_pass[rf._rest_name] = [] continue # text element is primitive type @@ -891,6 +894,8 @@ def _get_deserialize_callable_from_annotation( # pylint: disable=too-many-retur # is it optional? try: if any(a is _NONE_TYPE for a in annotation.__args__): # pyright: ignore + if rf: + rf._is_optional = True if len(annotation.__args__) <= 2: # pyright: ignore if_obj_deserializer = _get_deserialize_callable_from_annotation( next(a for a in annotation.__args__ if a is not _NONE_TYPE), module, rf # pyright: ignore @@ -1049,6 +1054,7 @@ def _failsafe_deserialize_xml( return None +# pylint: disable=too-many-instance-attributes class _RestField: def __init__( self, @@ -1068,6 +1074,7 @@ def __init__( self._is_discriminator = is_discriminator self._visibility = visibility self._is_model = False + self._is_optional = False self._default = default self._format = format self._is_multipart_file_input = is_multipart_file_input diff --git a/packages/typespec-python/test/azure/generated/azure-resource-manager-resources/azure/resourcemanager/resources/_utils/model_base.py b/packages/typespec-python/test/azure/generated/azure-resource-manager-resources/azure/resourcemanager/resources/_utils/model_base.py index b4433021b4e..7b7f8ba67b5 100644 --- a/packages/typespec-python/test/azure/generated/azure-resource-manager-resources/azure/resourcemanager/resources/_utils/model_base.py +++ b/packages/typespec-python/test/azure/generated/azure-resource-manager-resources/azure/resourcemanager/resources/_utils/model_base.py @@ -630,6 +630,9 @@ def __init__(self, *args: typing.Any, **kwargs: typing.Any) -> None: if len(items) > 0: existed_attr_keys.append(xml_name) dict_to_pass[rf._rest_name] = _deserialize(rf._type, items) + elif not rf._is_optional: + existed_attr_keys.append(xml_name) + dict_to_pass[rf._rest_name] = [] continue # text element is primitive type @@ -891,6 +894,8 @@ def _get_deserialize_callable_from_annotation( # pylint: disable=too-many-retur # is it optional? try: if any(a is _NONE_TYPE for a in annotation.__args__): # pyright: ignore + if rf: + rf._is_optional = True if len(annotation.__args__) <= 2: # pyright: ignore if_obj_deserializer = _get_deserialize_callable_from_annotation( next(a for a in annotation.__args__ if a is not _NONE_TYPE), module, rf # pyright: ignore @@ -1049,6 +1054,7 @@ def _failsafe_deserialize_xml( return None +# pylint: disable=too-many-instance-attributes class _RestField: def __init__( self, @@ -1068,6 +1074,7 @@ def __init__( self._is_discriminator = is_discriminator self._visibility = visibility self._is_model = False + self._is_optional = False self._default = default self._format = format self._is_multipart_file_input = is_multipart_file_input diff --git a/packages/typespec-python/test/azure/generated/azure-special-headers-client-request-id/azure/specialheaders/xmsclientrequestid/_utils/model_base.py b/packages/typespec-python/test/azure/generated/azure-special-headers-client-request-id/azure/specialheaders/xmsclientrequestid/_utils/model_base.py index b4433021b4e..7b7f8ba67b5 100644 --- a/packages/typespec-python/test/azure/generated/azure-special-headers-client-request-id/azure/specialheaders/xmsclientrequestid/_utils/model_base.py +++ b/packages/typespec-python/test/azure/generated/azure-special-headers-client-request-id/azure/specialheaders/xmsclientrequestid/_utils/model_base.py @@ -630,6 +630,9 @@ def __init__(self, *args: typing.Any, **kwargs: typing.Any) -> None: if len(items) > 0: existed_attr_keys.append(xml_name) dict_to_pass[rf._rest_name] = _deserialize(rf._type, items) + elif not rf._is_optional: + existed_attr_keys.append(xml_name) + dict_to_pass[rf._rest_name] = [] continue # text element is primitive type @@ -891,6 +894,8 @@ def _get_deserialize_callable_from_annotation( # pylint: disable=too-many-retur # is it optional? try: if any(a is _NONE_TYPE for a in annotation.__args__): # pyright: ignore + if rf: + rf._is_optional = True if len(annotation.__args__) <= 2: # pyright: ignore if_obj_deserializer = _get_deserialize_callable_from_annotation( next(a for a in annotation.__args__ if a is not _NONE_TYPE), module, rf # pyright: ignore @@ -1049,6 +1054,7 @@ def _failsafe_deserialize_xml( return None +# pylint: disable=too-many-instance-attributes class _RestField: def __init__( self, @@ -1068,6 +1074,7 @@ def __init__( self._is_discriminator = is_discriminator self._visibility = visibility self._is_model = False + self._is_optional = False self._default = default self._format = format self._is_multipart_file_input = is_multipart_file_input diff --git a/packages/typespec-python/test/azure/generated/azure-versioning-previewversion/specs/azure/versioning/previewversion/_utils/model_base.py b/packages/typespec-python/test/azure/generated/azure-versioning-previewversion/specs/azure/versioning/previewversion/_utils/model_base.py index b4433021b4e..7b7f8ba67b5 100644 --- a/packages/typespec-python/test/azure/generated/azure-versioning-previewversion/specs/azure/versioning/previewversion/_utils/model_base.py +++ b/packages/typespec-python/test/azure/generated/azure-versioning-previewversion/specs/azure/versioning/previewversion/_utils/model_base.py @@ -630,6 +630,9 @@ def __init__(self, *args: typing.Any, **kwargs: typing.Any) -> None: if len(items) > 0: existed_attr_keys.append(xml_name) dict_to_pass[rf._rest_name] = _deserialize(rf._type, items) + elif not rf._is_optional: + existed_attr_keys.append(xml_name) + dict_to_pass[rf._rest_name] = [] continue # text element is primitive type @@ -891,6 +894,8 @@ def _get_deserialize_callable_from_annotation( # pylint: disable=too-many-retur # is it optional? try: if any(a is _NONE_TYPE for a in annotation.__args__): # pyright: ignore + if rf: + rf._is_optional = True if len(annotation.__args__) <= 2: # pyright: ignore if_obj_deserializer = _get_deserialize_callable_from_annotation( next(a for a in annotation.__args__ if a is not _NONE_TYPE), module, rf # pyright: ignore @@ -1049,6 +1054,7 @@ def _failsafe_deserialize_xml( return None +# pylint: disable=too-many-instance-attributes class _RestField: def __init__( self, @@ -1068,6 +1074,7 @@ def __init__( self._is_discriminator = is_discriminator self._visibility = visibility self._is_model = False + self._is_optional = False self._default = default self._format = format self._is_multipart_file_input = is_multipart_file_input diff --git a/packages/typespec-python/test/azure/generated/client-namespace/client/clientnamespace/_utils/model_base.py b/packages/typespec-python/test/azure/generated/client-namespace/client/clientnamespace/_utils/model_base.py index b4433021b4e..7b7f8ba67b5 100644 --- a/packages/typespec-python/test/azure/generated/client-namespace/client/clientnamespace/_utils/model_base.py +++ b/packages/typespec-python/test/azure/generated/client-namespace/client/clientnamespace/_utils/model_base.py @@ -630,6 +630,9 @@ def __init__(self, *args: typing.Any, **kwargs: typing.Any) -> None: if len(items) > 0: existed_attr_keys.append(xml_name) dict_to_pass[rf._rest_name] = _deserialize(rf._type, items) + elif not rf._is_optional: + existed_attr_keys.append(xml_name) + dict_to_pass[rf._rest_name] = [] continue # text element is primitive type @@ -891,6 +894,8 @@ def _get_deserialize_callable_from_annotation( # pylint: disable=too-many-retur # is it optional? try: if any(a is _NONE_TYPE for a in annotation.__args__): # pyright: ignore + if rf: + rf._is_optional = True if len(annotation.__args__) <= 2: # pyright: ignore if_obj_deserializer = _get_deserialize_callable_from_annotation( next(a for a in annotation.__args__ if a is not _NONE_TYPE), module, rf # pyright: ignore @@ -1049,6 +1054,7 @@ def _failsafe_deserialize_xml( return None +# pylint: disable=too-many-instance-attributes class _RestField: def __init__( self, @@ -1068,6 +1074,7 @@ def __init__( self._is_discriminator = is_discriminator self._visibility = visibility self._is_model = False + self._is_optional = False self._default = default self._format = format self._is_multipart_file_input = is_multipart_file_input diff --git a/packages/typespec-python/test/azure/generated/client-namespace/client/clientnamespace/second/_utils/model_base.py b/packages/typespec-python/test/azure/generated/client-namespace/client/clientnamespace/second/_utils/model_base.py index b4433021b4e..7b7f8ba67b5 100644 --- a/packages/typespec-python/test/azure/generated/client-namespace/client/clientnamespace/second/_utils/model_base.py +++ b/packages/typespec-python/test/azure/generated/client-namespace/client/clientnamespace/second/_utils/model_base.py @@ -630,6 +630,9 @@ def __init__(self, *args: typing.Any, **kwargs: typing.Any) -> None: if len(items) > 0: existed_attr_keys.append(xml_name) dict_to_pass[rf._rest_name] = _deserialize(rf._type, items) + elif not rf._is_optional: + existed_attr_keys.append(xml_name) + dict_to_pass[rf._rest_name] = [] continue # text element is primitive type @@ -891,6 +894,8 @@ def _get_deserialize_callable_from_annotation( # pylint: disable=too-many-retur # is it optional? try: if any(a is _NONE_TYPE for a in annotation.__args__): # pyright: ignore + if rf: + rf._is_optional = True if len(annotation.__args__) <= 2: # pyright: ignore if_obj_deserializer = _get_deserialize_callable_from_annotation( next(a for a in annotation.__args__ if a is not _NONE_TYPE), module, rf # pyright: ignore @@ -1049,6 +1054,7 @@ def _failsafe_deserialize_xml( return None +# pylint: disable=too-many-instance-attributes class _RestField: def __init__( self, @@ -1068,6 +1074,7 @@ def __init__( self._is_discriminator = is_discriminator self._visibility = visibility self._is_model = False + self._is_optional = False self._default = default self._format = format self._is_multipart_file_input = is_multipart_file_input diff --git a/packages/typespec-python/test/azure/generated/client-naming-enum-conflict/client/naming/enumconflict/_utils/model_base.py b/packages/typespec-python/test/azure/generated/client-naming-enum-conflict/client/naming/enumconflict/_utils/model_base.py index b4433021b4e..7b7f8ba67b5 100644 --- a/packages/typespec-python/test/azure/generated/client-naming-enum-conflict/client/naming/enumconflict/_utils/model_base.py +++ b/packages/typespec-python/test/azure/generated/client-naming-enum-conflict/client/naming/enumconflict/_utils/model_base.py @@ -630,6 +630,9 @@ def __init__(self, *args: typing.Any, **kwargs: typing.Any) -> None: if len(items) > 0: existed_attr_keys.append(xml_name) dict_to_pass[rf._rest_name] = _deserialize(rf._type, items) + elif not rf._is_optional: + existed_attr_keys.append(xml_name) + dict_to_pass[rf._rest_name] = [] continue # text element is primitive type @@ -891,6 +894,8 @@ def _get_deserialize_callable_from_annotation( # pylint: disable=too-many-retur # is it optional? try: if any(a is _NONE_TYPE for a in annotation.__args__): # pyright: ignore + if rf: + rf._is_optional = True if len(annotation.__args__) <= 2: # pyright: ignore if_obj_deserializer = _get_deserialize_callable_from_annotation( next(a for a in annotation.__args__ if a is not _NONE_TYPE), module, rf # pyright: ignore @@ -1049,6 +1054,7 @@ def _failsafe_deserialize_xml( return None +# pylint: disable=too-many-instance-attributes class _RestField: def __init__( self, @@ -1068,6 +1074,7 @@ def __init__( self._is_discriminator = is_discriminator self._visibility = visibility self._is_model = False + self._is_optional = False self._default = default self._format = format self._is_multipart_file_input = is_multipart_file_input diff --git a/packages/typespec-python/test/azure/generated/client-naming/client/naming/main/_utils/model_base.py b/packages/typespec-python/test/azure/generated/client-naming/client/naming/main/_utils/model_base.py index b4433021b4e..7b7f8ba67b5 100644 --- a/packages/typespec-python/test/azure/generated/client-naming/client/naming/main/_utils/model_base.py +++ b/packages/typespec-python/test/azure/generated/client-naming/client/naming/main/_utils/model_base.py @@ -630,6 +630,9 @@ def __init__(self, *args: typing.Any, **kwargs: typing.Any) -> None: if len(items) > 0: existed_attr_keys.append(xml_name) dict_to_pass[rf._rest_name] = _deserialize(rf._type, items) + elif not rf._is_optional: + existed_attr_keys.append(xml_name) + dict_to_pass[rf._rest_name] = [] continue # text element is primitive type @@ -891,6 +894,8 @@ def _get_deserialize_callable_from_annotation( # pylint: disable=too-many-retur # is it optional? try: if any(a is _NONE_TYPE for a in annotation.__args__): # pyright: ignore + if rf: + rf._is_optional = True if len(annotation.__args__) <= 2: # pyright: ignore if_obj_deserializer = _get_deserialize_callable_from_annotation( next(a for a in annotation.__args__ if a is not _NONE_TYPE), module, rf # pyright: ignore @@ -1049,6 +1054,7 @@ def _failsafe_deserialize_xml( return None +# pylint: disable=too-many-instance-attributes class _RestField: def __init__( self, @@ -1068,6 +1074,7 @@ def __init__( self._is_discriminator = is_discriminator self._visibility = visibility self._is_model = False + self._is_optional = False self._default = default self._format = format self._is_multipart_file_input = is_multipart_file_input diff --git a/packages/typespec-python/test/azure/generated/client-overload/client/overload/_utils/model_base.py b/packages/typespec-python/test/azure/generated/client-overload/client/overload/_utils/model_base.py index b4433021b4e..7b7f8ba67b5 100644 --- a/packages/typespec-python/test/azure/generated/client-overload/client/overload/_utils/model_base.py +++ b/packages/typespec-python/test/azure/generated/client-overload/client/overload/_utils/model_base.py @@ -630,6 +630,9 @@ def __init__(self, *args: typing.Any, **kwargs: typing.Any) -> None: if len(items) > 0: existed_attr_keys.append(xml_name) dict_to_pass[rf._rest_name] = _deserialize(rf._type, items) + elif not rf._is_optional: + existed_attr_keys.append(xml_name) + dict_to_pass[rf._rest_name] = [] continue # text element is primitive type @@ -891,6 +894,8 @@ def _get_deserialize_callable_from_annotation( # pylint: disable=too-many-retur # is it optional? try: if any(a is _NONE_TYPE for a in annotation.__args__): # pyright: ignore + if rf: + rf._is_optional = True if len(annotation.__args__) <= 2: # pyright: ignore if_obj_deserializer = _get_deserialize_callable_from_annotation( next(a for a in annotation.__args__ if a is not _NONE_TYPE), module, rf # pyright: ignore @@ -1049,6 +1054,7 @@ def _failsafe_deserialize_xml( return None +# pylint: disable=too-many-instance-attributes class _RestField: def __init__( self, @@ -1068,6 +1074,7 @@ def __init__( self._is_discriminator = is_discriminator self._visibility = visibility self._is_model = False + self._is_optional = False self._default = default self._format = format self._is_multipart_file_input = is_multipart_file_input diff --git a/packages/typespec-python/test/azure/generated/client-structure-clientoperationgroup/client/structure/clientoperationgroup/_utils/model_base.py b/packages/typespec-python/test/azure/generated/client-structure-clientoperationgroup/client/structure/clientoperationgroup/_utils/model_base.py index b4433021b4e..7b7f8ba67b5 100644 --- a/packages/typespec-python/test/azure/generated/client-structure-clientoperationgroup/client/structure/clientoperationgroup/_utils/model_base.py +++ b/packages/typespec-python/test/azure/generated/client-structure-clientoperationgroup/client/structure/clientoperationgroup/_utils/model_base.py @@ -630,6 +630,9 @@ def __init__(self, *args: typing.Any, **kwargs: typing.Any) -> None: if len(items) > 0: existed_attr_keys.append(xml_name) dict_to_pass[rf._rest_name] = _deserialize(rf._type, items) + elif not rf._is_optional: + existed_attr_keys.append(xml_name) + dict_to_pass[rf._rest_name] = [] continue # text element is primitive type @@ -891,6 +894,8 @@ def _get_deserialize_callable_from_annotation( # pylint: disable=too-many-retur # is it optional? try: if any(a is _NONE_TYPE for a in annotation.__args__): # pyright: ignore + if rf: + rf._is_optional = True if len(annotation.__args__) <= 2: # pyright: ignore if_obj_deserializer = _get_deserialize_callable_from_annotation( next(a for a in annotation.__args__ if a is not _NONE_TYPE), module, rf # pyright: ignore @@ -1049,6 +1054,7 @@ def _failsafe_deserialize_xml( return None +# pylint: disable=too-many-instance-attributes class _RestField: def __init__( self, @@ -1068,6 +1074,7 @@ def __init__( self._is_discriminator = is_discriminator self._visibility = visibility self._is_model = False + self._is_optional = False self._default = default self._format = format self._is_multipart_file_input = is_multipart_file_input diff --git a/packages/typespec-python/test/azure/generated/client-structure-default/client/structure/service/_utils/model_base.py b/packages/typespec-python/test/azure/generated/client-structure-default/client/structure/service/_utils/model_base.py index b4433021b4e..7b7f8ba67b5 100644 --- a/packages/typespec-python/test/azure/generated/client-structure-default/client/structure/service/_utils/model_base.py +++ b/packages/typespec-python/test/azure/generated/client-structure-default/client/structure/service/_utils/model_base.py @@ -630,6 +630,9 @@ def __init__(self, *args: typing.Any, **kwargs: typing.Any) -> None: if len(items) > 0: existed_attr_keys.append(xml_name) dict_to_pass[rf._rest_name] = _deserialize(rf._type, items) + elif not rf._is_optional: + existed_attr_keys.append(xml_name) + dict_to_pass[rf._rest_name] = [] continue # text element is primitive type @@ -891,6 +894,8 @@ def _get_deserialize_callable_from_annotation( # pylint: disable=too-many-retur # is it optional? try: if any(a is _NONE_TYPE for a in annotation.__args__): # pyright: ignore + if rf: + rf._is_optional = True if len(annotation.__args__) <= 2: # pyright: ignore if_obj_deserializer = _get_deserialize_callable_from_annotation( next(a for a in annotation.__args__ if a is not _NONE_TYPE), module, rf # pyright: ignore @@ -1049,6 +1054,7 @@ def _failsafe_deserialize_xml( return None +# pylint: disable=too-many-instance-attributes class _RestField: def __init__( self, @@ -1068,6 +1074,7 @@ def __init__( self._is_discriminator = is_discriminator self._visibility = visibility self._is_model = False + self._is_optional = False self._default = default self._format = format self._is_multipart_file_input = is_multipart_file_input diff --git a/packages/typespec-python/test/azure/generated/client-structure-multiclient/client/structure/multiclient/_utils/model_base.py b/packages/typespec-python/test/azure/generated/client-structure-multiclient/client/structure/multiclient/_utils/model_base.py index b4433021b4e..7b7f8ba67b5 100644 --- a/packages/typespec-python/test/azure/generated/client-structure-multiclient/client/structure/multiclient/_utils/model_base.py +++ b/packages/typespec-python/test/azure/generated/client-structure-multiclient/client/structure/multiclient/_utils/model_base.py @@ -630,6 +630,9 @@ def __init__(self, *args: typing.Any, **kwargs: typing.Any) -> None: if len(items) > 0: existed_attr_keys.append(xml_name) dict_to_pass[rf._rest_name] = _deserialize(rf._type, items) + elif not rf._is_optional: + existed_attr_keys.append(xml_name) + dict_to_pass[rf._rest_name] = [] continue # text element is primitive type @@ -891,6 +894,8 @@ def _get_deserialize_callable_from_annotation( # pylint: disable=too-many-retur # is it optional? try: if any(a is _NONE_TYPE for a in annotation.__args__): # pyright: ignore + if rf: + rf._is_optional = True if len(annotation.__args__) <= 2: # pyright: ignore if_obj_deserializer = _get_deserialize_callable_from_annotation( next(a for a in annotation.__args__ if a is not _NONE_TYPE), module, rf # pyright: ignore @@ -1049,6 +1054,7 @@ def _failsafe_deserialize_xml( return None +# pylint: disable=too-many-instance-attributes class _RestField: def __init__( self, @@ -1068,6 +1074,7 @@ def __init__( self._is_discriminator = is_discriminator self._visibility = visibility self._is_model = False + self._is_optional = False self._default = default self._format = format self._is_multipart_file_input = is_multipart_file_input diff --git a/packages/typespec-python/test/azure/generated/client-structure-renamedoperation/client/structure/renamedoperation/_utils/model_base.py b/packages/typespec-python/test/azure/generated/client-structure-renamedoperation/client/structure/renamedoperation/_utils/model_base.py index b4433021b4e..7b7f8ba67b5 100644 --- a/packages/typespec-python/test/azure/generated/client-structure-renamedoperation/client/structure/renamedoperation/_utils/model_base.py +++ b/packages/typespec-python/test/azure/generated/client-structure-renamedoperation/client/structure/renamedoperation/_utils/model_base.py @@ -630,6 +630,9 @@ def __init__(self, *args: typing.Any, **kwargs: typing.Any) -> None: if len(items) > 0: existed_attr_keys.append(xml_name) dict_to_pass[rf._rest_name] = _deserialize(rf._type, items) + elif not rf._is_optional: + existed_attr_keys.append(xml_name) + dict_to_pass[rf._rest_name] = [] continue # text element is primitive type @@ -891,6 +894,8 @@ def _get_deserialize_callable_from_annotation( # pylint: disable=too-many-retur # is it optional? try: if any(a is _NONE_TYPE for a in annotation.__args__): # pyright: ignore + if rf: + rf._is_optional = True if len(annotation.__args__) <= 2: # pyright: ignore if_obj_deserializer = _get_deserialize_callable_from_annotation( next(a for a in annotation.__args__ if a is not _NONE_TYPE), module, rf # pyright: ignore @@ -1049,6 +1054,7 @@ def _failsafe_deserialize_xml( return None +# pylint: disable=too-many-instance-attributes class _RestField: def __init__( self, @@ -1068,6 +1074,7 @@ def __init__( self._is_discriminator = is_discriminator self._visibility = visibility self._is_model = False + self._is_optional = False self._default = default self._format = format self._is_multipart_file_input = is_multipart_file_input diff --git a/packages/typespec-python/test/azure/generated/client-structure-twooperationgroup/client/structure/twooperationgroup/_utils/model_base.py b/packages/typespec-python/test/azure/generated/client-structure-twooperationgroup/client/structure/twooperationgroup/_utils/model_base.py index b4433021b4e..7b7f8ba67b5 100644 --- a/packages/typespec-python/test/azure/generated/client-structure-twooperationgroup/client/structure/twooperationgroup/_utils/model_base.py +++ b/packages/typespec-python/test/azure/generated/client-structure-twooperationgroup/client/structure/twooperationgroup/_utils/model_base.py @@ -630,6 +630,9 @@ def __init__(self, *args: typing.Any, **kwargs: typing.Any) -> None: if len(items) > 0: existed_attr_keys.append(xml_name) dict_to_pass[rf._rest_name] = _deserialize(rf._type, items) + elif not rf._is_optional: + existed_attr_keys.append(xml_name) + dict_to_pass[rf._rest_name] = [] continue # text element is primitive type @@ -891,6 +894,8 @@ def _get_deserialize_callable_from_annotation( # pylint: disable=too-many-retur # is it optional? try: if any(a is _NONE_TYPE for a in annotation.__args__): # pyright: ignore + if rf: + rf._is_optional = True if len(annotation.__args__) <= 2: # pyright: ignore if_obj_deserializer = _get_deserialize_callable_from_annotation( next(a for a in annotation.__args__ if a is not _NONE_TYPE), module, rf # pyright: ignore @@ -1049,6 +1054,7 @@ def _failsafe_deserialize_xml( return None +# pylint: disable=too-many-instance-attributes class _RestField: def __init__( self, @@ -1068,6 +1074,7 @@ def __init__( self._is_discriminator = is_discriminator self._visibility = visibility self._is_model = False + self._is_optional = False self._default = default self._format = format self._is_multipart_file_input = is_multipart_file_input diff --git a/packages/typespec-python/test/azure/generated/encode-array/encode/array/_utils/model_base.py b/packages/typespec-python/test/azure/generated/encode-array/encode/array/_utils/model_base.py index b4433021b4e..7b7f8ba67b5 100644 --- a/packages/typespec-python/test/azure/generated/encode-array/encode/array/_utils/model_base.py +++ b/packages/typespec-python/test/azure/generated/encode-array/encode/array/_utils/model_base.py @@ -630,6 +630,9 @@ def __init__(self, *args: typing.Any, **kwargs: typing.Any) -> None: if len(items) > 0: existed_attr_keys.append(xml_name) dict_to_pass[rf._rest_name] = _deserialize(rf._type, items) + elif not rf._is_optional: + existed_attr_keys.append(xml_name) + dict_to_pass[rf._rest_name] = [] continue # text element is primitive type @@ -891,6 +894,8 @@ def _get_deserialize_callable_from_annotation( # pylint: disable=too-many-retur # is it optional? try: if any(a is _NONE_TYPE for a in annotation.__args__): # pyright: ignore + if rf: + rf._is_optional = True if len(annotation.__args__) <= 2: # pyright: ignore if_obj_deserializer = _get_deserialize_callable_from_annotation( next(a for a in annotation.__args__ if a is not _NONE_TYPE), module, rf # pyright: ignore @@ -1049,6 +1054,7 @@ def _failsafe_deserialize_xml( return None +# pylint: disable=too-many-instance-attributes class _RestField: def __init__( self, @@ -1068,6 +1074,7 @@ def __init__( self._is_discriminator = is_discriminator self._visibility = visibility self._is_model = False + self._is_optional = False self._default = default self._format = format self._is_multipart_file_input = is_multipart_file_input diff --git a/packages/typespec-python/test/azure/generated/encode-bytes/encode/bytes/_utils/model_base.py b/packages/typespec-python/test/azure/generated/encode-bytes/encode/bytes/_utils/model_base.py index b4433021b4e..7b7f8ba67b5 100644 --- a/packages/typespec-python/test/azure/generated/encode-bytes/encode/bytes/_utils/model_base.py +++ b/packages/typespec-python/test/azure/generated/encode-bytes/encode/bytes/_utils/model_base.py @@ -630,6 +630,9 @@ def __init__(self, *args: typing.Any, **kwargs: typing.Any) -> None: if len(items) > 0: existed_attr_keys.append(xml_name) dict_to_pass[rf._rest_name] = _deserialize(rf._type, items) + elif not rf._is_optional: + existed_attr_keys.append(xml_name) + dict_to_pass[rf._rest_name] = [] continue # text element is primitive type @@ -891,6 +894,8 @@ def _get_deserialize_callable_from_annotation( # pylint: disable=too-many-retur # is it optional? try: if any(a is _NONE_TYPE for a in annotation.__args__): # pyright: ignore + if rf: + rf._is_optional = True if len(annotation.__args__) <= 2: # pyright: ignore if_obj_deserializer = _get_deserialize_callable_from_annotation( next(a for a in annotation.__args__ if a is not _NONE_TYPE), module, rf # pyright: ignore @@ -1049,6 +1054,7 @@ def _failsafe_deserialize_xml( return None +# pylint: disable=too-many-instance-attributes class _RestField: def __init__( self, @@ -1068,6 +1074,7 @@ def __init__( self._is_discriminator = is_discriminator self._visibility = visibility self._is_model = False + self._is_optional = False self._default = default self._format = format self._is_multipart_file_input = is_multipart_file_input diff --git a/packages/typespec-python/test/azure/generated/encode-datetime/encode/datetime/_utils/model_base.py b/packages/typespec-python/test/azure/generated/encode-datetime/encode/datetime/_utils/model_base.py index b4433021b4e..7b7f8ba67b5 100644 --- a/packages/typespec-python/test/azure/generated/encode-datetime/encode/datetime/_utils/model_base.py +++ b/packages/typespec-python/test/azure/generated/encode-datetime/encode/datetime/_utils/model_base.py @@ -630,6 +630,9 @@ def __init__(self, *args: typing.Any, **kwargs: typing.Any) -> None: if len(items) > 0: existed_attr_keys.append(xml_name) dict_to_pass[rf._rest_name] = _deserialize(rf._type, items) + elif not rf._is_optional: + existed_attr_keys.append(xml_name) + dict_to_pass[rf._rest_name] = [] continue # text element is primitive type @@ -891,6 +894,8 @@ def _get_deserialize_callable_from_annotation( # pylint: disable=too-many-retur # is it optional? try: if any(a is _NONE_TYPE for a in annotation.__args__): # pyright: ignore + if rf: + rf._is_optional = True if len(annotation.__args__) <= 2: # pyright: ignore if_obj_deserializer = _get_deserialize_callable_from_annotation( next(a for a in annotation.__args__ if a is not _NONE_TYPE), module, rf # pyright: ignore @@ -1049,6 +1054,7 @@ def _failsafe_deserialize_xml( return None +# pylint: disable=too-many-instance-attributes class _RestField: def __init__( self, @@ -1068,6 +1074,7 @@ def __init__( self._is_discriminator = is_discriminator self._visibility = visibility self._is_model = False + self._is_optional = False self._default = default self._format = format self._is_multipart_file_input = is_multipart_file_input diff --git a/packages/typespec-python/test/azure/generated/encode-duration/encode/duration/_utils/model_base.py b/packages/typespec-python/test/azure/generated/encode-duration/encode/duration/_utils/model_base.py index b4433021b4e..7b7f8ba67b5 100644 --- a/packages/typespec-python/test/azure/generated/encode-duration/encode/duration/_utils/model_base.py +++ b/packages/typespec-python/test/azure/generated/encode-duration/encode/duration/_utils/model_base.py @@ -630,6 +630,9 @@ def __init__(self, *args: typing.Any, **kwargs: typing.Any) -> None: if len(items) > 0: existed_attr_keys.append(xml_name) dict_to_pass[rf._rest_name] = _deserialize(rf._type, items) + elif not rf._is_optional: + existed_attr_keys.append(xml_name) + dict_to_pass[rf._rest_name] = [] continue # text element is primitive type @@ -891,6 +894,8 @@ def _get_deserialize_callable_from_annotation( # pylint: disable=too-many-retur # is it optional? try: if any(a is _NONE_TYPE for a in annotation.__args__): # pyright: ignore + if rf: + rf._is_optional = True if len(annotation.__args__) <= 2: # pyright: ignore if_obj_deserializer = _get_deserialize_callable_from_annotation( next(a for a in annotation.__args__ if a is not _NONE_TYPE), module, rf # pyright: ignore @@ -1049,6 +1054,7 @@ def _failsafe_deserialize_xml( return None +# pylint: disable=too-many-instance-attributes class _RestField: def __init__( self, @@ -1068,6 +1074,7 @@ def __init__( self._is_discriminator = is_discriminator self._visibility = visibility self._is_model = False + self._is_optional = False self._default = default self._format = format self._is_multipart_file_input = is_multipart_file_input diff --git a/packages/typespec-python/test/azure/generated/encode-numeric/encode/numeric/_utils/model_base.py b/packages/typespec-python/test/azure/generated/encode-numeric/encode/numeric/_utils/model_base.py index b4433021b4e..7b7f8ba67b5 100644 --- a/packages/typespec-python/test/azure/generated/encode-numeric/encode/numeric/_utils/model_base.py +++ b/packages/typespec-python/test/azure/generated/encode-numeric/encode/numeric/_utils/model_base.py @@ -630,6 +630,9 @@ def __init__(self, *args: typing.Any, **kwargs: typing.Any) -> None: if len(items) > 0: existed_attr_keys.append(xml_name) dict_to_pass[rf._rest_name] = _deserialize(rf._type, items) + elif not rf._is_optional: + existed_attr_keys.append(xml_name) + dict_to_pass[rf._rest_name] = [] continue # text element is primitive type @@ -891,6 +894,8 @@ def _get_deserialize_callable_from_annotation( # pylint: disable=too-many-retur # is it optional? try: if any(a is _NONE_TYPE for a in annotation.__args__): # pyright: ignore + if rf: + rf._is_optional = True if len(annotation.__args__) <= 2: # pyright: ignore if_obj_deserializer = _get_deserialize_callable_from_annotation( next(a for a in annotation.__args__ if a is not _NONE_TYPE), module, rf # pyright: ignore @@ -1049,6 +1054,7 @@ def _failsafe_deserialize_xml( return None +# pylint: disable=too-many-instance-attributes class _RestField: def __init__( self, @@ -1068,6 +1074,7 @@ def __init__( self._is_discriminator = is_discriminator self._visibility = visibility self._is_model = False + self._is_optional = False self._default = default self._format = format self._is_multipart_file_input = is_multipart_file_input diff --git a/packages/typespec-python/test/azure/generated/generation-subdir/generation/subdir/_generated/_utils/model_base.py b/packages/typespec-python/test/azure/generated/generation-subdir/generation/subdir/_generated/_utils/model_base.py index b4433021b4e..7b7f8ba67b5 100644 --- a/packages/typespec-python/test/azure/generated/generation-subdir/generation/subdir/_generated/_utils/model_base.py +++ b/packages/typespec-python/test/azure/generated/generation-subdir/generation/subdir/_generated/_utils/model_base.py @@ -630,6 +630,9 @@ def __init__(self, *args: typing.Any, **kwargs: typing.Any) -> None: if len(items) > 0: existed_attr_keys.append(xml_name) dict_to_pass[rf._rest_name] = _deserialize(rf._type, items) + elif not rf._is_optional: + existed_attr_keys.append(xml_name) + dict_to_pass[rf._rest_name] = [] continue # text element is primitive type @@ -891,6 +894,8 @@ def _get_deserialize_callable_from_annotation( # pylint: disable=too-many-retur # is it optional? try: if any(a is _NONE_TYPE for a in annotation.__args__): # pyright: ignore + if rf: + rf._is_optional = True if len(annotation.__args__) <= 2: # pyright: ignore if_obj_deserializer = _get_deserialize_callable_from_annotation( next(a for a in annotation.__args__ if a is not _NONE_TYPE), module, rf # pyright: ignore @@ -1049,6 +1054,7 @@ def _failsafe_deserialize_xml( return None +# pylint: disable=too-many-instance-attributes class _RestField: def __init__( self, @@ -1068,6 +1074,7 @@ def __init__( self._is_discriminator = is_discriminator self._visibility = visibility self._is_model = False + self._is_optional = False self._default = default self._format = format self._is_multipart_file_input = is_multipart_file_input diff --git a/packages/typespec-python/test/azure/generated/headasbooleanfalse/headasbooleanfalse/_utils/model_base.py b/packages/typespec-python/test/azure/generated/headasbooleanfalse/headasbooleanfalse/_utils/model_base.py index b4433021b4e..7b7f8ba67b5 100644 --- a/packages/typespec-python/test/azure/generated/headasbooleanfalse/headasbooleanfalse/_utils/model_base.py +++ b/packages/typespec-python/test/azure/generated/headasbooleanfalse/headasbooleanfalse/_utils/model_base.py @@ -630,6 +630,9 @@ def __init__(self, *args: typing.Any, **kwargs: typing.Any) -> None: if len(items) > 0: existed_attr_keys.append(xml_name) dict_to_pass[rf._rest_name] = _deserialize(rf._type, items) + elif not rf._is_optional: + existed_attr_keys.append(xml_name) + dict_to_pass[rf._rest_name] = [] continue # text element is primitive type @@ -891,6 +894,8 @@ def _get_deserialize_callable_from_annotation( # pylint: disable=too-many-retur # is it optional? try: if any(a is _NONE_TYPE for a in annotation.__args__): # pyright: ignore + if rf: + rf._is_optional = True if len(annotation.__args__) <= 2: # pyright: ignore if_obj_deserializer = _get_deserialize_callable_from_annotation( next(a for a in annotation.__args__ if a is not _NONE_TYPE), module, rf # pyright: ignore @@ -1049,6 +1054,7 @@ def _failsafe_deserialize_xml( return None +# pylint: disable=too-many-instance-attributes class _RestField: def __init__( self, @@ -1068,6 +1074,7 @@ def __init__( self._is_discriminator = is_discriminator self._visibility = visibility self._is_model = False + self._is_optional = False self._default = default self._format = format self._is_multipart_file_input = is_multipart_file_input diff --git a/packages/typespec-python/test/azure/generated/headasbooleantrue/headasbooleantrue/_utils/model_base.py b/packages/typespec-python/test/azure/generated/headasbooleantrue/headasbooleantrue/_utils/model_base.py index b4433021b4e..7b7f8ba67b5 100644 --- a/packages/typespec-python/test/azure/generated/headasbooleantrue/headasbooleantrue/_utils/model_base.py +++ b/packages/typespec-python/test/azure/generated/headasbooleantrue/headasbooleantrue/_utils/model_base.py @@ -630,6 +630,9 @@ def __init__(self, *args: typing.Any, **kwargs: typing.Any) -> None: if len(items) > 0: existed_attr_keys.append(xml_name) dict_to_pass[rf._rest_name] = _deserialize(rf._type, items) + elif not rf._is_optional: + existed_attr_keys.append(xml_name) + dict_to_pass[rf._rest_name] = [] continue # text element is primitive type @@ -891,6 +894,8 @@ def _get_deserialize_callable_from_annotation( # pylint: disable=too-many-retur # is it optional? try: if any(a is _NONE_TYPE for a in annotation.__args__): # pyright: ignore + if rf: + rf._is_optional = True if len(annotation.__args__) <= 2: # pyright: ignore if_obj_deserializer = _get_deserialize_callable_from_annotation( next(a for a in annotation.__args__ if a is not _NONE_TYPE), module, rf # pyright: ignore @@ -1049,6 +1054,7 @@ def _failsafe_deserialize_xml( return None +# pylint: disable=too-many-instance-attributes class _RestField: def __init__( self, @@ -1068,6 +1074,7 @@ def __init__( self._is_discriminator = is_discriminator self._visibility = visibility self._is_model = False + self._is_optional = False self._default = default self._format = format self._is_multipart_file_input = is_multipart_file_input diff --git a/packages/typespec-python/test/azure/generated/parameters-basic/parameters/basic/_utils/model_base.py b/packages/typespec-python/test/azure/generated/parameters-basic/parameters/basic/_utils/model_base.py index b4433021b4e..7b7f8ba67b5 100644 --- a/packages/typespec-python/test/azure/generated/parameters-basic/parameters/basic/_utils/model_base.py +++ b/packages/typespec-python/test/azure/generated/parameters-basic/parameters/basic/_utils/model_base.py @@ -630,6 +630,9 @@ def __init__(self, *args: typing.Any, **kwargs: typing.Any) -> None: if len(items) > 0: existed_attr_keys.append(xml_name) dict_to_pass[rf._rest_name] = _deserialize(rf._type, items) + elif not rf._is_optional: + existed_attr_keys.append(xml_name) + dict_to_pass[rf._rest_name] = [] continue # text element is primitive type @@ -891,6 +894,8 @@ def _get_deserialize_callable_from_annotation( # pylint: disable=too-many-retur # is it optional? try: if any(a is _NONE_TYPE for a in annotation.__args__): # pyright: ignore + if rf: + rf._is_optional = True if len(annotation.__args__) <= 2: # pyright: ignore if_obj_deserializer = _get_deserialize_callable_from_annotation( next(a for a in annotation.__args__ if a is not _NONE_TYPE), module, rf # pyright: ignore @@ -1049,6 +1054,7 @@ def _failsafe_deserialize_xml( return None +# pylint: disable=too-many-instance-attributes class _RestField: def __init__( self, @@ -1068,6 +1074,7 @@ def __init__( self._is_discriminator = is_discriminator self._visibility = visibility self._is_model = False + self._is_optional = False self._default = default self._format = format self._is_multipart_file_input = is_multipart_file_input diff --git a/packages/typespec-python/test/azure/generated/parameters-body-optionality/parameters/bodyoptionality/_utils/model_base.py b/packages/typespec-python/test/azure/generated/parameters-body-optionality/parameters/bodyoptionality/_utils/model_base.py index b4433021b4e..7b7f8ba67b5 100644 --- a/packages/typespec-python/test/azure/generated/parameters-body-optionality/parameters/bodyoptionality/_utils/model_base.py +++ b/packages/typespec-python/test/azure/generated/parameters-body-optionality/parameters/bodyoptionality/_utils/model_base.py @@ -630,6 +630,9 @@ def __init__(self, *args: typing.Any, **kwargs: typing.Any) -> None: if len(items) > 0: existed_attr_keys.append(xml_name) dict_to_pass[rf._rest_name] = _deserialize(rf._type, items) + elif not rf._is_optional: + existed_attr_keys.append(xml_name) + dict_to_pass[rf._rest_name] = [] continue # text element is primitive type @@ -891,6 +894,8 @@ def _get_deserialize_callable_from_annotation( # pylint: disable=too-many-retur # is it optional? try: if any(a is _NONE_TYPE for a in annotation.__args__): # pyright: ignore + if rf: + rf._is_optional = True if len(annotation.__args__) <= 2: # pyright: ignore if_obj_deserializer = _get_deserialize_callable_from_annotation( next(a for a in annotation.__args__ if a is not _NONE_TYPE), module, rf # pyright: ignore @@ -1049,6 +1054,7 @@ def _failsafe_deserialize_xml( return None +# pylint: disable=too-many-instance-attributes class _RestField: def __init__( self, @@ -1068,6 +1074,7 @@ def __init__( self._is_discriminator = is_discriminator self._visibility = visibility self._is_model = False + self._is_optional = False self._default = default self._format = format self._is_multipart_file_input = is_multipart_file_input diff --git a/packages/typespec-python/test/azure/generated/parameters-collection-format/parameters/collectionformat/_utils/model_base.py b/packages/typespec-python/test/azure/generated/parameters-collection-format/parameters/collectionformat/_utils/model_base.py index b4433021b4e..7b7f8ba67b5 100644 --- a/packages/typespec-python/test/azure/generated/parameters-collection-format/parameters/collectionformat/_utils/model_base.py +++ b/packages/typespec-python/test/azure/generated/parameters-collection-format/parameters/collectionformat/_utils/model_base.py @@ -630,6 +630,9 @@ def __init__(self, *args: typing.Any, **kwargs: typing.Any) -> None: if len(items) > 0: existed_attr_keys.append(xml_name) dict_to_pass[rf._rest_name] = _deserialize(rf._type, items) + elif not rf._is_optional: + existed_attr_keys.append(xml_name) + dict_to_pass[rf._rest_name] = [] continue # text element is primitive type @@ -891,6 +894,8 @@ def _get_deserialize_callable_from_annotation( # pylint: disable=too-many-retur # is it optional? try: if any(a is _NONE_TYPE for a in annotation.__args__): # pyright: ignore + if rf: + rf._is_optional = True if len(annotation.__args__) <= 2: # pyright: ignore if_obj_deserializer = _get_deserialize_callable_from_annotation( next(a for a in annotation.__args__ if a is not _NONE_TYPE), module, rf # pyright: ignore @@ -1049,6 +1054,7 @@ def _failsafe_deserialize_xml( return None +# pylint: disable=too-many-instance-attributes class _RestField: def __init__( self, @@ -1068,6 +1074,7 @@ def __init__( self._is_discriminator = is_discriminator self._visibility = visibility self._is_model = False + self._is_optional = False self._default = default self._format = format self._is_multipart_file_input = is_multipart_file_input diff --git a/packages/typespec-python/test/azure/generated/parameters-path/parameters/path/_utils/model_base.py b/packages/typespec-python/test/azure/generated/parameters-path/parameters/path/_utils/model_base.py index b4433021b4e..7b7f8ba67b5 100644 --- a/packages/typespec-python/test/azure/generated/parameters-path/parameters/path/_utils/model_base.py +++ b/packages/typespec-python/test/azure/generated/parameters-path/parameters/path/_utils/model_base.py @@ -630,6 +630,9 @@ def __init__(self, *args: typing.Any, **kwargs: typing.Any) -> None: if len(items) > 0: existed_attr_keys.append(xml_name) dict_to_pass[rf._rest_name] = _deserialize(rf._type, items) + elif not rf._is_optional: + existed_attr_keys.append(xml_name) + dict_to_pass[rf._rest_name] = [] continue # text element is primitive type @@ -891,6 +894,8 @@ def _get_deserialize_callable_from_annotation( # pylint: disable=too-many-retur # is it optional? try: if any(a is _NONE_TYPE for a in annotation.__args__): # pyright: ignore + if rf: + rf._is_optional = True if len(annotation.__args__) <= 2: # pyright: ignore if_obj_deserializer = _get_deserialize_callable_from_annotation( next(a for a in annotation.__args__ if a is not _NONE_TYPE), module, rf # pyright: ignore @@ -1049,6 +1054,7 @@ def _failsafe_deserialize_xml( return None +# pylint: disable=too-many-instance-attributes class _RestField: def __init__( self, @@ -1068,6 +1074,7 @@ def __init__( self._is_discriminator = is_discriminator self._visibility = visibility self._is_model = False + self._is_optional = False self._default = default self._format = format self._is_multipart_file_input = is_multipart_file_input diff --git a/packages/typespec-python/test/azure/generated/parameters-query/parameters/query/_utils/model_base.py b/packages/typespec-python/test/azure/generated/parameters-query/parameters/query/_utils/model_base.py index b4433021b4e..7b7f8ba67b5 100644 --- a/packages/typespec-python/test/azure/generated/parameters-query/parameters/query/_utils/model_base.py +++ b/packages/typespec-python/test/azure/generated/parameters-query/parameters/query/_utils/model_base.py @@ -630,6 +630,9 @@ def __init__(self, *args: typing.Any, **kwargs: typing.Any) -> None: if len(items) > 0: existed_attr_keys.append(xml_name) dict_to_pass[rf._rest_name] = _deserialize(rf._type, items) + elif not rf._is_optional: + existed_attr_keys.append(xml_name) + dict_to_pass[rf._rest_name] = [] continue # text element is primitive type @@ -891,6 +894,8 @@ def _get_deserialize_callable_from_annotation( # pylint: disable=too-many-retur # is it optional? try: if any(a is _NONE_TYPE for a in annotation.__args__): # pyright: ignore + if rf: + rf._is_optional = True if len(annotation.__args__) <= 2: # pyright: ignore if_obj_deserializer = _get_deserialize_callable_from_annotation( next(a for a in annotation.__args__ if a is not _NONE_TYPE), module, rf # pyright: ignore @@ -1049,6 +1054,7 @@ def _failsafe_deserialize_xml( return None +# pylint: disable=too-many-instance-attributes class _RestField: def __init__( self, @@ -1068,6 +1074,7 @@ def __init__( self._is_discriminator = is_discriminator self._visibility = visibility self._is_model = False + self._is_optional = False self._default = default self._format = format self._is_multipart_file_input = is_multipart_file_input diff --git a/packages/typespec-python/test/azure/generated/parameters-spread/parameters/spread/_utils/model_base.py b/packages/typespec-python/test/azure/generated/parameters-spread/parameters/spread/_utils/model_base.py index b4433021b4e..7b7f8ba67b5 100644 --- a/packages/typespec-python/test/azure/generated/parameters-spread/parameters/spread/_utils/model_base.py +++ b/packages/typespec-python/test/azure/generated/parameters-spread/parameters/spread/_utils/model_base.py @@ -630,6 +630,9 @@ def __init__(self, *args: typing.Any, **kwargs: typing.Any) -> None: if len(items) > 0: existed_attr_keys.append(xml_name) dict_to_pass[rf._rest_name] = _deserialize(rf._type, items) + elif not rf._is_optional: + existed_attr_keys.append(xml_name) + dict_to_pass[rf._rest_name] = [] continue # text element is primitive type @@ -891,6 +894,8 @@ def _get_deserialize_callable_from_annotation( # pylint: disable=too-many-retur # is it optional? try: if any(a is _NONE_TYPE for a in annotation.__args__): # pyright: ignore + if rf: + rf._is_optional = True if len(annotation.__args__) <= 2: # pyright: ignore if_obj_deserializer = _get_deserialize_callable_from_annotation( next(a for a in annotation.__args__ if a is not _NONE_TYPE), module, rf # pyright: ignore @@ -1049,6 +1054,7 @@ def _failsafe_deserialize_xml( return None +# pylint: disable=too-many-instance-attributes class _RestField: def __init__( self, @@ -1068,6 +1074,7 @@ def __init__( self._is_discriminator = is_discriminator self._visibility = visibility self._is_model = False + self._is_optional = False self._default = default self._format = format self._is_multipart_file_input = is_multipart_file_input diff --git a/packages/typespec-python/test/azure/generated/payload-content-negotiation/payload/contentnegotiation/_utils/model_base.py b/packages/typespec-python/test/azure/generated/payload-content-negotiation/payload/contentnegotiation/_utils/model_base.py index b4433021b4e..7b7f8ba67b5 100644 --- a/packages/typespec-python/test/azure/generated/payload-content-negotiation/payload/contentnegotiation/_utils/model_base.py +++ b/packages/typespec-python/test/azure/generated/payload-content-negotiation/payload/contentnegotiation/_utils/model_base.py @@ -630,6 +630,9 @@ def __init__(self, *args: typing.Any, **kwargs: typing.Any) -> None: if len(items) > 0: existed_attr_keys.append(xml_name) dict_to_pass[rf._rest_name] = _deserialize(rf._type, items) + elif not rf._is_optional: + existed_attr_keys.append(xml_name) + dict_to_pass[rf._rest_name] = [] continue # text element is primitive type @@ -891,6 +894,8 @@ def _get_deserialize_callable_from_annotation( # pylint: disable=too-many-retur # is it optional? try: if any(a is _NONE_TYPE for a in annotation.__args__): # pyright: ignore + if rf: + rf._is_optional = True if len(annotation.__args__) <= 2: # pyright: ignore if_obj_deserializer = _get_deserialize_callable_from_annotation( next(a for a in annotation.__args__ if a is not _NONE_TYPE), module, rf # pyright: ignore @@ -1049,6 +1054,7 @@ def _failsafe_deserialize_xml( return None +# pylint: disable=too-many-instance-attributes class _RestField: def __init__( self, @@ -1068,6 +1074,7 @@ def __init__( self._is_discriminator = is_discriminator self._visibility = visibility self._is_model = False + self._is_optional = False self._default = default self._format = format self._is_multipart_file_input = is_multipart_file_input diff --git a/packages/typespec-python/test/azure/generated/payload-json-merge-patch/payload/jsonmergepatch/_utils/model_base.py b/packages/typespec-python/test/azure/generated/payload-json-merge-patch/payload/jsonmergepatch/_utils/model_base.py index b4433021b4e..7b7f8ba67b5 100644 --- a/packages/typespec-python/test/azure/generated/payload-json-merge-patch/payload/jsonmergepatch/_utils/model_base.py +++ b/packages/typespec-python/test/azure/generated/payload-json-merge-patch/payload/jsonmergepatch/_utils/model_base.py @@ -630,6 +630,9 @@ def __init__(self, *args: typing.Any, **kwargs: typing.Any) -> None: if len(items) > 0: existed_attr_keys.append(xml_name) dict_to_pass[rf._rest_name] = _deserialize(rf._type, items) + elif not rf._is_optional: + existed_attr_keys.append(xml_name) + dict_to_pass[rf._rest_name] = [] continue # text element is primitive type @@ -891,6 +894,8 @@ def _get_deserialize_callable_from_annotation( # pylint: disable=too-many-retur # is it optional? try: if any(a is _NONE_TYPE for a in annotation.__args__): # pyright: ignore + if rf: + rf._is_optional = True if len(annotation.__args__) <= 2: # pyright: ignore if_obj_deserializer = _get_deserialize_callable_from_annotation( next(a for a in annotation.__args__ if a is not _NONE_TYPE), module, rf # pyright: ignore @@ -1049,6 +1054,7 @@ def _failsafe_deserialize_xml( return None +# pylint: disable=too-many-instance-attributes class _RestField: def __init__( self, @@ -1068,6 +1074,7 @@ def __init__( self._is_discriminator = is_discriminator self._visibility = visibility self._is_model = False + self._is_optional = False self._default = default self._format = format self._is_multipart_file_input = is_multipart_file_input diff --git a/packages/typespec-python/test/azure/generated/payload-media-type/payload/mediatype/_utils/model_base.py b/packages/typespec-python/test/azure/generated/payload-media-type/payload/mediatype/_utils/model_base.py index b4433021b4e..7b7f8ba67b5 100644 --- a/packages/typespec-python/test/azure/generated/payload-media-type/payload/mediatype/_utils/model_base.py +++ b/packages/typespec-python/test/azure/generated/payload-media-type/payload/mediatype/_utils/model_base.py @@ -630,6 +630,9 @@ def __init__(self, *args: typing.Any, **kwargs: typing.Any) -> None: if len(items) > 0: existed_attr_keys.append(xml_name) dict_to_pass[rf._rest_name] = _deserialize(rf._type, items) + elif not rf._is_optional: + existed_attr_keys.append(xml_name) + dict_to_pass[rf._rest_name] = [] continue # text element is primitive type @@ -891,6 +894,8 @@ def _get_deserialize_callable_from_annotation( # pylint: disable=too-many-retur # is it optional? try: if any(a is _NONE_TYPE for a in annotation.__args__): # pyright: ignore + if rf: + rf._is_optional = True if len(annotation.__args__) <= 2: # pyright: ignore if_obj_deserializer = _get_deserialize_callable_from_annotation( next(a for a in annotation.__args__ if a is not _NONE_TYPE), module, rf # pyright: ignore @@ -1049,6 +1054,7 @@ def _failsafe_deserialize_xml( return None +# pylint: disable=too-many-instance-attributes class _RestField: def __init__( self, @@ -1068,6 +1074,7 @@ def __init__( self._is_discriminator = is_discriminator self._visibility = visibility self._is_model = False + self._is_optional = False self._default = default self._format = format self._is_multipart_file_input = is_multipart_file_input diff --git a/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/_utils/model_base.py b/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/_utils/model_base.py index b4433021b4e..7b7f8ba67b5 100644 --- a/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/_utils/model_base.py +++ b/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/_utils/model_base.py @@ -630,6 +630,9 @@ def __init__(self, *args: typing.Any, **kwargs: typing.Any) -> None: if len(items) > 0: existed_attr_keys.append(xml_name) dict_to_pass[rf._rest_name] = _deserialize(rf._type, items) + elif not rf._is_optional: + existed_attr_keys.append(xml_name) + dict_to_pass[rf._rest_name] = [] continue # text element is primitive type @@ -891,6 +894,8 @@ def _get_deserialize_callable_from_annotation( # pylint: disable=too-many-retur # is it optional? try: if any(a is _NONE_TYPE for a in annotation.__args__): # pyright: ignore + if rf: + rf._is_optional = True if len(annotation.__args__) <= 2: # pyright: ignore if_obj_deserializer = _get_deserialize_callable_from_annotation( next(a for a in annotation.__args__ if a is not _NONE_TYPE), module, rf # pyright: ignore @@ -1049,6 +1054,7 @@ def _failsafe_deserialize_xml( return None +# pylint: disable=too-many-instance-attributes class _RestField: def __init__( self, @@ -1068,6 +1074,7 @@ def __init__( self._is_discriminator = is_discriminator self._visibility = visibility self._is_model = False + self._is_optional = False self._default = default self._format = format self._is_multipart_file_input = is_multipart_file_input diff --git a/packages/typespec-python/test/azure/generated/payload-pageable/payload/pageable/_utils/model_base.py b/packages/typespec-python/test/azure/generated/payload-pageable/payload/pageable/_utils/model_base.py index b4433021b4e..7b7f8ba67b5 100644 --- a/packages/typespec-python/test/azure/generated/payload-pageable/payload/pageable/_utils/model_base.py +++ b/packages/typespec-python/test/azure/generated/payload-pageable/payload/pageable/_utils/model_base.py @@ -630,6 +630,9 @@ def __init__(self, *args: typing.Any, **kwargs: typing.Any) -> None: if len(items) > 0: existed_attr_keys.append(xml_name) dict_to_pass[rf._rest_name] = _deserialize(rf._type, items) + elif not rf._is_optional: + existed_attr_keys.append(xml_name) + dict_to_pass[rf._rest_name] = [] continue # text element is primitive type @@ -891,6 +894,8 @@ def _get_deserialize_callable_from_annotation( # pylint: disable=too-many-retur # is it optional? try: if any(a is _NONE_TYPE for a in annotation.__args__): # pyright: ignore + if rf: + rf._is_optional = True if len(annotation.__args__) <= 2: # pyright: ignore if_obj_deserializer = _get_deserialize_callable_from_annotation( next(a for a in annotation.__args__ if a is not _NONE_TYPE), module, rf # pyright: ignore @@ -1049,6 +1054,7 @@ def _failsafe_deserialize_xml( return None +# pylint: disable=too-many-instance-attributes class _RestField: def __init__( self, @@ -1068,6 +1074,7 @@ def __init__( self._is_discriminator = is_discriminator self._visibility = visibility self._is_model = False + self._is_optional = False self._default = default self._format = format self._is_multipart_file_input = is_multipart_file_input diff --git a/packages/typespec-python/test/azure/generated/payload-xml/payload/xml/_utils/model_base.py b/packages/typespec-python/test/azure/generated/payload-xml/payload/xml/_utils/model_base.py index 9616929f741..a75a22adbb9 100644 --- a/packages/typespec-python/test/azure/generated/payload-xml/payload/xml/_utils/model_base.py +++ b/packages/typespec-python/test/azure/generated/payload-xml/payload/xml/_utils/model_base.py @@ -630,6 +630,9 @@ def __init__(self, *args: typing.Any, **kwargs: typing.Any) -> None: if len(items) > 0: existed_attr_keys.append(xml_name) dict_to_pass[rf._rest_name] = _deserialize(rf._type, items) + elif not rf._is_optional: + existed_attr_keys.append(xml_name) + dict_to_pass[rf._rest_name] = [] continue # text element is primitive type @@ -905,6 +908,8 @@ def _get_deserialize_callable_from_annotation( # pylint: disable=too-many-retur # is it optional? try: if any(a is _NONE_TYPE for a in annotation.__args__): # pyright: ignore + if rf: + rf._is_optional = True if len(annotation.__args__) <= 2: # pyright: ignore if_obj_deserializer = _get_deserialize_callable_from_annotation( next(a for a in annotation.__args__ if a is not _NONE_TYPE), module, rf # pyright: ignore @@ -1084,6 +1089,7 @@ def __init__( self._is_discriminator = is_discriminator self._visibility = visibility self._is_model = False + self._is_optional = False self._default = default self._format = format self._is_multipart_file_input = is_multipart_file_input diff --git a/packages/typespec-python/test/azure/generated/resiliency-srv-driven1/resiliency/srv/driven1/_utils/model_base.py b/packages/typespec-python/test/azure/generated/resiliency-srv-driven1/resiliency/srv/driven1/_utils/model_base.py index b4433021b4e..7b7f8ba67b5 100644 --- a/packages/typespec-python/test/azure/generated/resiliency-srv-driven1/resiliency/srv/driven1/_utils/model_base.py +++ b/packages/typespec-python/test/azure/generated/resiliency-srv-driven1/resiliency/srv/driven1/_utils/model_base.py @@ -630,6 +630,9 @@ def __init__(self, *args: typing.Any, **kwargs: typing.Any) -> None: if len(items) > 0: existed_attr_keys.append(xml_name) dict_to_pass[rf._rest_name] = _deserialize(rf._type, items) + elif not rf._is_optional: + existed_attr_keys.append(xml_name) + dict_to_pass[rf._rest_name] = [] continue # text element is primitive type @@ -891,6 +894,8 @@ def _get_deserialize_callable_from_annotation( # pylint: disable=too-many-retur # is it optional? try: if any(a is _NONE_TYPE for a in annotation.__args__): # pyright: ignore + if rf: + rf._is_optional = True if len(annotation.__args__) <= 2: # pyright: ignore if_obj_deserializer = _get_deserialize_callable_from_annotation( next(a for a in annotation.__args__ if a is not _NONE_TYPE), module, rf # pyright: ignore @@ -1049,6 +1054,7 @@ def _failsafe_deserialize_xml( return None +# pylint: disable=too-many-instance-attributes class _RestField: def __init__( self, @@ -1068,6 +1074,7 @@ def __init__( self._is_discriminator = is_discriminator self._visibility = visibility self._is_model = False + self._is_optional = False self._default = default self._format = format self._is_multipart_file_input = is_multipart_file_input diff --git a/packages/typespec-python/test/azure/generated/resiliency-srv-driven2/resiliency/srv/driven2/_utils/model_base.py b/packages/typespec-python/test/azure/generated/resiliency-srv-driven2/resiliency/srv/driven2/_utils/model_base.py index b4433021b4e..7b7f8ba67b5 100644 --- a/packages/typespec-python/test/azure/generated/resiliency-srv-driven2/resiliency/srv/driven2/_utils/model_base.py +++ b/packages/typespec-python/test/azure/generated/resiliency-srv-driven2/resiliency/srv/driven2/_utils/model_base.py @@ -630,6 +630,9 @@ def __init__(self, *args: typing.Any, **kwargs: typing.Any) -> None: if len(items) > 0: existed_attr_keys.append(xml_name) dict_to_pass[rf._rest_name] = _deserialize(rf._type, items) + elif not rf._is_optional: + existed_attr_keys.append(xml_name) + dict_to_pass[rf._rest_name] = [] continue # text element is primitive type @@ -891,6 +894,8 @@ def _get_deserialize_callable_from_annotation( # pylint: disable=too-many-retur # is it optional? try: if any(a is _NONE_TYPE for a in annotation.__args__): # pyright: ignore + if rf: + rf._is_optional = True if len(annotation.__args__) <= 2: # pyright: ignore if_obj_deserializer = _get_deserialize_callable_from_annotation( next(a for a in annotation.__args__ if a is not _NONE_TYPE), module, rf # pyright: ignore @@ -1049,6 +1054,7 @@ def _failsafe_deserialize_xml( return None +# pylint: disable=too-many-instance-attributes class _RestField: def __init__( self, @@ -1068,6 +1074,7 @@ def __init__( self._is_discriminator = is_discriminator self._visibility = visibility self._is_model = False + self._is_optional = False self._default = default self._format = format self._is_multipart_file_input = is_multipart_file_input diff --git a/packages/typespec-python/test/azure/generated/response-status-code-range/response/statuscoderange/_utils/model_base.py b/packages/typespec-python/test/azure/generated/response-status-code-range/response/statuscoderange/_utils/model_base.py index b4433021b4e..7b7f8ba67b5 100644 --- a/packages/typespec-python/test/azure/generated/response-status-code-range/response/statuscoderange/_utils/model_base.py +++ b/packages/typespec-python/test/azure/generated/response-status-code-range/response/statuscoderange/_utils/model_base.py @@ -630,6 +630,9 @@ def __init__(self, *args: typing.Any, **kwargs: typing.Any) -> None: if len(items) > 0: existed_attr_keys.append(xml_name) dict_to_pass[rf._rest_name] = _deserialize(rf._type, items) + elif not rf._is_optional: + existed_attr_keys.append(xml_name) + dict_to_pass[rf._rest_name] = [] continue # text element is primitive type @@ -891,6 +894,8 @@ def _get_deserialize_callable_from_annotation( # pylint: disable=too-many-retur # is it optional? try: if any(a is _NONE_TYPE for a in annotation.__args__): # pyright: ignore + if rf: + rf._is_optional = True if len(annotation.__args__) <= 2: # pyright: ignore if_obj_deserializer = _get_deserialize_callable_from_annotation( next(a for a in annotation.__args__ if a is not _NONE_TYPE), module, rf # pyright: ignore @@ -1049,6 +1054,7 @@ def _failsafe_deserialize_xml( return None +# pylint: disable=too-many-instance-attributes class _RestField: def __init__( self, @@ -1068,6 +1074,7 @@ def __init__( self._is_discriminator = is_discriminator self._visibility = visibility self._is_model = False + self._is_optional = False self._default = default self._format = format self._is_multipart_file_input = is_multipart_file_input diff --git a/packages/typespec-python/test/azure/generated/routes/routes/_utils/model_base.py b/packages/typespec-python/test/azure/generated/routes/routes/_utils/model_base.py index b4433021b4e..7b7f8ba67b5 100644 --- a/packages/typespec-python/test/azure/generated/routes/routes/_utils/model_base.py +++ b/packages/typespec-python/test/azure/generated/routes/routes/_utils/model_base.py @@ -630,6 +630,9 @@ def __init__(self, *args: typing.Any, **kwargs: typing.Any) -> None: if len(items) > 0: existed_attr_keys.append(xml_name) dict_to_pass[rf._rest_name] = _deserialize(rf._type, items) + elif not rf._is_optional: + existed_attr_keys.append(xml_name) + dict_to_pass[rf._rest_name] = [] continue # text element is primitive type @@ -891,6 +894,8 @@ def _get_deserialize_callable_from_annotation( # pylint: disable=too-many-retur # is it optional? try: if any(a is _NONE_TYPE for a in annotation.__args__): # pyright: ignore + if rf: + rf._is_optional = True if len(annotation.__args__) <= 2: # pyright: ignore if_obj_deserializer = _get_deserialize_callable_from_annotation( next(a for a in annotation.__args__ if a is not _NONE_TYPE), module, rf # pyright: ignore @@ -1049,6 +1054,7 @@ def _failsafe_deserialize_xml( return None +# pylint: disable=too-many-instance-attributes class _RestField: def __init__( self, @@ -1068,6 +1074,7 @@ def __init__( self._is_discriminator = is_discriminator self._visibility = visibility self._is_model = False + self._is_optional = False self._default = default self._format = format self._is_multipart_file_input = is_multipart_file_input diff --git a/packages/typespec-python/test/azure/generated/serialization-encoded-name-json/serialization/encodedname/json/_utils/model_base.py b/packages/typespec-python/test/azure/generated/serialization-encoded-name-json/serialization/encodedname/json/_utils/model_base.py index b4433021b4e..7b7f8ba67b5 100644 --- a/packages/typespec-python/test/azure/generated/serialization-encoded-name-json/serialization/encodedname/json/_utils/model_base.py +++ b/packages/typespec-python/test/azure/generated/serialization-encoded-name-json/serialization/encodedname/json/_utils/model_base.py @@ -630,6 +630,9 @@ def __init__(self, *args: typing.Any, **kwargs: typing.Any) -> None: if len(items) > 0: existed_attr_keys.append(xml_name) dict_to_pass[rf._rest_name] = _deserialize(rf._type, items) + elif not rf._is_optional: + existed_attr_keys.append(xml_name) + dict_to_pass[rf._rest_name] = [] continue # text element is primitive type @@ -891,6 +894,8 @@ def _get_deserialize_callable_from_annotation( # pylint: disable=too-many-retur # is it optional? try: if any(a is _NONE_TYPE for a in annotation.__args__): # pyright: ignore + if rf: + rf._is_optional = True if len(annotation.__args__) <= 2: # pyright: ignore if_obj_deserializer = _get_deserialize_callable_from_annotation( next(a for a in annotation.__args__ if a is not _NONE_TYPE), module, rf # pyright: ignore @@ -1049,6 +1054,7 @@ def _failsafe_deserialize_xml( return None +# pylint: disable=too-many-instance-attributes class _RestField: def __init__( self, @@ -1068,6 +1074,7 @@ def __init__( self._is_discriminator = is_discriminator self._visibility = visibility self._is_model = False + self._is_optional = False self._default = default self._format = format self._is_multipart_file_input = is_multipart_file_input diff --git a/packages/typespec-python/test/azure/generated/server-endpoint-not-defined/server/endpoint/notdefined/_utils/model_base.py b/packages/typespec-python/test/azure/generated/server-endpoint-not-defined/server/endpoint/notdefined/_utils/model_base.py index b4433021b4e..7b7f8ba67b5 100644 --- a/packages/typespec-python/test/azure/generated/server-endpoint-not-defined/server/endpoint/notdefined/_utils/model_base.py +++ b/packages/typespec-python/test/azure/generated/server-endpoint-not-defined/server/endpoint/notdefined/_utils/model_base.py @@ -630,6 +630,9 @@ def __init__(self, *args: typing.Any, **kwargs: typing.Any) -> None: if len(items) > 0: existed_attr_keys.append(xml_name) dict_to_pass[rf._rest_name] = _deserialize(rf._type, items) + elif not rf._is_optional: + existed_attr_keys.append(xml_name) + dict_to_pass[rf._rest_name] = [] continue # text element is primitive type @@ -891,6 +894,8 @@ def _get_deserialize_callable_from_annotation( # pylint: disable=too-many-retur # is it optional? try: if any(a is _NONE_TYPE for a in annotation.__args__): # pyright: ignore + if rf: + rf._is_optional = True if len(annotation.__args__) <= 2: # pyright: ignore if_obj_deserializer = _get_deserialize_callable_from_annotation( next(a for a in annotation.__args__ if a is not _NONE_TYPE), module, rf # pyright: ignore @@ -1049,6 +1054,7 @@ def _failsafe_deserialize_xml( return None +# pylint: disable=too-many-instance-attributes class _RestField: def __init__( self, @@ -1068,6 +1074,7 @@ def __init__( self._is_discriminator = is_discriminator self._visibility = visibility self._is_model = False + self._is_optional = False self._default = default self._format = format self._is_multipart_file_input = is_multipart_file_input diff --git a/packages/typespec-python/test/azure/generated/server-path-multiple/server/path/multiple/_utils/model_base.py b/packages/typespec-python/test/azure/generated/server-path-multiple/server/path/multiple/_utils/model_base.py index b4433021b4e..7b7f8ba67b5 100644 --- a/packages/typespec-python/test/azure/generated/server-path-multiple/server/path/multiple/_utils/model_base.py +++ b/packages/typespec-python/test/azure/generated/server-path-multiple/server/path/multiple/_utils/model_base.py @@ -630,6 +630,9 @@ def __init__(self, *args: typing.Any, **kwargs: typing.Any) -> None: if len(items) > 0: existed_attr_keys.append(xml_name) dict_to_pass[rf._rest_name] = _deserialize(rf._type, items) + elif not rf._is_optional: + existed_attr_keys.append(xml_name) + dict_to_pass[rf._rest_name] = [] continue # text element is primitive type @@ -891,6 +894,8 @@ def _get_deserialize_callable_from_annotation( # pylint: disable=too-many-retur # is it optional? try: if any(a is _NONE_TYPE for a in annotation.__args__): # pyright: ignore + if rf: + rf._is_optional = True if len(annotation.__args__) <= 2: # pyright: ignore if_obj_deserializer = _get_deserialize_callable_from_annotation( next(a for a in annotation.__args__ if a is not _NONE_TYPE), module, rf # pyright: ignore @@ -1049,6 +1054,7 @@ def _failsafe_deserialize_xml( return None +# pylint: disable=too-many-instance-attributes class _RestField: def __init__( self, @@ -1068,6 +1074,7 @@ def __init__( self._is_discriminator = is_discriminator self._visibility = visibility self._is_model = False + self._is_optional = False self._default = default self._format = format self._is_multipart_file_input = is_multipart_file_input diff --git a/packages/typespec-python/test/azure/generated/server-path-single/server/path/single/_utils/model_base.py b/packages/typespec-python/test/azure/generated/server-path-single/server/path/single/_utils/model_base.py index b4433021b4e..7b7f8ba67b5 100644 --- a/packages/typespec-python/test/azure/generated/server-path-single/server/path/single/_utils/model_base.py +++ b/packages/typespec-python/test/azure/generated/server-path-single/server/path/single/_utils/model_base.py @@ -630,6 +630,9 @@ def __init__(self, *args: typing.Any, **kwargs: typing.Any) -> None: if len(items) > 0: existed_attr_keys.append(xml_name) dict_to_pass[rf._rest_name] = _deserialize(rf._type, items) + elif not rf._is_optional: + existed_attr_keys.append(xml_name) + dict_to_pass[rf._rest_name] = [] continue # text element is primitive type @@ -891,6 +894,8 @@ def _get_deserialize_callable_from_annotation( # pylint: disable=too-many-retur # is it optional? try: if any(a is _NONE_TYPE for a in annotation.__args__): # pyright: ignore + if rf: + rf._is_optional = True if len(annotation.__args__) <= 2: # pyright: ignore if_obj_deserializer = _get_deserialize_callable_from_annotation( next(a for a in annotation.__args__ if a is not _NONE_TYPE), module, rf # pyright: ignore @@ -1049,6 +1054,7 @@ def _failsafe_deserialize_xml( return None +# pylint: disable=too-many-instance-attributes class _RestField: def __init__( self, @@ -1068,6 +1074,7 @@ def __init__( self._is_discriminator = is_discriminator self._visibility = visibility self._is_model = False + self._is_optional = False self._default = default self._format = format self._is_multipart_file_input = is_multipart_file_input diff --git a/packages/typespec-python/test/azure/generated/server-versions-not-versioned/server/versions/notversioned/_utils/model_base.py b/packages/typespec-python/test/azure/generated/server-versions-not-versioned/server/versions/notversioned/_utils/model_base.py index b4433021b4e..7b7f8ba67b5 100644 --- a/packages/typespec-python/test/azure/generated/server-versions-not-versioned/server/versions/notversioned/_utils/model_base.py +++ b/packages/typespec-python/test/azure/generated/server-versions-not-versioned/server/versions/notversioned/_utils/model_base.py @@ -630,6 +630,9 @@ def __init__(self, *args: typing.Any, **kwargs: typing.Any) -> None: if len(items) > 0: existed_attr_keys.append(xml_name) dict_to_pass[rf._rest_name] = _deserialize(rf._type, items) + elif not rf._is_optional: + existed_attr_keys.append(xml_name) + dict_to_pass[rf._rest_name] = [] continue # text element is primitive type @@ -891,6 +894,8 @@ def _get_deserialize_callable_from_annotation( # pylint: disable=too-many-retur # is it optional? try: if any(a is _NONE_TYPE for a in annotation.__args__): # pyright: ignore + if rf: + rf._is_optional = True if len(annotation.__args__) <= 2: # pyright: ignore if_obj_deserializer = _get_deserialize_callable_from_annotation( next(a for a in annotation.__args__ if a is not _NONE_TYPE), module, rf # pyright: ignore @@ -1049,6 +1054,7 @@ def _failsafe_deserialize_xml( return None +# pylint: disable=too-many-instance-attributes class _RestField: def __init__( self, @@ -1068,6 +1074,7 @@ def __init__( self._is_discriminator = is_discriminator self._visibility = visibility self._is_model = False + self._is_optional = False self._default = default self._format = format self._is_multipart_file_input = is_multipart_file_input diff --git a/packages/typespec-python/test/azure/generated/server-versions-versioned/server/versions/versioned/_utils/model_base.py b/packages/typespec-python/test/azure/generated/server-versions-versioned/server/versions/versioned/_utils/model_base.py index b4433021b4e..7b7f8ba67b5 100644 --- a/packages/typespec-python/test/azure/generated/server-versions-versioned/server/versions/versioned/_utils/model_base.py +++ b/packages/typespec-python/test/azure/generated/server-versions-versioned/server/versions/versioned/_utils/model_base.py @@ -630,6 +630,9 @@ def __init__(self, *args: typing.Any, **kwargs: typing.Any) -> None: if len(items) > 0: existed_attr_keys.append(xml_name) dict_to_pass[rf._rest_name] = _deserialize(rf._type, items) + elif not rf._is_optional: + existed_attr_keys.append(xml_name) + dict_to_pass[rf._rest_name] = [] continue # text element is primitive type @@ -891,6 +894,8 @@ def _get_deserialize_callable_from_annotation( # pylint: disable=too-many-retur # is it optional? try: if any(a is _NONE_TYPE for a in annotation.__args__): # pyright: ignore + if rf: + rf._is_optional = True if len(annotation.__args__) <= 2: # pyright: ignore if_obj_deserializer = _get_deserialize_callable_from_annotation( next(a for a in annotation.__args__ if a is not _NONE_TYPE), module, rf # pyright: ignore @@ -1049,6 +1054,7 @@ def _failsafe_deserialize_xml( return None +# pylint: disable=too-many-instance-attributes class _RestField: def __init__( self, @@ -1068,6 +1074,7 @@ def __init__( self._is_discriminator = is_discriminator self._visibility = visibility self._is_model = False + self._is_optional = False self._default = default self._format = format self._is_multipart_file_input = is_multipart_file_input diff --git a/packages/typespec-python/test/azure/generated/service-multi-service/service/multiservice/_utils/model_base.py b/packages/typespec-python/test/azure/generated/service-multi-service/service/multiservice/_utils/model_base.py index b4433021b4e..7b7f8ba67b5 100644 --- a/packages/typespec-python/test/azure/generated/service-multi-service/service/multiservice/_utils/model_base.py +++ b/packages/typespec-python/test/azure/generated/service-multi-service/service/multiservice/_utils/model_base.py @@ -630,6 +630,9 @@ def __init__(self, *args: typing.Any, **kwargs: typing.Any) -> None: if len(items) > 0: existed_attr_keys.append(xml_name) dict_to_pass[rf._rest_name] = _deserialize(rf._type, items) + elif not rf._is_optional: + existed_attr_keys.append(xml_name) + dict_to_pass[rf._rest_name] = [] continue # text element is primitive type @@ -891,6 +894,8 @@ def _get_deserialize_callable_from_annotation( # pylint: disable=too-many-retur # is it optional? try: if any(a is _NONE_TYPE for a in annotation.__args__): # pyright: ignore + if rf: + rf._is_optional = True if len(annotation.__args__) <= 2: # pyright: ignore if_obj_deserializer = _get_deserialize_callable_from_annotation( next(a for a in annotation.__args__ if a is not _NONE_TYPE), module, rf # pyright: ignore @@ -1049,6 +1054,7 @@ def _failsafe_deserialize_xml( return None +# pylint: disable=too-many-instance-attributes class _RestField: def __init__( self, @@ -1068,6 +1074,7 @@ def __init__( self._is_discriminator = is_discriminator self._visibility = visibility self._is_model = False + self._is_optional = False self._default = default self._format = format self._is_multipart_file_input = is_multipart_file_input diff --git a/packages/typespec-python/test/azure/generated/setuppy-authentication-union/setuppy/authentication/union/_utils/model_base.py b/packages/typespec-python/test/azure/generated/setuppy-authentication-union/setuppy/authentication/union/_utils/model_base.py index b4433021b4e..7b7f8ba67b5 100644 --- a/packages/typespec-python/test/azure/generated/setuppy-authentication-union/setuppy/authentication/union/_utils/model_base.py +++ b/packages/typespec-python/test/azure/generated/setuppy-authentication-union/setuppy/authentication/union/_utils/model_base.py @@ -630,6 +630,9 @@ def __init__(self, *args: typing.Any, **kwargs: typing.Any) -> None: if len(items) > 0: existed_attr_keys.append(xml_name) dict_to_pass[rf._rest_name] = _deserialize(rf._type, items) + elif not rf._is_optional: + existed_attr_keys.append(xml_name) + dict_to_pass[rf._rest_name] = [] continue # text element is primitive type @@ -891,6 +894,8 @@ def _get_deserialize_callable_from_annotation( # pylint: disable=too-many-retur # is it optional? try: if any(a is _NONE_TYPE for a in annotation.__args__): # pyright: ignore + if rf: + rf._is_optional = True if len(annotation.__args__) <= 2: # pyright: ignore if_obj_deserializer = _get_deserialize_callable_from_annotation( next(a for a in annotation.__args__ if a is not _NONE_TYPE), module, rf # pyright: ignore @@ -1049,6 +1054,7 @@ def _failsafe_deserialize_xml( return None +# pylint: disable=too-many-instance-attributes class _RestField: def __init__( self, @@ -1068,6 +1074,7 @@ def __init__( self._is_discriminator = is_discriminator self._visibility = visibility self._is_model = False + self._is_optional = False self._default = default self._format = format self._is_multipart_file_input = is_multipart_file_input diff --git a/packages/typespec-python/test/azure/generated/special-headers-conditional-request/specialheaders/conditionalrequest/_utils/model_base.py b/packages/typespec-python/test/azure/generated/special-headers-conditional-request/specialheaders/conditionalrequest/_utils/model_base.py index b4433021b4e..7b7f8ba67b5 100644 --- a/packages/typespec-python/test/azure/generated/special-headers-conditional-request/specialheaders/conditionalrequest/_utils/model_base.py +++ b/packages/typespec-python/test/azure/generated/special-headers-conditional-request/specialheaders/conditionalrequest/_utils/model_base.py @@ -630,6 +630,9 @@ def __init__(self, *args: typing.Any, **kwargs: typing.Any) -> None: if len(items) > 0: existed_attr_keys.append(xml_name) dict_to_pass[rf._rest_name] = _deserialize(rf._type, items) + elif not rf._is_optional: + existed_attr_keys.append(xml_name) + dict_to_pass[rf._rest_name] = [] continue # text element is primitive type @@ -891,6 +894,8 @@ def _get_deserialize_callable_from_annotation( # pylint: disable=too-many-retur # is it optional? try: if any(a is _NONE_TYPE for a in annotation.__args__): # pyright: ignore + if rf: + rf._is_optional = True if len(annotation.__args__) <= 2: # pyright: ignore if_obj_deserializer = _get_deserialize_callable_from_annotation( next(a for a in annotation.__args__ if a is not _NONE_TYPE), module, rf # pyright: ignore @@ -1049,6 +1054,7 @@ def _failsafe_deserialize_xml( return None +# pylint: disable=too-many-instance-attributes class _RestField: def __init__( self, @@ -1068,6 +1074,7 @@ def __init__( self._is_discriminator = is_discriminator self._visibility = visibility self._is_model = False + self._is_optional = False self._default = default self._format = format self._is_multipart_file_input = is_multipart_file_input diff --git a/packages/typespec-python/test/azure/generated/special-headers-repeatability/specialheaders/repeatability/_utils/model_base.py b/packages/typespec-python/test/azure/generated/special-headers-repeatability/specialheaders/repeatability/_utils/model_base.py index b4433021b4e..7b7f8ba67b5 100644 --- a/packages/typespec-python/test/azure/generated/special-headers-repeatability/specialheaders/repeatability/_utils/model_base.py +++ b/packages/typespec-python/test/azure/generated/special-headers-repeatability/specialheaders/repeatability/_utils/model_base.py @@ -630,6 +630,9 @@ def __init__(self, *args: typing.Any, **kwargs: typing.Any) -> None: if len(items) > 0: existed_attr_keys.append(xml_name) dict_to_pass[rf._rest_name] = _deserialize(rf._type, items) + elif not rf._is_optional: + existed_attr_keys.append(xml_name) + dict_to_pass[rf._rest_name] = [] continue # text element is primitive type @@ -891,6 +894,8 @@ def _get_deserialize_callable_from_annotation( # pylint: disable=too-many-retur # is it optional? try: if any(a is _NONE_TYPE for a in annotation.__args__): # pyright: ignore + if rf: + rf._is_optional = True if len(annotation.__args__) <= 2: # pyright: ignore if_obj_deserializer = _get_deserialize_callable_from_annotation( next(a for a in annotation.__args__ if a is not _NONE_TYPE), module, rf # pyright: ignore @@ -1049,6 +1054,7 @@ def _failsafe_deserialize_xml( return None +# pylint: disable=too-many-instance-attributes class _RestField: def __init__( self, @@ -1068,6 +1074,7 @@ def __init__( self._is_discriminator = is_discriminator self._visibility = visibility self._is_model = False + self._is_optional = False self._default = default self._format = format self._is_multipart_file_input = is_multipart_file_input diff --git a/packages/typespec-python/test/azure/generated/special-words/specialwords/_utils/model_base.py b/packages/typespec-python/test/azure/generated/special-words/specialwords/_utils/model_base.py index 9616929f741..a75a22adbb9 100644 --- a/packages/typespec-python/test/azure/generated/special-words/specialwords/_utils/model_base.py +++ b/packages/typespec-python/test/azure/generated/special-words/specialwords/_utils/model_base.py @@ -630,6 +630,9 @@ def __init__(self, *args: typing.Any, **kwargs: typing.Any) -> None: if len(items) > 0: existed_attr_keys.append(xml_name) dict_to_pass[rf._rest_name] = _deserialize(rf._type, items) + elif not rf._is_optional: + existed_attr_keys.append(xml_name) + dict_to_pass[rf._rest_name] = [] continue # text element is primitive type @@ -905,6 +908,8 @@ def _get_deserialize_callable_from_annotation( # pylint: disable=too-many-retur # is it optional? try: if any(a is _NONE_TYPE for a in annotation.__args__): # pyright: ignore + if rf: + rf._is_optional = True if len(annotation.__args__) <= 2: # pyright: ignore if_obj_deserializer = _get_deserialize_callable_from_annotation( next(a for a in annotation.__args__ if a is not _NONE_TYPE), module, rf # pyright: ignore @@ -1084,6 +1089,7 @@ def __init__( self._is_discriminator = is_discriminator self._visibility = visibility self._is_model = False + self._is_optional = False self._default = default self._format = format self._is_multipart_file_input = is_multipart_file_input diff --git a/packages/typespec-python/test/azure/generated/specs-documentation/specs/documentation/_utils/model_base.py b/packages/typespec-python/test/azure/generated/specs-documentation/specs/documentation/_utils/model_base.py index b4433021b4e..7b7f8ba67b5 100644 --- a/packages/typespec-python/test/azure/generated/specs-documentation/specs/documentation/_utils/model_base.py +++ b/packages/typespec-python/test/azure/generated/specs-documentation/specs/documentation/_utils/model_base.py @@ -630,6 +630,9 @@ def __init__(self, *args: typing.Any, **kwargs: typing.Any) -> None: if len(items) > 0: existed_attr_keys.append(xml_name) dict_to_pass[rf._rest_name] = _deserialize(rf._type, items) + elif not rf._is_optional: + existed_attr_keys.append(xml_name) + dict_to_pass[rf._rest_name] = [] continue # text element is primitive type @@ -891,6 +894,8 @@ def _get_deserialize_callable_from_annotation( # pylint: disable=too-many-retur # is it optional? try: if any(a is _NONE_TYPE for a in annotation.__args__): # pyright: ignore + if rf: + rf._is_optional = True if len(annotation.__args__) <= 2: # pyright: ignore if_obj_deserializer = _get_deserialize_callable_from_annotation( next(a for a in annotation.__args__ if a is not _NONE_TYPE), module, rf # pyright: ignore @@ -1049,6 +1054,7 @@ def _failsafe_deserialize_xml( return None +# pylint: disable=too-many-instance-attributes class _RestField: def __init__( self, @@ -1068,6 +1074,7 @@ def __init__( self._is_discriminator = is_discriminator self._visibility = visibility self._is_model = False + self._is_optional = False self._default = default self._format = format self._is_multipart_file_input = is_multipart_file_input diff --git a/packages/typespec-python/test/azure/generated/streaming-jsonl/streaming/jsonl/_utils/model_base.py b/packages/typespec-python/test/azure/generated/streaming-jsonl/streaming/jsonl/_utils/model_base.py index b4433021b4e..7b7f8ba67b5 100644 --- a/packages/typespec-python/test/azure/generated/streaming-jsonl/streaming/jsonl/_utils/model_base.py +++ b/packages/typespec-python/test/azure/generated/streaming-jsonl/streaming/jsonl/_utils/model_base.py @@ -630,6 +630,9 @@ def __init__(self, *args: typing.Any, **kwargs: typing.Any) -> None: if len(items) > 0: existed_attr_keys.append(xml_name) dict_to_pass[rf._rest_name] = _deserialize(rf._type, items) + elif not rf._is_optional: + existed_attr_keys.append(xml_name) + dict_to_pass[rf._rest_name] = [] continue # text element is primitive type @@ -891,6 +894,8 @@ def _get_deserialize_callable_from_annotation( # pylint: disable=too-many-retur # is it optional? try: if any(a is _NONE_TYPE for a in annotation.__args__): # pyright: ignore + if rf: + rf._is_optional = True if len(annotation.__args__) <= 2: # pyright: ignore if_obj_deserializer = _get_deserialize_callable_from_annotation( next(a for a in annotation.__args__ if a is not _NONE_TYPE), module, rf # pyright: ignore @@ -1049,6 +1054,7 @@ def _failsafe_deserialize_xml( return None +# pylint: disable=too-many-instance-attributes class _RestField: def __init__( self, @@ -1068,6 +1074,7 @@ def __init__( self._is_discriminator = is_discriminator self._visibility = visibility self._is_model = False + self._is_optional = False self._default = default self._format = format self._is_multipart_file_input = is_multipart_file_input diff --git a/packages/typespec-python/test/azure/generated/typetest-array/typetest/array/_utils/model_base.py b/packages/typespec-python/test/azure/generated/typetest-array/typetest/array/_utils/model_base.py index b4433021b4e..7b7f8ba67b5 100644 --- a/packages/typespec-python/test/azure/generated/typetest-array/typetest/array/_utils/model_base.py +++ b/packages/typespec-python/test/azure/generated/typetest-array/typetest/array/_utils/model_base.py @@ -630,6 +630,9 @@ def __init__(self, *args: typing.Any, **kwargs: typing.Any) -> None: if len(items) > 0: existed_attr_keys.append(xml_name) dict_to_pass[rf._rest_name] = _deserialize(rf._type, items) + elif not rf._is_optional: + existed_attr_keys.append(xml_name) + dict_to_pass[rf._rest_name] = [] continue # text element is primitive type @@ -891,6 +894,8 @@ def _get_deserialize_callable_from_annotation( # pylint: disable=too-many-retur # is it optional? try: if any(a is _NONE_TYPE for a in annotation.__args__): # pyright: ignore + if rf: + rf._is_optional = True if len(annotation.__args__) <= 2: # pyright: ignore if_obj_deserializer = _get_deserialize_callable_from_annotation( next(a for a in annotation.__args__ if a is not _NONE_TYPE), module, rf # pyright: ignore @@ -1049,6 +1054,7 @@ def _failsafe_deserialize_xml( return None +# pylint: disable=too-many-instance-attributes class _RestField: def __init__( self, @@ -1068,6 +1074,7 @@ def __init__( self._is_discriminator = is_discriminator self._visibility = visibility self._is_model = False + self._is_optional = False self._default = default self._format = format self._is_multipart_file_input = is_multipart_file_input diff --git a/packages/typespec-python/test/azure/generated/typetest-dictionary/typetest/dictionary/_utils/model_base.py b/packages/typespec-python/test/azure/generated/typetest-dictionary/typetest/dictionary/_utils/model_base.py index b4433021b4e..7b7f8ba67b5 100644 --- a/packages/typespec-python/test/azure/generated/typetest-dictionary/typetest/dictionary/_utils/model_base.py +++ b/packages/typespec-python/test/azure/generated/typetest-dictionary/typetest/dictionary/_utils/model_base.py @@ -630,6 +630,9 @@ def __init__(self, *args: typing.Any, **kwargs: typing.Any) -> None: if len(items) > 0: existed_attr_keys.append(xml_name) dict_to_pass[rf._rest_name] = _deserialize(rf._type, items) + elif not rf._is_optional: + existed_attr_keys.append(xml_name) + dict_to_pass[rf._rest_name] = [] continue # text element is primitive type @@ -891,6 +894,8 @@ def _get_deserialize_callable_from_annotation( # pylint: disable=too-many-retur # is it optional? try: if any(a is _NONE_TYPE for a in annotation.__args__): # pyright: ignore + if rf: + rf._is_optional = True if len(annotation.__args__) <= 2: # pyright: ignore if_obj_deserializer = _get_deserialize_callable_from_annotation( next(a for a in annotation.__args__ if a is not _NONE_TYPE), module, rf # pyright: ignore @@ -1049,6 +1054,7 @@ def _failsafe_deserialize_xml( return None +# pylint: disable=too-many-instance-attributes class _RestField: def __init__( self, @@ -1068,6 +1074,7 @@ def __init__( self._is_discriminator = is_discriminator self._visibility = visibility self._is_model = False + self._is_optional = False self._default = default self._format = format self._is_multipart_file_input = is_multipart_file_input diff --git a/packages/typespec-python/test/azure/generated/typetest-discriminatedunion/typetest/discriminatedunion/_utils/model_base.py b/packages/typespec-python/test/azure/generated/typetest-discriminatedunion/typetest/discriminatedunion/_utils/model_base.py index b4433021b4e..7b7f8ba67b5 100644 --- a/packages/typespec-python/test/azure/generated/typetest-discriminatedunion/typetest/discriminatedunion/_utils/model_base.py +++ b/packages/typespec-python/test/azure/generated/typetest-discriminatedunion/typetest/discriminatedunion/_utils/model_base.py @@ -630,6 +630,9 @@ def __init__(self, *args: typing.Any, **kwargs: typing.Any) -> None: if len(items) > 0: existed_attr_keys.append(xml_name) dict_to_pass[rf._rest_name] = _deserialize(rf._type, items) + elif not rf._is_optional: + existed_attr_keys.append(xml_name) + dict_to_pass[rf._rest_name] = [] continue # text element is primitive type @@ -891,6 +894,8 @@ def _get_deserialize_callable_from_annotation( # pylint: disable=too-many-retur # is it optional? try: if any(a is _NONE_TYPE for a in annotation.__args__): # pyright: ignore + if rf: + rf._is_optional = True if len(annotation.__args__) <= 2: # pyright: ignore if_obj_deserializer = _get_deserialize_callable_from_annotation( next(a for a in annotation.__args__ if a is not _NONE_TYPE), module, rf # pyright: ignore @@ -1049,6 +1054,7 @@ def _failsafe_deserialize_xml( return None +# pylint: disable=too-many-instance-attributes class _RestField: def __init__( self, @@ -1068,6 +1074,7 @@ def __init__( self._is_discriminator = is_discriminator self._visibility = visibility self._is_model = False + self._is_optional = False self._default = default self._format = format self._is_multipart_file_input = is_multipart_file_input diff --git a/packages/typespec-python/test/azure/generated/typetest-enum-extensible/typetest/enum/extensible/_utils/model_base.py b/packages/typespec-python/test/azure/generated/typetest-enum-extensible/typetest/enum/extensible/_utils/model_base.py index b4433021b4e..7b7f8ba67b5 100644 --- a/packages/typespec-python/test/azure/generated/typetest-enum-extensible/typetest/enum/extensible/_utils/model_base.py +++ b/packages/typespec-python/test/azure/generated/typetest-enum-extensible/typetest/enum/extensible/_utils/model_base.py @@ -630,6 +630,9 @@ def __init__(self, *args: typing.Any, **kwargs: typing.Any) -> None: if len(items) > 0: existed_attr_keys.append(xml_name) dict_to_pass[rf._rest_name] = _deserialize(rf._type, items) + elif not rf._is_optional: + existed_attr_keys.append(xml_name) + dict_to_pass[rf._rest_name] = [] continue # text element is primitive type @@ -891,6 +894,8 @@ def _get_deserialize_callable_from_annotation( # pylint: disable=too-many-retur # is it optional? try: if any(a is _NONE_TYPE for a in annotation.__args__): # pyright: ignore + if rf: + rf._is_optional = True if len(annotation.__args__) <= 2: # pyright: ignore if_obj_deserializer = _get_deserialize_callable_from_annotation( next(a for a in annotation.__args__ if a is not _NONE_TYPE), module, rf # pyright: ignore @@ -1049,6 +1054,7 @@ def _failsafe_deserialize_xml( return None +# pylint: disable=too-many-instance-attributes class _RestField: def __init__( self, @@ -1068,6 +1074,7 @@ def __init__( self._is_discriminator = is_discriminator self._visibility = visibility self._is_model = False + self._is_optional = False self._default = default self._format = format self._is_multipart_file_input = is_multipart_file_input diff --git a/packages/typespec-python/test/azure/generated/typetest-enum-fixed/typetest/enum/fixed/_utils/model_base.py b/packages/typespec-python/test/azure/generated/typetest-enum-fixed/typetest/enum/fixed/_utils/model_base.py index b4433021b4e..7b7f8ba67b5 100644 --- a/packages/typespec-python/test/azure/generated/typetest-enum-fixed/typetest/enum/fixed/_utils/model_base.py +++ b/packages/typespec-python/test/azure/generated/typetest-enum-fixed/typetest/enum/fixed/_utils/model_base.py @@ -630,6 +630,9 @@ def __init__(self, *args: typing.Any, **kwargs: typing.Any) -> None: if len(items) > 0: existed_attr_keys.append(xml_name) dict_to_pass[rf._rest_name] = _deserialize(rf._type, items) + elif not rf._is_optional: + existed_attr_keys.append(xml_name) + dict_to_pass[rf._rest_name] = [] continue # text element is primitive type @@ -891,6 +894,8 @@ def _get_deserialize_callable_from_annotation( # pylint: disable=too-many-retur # is it optional? try: if any(a is _NONE_TYPE for a in annotation.__args__): # pyright: ignore + if rf: + rf._is_optional = True if len(annotation.__args__) <= 2: # pyright: ignore if_obj_deserializer = _get_deserialize_callable_from_annotation( next(a for a in annotation.__args__ if a is not _NONE_TYPE), module, rf # pyright: ignore @@ -1049,6 +1054,7 @@ def _failsafe_deserialize_xml( return None +# pylint: disable=too-many-instance-attributes class _RestField: def __init__( self, @@ -1068,6 +1074,7 @@ def __init__( self._is_discriminator = is_discriminator self._visibility = visibility self._is_model = False + self._is_optional = False self._default = default self._format = format self._is_multipart_file_input = is_multipart_file_input diff --git a/packages/typespec-python/test/azure/generated/typetest-model-empty/typetest/model/empty/_utils/model_base.py b/packages/typespec-python/test/azure/generated/typetest-model-empty/typetest/model/empty/_utils/model_base.py index b4433021b4e..7b7f8ba67b5 100644 --- a/packages/typespec-python/test/azure/generated/typetest-model-empty/typetest/model/empty/_utils/model_base.py +++ b/packages/typespec-python/test/azure/generated/typetest-model-empty/typetest/model/empty/_utils/model_base.py @@ -630,6 +630,9 @@ def __init__(self, *args: typing.Any, **kwargs: typing.Any) -> None: if len(items) > 0: existed_attr_keys.append(xml_name) dict_to_pass[rf._rest_name] = _deserialize(rf._type, items) + elif not rf._is_optional: + existed_attr_keys.append(xml_name) + dict_to_pass[rf._rest_name] = [] continue # text element is primitive type @@ -891,6 +894,8 @@ def _get_deserialize_callable_from_annotation( # pylint: disable=too-many-retur # is it optional? try: if any(a is _NONE_TYPE for a in annotation.__args__): # pyright: ignore + if rf: + rf._is_optional = True if len(annotation.__args__) <= 2: # pyright: ignore if_obj_deserializer = _get_deserialize_callable_from_annotation( next(a for a in annotation.__args__ if a is not _NONE_TYPE), module, rf # pyright: ignore @@ -1049,6 +1054,7 @@ def _failsafe_deserialize_xml( return None +# pylint: disable=too-many-instance-attributes class _RestField: def __init__( self, @@ -1068,6 +1074,7 @@ def __init__( self._is_discriminator = is_discriminator self._visibility = visibility self._is_model = False + self._is_optional = False self._default = default self._format = format self._is_multipart_file_input = is_multipart_file_input diff --git a/packages/typespec-python/test/azure/generated/typetest-model-enumdiscriminator/typetest/model/enumdiscriminator/_utils/model_base.py b/packages/typespec-python/test/azure/generated/typetest-model-enumdiscriminator/typetest/model/enumdiscriminator/_utils/model_base.py index b4433021b4e..7b7f8ba67b5 100644 --- a/packages/typespec-python/test/azure/generated/typetest-model-enumdiscriminator/typetest/model/enumdiscriminator/_utils/model_base.py +++ b/packages/typespec-python/test/azure/generated/typetest-model-enumdiscriminator/typetest/model/enumdiscriminator/_utils/model_base.py @@ -630,6 +630,9 @@ def __init__(self, *args: typing.Any, **kwargs: typing.Any) -> None: if len(items) > 0: existed_attr_keys.append(xml_name) dict_to_pass[rf._rest_name] = _deserialize(rf._type, items) + elif not rf._is_optional: + existed_attr_keys.append(xml_name) + dict_to_pass[rf._rest_name] = [] continue # text element is primitive type @@ -891,6 +894,8 @@ def _get_deserialize_callable_from_annotation( # pylint: disable=too-many-retur # is it optional? try: if any(a is _NONE_TYPE for a in annotation.__args__): # pyright: ignore + if rf: + rf._is_optional = True if len(annotation.__args__) <= 2: # pyright: ignore if_obj_deserializer = _get_deserialize_callable_from_annotation( next(a for a in annotation.__args__ if a is not _NONE_TYPE), module, rf # pyright: ignore @@ -1049,6 +1054,7 @@ def _failsafe_deserialize_xml( return None +# pylint: disable=too-many-instance-attributes class _RestField: def __init__( self, @@ -1068,6 +1074,7 @@ def __init__( self._is_discriminator = is_discriminator self._visibility = visibility self._is_model = False + self._is_optional = False self._default = default self._format = format self._is_multipart_file_input = is_multipart_file_input diff --git a/packages/typespec-python/test/azure/generated/typetest-model-nesteddiscriminator/typetest/model/nesteddiscriminator/_utils/model_base.py b/packages/typespec-python/test/azure/generated/typetest-model-nesteddiscriminator/typetest/model/nesteddiscriminator/_utils/model_base.py index b4433021b4e..7b7f8ba67b5 100644 --- a/packages/typespec-python/test/azure/generated/typetest-model-nesteddiscriminator/typetest/model/nesteddiscriminator/_utils/model_base.py +++ b/packages/typespec-python/test/azure/generated/typetest-model-nesteddiscriminator/typetest/model/nesteddiscriminator/_utils/model_base.py @@ -630,6 +630,9 @@ def __init__(self, *args: typing.Any, **kwargs: typing.Any) -> None: if len(items) > 0: existed_attr_keys.append(xml_name) dict_to_pass[rf._rest_name] = _deserialize(rf._type, items) + elif not rf._is_optional: + existed_attr_keys.append(xml_name) + dict_to_pass[rf._rest_name] = [] continue # text element is primitive type @@ -891,6 +894,8 @@ def _get_deserialize_callable_from_annotation( # pylint: disable=too-many-retur # is it optional? try: if any(a is _NONE_TYPE for a in annotation.__args__): # pyright: ignore + if rf: + rf._is_optional = True if len(annotation.__args__) <= 2: # pyright: ignore if_obj_deserializer = _get_deserialize_callable_from_annotation( next(a for a in annotation.__args__ if a is not _NONE_TYPE), module, rf # pyright: ignore @@ -1049,6 +1054,7 @@ def _failsafe_deserialize_xml( return None +# pylint: disable=too-many-instance-attributes class _RestField: def __init__( self, @@ -1068,6 +1074,7 @@ def __init__( self._is_discriminator = is_discriminator self._visibility = visibility self._is_model = False + self._is_optional = False self._default = default self._format = format self._is_multipart_file_input = is_multipart_file_input diff --git a/packages/typespec-python/test/azure/generated/typetest-model-notdiscriminated/typetest/model/notdiscriminated/_utils/model_base.py b/packages/typespec-python/test/azure/generated/typetest-model-notdiscriminated/typetest/model/notdiscriminated/_utils/model_base.py index b4433021b4e..7b7f8ba67b5 100644 --- a/packages/typespec-python/test/azure/generated/typetest-model-notdiscriminated/typetest/model/notdiscriminated/_utils/model_base.py +++ b/packages/typespec-python/test/azure/generated/typetest-model-notdiscriminated/typetest/model/notdiscriminated/_utils/model_base.py @@ -630,6 +630,9 @@ def __init__(self, *args: typing.Any, **kwargs: typing.Any) -> None: if len(items) > 0: existed_attr_keys.append(xml_name) dict_to_pass[rf._rest_name] = _deserialize(rf._type, items) + elif not rf._is_optional: + existed_attr_keys.append(xml_name) + dict_to_pass[rf._rest_name] = [] continue # text element is primitive type @@ -891,6 +894,8 @@ def _get_deserialize_callable_from_annotation( # pylint: disable=too-many-retur # is it optional? try: if any(a is _NONE_TYPE for a in annotation.__args__): # pyright: ignore + if rf: + rf._is_optional = True if len(annotation.__args__) <= 2: # pyright: ignore if_obj_deserializer = _get_deserialize_callable_from_annotation( next(a for a in annotation.__args__ if a is not _NONE_TYPE), module, rf # pyright: ignore @@ -1049,6 +1054,7 @@ def _failsafe_deserialize_xml( return None +# pylint: disable=too-many-instance-attributes class _RestField: def __init__( self, @@ -1068,6 +1074,7 @@ def __init__( self._is_discriminator = is_discriminator self._visibility = visibility self._is_model = False + self._is_optional = False self._default = default self._format = format self._is_multipart_file_input = is_multipart_file_input diff --git a/packages/typespec-python/test/azure/generated/typetest-model-recursive/typetest/model/recursive/_utils/model_base.py b/packages/typespec-python/test/azure/generated/typetest-model-recursive/typetest/model/recursive/_utils/model_base.py index b4433021b4e..7b7f8ba67b5 100644 --- a/packages/typespec-python/test/azure/generated/typetest-model-recursive/typetest/model/recursive/_utils/model_base.py +++ b/packages/typespec-python/test/azure/generated/typetest-model-recursive/typetest/model/recursive/_utils/model_base.py @@ -630,6 +630,9 @@ def __init__(self, *args: typing.Any, **kwargs: typing.Any) -> None: if len(items) > 0: existed_attr_keys.append(xml_name) dict_to_pass[rf._rest_name] = _deserialize(rf._type, items) + elif not rf._is_optional: + existed_attr_keys.append(xml_name) + dict_to_pass[rf._rest_name] = [] continue # text element is primitive type @@ -891,6 +894,8 @@ def _get_deserialize_callable_from_annotation( # pylint: disable=too-many-retur # is it optional? try: if any(a is _NONE_TYPE for a in annotation.__args__): # pyright: ignore + if rf: + rf._is_optional = True if len(annotation.__args__) <= 2: # pyright: ignore if_obj_deserializer = _get_deserialize_callable_from_annotation( next(a for a in annotation.__args__ if a is not _NONE_TYPE), module, rf # pyright: ignore @@ -1049,6 +1054,7 @@ def _failsafe_deserialize_xml( return None +# pylint: disable=too-many-instance-attributes class _RestField: def __init__( self, @@ -1068,6 +1074,7 @@ def __init__( self._is_discriminator = is_discriminator self._visibility = visibility self._is_model = False + self._is_optional = False self._default = default self._format = format self._is_multipart_file_input = is_multipart_file_input diff --git a/packages/typespec-python/test/azure/generated/typetest-model-singlediscriminator/typetest/model/singlediscriminator/_utils/model_base.py b/packages/typespec-python/test/azure/generated/typetest-model-singlediscriminator/typetest/model/singlediscriminator/_utils/model_base.py index b4433021b4e..7b7f8ba67b5 100644 --- a/packages/typespec-python/test/azure/generated/typetest-model-singlediscriminator/typetest/model/singlediscriminator/_utils/model_base.py +++ b/packages/typespec-python/test/azure/generated/typetest-model-singlediscriminator/typetest/model/singlediscriminator/_utils/model_base.py @@ -630,6 +630,9 @@ def __init__(self, *args: typing.Any, **kwargs: typing.Any) -> None: if len(items) > 0: existed_attr_keys.append(xml_name) dict_to_pass[rf._rest_name] = _deserialize(rf._type, items) + elif not rf._is_optional: + existed_attr_keys.append(xml_name) + dict_to_pass[rf._rest_name] = [] continue # text element is primitive type @@ -891,6 +894,8 @@ def _get_deserialize_callable_from_annotation( # pylint: disable=too-many-retur # is it optional? try: if any(a is _NONE_TYPE for a in annotation.__args__): # pyright: ignore + if rf: + rf._is_optional = True if len(annotation.__args__) <= 2: # pyright: ignore if_obj_deserializer = _get_deserialize_callable_from_annotation( next(a for a in annotation.__args__ if a is not _NONE_TYPE), module, rf # pyright: ignore @@ -1049,6 +1054,7 @@ def _failsafe_deserialize_xml( return None +# pylint: disable=too-many-instance-attributes class _RestField: def __init__( self, @@ -1068,6 +1074,7 @@ def __init__( self._is_discriminator = is_discriminator self._visibility = visibility self._is_model = False + self._is_optional = False self._default = default self._format = format self._is_multipart_file_input = is_multipart_file_input diff --git a/packages/typespec-python/test/azure/generated/typetest-model-usage/typetest/model/usage/_utils/model_base.py b/packages/typespec-python/test/azure/generated/typetest-model-usage/typetest/model/usage/_utils/model_base.py index b4433021b4e..7b7f8ba67b5 100644 --- a/packages/typespec-python/test/azure/generated/typetest-model-usage/typetest/model/usage/_utils/model_base.py +++ b/packages/typespec-python/test/azure/generated/typetest-model-usage/typetest/model/usage/_utils/model_base.py @@ -630,6 +630,9 @@ def __init__(self, *args: typing.Any, **kwargs: typing.Any) -> None: if len(items) > 0: existed_attr_keys.append(xml_name) dict_to_pass[rf._rest_name] = _deserialize(rf._type, items) + elif not rf._is_optional: + existed_attr_keys.append(xml_name) + dict_to_pass[rf._rest_name] = [] continue # text element is primitive type @@ -891,6 +894,8 @@ def _get_deserialize_callable_from_annotation( # pylint: disable=too-many-retur # is it optional? try: if any(a is _NONE_TYPE for a in annotation.__args__): # pyright: ignore + if rf: + rf._is_optional = True if len(annotation.__args__) <= 2: # pyright: ignore if_obj_deserializer = _get_deserialize_callable_from_annotation( next(a for a in annotation.__args__ if a is not _NONE_TYPE), module, rf # pyright: ignore @@ -1049,6 +1054,7 @@ def _failsafe_deserialize_xml( return None +# pylint: disable=too-many-instance-attributes class _RestField: def __init__( self, @@ -1068,6 +1074,7 @@ def __init__( self._is_discriminator = is_discriminator self._visibility = visibility self._is_model = False + self._is_optional = False self._default = default self._format = format self._is_multipart_file_input = is_multipart_file_input diff --git a/packages/typespec-python/test/azure/generated/typetest-model-visibility/typetest/model/visibility/_utils/model_base.py b/packages/typespec-python/test/azure/generated/typetest-model-visibility/typetest/model/visibility/_utils/model_base.py index b4433021b4e..7b7f8ba67b5 100644 --- a/packages/typespec-python/test/azure/generated/typetest-model-visibility/typetest/model/visibility/_utils/model_base.py +++ b/packages/typespec-python/test/azure/generated/typetest-model-visibility/typetest/model/visibility/_utils/model_base.py @@ -630,6 +630,9 @@ def __init__(self, *args: typing.Any, **kwargs: typing.Any) -> None: if len(items) > 0: existed_attr_keys.append(xml_name) dict_to_pass[rf._rest_name] = _deserialize(rf._type, items) + elif not rf._is_optional: + existed_attr_keys.append(xml_name) + dict_to_pass[rf._rest_name] = [] continue # text element is primitive type @@ -891,6 +894,8 @@ def _get_deserialize_callable_from_annotation( # pylint: disable=too-many-retur # is it optional? try: if any(a is _NONE_TYPE for a in annotation.__args__): # pyright: ignore + if rf: + rf._is_optional = True if len(annotation.__args__) <= 2: # pyright: ignore if_obj_deserializer = _get_deserialize_callable_from_annotation( next(a for a in annotation.__args__ if a is not _NONE_TYPE), module, rf # pyright: ignore @@ -1049,6 +1054,7 @@ def _failsafe_deserialize_xml( return None +# pylint: disable=too-many-instance-attributes class _RestField: def __init__( self, @@ -1068,6 +1074,7 @@ def __init__( self._is_discriminator = is_discriminator self._visibility = visibility self._is_model = False + self._is_optional = False self._default = default self._format = format self._is_multipart_file_input = is_multipart_file_input diff --git a/packages/typespec-python/test/azure/generated/typetest-property-additionalproperties/typetest/property/additionalproperties/_utils/model_base.py b/packages/typespec-python/test/azure/generated/typetest-property-additionalproperties/typetest/property/additionalproperties/_utils/model_base.py index b4433021b4e..7b7f8ba67b5 100644 --- a/packages/typespec-python/test/azure/generated/typetest-property-additionalproperties/typetest/property/additionalproperties/_utils/model_base.py +++ b/packages/typespec-python/test/azure/generated/typetest-property-additionalproperties/typetest/property/additionalproperties/_utils/model_base.py @@ -630,6 +630,9 @@ def __init__(self, *args: typing.Any, **kwargs: typing.Any) -> None: if len(items) > 0: existed_attr_keys.append(xml_name) dict_to_pass[rf._rest_name] = _deserialize(rf._type, items) + elif not rf._is_optional: + existed_attr_keys.append(xml_name) + dict_to_pass[rf._rest_name] = [] continue # text element is primitive type @@ -891,6 +894,8 @@ def _get_deserialize_callable_from_annotation( # pylint: disable=too-many-retur # is it optional? try: if any(a is _NONE_TYPE for a in annotation.__args__): # pyright: ignore + if rf: + rf._is_optional = True if len(annotation.__args__) <= 2: # pyright: ignore if_obj_deserializer = _get_deserialize_callable_from_annotation( next(a for a in annotation.__args__ if a is not _NONE_TYPE), module, rf # pyright: ignore @@ -1049,6 +1054,7 @@ def _failsafe_deserialize_xml( return None +# pylint: disable=too-many-instance-attributes class _RestField: def __init__( self, @@ -1068,6 +1074,7 @@ def __init__( self._is_discriminator = is_discriminator self._visibility = visibility self._is_model = False + self._is_optional = False self._default = default self._format = format self._is_multipart_file_input = is_multipart_file_input diff --git a/packages/typespec-python/test/azure/generated/typetest-property-nullable/typetest/property/nullable/_utils/model_base.py b/packages/typespec-python/test/azure/generated/typetest-property-nullable/typetest/property/nullable/_utils/model_base.py index b4433021b4e..7b7f8ba67b5 100644 --- a/packages/typespec-python/test/azure/generated/typetest-property-nullable/typetest/property/nullable/_utils/model_base.py +++ b/packages/typespec-python/test/azure/generated/typetest-property-nullable/typetest/property/nullable/_utils/model_base.py @@ -630,6 +630,9 @@ def __init__(self, *args: typing.Any, **kwargs: typing.Any) -> None: if len(items) > 0: existed_attr_keys.append(xml_name) dict_to_pass[rf._rest_name] = _deserialize(rf._type, items) + elif not rf._is_optional: + existed_attr_keys.append(xml_name) + dict_to_pass[rf._rest_name] = [] continue # text element is primitive type @@ -891,6 +894,8 @@ def _get_deserialize_callable_from_annotation( # pylint: disable=too-many-retur # is it optional? try: if any(a is _NONE_TYPE for a in annotation.__args__): # pyright: ignore + if rf: + rf._is_optional = True if len(annotation.__args__) <= 2: # pyright: ignore if_obj_deserializer = _get_deserialize_callable_from_annotation( next(a for a in annotation.__args__ if a is not _NONE_TYPE), module, rf # pyright: ignore @@ -1049,6 +1054,7 @@ def _failsafe_deserialize_xml( return None +# pylint: disable=too-many-instance-attributes class _RestField: def __init__( self, @@ -1068,6 +1074,7 @@ def __init__( self._is_discriminator = is_discriminator self._visibility = visibility self._is_model = False + self._is_optional = False self._default = default self._format = format self._is_multipart_file_input = is_multipart_file_input diff --git a/packages/typespec-python/test/azure/generated/typetest-property-optional/typetest/property/optional/_utils/model_base.py b/packages/typespec-python/test/azure/generated/typetest-property-optional/typetest/property/optional/_utils/model_base.py index b4433021b4e..7b7f8ba67b5 100644 --- a/packages/typespec-python/test/azure/generated/typetest-property-optional/typetest/property/optional/_utils/model_base.py +++ b/packages/typespec-python/test/azure/generated/typetest-property-optional/typetest/property/optional/_utils/model_base.py @@ -630,6 +630,9 @@ def __init__(self, *args: typing.Any, **kwargs: typing.Any) -> None: if len(items) > 0: existed_attr_keys.append(xml_name) dict_to_pass[rf._rest_name] = _deserialize(rf._type, items) + elif not rf._is_optional: + existed_attr_keys.append(xml_name) + dict_to_pass[rf._rest_name] = [] continue # text element is primitive type @@ -891,6 +894,8 @@ def _get_deserialize_callable_from_annotation( # pylint: disable=too-many-retur # is it optional? try: if any(a is _NONE_TYPE for a in annotation.__args__): # pyright: ignore + if rf: + rf._is_optional = True if len(annotation.__args__) <= 2: # pyright: ignore if_obj_deserializer = _get_deserialize_callable_from_annotation( next(a for a in annotation.__args__ if a is not _NONE_TYPE), module, rf # pyright: ignore @@ -1049,6 +1054,7 @@ def _failsafe_deserialize_xml( return None +# pylint: disable=too-many-instance-attributes class _RestField: def __init__( self, @@ -1068,6 +1074,7 @@ def __init__( self._is_discriminator = is_discriminator self._visibility = visibility self._is_model = False + self._is_optional = False self._default = default self._format = format self._is_multipart_file_input = is_multipart_file_input diff --git a/packages/typespec-python/test/azure/generated/typetest-property-valuetypes/typetest/property/valuetypes/_utils/model_base.py b/packages/typespec-python/test/azure/generated/typetest-property-valuetypes/typetest/property/valuetypes/_utils/model_base.py index b4433021b4e..7b7f8ba67b5 100644 --- a/packages/typespec-python/test/azure/generated/typetest-property-valuetypes/typetest/property/valuetypes/_utils/model_base.py +++ b/packages/typespec-python/test/azure/generated/typetest-property-valuetypes/typetest/property/valuetypes/_utils/model_base.py @@ -630,6 +630,9 @@ def __init__(self, *args: typing.Any, **kwargs: typing.Any) -> None: if len(items) > 0: existed_attr_keys.append(xml_name) dict_to_pass[rf._rest_name] = _deserialize(rf._type, items) + elif not rf._is_optional: + existed_attr_keys.append(xml_name) + dict_to_pass[rf._rest_name] = [] continue # text element is primitive type @@ -891,6 +894,8 @@ def _get_deserialize_callable_from_annotation( # pylint: disable=too-many-retur # is it optional? try: if any(a is _NONE_TYPE for a in annotation.__args__): # pyright: ignore + if rf: + rf._is_optional = True if len(annotation.__args__) <= 2: # pyright: ignore if_obj_deserializer = _get_deserialize_callable_from_annotation( next(a for a in annotation.__args__ if a is not _NONE_TYPE), module, rf # pyright: ignore @@ -1049,6 +1054,7 @@ def _failsafe_deserialize_xml( return None +# pylint: disable=too-many-instance-attributes class _RestField: def __init__( self, @@ -1068,6 +1074,7 @@ def __init__( self._is_discriminator = is_discriminator self._visibility = visibility self._is_model = False + self._is_optional = False self._default = default self._format = format self._is_multipart_file_input = is_multipart_file_input diff --git a/packages/typespec-python/test/azure/generated/typetest-scalar/typetest/scalar/_utils/model_base.py b/packages/typespec-python/test/azure/generated/typetest-scalar/typetest/scalar/_utils/model_base.py index b4433021b4e..7b7f8ba67b5 100644 --- a/packages/typespec-python/test/azure/generated/typetest-scalar/typetest/scalar/_utils/model_base.py +++ b/packages/typespec-python/test/azure/generated/typetest-scalar/typetest/scalar/_utils/model_base.py @@ -630,6 +630,9 @@ def __init__(self, *args: typing.Any, **kwargs: typing.Any) -> None: if len(items) > 0: existed_attr_keys.append(xml_name) dict_to_pass[rf._rest_name] = _deserialize(rf._type, items) + elif not rf._is_optional: + existed_attr_keys.append(xml_name) + dict_to_pass[rf._rest_name] = [] continue # text element is primitive type @@ -891,6 +894,8 @@ def _get_deserialize_callable_from_annotation( # pylint: disable=too-many-retur # is it optional? try: if any(a is _NONE_TYPE for a in annotation.__args__): # pyright: ignore + if rf: + rf._is_optional = True if len(annotation.__args__) <= 2: # pyright: ignore if_obj_deserializer = _get_deserialize_callable_from_annotation( next(a for a in annotation.__args__ if a is not _NONE_TYPE), module, rf # pyright: ignore @@ -1049,6 +1054,7 @@ def _failsafe_deserialize_xml( return None +# pylint: disable=too-many-instance-attributes class _RestField: def __init__( self, @@ -1068,6 +1074,7 @@ def __init__( self._is_discriminator = is_discriminator self._visibility = visibility self._is_model = False + self._is_optional = False self._default = default self._format = format self._is_multipart_file_input = is_multipart_file_input diff --git a/packages/typespec-python/test/azure/generated/typetest-union/typetest/union/_utils/model_base.py b/packages/typespec-python/test/azure/generated/typetest-union/typetest/union/_utils/model_base.py index b4433021b4e..7b7f8ba67b5 100644 --- a/packages/typespec-python/test/azure/generated/typetest-union/typetest/union/_utils/model_base.py +++ b/packages/typespec-python/test/azure/generated/typetest-union/typetest/union/_utils/model_base.py @@ -630,6 +630,9 @@ def __init__(self, *args: typing.Any, **kwargs: typing.Any) -> None: if len(items) > 0: existed_attr_keys.append(xml_name) dict_to_pass[rf._rest_name] = _deserialize(rf._type, items) + elif not rf._is_optional: + existed_attr_keys.append(xml_name) + dict_to_pass[rf._rest_name] = [] continue # text element is primitive type @@ -891,6 +894,8 @@ def _get_deserialize_callable_from_annotation( # pylint: disable=too-many-retur # is it optional? try: if any(a is _NONE_TYPE for a in annotation.__args__): # pyright: ignore + if rf: + rf._is_optional = True if len(annotation.__args__) <= 2: # pyright: ignore if_obj_deserializer = _get_deserialize_callable_from_annotation( next(a for a in annotation.__args__ if a is not _NONE_TYPE), module, rf # pyright: ignore @@ -1049,6 +1054,7 @@ def _failsafe_deserialize_xml( return None +# pylint: disable=too-many-instance-attributes class _RestField: def __init__( self, @@ -1068,6 +1074,7 @@ def __init__( self._is_discriminator = is_discriminator self._visibility = visibility self._is_model = False + self._is_optional = False self._default = default self._format = format self._is_multipart_file_input = is_multipart_file_input diff --git a/packages/typespec-python/test/azure/generated/versioning-added/versioning/added/_utils/model_base.py b/packages/typespec-python/test/azure/generated/versioning-added/versioning/added/_utils/model_base.py index b4433021b4e..7b7f8ba67b5 100644 --- a/packages/typespec-python/test/azure/generated/versioning-added/versioning/added/_utils/model_base.py +++ b/packages/typespec-python/test/azure/generated/versioning-added/versioning/added/_utils/model_base.py @@ -630,6 +630,9 @@ def __init__(self, *args: typing.Any, **kwargs: typing.Any) -> None: if len(items) > 0: existed_attr_keys.append(xml_name) dict_to_pass[rf._rest_name] = _deserialize(rf._type, items) + elif not rf._is_optional: + existed_attr_keys.append(xml_name) + dict_to_pass[rf._rest_name] = [] continue # text element is primitive type @@ -891,6 +894,8 @@ def _get_deserialize_callable_from_annotation( # pylint: disable=too-many-retur # is it optional? try: if any(a is _NONE_TYPE for a in annotation.__args__): # pyright: ignore + if rf: + rf._is_optional = True if len(annotation.__args__) <= 2: # pyright: ignore if_obj_deserializer = _get_deserialize_callable_from_annotation( next(a for a in annotation.__args__ if a is not _NONE_TYPE), module, rf # pyright: ignore @@ -1049,6 +1054,7 @@ def _failsafe_deserialize_xml( return None +# pylint: disable=too-many-instance-attributes class _RestField: def __init__( self, @@ -1068,6 +1074,7 @@ def __init__( self._is_discriminator = is_discriminator self._visibility = visibility self._is_model = False + self._is_optional = False self._default = default self._format = format self._is_multipart_file_input = is_multipart_file_input diff --git a/packages/typespec-python/test/azure/generated/versioning-madeoptional/versioning/madeoptional/_utils/model_base.py b/packages/typespec-python/test/azure/generated/versioning-madeoptional/versioning/madeoptional/_utils/model_base.py index b4433021b4e..7b7f8ba67b5 100644 --- a/packages/typespec-python/test/azure/generated/versioning-madeoptional/versioning/madeoptional/_utils/model_base.py +++ b/packages/typespec-python/test/azure/generated/versioning-madeoptional/versioning/madeoptional/_utils/model_base.py @@ -630,6 +630,9 @@ def __init__(self, *args: typing.Any, **kwargs: typing.Any) -> None: if len(items) > 0: existed_attr_keys.append(xml_name) dict_to_pass[rf._rest_name] = _deserialize(rf._type, items) + elif not rf._is_optional: + existed_attr_keys.append(xml_name) + dict_to_pass[rf._rest_name] = [] continue # text element is primitive type @@ -891,6 +894,8 @@ def _get_deserialize_callable_from_annotation( # pylint: disable=too-many-retur # is it optional? try: if any(a is _NONE_TYPE for a in annotation.__args__): # pyright: ignore + if rf: + rf._is_optional = True if len(annotation.__args__) <= 2: # pyright: ignore if_obj_deserializer = _get_deserialize_callable_from_annotation( next(a for a in annotation.__args__ if a is not _NONE_TYPE), module, rf # pyright: ignore @@ -1049,6 +1054,7 @@ def _failsafe_deserialize_xml( return None +# pylint: disable=too-many-instance-attributes class _RestField: def __init__( self, @@ -1068,6 +1074,7 @@ def __init__( self._is_discriminator = is_discriminator self._visibility = visibility self._is_model = False + self._is_optional = False self._default = default self._format = format self._is_multipart_file_input = is_multipart_file_input diff --git a/packages/typespec-python/test/azure/generated/versioning-removed/versioning/removed/_utils/model_base.py b/packages/typespec-python/test/azure/generated/versioning-removed/versioning/removed/_utils/model_base.py index b4433021b4e..7b7f8ba67b5 100644 --- a/packages/typespec-python/test/azure/generated/versioning-removed/versioning/removed/_utils/model_base.py +++ b/packages/typespec-python/test/azure/generated/versioning-removed/versioning/removed/_utils/model_base.py @@ -630,6 +630,9 @@ def __init__(self, *args: typing.Any, **kwargs: typing.Any) -> None: if len(items) > 0: existed_attr_keys.append(xml_name) dict_to_pass[rf._rest_name] = _deserialize(rf._type, items) + elif not rf._is_optional: + existed_attr_keys.append(xml_name) + dict_to_pass[rf._rest_name] = [] continue # text element is primitive type @@ -891,6 +894,8 @@ def _get_deserialize_callable_from_annotation( # pylint: disable=too-many-retur # is it optional? try: if any(a is _NONE_TYPE for a in annotation.__args__): # pyright: ignore + if rf: + rf._is_optional = True if len(annotation.__args__) <= 2: # pyright: ignore if_obj_deserializer = _get_deserialize_callable_from_annotation( next(a for a in annotation.__args__ if a is not _NONE_TYPE), module, rf # pyright: ignore @@ -1049,6 +1054,7 @@ def _failsafe_deserialize_xml( return None +# pylint: disable=too-many-instance-attributes class _RestField: def __init__( self, @@ -1068,6 +1074,7 @@ def __init__( self._is_discriminator = is_discriminator self._visibility = visibility self._is_model = False + self._is_optional = False self._default = default self._format = format self._is_multipart_file_input = is_multipart_file_input diff --git a/packages/typespec-python/test/azure/generated/versioning-renamedfrom/versioning/renamedfrom/_utils/model_base.py b/packages/typespec-python/test/azure/generated/versioning-renamedfrom/versioning/renamedfrom/_utils/model_base.py index b4433021b4e..7b7f8ba67b5 100644 --- a/packages/typespec-python/test/azure/generated/versioning-renamedfrom/versioning/renamedfrom/_utils/model_base.py +++ b/packages/typespec-python/test/azure/generated/versioning-renamedfrom/versioning/renamedfrom/_utils/model_base.py @@ -630,6 +630,9 @@ def __init__(self, *args: typing.Any, **kwargs: typing.Any) -> None: if len(items) > 0: existed_attr_keys.append(xml_name) dict_to_pass[rf._rest_name] = _deserialize(rf._type, items) + elif not rf._is_optional: + existed_attr_keys.append(xml_name) + dict_to_pass[rf._rest_name] = [] continue # text element is primitive type @@ -891,6 +894,8 @@ def _get_deserialize_callable_from_annotation( # pylint: disable=too-many-retur # is it optional? try: if any(a is _NONE_TYPE for a in annotation.__args__): # pyright: ignore + if rf: + rf._is_optional = True if len(annotation.__args__) <= 2: # pyright: ignore if_obj_deserializer = _get_deserialize_callable_from_annotation( next(a for a in annotation.__args__ if a is not _NONE_TYPE), module, rf # pyright: ignore @@ -1049,6 +1054,7 @@ def _failsafe_deserialize_xml( return None +# pylint: disable=too-many-instance-attributes class _RestField: def __init__( self, @@ -1068,6 +1074,7 @@ def __init__( self._is_discriminator = is_discriminator self._visibility = visibility self._is_model = False + self._is_optional = False self._default = default self._format = format self._is_multipart_file_input = is_multipart_file_input diff --git a/packages/typespec-python/test/azure/generated/versioning-returntypechangedfrom/versioning/returntypechangedfrom/_utils/model_base.py b/packages/typespec-python/test/azure/generated/versioning-returntypechangedfrom/versioning/returntypechangedfrom/_utils/model_base.py index b4433021b4e..7b7f8ba67b5 100644 --- a/packages/typespec-python/test/azure/generated/versioning-returntypechangedfrom/versioning/returntypechangedfrom/_utils/model_base.py +++ b/packages/typespec-python/test/azure/generated/versioning-returntypechangedfrom/versioning/returntypechangedfrom/_utils/model_base.py @@ -630,6 +630,9 @@ def __init__(self, *args: typing.Any, **kwargs: typing.Any) -> None: if len(items) > 0: existed_attr_keys.append(xml_name) dict_to_pass[rf._rest_name] = _deserialize(rf._type, items) + elif not rf._is_optional: + existed_attr_keys.append(xml_name) + dict_to_pass[rf._rest_name] = [] continue # text element is primitive type @@ -891,6 +894,8 @@ def _get_deserialize_callable_from_annotation( # pylint: disable=too-many-retur # is it optional? try: if any(a is _NONE_TYPE for a in annotation.__args__): # pyright: ignore + if rf: + rf._is_optional = True if len(annotation.__args__) <= 2: # pyright: ignore if_obj_deserializer = _get_deserialize_callable_from_annotation( next(a for a in annotation.__args__ if a is not _NONE_TYPE), module, rf # pyright: ignore @@ -1049,6 +1054,7 @@ def _failsafe_deserialize_xml( return None +# pylint: disable=too-many-instance-attributes class _RestField: def __init__( self, @@ -1068,6 +1074,7 @@ def __init__( self._is_discriminator = is_discriminator self._visibility = visibility self._is_model = False + self._is_optional = False self._default = default self._format = format self._is_multipart_file_input = is_multipart_file_input diff --git a/packages/typespec-python/test/azure/generated/versioning-typechangedfrom/versioning/typechangedfrom/_utils/model_base.py b/packages/typespec-python/test/azure/generated/versioning-typechangedfrom/versioning/typechangedfrom/_utils/model_base.py index b4433021b4e..7b7f8ba67b5 100644 --- a/packages/typespec-python/test/azure/generated/versioning-typechangedfrom/versioning/typechangedfrom/_utils/model_base.py +++ b/packages/typespec-python/test/azure/generated/versioning-typechangedfrom/versioning/typechangedfrom/_utils/model_base.py @@ -630,6 +630,9 @@ def __init__(self, *args: typing.Any, **kwargs: typing.Any) -> None: if len(items) > 0: existed_attr_keys.append(xml_name) dict_to_pass[rf._rest_name] = _deserialize(rf._type, items) + elif not rf._is_optional: + existed_attr_keys.append(xml_name) + dict_to_pass[rf._rest_name] = [] continue # text element is primitive type @@ -891,6 +894,8 @@ def _get_deserialize_callable_from_annotation( # pylint: disable=too-many-retur # is it optional? try: if any(a is _NONE_TYPE for a in annotation.__args__): # pyright: ignore + if rf: + rf._is_optional = True if len(annotation.__args__) <= 2: # pyright: ignore if_obj_deserializer = _get_deserialize_callable_from_annotation( next(a for a in annotation.__args__ if a is not _NONE_TYPE), module, rf # pyright: ignore @@ -1049,6 +1054,7 @@ def _failsafe_deserialize_xml( return None +# pylint: disable=too-many-instance-attributes class _RestField: def __init__( self, @@ -1068,6 +1074,7 @@ def __init__( self._is_discriminator = is_discriminator self._visibility = visibility self._is_model = False + self._is_optional = False self._default = default self._format = format self._is_multipart_file_input = is_multipart_file_input diff --git a/packages/typespec-python/test/generic_mock_api_tests/unittests/test_model_base_serialization.py b/packages/typespec-python/test/generic_mock_api_tests/unittests/test_model_base_serialization.py deleted file mode 100644 index ca39a14e25e..00000000000 --- a/packages/typespec-python/test/generic_mock_api_tests/unittests/test_model_base_serialization.py +++ /dev/null @@ -1,4131 +0,0 @@ -# ------------------------------------ -# Copyright (c) Microsoft Corporation. -# Licensed under the MIT License. -# ------------------------------------ -import copy -import decimal -import json -import datetime -from pathlib import Path -from typing import ( - Any, - Iterable, - List, - Literal, - Dict, - Mapping, - Sequence, - Set, - Tuple, - Optional, - overload, - Union, -) -import pytest -import isodate -import sys -from enum import Enum - -from specialwords._utils.model_base import ( - SdkJSONEncoder, - Model, - rest_field, - _is_model, - rest_discriminator, - _deserialize, -) - -if sys.version_info >= (3, 9): - from collections.abc import MutableMapping -else: - from typing import MutableMapping # type: ignore # pylint: disable=ungrouped-imports -JSON = MutableMapping[str, Any] # pylint: disable=unsubscriptable-object - - -class BasicResource(Model): - platform_update_domain_count: int = rest_field( - name="platformUpdateDomainCount" - ) # How many times the platform update domain has been counted - platform_fault_domain_count: int = rest_field( - name="platformFaultDomainCount" - ) # How many times the platform fault domain has been counted - virtual_machines: List[Any] = rest_field(name="virtualMachines") # List of virtual machines - - @overload - def __init__( - self, - *, - platform_update_domain_count: int, - platform_fault_domain_count: int, - virtual_machines: List[Any], - ): ... - - @overload - def __init__(self, mapping: Mapping[str, Any], /): ... - - def __init__(self, *args, **kwargs): - super().__init__(*args, **kwargs) - - -class Pet(Model): - name: str = rest_field() # my name - species: str = rest_field() # my species - - @overload - def __init__(self, *, name: str, species: str): ... - - @overload - def __init__(self, mapping: Mapping[str, Any], /): ... - - def __init__(self, *args, **kwargs): - super().__init__(*args, **kwargs) - - -def test_model_and_dict_equal(): - dict_response = { - "platformUpdateDomainCount": 5, - "platformFaultDomainCount": 3, - "virtualMachines": [], - } - model = BasicResource( - platform_update_domain_count=5, - platform_fault_domain_count=3, - virtual_machines=[], - ) - - assert model == dict_response - assert ( - model.platform_update_domain_count - == model["platformUpdateDomainCount"] - == dict_response["platformUpdateDomainCount"] - == 5 - ) - assert ( - model.platform_fault_domain_count - == model["platformFaultDomainCount"] - == dict_response["platformFaultDomainCount"] - == 3 - ) - assert model.virtual_machines == model["virtualMachines"] == dict_response["virtualMachines"] - - -def test_json_roundtrip(): - dict_response = { - "platformUpdateDomainCount": 5, - "platformFaultDomainCount": 3, - "virtualMachines": [], - } - model = BasicResource( - platform_update_domain_count=5, - platform_fault_domain_count=3, - virtual_machines=[], - ) - with pytest.raises(TypeError): - json.dumps(model) - assert ( - json.dumps(dict(model)) - == '{"platformUpdateDomainCount": 5, "platformFaultDomainCount": 3, "virtualMachines": []}' - ) - assert json.loads(json.dumps(dict(model))) == model == dict_response - - -def test_has_no_property(): - dict_response = { - "platformUpdateDomainCount": 5, - "platformFaultDomainCount": 3, - "virtualMachines": [], - "noprop": "bonjour!", - } - model = BasicResource(dict_response) - assert ( - model.platform_update_domain_count - == model["platformUpdateDomainCount"] - == dict_response["platformUpdateDomainCount"] - == 5 - ) - assert not hasattr(model, "no_prop") - with pytest.raises(AttributeError) as ex: - model.no_prop - - assert str(ex.value) == "'BasicResource' object has no attribute 'no_prop'" - assert model["noprop"] == dict_response["noprop"] == "bonjour!" - - # let's add it to model now - - class BasicResourceWithProperty(BasicResource): - no_prop: str = rest_field(name="noprop") - - model = BasicResourceWithProperty( - platform_update_domain_count=5, - platform_fault_domain_count=3, - virtual_machines=[], - no_prop="bonjour!", - ) - assert model.no_prop == model["noprop"] == dict_response["noprop"] == "bonjour!" - - -def test_original_and_attr_name_same(): - class MyModel(Model): - hello: str = rest_field() - - @overload - def __init__(self, *, hello: str): ... - - @overload - def __init__(self, mapping: Mapping[str, Any], /): ... - - def __init__(self, *args, **kwargs): - super().__init__(*args, **kwargs) - - dict_response = {"hello": "nihao"} - model = MyModel(hello="nihao") - assert model.hello == model["hello"] == dict_response["hello"] - - -class OptionalModel(Model): - optional_str: Optional[str] = rest_field() - optional_time: Optional[datetime.time] = rest_field() - optional_dict: Optional[Dict[str, Optional[Pet]]] = rest_field(name="optionalDict") - optional_model: Optional[Pet] = rest_field() - optional_myself: Optional["OptionalModel"] = rest_field() - - @overload - def __init__( - self, - *, - optional_str: Optional[str] = None, - optional_time: Optional[datetime.time] = None, - optional_dict: Optional[Dict[str, Optional[Pet]]] = None, - optional_myself: Optional["OptionalModel"] = None, - ): ... - - @overload - def __init__(self, mapping: Mapping[str, Any], /): ... - - def __init__(self, *args, **kwargs): - super().__init__(*args, **kwargs) - - -def test_optional_property(): - dict_response = { - "optional_str": "hello!", - "optional_time": None, - "optionalDict": { - "Eugene": { - "name": "Eugene", - "species": "Dog", - }, - "Lady": None, - }, - "optional_model": None, - "optional_myself": { - "optional_str": None, - "optional_time": "11:34:56", - "optionalDict": None, - "optional_model": {"name": "Lady", "species": "Newt"}, - "optional_myself": None, - }, - } - - model = OptionalModel(dict_response) - assert model.optional_str == model["optional_str"] == "hello!" - assert model.optional_time == model["optional_time"] == None - assert ( - model.optional_dict - == model["optionalDict"] - == { - "Eugene": { - "name": "Eugene", - "species": "Dog", - }, - "Lady": None, - } - ) - assert model.optional_dict - assert model.optional_dict["Eugene"].name == model.optional_dict["Eugene"]["name"] == "Eugene" - assert model.optional_dict["Lady"] is None - - assert ( - model.optional_myself - == model["optional_myself"] - == { - "optional_str": None, - "optional_time": "11:34:56", - "optionalDict": None, - "optional_model": {"name": "Lady", "species": "Newt"}, - "optional_myself": None, - } - ) - assert model.optional_myself - assert model.optional_myself.optional_str is None - assert model.optional_myself.optional_time == datetime.time(11, 34, 56) - assert model.optional_myself.optional_dict is None - assert model.optional_myself.optional_model - assert model.optional_myself.optional_model.name == "Lady" - assert model.optional_myself.optional_model.species == "Newt" - assert model.optional_myself.optional_myself is None - - -def test_model_pass_in_none(): - model = OptionalModel(optional_str=None) - assert model.optional_str == None - with pytest.raises(KeyError): - model["optionalStr"] - - -def test_modify_dict(): - model = BasicResource( - platform_update_domain_count=5, - platform_fault_domain_count=3, - virtual_machines=[], - ) - - # now let's modify the model as a dict - model["platformUpdateDomainCount"] = 100 - assert model.platform_update_domain_count == model["platformUpdateDomainCount"] == 100 - - -def test_modify_property(): - dict_response = { - "platformUpdateDomainCount": 5, - "platformFaultDomainCount": 3, - "virtualMachines": [], - } - model = BasicResource( - platform_update_domain_count=5, - platform_fault_domain_count=3, - virtual_machines=[], - ) - - # now let's modify the model through it's properties - model.platform_fault_domain_count = 2000 - model["platformFaultDomainCount"] - assert model.platform_fault_domain_count == model["platformFaultDomainCount"] == 2000 - - -def test_property_is_a_type(): - class Fish(Model): - name: str = rest_field() - species: Literal["Salmon", "Halibut"] = rest_field() - - @overload - def __init__(self, *, name: str, species: Literal["Salmon", "Halibut"]): ... - - @overload - def __init__(self, mapping: Mapping[str, Any], /): ... - - def __init__(self, *args, **kwargs): - super().__init__(*args, **kwargs) - - class Fishery(Model): - fish: Fish = rest_field() - - @overload - def __init__(self, *, fish: Fish): ... - - @overload - def __init__(self, mapping: Mapping[str, Any], /): ... - - def __init__(self, *args, **kwargs): - super().__init__(*args, **kwargs) - - fishery = Fishery({"fish": {"name": "Benjamin", "species": "Salmon"}}) - assert isinstance(fishery.fish, Fish) - assert fishery.fish.name == fishery.fish["name"] == fishery["fish"]["name"] == "Benjamin" - assert fishery.fish.species == fishery.fish["species"] == fishery["fish"]["species"] == "Salmon" - - -def test_model_initialization(): - class DatetimeModel(Model): - datetime_value: datetime.datetime = rest_field(name="datetimeValue") - - @overload - def __init__(self, *, datetime_value: datetime.datetime): ... - - @overload - def __init__(self, mapping: Mapping[str, Any], /): ... - - def __init__(self, *args, **kwargs): - super().__init__(*args, **kwargs) - - val_str = "9999-12-31T23:59:59.999000Z" - val = isodate.parse_datetime(val_str) - - # when initialize model with dict, the dict value is shall be serialized value - model1 = DatetimeModel({"datetimeValue": val_str}) - assert model1["datetimeValue"] == val_str - assert model1.datetime_value == val - - # when initialize model with keyword args, the value is deserialized value - model2 = DatetimeModel(datetime_value=val) - assert model2["datetimeValue"] == val_str - assert model2.datetime_value == val - - # what if we initialize with dict but the dict has deserialized value? this case show what happens. - # Since we always serialize the value before initializing the model from dict, we could still get correct result - model3 = DatetimeModel({"datetimeValue": val}) - assert model3["datetimeValue"] == val_str - assert model3.datetime_value == val - - -def test_model_dict_prop_initialization(): - class DatetimeModel(Model): - dict_prop: dict[str, datetime.datetime] = rest_field(name="dictProp") - - @overload - def __init__(self, *, dict_prop: dict[str, datetime.datetime]): ... - - @overload - def __init__(self, mapping: Mapping[str, Any], /): ... - - def __init__(self, *args, **kwargs): - super().__init__(*args, **kwargs) - - val_str = "9999-12-31T23:59:59.999000Z" - val = isodate.parse_datetime(val_str) - - # when initialize model with dict, the dict value is shall be serialized value - model1 = DatetimeModel({"dictProp": {"key1": val_str}}) - assert model1["dictProp"] == {"key1": val_str} - assert model1.dict_prop == {"key1": val} - - # when initialize model with keyword args, the value is deserialized value - model2 = DatetimeModel(dict_prop={"key1": val}) - assert model2["dictProp"] == {"key1": val_str} - assert model2.dict_prop == {"key1": val} - - # what if we initialize with dict but the dict has deserialized value? this case show what happens. - # Since we always serialize the value before initializing the model from dict, we could still get correct result - model3 = DatetimeModel({"dictProp": {"key1": val}}) - assert model3["dictProp"] == {"key1": val_str} - assert model3.dict_prop == {"key1": val} - - -def test_datetime_deserialization(): - class DatetimeModel(Model): - datetime_value: datetime.datetime = rest_field(name="datetimeValue") - - @overload - def __init__(self, *, datetime_value: datetime.datetime): ... - - @overload - def __init__(self, mapping: Mapping[str, Any], /): ... - - def __init__(self, *args, **kwargs): - super().__init__(*args, **kwargs) - - val_str = "9999-12-31T23:59:59.999Z" - val = isodate.parse_datetime(val_str) - model = DatetimeModel({"datetimeValue": val_str}) - assert model["datetimeValue"] == val_str - assert model.datetime_value == val - - class BaseModel(Model): - my_prop: DatetimeModel = rest_field(name="myProp") - - model = BaseModel({"myProp": {"datetimeValue": val_str}}) - assert isinstance(model.my_prop, DatetimeModel) - model.my_prop["datetimeValue"] - assert model.my_prop["datetimeValue"] == model["myProp"]["datetimeValue"] == val_str - assert model.my_prop.datetime_value == val - - -def test_date_deserialization(): - class DateModel(Model): - date_value: datetime.date = rest_field(name="dateValue") - - @overload - def __init__(self, *, date_value: datetime.date): ... - - @overload - def __init__(self, mapping: Mapping[str, Any], /): ... - - def __init__(self, *args, **kwargs): - super().__init__(*args, **kwargs) - - val_str = "2016-02-29" - val = isodate.parse_date(val_str) - model = DateModel({"dateValue": val_str}) - assert model["dateValue"] == val_str - assert model.date_value == val - - class BaseModel(Model): - my_prop: DateModel = rest_field(name="myProp") - - model = BaseModel({"myProp": {"dateValue": val_str}}) - assert isinstance(model.my_prop, DateModel) - assert model.my_prop["dateValue"] == model["myProp"]["dateValue"] == val_str - assert model.my_prop.date_value == val - - -def test_time_deserialization(): - class TimeModel(Model): - time_value: datetime.time = rest_field(name="timeValue") - - @overload - def __init__(self, *, time_value: datetime.time): ... - - @overload - def __init__(self, mapping: Mapping[str, Any], /): ... - - def __init__(self, *args, **kwargs): - super().__init__(*args, **kwargs) - - val_str = "11:34:56" - val = datetime.time(11, 34, 56) - model = TimeModel({"timeValue": val_str}) - assert model["timeValue"] == val_str - assert model.time_value == val - - class BaseModel(Model): - my_prop: TimeModel = rest_field(name="myProp") - - model = BaseModel({"myProp": {"timeValue": val_str}}) - assert isinstance(model.my_prop, TimeModel) - assert model.my_prop["timeValue"] == model["myProp"]["timeValue"] == val_str - assert model.my_prop.time_value == val - - -class SimpleRecursiveModel(Model): - name: str = rest_field() - me: "SimpleRecursiveModel" = rest_field() - - @overload - def __init__(self, *, name: str, me: "SimpleRecursiveModel"): ... - - @overload - def __init__(self, mapping: Mapping[str, Any], /): ... - - def __init__(self, *args, **kwargs): - super().__init__(*args, **kwargs) - - -def test_model_recursion(): - dict_response = {"name": "Snoopy", "me": {"name": "Egg", "me": {"name": "Chicken"}}} - - model = SimpleRecursiveModel(dict_response) - assert model["name"] == model.name == "Snoopy" - assert model["me"] == {"name": "Egg", "me": {"name": "Chicken"}} - assert isinstance(model.me, SimpleRecursiveModel) - assert model.me["name"] == model.me.name == "Egg" - assert model.me["me"] == {"name": "Chicken"} - assert model.me.me.name == "Chicken" - - -def test_dictionary_deserialization(): - class DictionaryModel(Model): - prop: Dict[str, datetime.datetime] = rest_field() - - @overload - def __init__(self, *, prop: datetime.datetime): ... - - @overload - def __init__(self, mapping: Mapping[str, Any], /): ... - - def __init__(self, *args, **kwargs): - super().__init__(*args, **kwargs) - - val_str = "9999-12-31T23:59:59.999Z" - val = isodate.parse_datetime(val_str) - dict_response = {"prop": {"datetime": val_str}} - model = DictionaryModel(dict_response) - assert model["prop"] == {"datetime": val_str} - assert model.prop == {"datetime": val} - - -def test_attr_and_rest_case(): - class ModelTest(Model): - our_attr: str = rest_field(name="ourAttr") - - @overload - def __init__(self, *, our_attr: str): ... - - @overload - def __init__(self, mapping: Mapping[str, Any], /): ... - - def __init__(self, *args, **kwargs): - super().__init__(*args, **kwargs) - - test_model = ModelTest({"ourAttr": "camel"}) - assert test_model.our_attr == test_model["ourAttr"] == "camel" - - test_model = ModelTest(ModelTest({"ourAttr": "camel"})) - assert test_model.our_attr == test_model["ourAttr"] == "camel" - - test_model = ModelTest(our_attr="snake") - assert test_model.our_attr == test_model["ourAttr"] == "snake" - - -def test_dictionary_deserialization_model(): - class DictionaryModel(Model): - prop: Dict[str, Pet] = rest_field() - - @overload - def __init__(self, *, prop: Dict[str, Pet]): ... - - @overload - def __init__(self, mapping: Mapping[str, Any], /): ... - - def __init__(self, *args, **kwargs): - super().__init__(*args, **kwargs) - - dict_response = { - "prop": { - "Eugene": { - "name": "Eugene", - "species": "Dog", - }, - "Lady": { - "name": "Lady", - "species": "Newt", - }, - } - } - - model = DictionaryModel(dict_response) - assert model["prop"] == { - "Eugene": { - "name": "Eugene", - "species": "Dog", - }, - "Lady": { - "name": "Lady", - "species": "Newt", - }, - } - assert model.prop == { - "Eugene": Pet({"name": "Eugene", "species": "Dog"}), - "Lady": Pet({"name": "Lady", "species": "Newt"}), - } - assert model.prop["Eugene"].name == model.prop["Eugene"]["name"] == "Eugene" - assert model.prop["Eugene"].species == model.prop["Eugene"]["species"] == "Dog" - assert model.prop["Lady"].name == model.prop["Lady"]["name"] == "Lady" - assert model.prop["Lady"].species == model.prop["Lady"]["species"] == "Newt" - - -def test_list_deserialization(): - class ListModel(Model): - prop: List[datetime.datetime] = rest_field() - - @overload - def __init__(self, *, prop: List[datetime.datetime]): ... - - @overload - def __init__(self, mapping: Mapping[str, Any], /): ... - - def __init__(self, *args, **kwargs): - super().__init__(*args, **kwargs) - - val_str = "9999-12-31T23:59:59.999Z" - val = isodate.parse_datetime(val_str) - dict_response = {"prop": [val_str, val_str]} - model = ListModel(dict_response) - assert model["prop"] == [val_str, val_str] - assert model.prop == [val, val] - - -def test_list_deserialization_model(): - class ListModel(Model): - prop: List[Pet] = rest_field() - - @overload - def __init__(self, *, prop: List[Pet]): ... - - @overload - def __init__(self, mapping: Mapping[str, Any], /): ... - - def __init__(self, *args, **kwargs): - super().__init__(*args, **kwargs) - - dict_response = { - "prop": [ - {"name": "Eugene", "species": "Dog"}, - {"name": "Lady", "species": "Newt"}, - ] - } - model = ListModel(dict_response) - assert model["prop"] == [ - {"name": "Eugene", "species": "Dog"}, - {"name": "Lady", "species": "Newt"}, - ] - assert model.prop == [ - Pet({"name": "Eugene", "species": "Dog"}), - Pet({"name": "Lady", "species": "Newt"}), - ] - assert len(model.prop) == 2 - assert model.prop[0].name == model.prop[0]["name"] == "Eugene" - assert model.prop[0].species == model.prop[0]["species"] == "Dog" - assert model.prop[1].name == model.prop[1]["name"] == "Lady" - assert model.prop[1].species == model.prop[1]["species"] == "Newt" - - -def test_set_deserialization(): - class SetModel(Model): - prop: Set[datetime.datetime] = rest_field() - - @overload - def __init__(self, *, prop: Set[datetime.datetime]): ... - - @overload - def __init__(self, mapping: Mapping[str, Any], /): ... - - def __init__(self, *args, **kwargs): - super().__init__(*args, **kwargs) - - val_str = "9999-12-31T23:59:59.999Z" - val = isodate.parse_datetime(val_str) - dict_response = {"prop": set([val_str, val_str])} - model = SetModel(dict_response) - assert model["prop"] == set([val_str, val_str]) - assert model.prop == set([val, val]) - - -def test_tuple_deserialization(): - class TupleModel(Model): - prop: Tuple[str, datetime.datetime] = rest_field() - - @overload - def __init__(self, *, prop: Tuple[str, datetime.datetime]): ... - - @overload - def __init__(self, mapping: Mapping[str, Any], /): ... - - def __init__(self, *args, **kwargs): - super().__init__(*args, **kwargs) - - val_str = "9999-12-31T23:59:59.999Z" - val = isodate.parse_datetime(val_str) - dict_response = {"prop": (val_str, val_str)} - model = TupleModel(dict_response) - assert model["prop"] == (val_str, val_str) - assert model.prop == (val_str, val) - - -def test_list_of_tuple_deserialization_model(): - class Owner(Model): - name: str = rest_field() - pet: Pet = rest_field() - - @overload - def __init__(self, *, name: str, pet: Pet): ... - - @overload - def __init__(self, mapping: Mapping[str, Any], /): ... - - def __init__(self, *args, **kwargs): - super().__init__(*args, **kwargs) - - class ListOfTupleModel(Model): - prop: List[Tuple[Pet, Owner]] = rest_field() - - @overload - def __init__(self, *, prop: List[Tuple[Pet, Owner]]): ... - - @overload - def __init__(self, mapping: Mapping[str, Any], /): ... - - def __init__(self, *args, **kwargs): - super().__init__(*args, **kwargs) - - eugene = {"name": "Eugene", "species": "Dog"} - lady = {"name": "Lady", "species": "Newt"} - giacamo = {"name": "Giacamo", "pet": eugene} - elizabeth = {"name": "Elizabeth", "pet": lady} - - dict_response: Dict[str, Any] = {"prop": [(eugene, giacamo), (lady, elizabeth)]} - model = ListOfTupleModel(dict_response) - assert ( - model["prop"] - == model.prop - == [(eugene, giacamo), (lady, elizabeth)] - == [(Pet(eugene), Owner(giacamo)), (Pet(lady), Owner(elizabeth))] - ) - assert len(model.prop[0]) == len(model["prop"][0]) == 2 - assert model.prop[0][0].name == model.prop[0][0]["name"] == "Eugene" - assert model.prop[0][0].species == model.prop[0][0]["species"] == "Dog" - assert model.prop[0][1].name == "Giacamo" - assert model.prop[0][1].pet == model.prop[0][0] - assert model.prop[0][1].pet.name == model.prop[0][1]["pet"]["name"] == "Eugene" - assert model.prop[1][0] == model.prop[1][1].pet - - -class RecursiveModel(Model): - name: str = rest_field() - list_of_me: Optional[List["RecursiveModel"]] = rest_field(name="listOfMe") - dict_of_me: Optional[Dict[str, "RecursiveModel"]] = rest_field(name="dictOfMe") - dict_of_list_of_me: Optional[Dict[str, List["RecursiveModel"]]] = rest_field(name="dictOfListOfMe") - list_of_dict_of_me: Optional[List[Dict[str, "RecursiveModel"]]] = rest_field(name="listOfDictOfMe") - - @overload - def __init__( - self, - *, - name: str, - list_of_me: Optional[List["RecursiveModel"]] = None, - dict_of_me: Optional[Dict[str, "RecursiveModel"]] = None, - dict_of_list_of_me: Optional[Dict[str, List["RecursiveModel"]]] = None, - list_of_dict_of_me: Optional[List[Dict[str, "RecursiveModel"]]] = None, - ): ... - - @overload - def __init__(self, mapping: Mapping[str, Any], /): ... - - def __init__(self, *args, **kwargs): - super().__init__(*args, **kwargs) - - -def test_model_recursion_complex(): - dict_response = { - "name": "it's me!", - "listOfMe": [ - { - "name": "it's me!", - "listOfMe": None, - "dictOfMe": None, - "dictOfListOfMe": None, - "listOfDictOfMe": None, - } - ], - "dictOfMe": { - "me": { - "name": "it's me!", - "listOfMe": None, - "dictOfMe": None, - "dictOfListOfMe": None, - "listOfDictOfMe": None, - } - }, - "dictOfListOfMe": { - "many mes": [ - { - "name": "it's me!", - "listOfMe": None, - "dictOfMe": None, - "dictOfListOfMe": None, - "listOfDictOfMe": None, - } - ] - }, - "listOfDictOfMe": [ - { - "me": { - "name": "it's me!", - "listOfMe": None, - "dictOfMe": None, - "dictOfListOfMe": None, - "listOfDictOfMe": None, - } - } - ], - } - - model = RecursiveModel(dict_response) - assert model.name == model["name"] == "it's me!" - assert model["listOfMe"] == [ - { - "name": "it's me!", - "listOfMe": None, - "dictOfMe": None, - "dictOfListOfMe": None, - "listOfDictOfMe": None, - } - ] - assert model.list_of_me == [ - RecursiveModel( - { - "name": "it's me!", - "listOfMe": None, - "dictOfMe": None, - "dictOfListOfMe": None, - "listOfDictOfMe": None, - } - ) - ] - assert model.list_of_me - assert model.list_of_me[0].name == "it's me!" - assert model.list_of_me[0].list_of_me is None - assert isinstance(model.list_of_me, List) - assert isinstance(model.list_of_me[0], RecursiveModel) - - assert model["dictOfMe"] == { - "me": { - "name": "it's me!", - "listOfMe": None, - "dictOfMe": None, - "dictOfListOfMe": None, - "listOfDictOfMe": None, - } - } - assert model.dict_of_me == { - "me": RecursiveModel( - { - "name": "it's me!", - "listOfMe": None, - "dictOfMe": None, - "dictOfListOfMe": None, - "listOfDictOfMe": None, - } - ) - } - - assert isinstance(model.dict_of_me, Dict) - assert isinstance(model.dict_of_me["me"], RecursiveModel) - - assert model["dictOfListOfMe"] == { - "many mes": [ - { - "name": "it's me!", - "listOfMe": None, - "dictOfMe": None, - "dictOfListOfMe": None, - "listOfDictOfMe": None, - } - ] - } - assert model.dict_of_list_of_me == { - "many mes": [ - RecursiveModel( - { - "name": "it's me!", - "listOfMe": None, - "dictOfMe": None, - "dictOfListOfMe": None, - "listOfDictOfMe": None, - } - ) - ] - } - assert isinstance(model.dict_of_list_of_me, Dict) - assert isinstance(model.dict_of_list_of_me["many mes"], List) - assert isinstance(model.dict_of_list_of_me["many mes"][0], RecursiveModel) - - assert model["listOfDictOfMe"] == [ - { - "me": { - "name": "it's me!", - "listOfMe": None, - "dictOfMe": None, - "dictOfListOfMe": None, - "listOfDictOfMe": None, - } - } - ] - assert model.list_of_dict_of_me == [ - { - "me": RecursiveModel( - { - "name": "it's me!", - "listOfMe": None, - "dictOfMe": None, - "dictOfListOfMe": None, - "listOfDictOfMe": None, - } - ) - } - ] - assert isinstance(model.list_of_dict_of_me, List) - assert isinstance(model.list_of_dict_of_me[0], Dict) - assert isinstance(model.list_of_dict_of_me[0]["me"], RecursiveModel) - - assert model.as_dict() == model == dict_response - - -def test_literals(): - class LiteralModel(Model): - species: Literal["Mongoose", "Eagle", "Penguin"] = rest_field() - age: Literal[1, 2, 3] = rest_field() - - @overload - def __init__( - self, - *, - species: Literal["Mongoose", "Eagle", "Penguin"], - age: Literal[1, 2, 3], - ): ... - - @overload - def __init__(self, mapping: Mapping[str, Any], /): ... - - def __init__(self, *args, **kwargs): - super().__init__(*args, **kwargs) - - dict_response = {"species": "Mongoose", "age": 3} - model = LiteralModel(dict_response) - assert model.species == model["species"] == "Mongoose" - assert model.age == model["age"] == 3 - - dict_response = {"species": "invalid", "age": 5} - model = LiteralModel(dict_response) - assert model["species"] == "invalid" - assert model["age"] == 5 - - assert model.species == "invalid" - - assert model.age == 5 - - -def test_deserialization_callback_override(): - def _callback(obj): - return [str(entry) for entry in obj] - - class MyModel(Model): - prop: Sequence[float] = rest_field() - - @overload - def __init__(self, *, prop: Sequence[float]): ... - - @overload - def __init__(self, mapping: Mapping[str, Any], /): ... - - def __init__(self, *args, **kwargs): - super().__init__(*args, **kwargs) - - model_without_callback = MyModel(prop=[1.3, 2.4, 3.5]) - assert model_without_callback.prop == [1.3, 2.4, 3.5] - assert model_without_callback["prop"] == [1.3, 2.4, 3.5] - - class MyModel2(Model): - prop: Sequence[int] = rest_field(type=_callback) - - @overload - def __init__(self, *, prop: Any): ... - - @overload - def __init__(self, mapping: Mapping[str, Any], /): ... - - def __init__(self, *args, **kwargs): - super().__init__(*args, **kwargs) - - model_with_callback = MyModel2(prop=[1.3, 2.4, 3.5]) - assert model_with_callback.prop == ["1.3", "2.4", "3.5"] - assert model_with_callback["prop"] == ["1.3", "2.4", "3.5"] - - -def test_deserialization_callback_override_parent(): - class ParentNoCallback(Model): - prop: Sequence[float] = rest_field() - - @overload - def __init__(self, *, prop: Sequence[float]): ... - - @overload - def __init__(self, mapping: Mapping[str, Any], /): ... - - def __init__(self, *args, **kwargs): - super().__init__(*args, **kwargs) - - def _callback(obj): - return set([str(entry) for entry in obj]) - - class ChildWithCallback(ParentNoCallback): - prop: Sequence[float] = rest_field(type=_callback) - - @overload - def __init__(self, *, prop: Sequence[float]): ... - - @overload - def __init__(self, mapping: Mapping[str, Any], /): ... - - def __init__(self, *args, **kwargs): - super().__init__(*args, **kwargs) - - parent_model = ParentNoCallback(prop=[1, 1, 2, 3]) - assert parent_model.prop == parent_model["prop"] == [1, 1, 2, 3] - - child_model = ChildWithCallback(prop=[1, 1, 2, 3]) - assert child_model.prop == set(["1", "1", "2", "3"]) - assert child_model["prop"] == set(["1", "1", "2", "3"]) - - -def test_inheritance_basic(): - def _callback(obj): - return [str(e) for e in obj] - - class Parent(Model): - parent_prop: List[int] = rest_field(name="parentProp", type=_callback) - prop: str = rest_field() - - @overload - def __init__(self, *, parent_prop: List[int], prop: str): ... - - @overload - def __init__(self, mapping: Mapping[str, Any], /): ... - - def __init__(self, *args, **kwargs): - super().__init__(*args, **kwargs) - - class Child(Parent): - pass - - c = Child(parent_prop=[1, 2, 3], prop="hello") - assert c == {"parentProp": [1, 2, 3], "prop": "hello"} - assert c.parent_prop == ["1", "2", "3"] - assert c.prop == "hello" - - -class ParentA(Model): - prop: float = rest_field() - - @overload - def __init__(self, *, prop: Any): ... - - @overload - def __init__(self, mapping: Mapping[str, Any], /): ... - - def __init__(self, *args, **kwargs): - super().__init__(*args, **kwargs) - - -class ParentB(ParentA): - prop: str = rest_field() - bcd_prop: Optional[List["ParentB"]] = rest_field(name="bcdProp") - - @overload - def __init__(self, *, prop: Any, bcd_prop: Optional[List["ParentB"]] = None): ... - - @overload - def __init__(self, mapping: Mapping[str, Any], /): ... - - def __init__(self, *args, **kwargs): - super().__init__(*args, **kwargs) - - -class ParentC(ParentB): - prop: float = rest_field() - cd_prop: ParentA = rest_field(name="cdProp") - - @overload - def __init__(self, *, prop: Any, bcd_prop: List[ParentB], cd_prop: ParentA, **kwargs): ... - - @overload - def __init__(self, mapping: Mapping[str, Any], /): ... - - def __init__(self, *args, **kwargs): - super().__init__(*args, **kwargs) - - -class ChildD(ParentC): - d_prop: Tuple[ParentA, ParentB, ParentC, Optional["ChildD"]] = rest_field(name="dProp") - - @overload - def __init__( - self, - *, - prop: Any, - bcd_prop: List[ParentB], - cd_prop: ParentA, - d_prop: Tuple[ParentA, ParentB, ParentC, Optional["ChildD"]], - ): ... - - @overload - def __init__(self, mapping: Mapping[str, Any], /): ... - - def __init__(self, *args, **kwargs): - super().__init__(*args, **kwargs) - - -def test_model_dict_comparisons(): - class Inner(Model): - prop: str = rest_field() - - @overload - def __init__( - self, - *, - prop: str, - ): ... - - @overload - def __init__(self, mapping: Mapping[str, Any], /): ... - - def __init__(self, *args, **kwargs): - super().__init__(*args, **kwargs) - - class Outer(Model): - inner: Inner = rest_field() - - @overload - def __init__( - self, - *, - inner: Inner, - ): ... - - @overload - def __init__(self, mapping: Mapping[str, Any], /): ... - - def __init__(self, *args, **kwargs): - super().__init__(*args, **kwargs) - - def _tests(outer): - assert outer.inner.prop == outer["inner"].prop == outer.inner["prop"] == outer["inner"]["prop"] == "hello" - assert outer.inner == outer["inner"] == {"prop": "hello"} - assert outer == {"inner": {"prop": "hello"}} - - _tests(Outer(inner=Inner(prop="hello"))) - _tests(Outer({"inner": {"prop": "hello"}})) - - -def test_model_dict_comparisons_list(): - class Inner(Model): - prop: str = rest_field() - - @overload - def __init__( - self, - *, - prop: str, - ): ... - - @overload - def __init__(self, mapping: Mapping[str, Any], /): ... - - def __init__(self, *args, **kwargs): - super().__init__(*args, **kwargs) - - class Outer(Model): - inner: List[Inner] = rest_field() - - @overload - def __init__( - self, - *, - inner: List[Inner], - ): ... - - @overload - def __init__(self, mapping: Mapping[str, Any], /): ... - - def __init__(self, *args, **kwargs): - super().__init__(*args, **kwargs) - - def _tests(outer): - assert ( - outer.inner[0].prop - == outer["inner"][0].prop - == outer.inner[0]["prop"] - == outer["inner"][0]["prop"] - == "hello" - ) - assert outer.inner == outer["inner"] == [{"prop": "hello"}] - assert outer == {"inner": [{"prop": "hello"}]} - - _tests(Outer(inner=[Inner(prop="hello")])) - _tests(Outer({"inner": [{"prop": "hello"}]})) - - -def test_model_dict_comparisons_dict(): - class Inner(Model): - prop: str = rest_field() - - @overload - def __init__( - self, - *, - prop: str, - ): ... - - @overload - def __init__(self, mapping: Mapping[str, Any], /): ... - - def __init__(self, *args, **kwargs): - super().__init__(*args, **kwargs) - - class Outer(Model): - inner: Dict[str, Inner] = rest_field() - - @overload - def __init__( - self, - *, - inner: Dict[str, Inner], - ): ... - - @overload - def __init__(self, mapping: Mapping[str, Any], /): ... - - def __init__(self, *args, **kwargs): - super().__init__(*args, **kwargs) - - def _tests(outer): - assert ( - outer.inner["key"].prop - == outer["inner"]["key"].prop - == outer.inner["key"]["prop"] - == outer["inner"]["key"]["prop"] - == "hello" - ) - assert outer.inner == outer["inner"] == {"key": {"prop": "hello"}} - with pytest.raises(AttributeError): - outer.inner.key - assert outer.inner["key"] == outer["inner"]["key"] == {"prop": "hello"} - assert outer == {"inner": {"key": {"prop": "hello"}}} - - _tests(Outer(inner={"key": Inner(prop="hello")})) - _tests(Outer({"inner": {"key": {"prop": "hello"}}})) - - -def test_inheritance_4_levels(): - a = ParentA(prop=3.4) - assert a.prop == 3.4 - assert a["prop"] == 3.4 - assert a == {"prop": 3.4} - assert isinstance(a, Model) - - b = ParentB(prop=3.4, bcd_prop=[ParentB(prop=4.3)]) - assert b.prop == "3.4" - assert b["prop"] == 3.4 - assert b.bcd_prop == [ParentB(prop=4.3)] - assert b["bcdProp"] != [{"prop": 4.3, "bcdProp": None}] - assert b["bcdProp"] == [{"prop": 4.3}] - assert b.bcd_prop - assert b.bcd_prop[0].prop == "4.3" - assert b.bcd_prop[0].bcd_prop is None - assert b == {"prop": 3.4, "bcdProp": [{"prop": 4.3}]} - assert isinstance(b, ParentB) - assert isinstance(b, ParentA) - - c = ParentC(prop=3.4, bcd_prop=[b], cd_prop=a) - assert c.prop == c["prop"] == 3.4 - assert c.bcd_prop == [b] - assert c.bcd_prop - assert isinstance(c.bcd_prop[0], ParentB) - assert c["bcdProp"] == [b] == [{"prop": 3.4, "bcdProp": [{"prop": 4.3}]}] - assert c.cd_prop == a - assert c["cdProp"] == a == {"prop": 3.4} - assert isinstance(c.cd_prop, ParentA) - - d = ChildD( - prop=3.4, - bcd_prop=[b], - cd_prop=a, - d_prop=( - a, - b, - c, - ChildD(prop=3.4, bcd_prop=[b], cd_prop=a, d_prop=(a, b, c, None)), - ), - ) - assert d == { - "prop": 3.4, - "bcdProp": [b], - "cdProp": a, - "dProp": ( - a, - b, - c, - {"prop": 3.4, "bcdProp": [b], "cdProp": a, "dProp": (a, b, c, None)}, - ), - } - assert d.prop == d["prop"] == 3.4 - assert d.bcd_prop == [b] - assert d.bcd_prop - assert isinstance(d.bcd_prop[0], ParentB) - assert d.cd_prop == a - assert isinstance(d.cd_prop, ParentA) - assert d.d_prop[0] == a # at a - assert isinstance(d.d_prop[0], ParentA) - assert d.d_prop[1] == b - assert isinstance(d.d_prop[1], ParentB) - assert d.d_prop[2] == c - assert isinstance(d.d_prop[2], ParentC) - assert isinstance(d.d_prop[3], ChildD) - - assert isinstance(d.d_prop[3].d_prop[0], ParentA) - assert isinstance(d.d_prop[3].d_prop[1], ParentB) - assert isinstance(d.d_prop[3].d_prop[2], ParentC) - assert d.d_prop[3].d_prop[3] is None - - -def test_multiple_inheritance_basic(): - class ParentOne(Model): - parent_one_prop: str = rest_field(name="parentOneProp") - - @overload - def __init__( - self, - *, - parent_one_prop: str, - ): ... - - @overload - def __init__(self, mapping: Mapping[str, Any], /): ... - - def __init__(self, *args, **kwargs): - super().__init__(*args, **kwargs) - - class ParentTwo(Model): - parent_two_prop: int = rest_field(name="parentTwoProp", type=lambda x: str(x)) - - @overload - def __init__( - self, - *, - parent_two_prop: int, - ): ... - - @overload - def __init__(self, mapping: Mapping[str, Any], /): ... - - def __init__(self, *args, **kwargs): - super().__init__(*args, **kwargs) - - class Child(ParentOne, ParentTwo): - @overload - def __init__( - self, - *, - parent_one_prop: str, - parent_two_prop: int, - ): ... - - @overload - def __init__(self, mapping: Mapping[str, Any], /): ... - - def __init__(self, *args, **kwargs): - super().__init__(*args, **kwargs) - - c = Child(parent_one_prop="Hello", parent_two_prop=3) - assert c == {"parentOneProp": "Hello", "parentTwoProp": 3} - assert c.parent_one_prop == "Hello" - assert c.parent_two_prop == "3" - assert isinstance(c, Child) - assert isinstance(c, ParentOne) - assert isinstance(c, ParentTwo) - - -def test_multiple_inheritance_mro(): - class A(Model): - prop: str = rest_field() - - @overload - def __init__(self, *, prop: str) -> None: ... - - @overload - def __init__(self, mapping: Mapping[str, Any], /): ... - - def __init__(self, *args, **kwargs): - super().__init__(*args, **kwargs) - - class B(Model): - prop: int = rest_field(type=lambda x: int(x)) - - @overload - def __init__(self, *, prop: str) -> None: ... - - @overload - def __init__(self, mapping: Mapping[str, Any], /): ... - - def __init__(self, *args, **kwargs): - super().__init__(*args, **kwargs) - - class C(A, B): - pass - - assert A(prop="1").prop == "1" - assert B(prop="1").prop == 1 - assert C(prop="1").prop == "1" # A should take precedence over B - - -class Feline(Model): - meows: bool = rest_field() - hisses: bool = rest_field() - siblings: Optional[List["Feline"]] = rest_field() - - @overload - def __init__( - self, - *, - meows: bool, - hisses: bool, - siblings: Optional[List["Feline"]] = None, - ): ... - - @overload - def __init__(self, mapping: Mapping[str, Any], /): ... - - def __init__(self, *args, **kwargs): - super().__init__(*args, **kwargs) - - -class Owner(Model): - first_name: str = rest_field(name="firstName", type=lambda x: x.capitalize()) - last_name: str = rest_field(name="lastName", type=lambda x: x.capitalize()) - - @overload - def __init__( - self, - *, - first_name: str, - last_name: str, - ): ... - - @overload - def __init__(self, mapping: Mapping[str, Any], /): ... - - def __init__(self, *args, **kwargs): - super().__init__(*args, **kwargs) - - -class PetModel(Model): - name: str = rest_field() - owner: Owner = rest_field() - - @overload - def __init__(self, *, name: str, owner: Owner): ... - - @overload - def __init__(self, mapping: Mapping[str, Any], /): ... - - def __init__(self, *args, **kwargs): - super().__init__(*args, **kwargs) - - -class Cat(PetModel, Feline): - likes_milk: bool = rest_field(name="likesMilk", type=lambda x: True) - - @overload - def __init__( - self, - *, - name: str, - owner: Owner, - meows: bool, - hisses: bool, - likes_milk: bool, - siblings: Optional[List[Feline]], - ): ... - - @overload - def __init__(self, mapping: Mapping[str, Any], /): ... - - def __init__(self, *args, **kwargs): - super().__init__(*args, **kwargs) - - -class CuteThing(Model): - how_cute_am_i: float = rest_field(name="howCuteAmI") - - @overload - def __init__(self, *, how_cute_am_i: float): ... - - @overload - def __init__(self, mapping: Mapping[str, Any], /): ... - - def __init__(self, *args, **kwargs): - super().__init__(*args, **kwargs) - - -class Kitten(Cat, CuteThing): - eats_mice_yet: bool = rest_field(name="eatsMiceYet") - - @overload - def __init__( - self, - *, - name: str, - owner: Owner, - meows: bool, - hisses: bool, - likes_milk: bool, - siblings: Optional[List[Feline]], - how_cute_am_i: float, - eats_mice_yet: bool, - ): ... - - @overload - def __init__(self, mapping: Mapping[str, Any], /): ... - - def __init__(self, *args, **kwargs): - super().__init__(*args, **kwargs) - - -def test_multiple_inheritance_complex(): - cat = Cat( - name="Stephanie", - owner=Owner(first_name="cecil", last_name="cai"), # gets capitalized in attr - meows=True, - hisses=True, - likes_milk=False, # likes_milk will change to True on the attribute - siblings=[Feline(meows=True, hisses=False)], - ) - assert cat == { - "name": "Stephanie", - "owner": { - "firstName": "cecil", - "lastName": "cai", - }, - "meows": True, - "hisses": True, - "likesMilk": False, - "siblings": [ - { - "meows": True, - "hisses": False, - } - ], - } - assert cat.name == "Stephanie" - assert isinstance(cat.owner, Owner) - assert cat.owner.first_name == "Cecil" - assert cat.owner.last_name == "Cai" - assert cat.meows - assert cat.hisses - assert cat.likes_milk - assert cat.siblings - assert len(cat.siblings) == 1 - assert isinstance(cat.siblings[0], Feline) - - kitten = Kitten( - name="Stephanie", - owner=Owner(first_name="cecil", last_name="cai"), # gets capitalized in attr - meows=True, - hisses=True, - likes_milk=False, # likes_milk will change to True on the attribute - siblings=[Feline(meows=True, hisses=False)], - how_cute_am_i=1.0, - eats_mice_yet=True, - ) - assert kitten != { - "name": "Stephanie", - "owner": { - "firstName": "cecil", - "lastName": "cai", - }, - "meows": True, - "hisses": True, - "likesMilk": False, - "siblings": [{"meows": True, "hisses": False, "siblings": None}], # we don't automatically set None here - "howCuteAmI": 1.0, - "eatsMiceYet": True, - } - assert kitten == { - "name": "Stephanie", - "owner": { - "firstName": "cecil", - "lastName": "cai", - }, - "meows": True, - "hisses": True, - "likesMilk": False, - "siblings": [ - { - "meows": True, - "hisses": False, - } - ], - "howCuteAmI": 1.0, - "eatsMiceYet": True, - } - assert kitten.name == "Stephanie" - assert isinstance(kitten.owner, Owner) - assert kitten.owner.first_name == "Cecil" - assert kitten.owner.last_name == "Cai" - assert kitten.meows - assert kitten.hisses - assert kitten.likes_milk - assert kitten.siblings - assert len(kitten.siblings) == 1 - assert isinstance(kitten.siblings[0], Feline) - assert kitten.eats_mice_yet - assert kitten.how_cute_am_i == 1.0 - assert isinstance(kitten, PetModel) - assert isinstance(kitten, Cat) - assert isinstance(kitten, Feline) - assert isinstance(kitten, CuteThing) - - -class A(Model): - b: "B" = rest_field() - - @overload - def __init__(self, b: "B"): ... - - @overload - def __init__(self, mapping: Mapping[str, Any], /): ... - - def __init__(self, *args, **kwargs): - super().__init__(*args, **kwargs) - - -class B(Model): - c: "C" = rest_field() - - @overload - def __init__(self, *, c: "C"): ... - - @overload - def __init__(self, mapping: Mapping[str, Any], /): ... - - def __init__(self, *args, **kwargs): - super().__init__(*args, **kwargs) - - -class C(Model): - d: str = rest_field() - - @overload - def __init__(self, *, d: str): ... - - @overload - def __init__(self, mapping: Mapping[str, Any], /): ... - - def __init__(self, *args, **kwargs): - super().__init__(*args, **kwargs) - - -def test_nested_creation(): - a = A({"b": {"c": {"d": "hello"}}}) - assert isinstance(a["b"], Model) - assert isinstance(a["b"]["c"], Model) - assert a["b"]["c"] == a["b"].c == a.b.c == {"d": "hello"} - - assert ( - a["b"]["c"]["d"] - == a["b"].c.d - == a.b["c"].d - == a["b"]["c"].d - == a["b"].c["d"] - == a.b["c"]["d"] - == a.b.c.d - == "hello" - ) - - -def test_nested_setting(): - a = A({"b": {"c": {"d": "hello"}}}) - - # set with dict - a["b"]["c"]["d"] = "setwithdict" - assert ( - a["b"]["c"]["d"] - == a["b"].c.d - == a.b["c"].d - == a["b"]["c"].d - == a["b"].c["d"] - == a.b["c"]["d"] - == a.b.c.d - == "setwithdict" - ) - - # set with attr - a.b.c.d = "setwithattr" - assert a["b"]["c"]["d"] == "setwithattr" - assert ( - a["b"]["c"]["d"] - == a["b"].c.d - == a.b["c"].d - == a["b"]["c"].d - == a["b"].c["d"] - == a.b["c"]["d"] - == a.b.c.d - == "setwithattr" - ) - - -class BaseModel(Model): - inner_model: "InnerModel" = rest_field(name="innerModel") - - @overload - def __init__(self, *, inner_model: "InnerModel"): ... - - @overload - def __init__(self, mapping: Mapping[str, Any], /): ... - - def __init__(self, *args, **kwargs): - super().__init__(*args, **kwargs) - - -class InnerModel(Model): - datetime_field: datetime.datetime = rest_field(name="datetimeField") - - @overload - def __init__(self, *, datetime_field: datetime.datetime): ... - - @overload - def __init__(self, mapping: Mapping[str, Any], /): ... - - def __init__(self, *args, **kwargs): - super().__init__(*args, **kwargs) - - -def test_nested_deserialization(): - serialized_datetime = "9999-12-31T23:59:59.999Z" - - model = BaseModel({"innerModel": {"datetimeField": serialized_datetime}}) - assert model.inner_model["datetimeField"] == model["innerModel"]["datetimeField"] == serialized_datetime - assert ( - model.inner_model.datetime_field - == model["innerModel"].datetime_field - == isodate.parse_datetime(serialized_datetime) - ) - - new_serialized_datetime = "2022-12-31T23:59:59.999Z" - model.inner_model.datetime_field = isodate.parse_datetime(new_serialized_datetime) - assert model.inner_model["datetimeField"] == "2022-12-31T23:59:59.999000Z" - - -class X(Model): - y: "Y" = rest_field() - - @overload - def __init__(self, *, y: "Y"): ... - - @overload - def __init__(self, mapping: Mapping[str, Any], /): ... - - def __init__(self, *args, **kwargs): - super().__init__(*args, **kwargs) - - -class Y(Model): - z: "Z" = rest_field() - - @overload - def __init__(self, *, z: "Z"): ... - - @overload - def __init__(self, mapping: Mapping[str, Any], /): ... - - def __init__(self, *args, **kwargs): - super().__init__(*args, **kwargs) - - -class Z(Model): - zval: datetime.datetime = rest_field() - - @overload - def __init__(self, *, zval: datetime.datetime): ... - - @overload - def __init__(self, mapping: Mapping[str, Any], /): ... - - def __init__(self, *args, **kwargs): - super().__init__(*args, **kwargs) - - -def test_nested_update(): - serialized_datetime = "9999-12-31T23:59:59.999Z" - parsed_datetime = isodate.parse_datetime(serialized_datetime) - x = X({"y": {"z": {"zval": serialized_datetime}}}) - assert x.y.z.zval == x["y"].z.zval == x.y["z"].zval == x["y"]["z"].zval == parsed_datetime - assert x.y.z["zval"] == x.y["z"]["zval"] == x["y"].z["zval"] == x["y"]["z"]["zval"] == serialized_datetime - - -def test_deserialization_is(): - # test without datetime deserialization - a = A({"b": {"c": {"d": "hello"}}}) - assert a.b is a.b - assert a.b.c is a.b.c - assert a.b.c.d is a.b.c.d - - serialized_datetime = "9999-12-31T23:59:59.999Z" - x = X({"y": {"z": {"zval": serialized_datetime}}}) - assert x.y is x.y - assert x.y.z is x.y.z - - assert x.y.z.zval == isodate.parse_datetime(serialized_datetime) - - -class InnerModelWithReadonly(Model): - normal_property: str = rest_field(name="normalProperty") - readonly_property: str = rest_field(name="readonlyProperty", visibility=["read"]) - - @overload - def __init__(self, *, normal_property: str): ... - - @overload - def __init__(self, mapping: Mapping[str, Any], /): ... - - def __init__(self, *args, **kwargs): - super().__init__(*args, **kwargs) - - -class ModelWithReadonly(Model): - normal_property: str = rest_field(name="normalProperty") - readonly_property: str = rest_field(name="readonlyProperty", visibility=["read"]) - inner_model: InnerModelWithReadonly = rest_field(name="innerModel") - - @overload - def __init__(self, *, normal_property: str): ... - - @overload - def __init__(self, mapping: Mapping[str, Any], /): ... - - def __init__(self, *args, **kwargs): - super().__init__(*args, **kwargs) - - -def test_readonly(): - # we pass the dict to json, so readonly shouldn't show up in the JSON version - value = { - "normalProperty": "normal", - "readonlyProperty": "readonly", - "innerModel": {"normalProperty": "normal", "readonlyProperty": "readonly"}, - } - model = ModelWithReadonly(value) - assert model.as_dict(exclude_readonly=True) == { - "normalProperty": "normal", - "innerModel": {"normalProperty": "normal"}, - } - assert json.loads(json.dumps(model, cls=SdkJSONEncoder)) == value - assert model == value - assert model["readonlyProperty"] == model.readonly_property == "readonly" - assert model["innerModel"]["readonlyProperty"] == model.inner_model.readonly_property == "readonly" - - -def test_readonly_set(): - value = { - "normalProperty": "normal", - "readonlyProperty": "readonly", - "innerModel": {"normalProperty": "normal", "readonlyProperty": "readonly"}, - } - - model = ModelWithReadonly(value) - assert model.normal_property == model["normalProperty"] == "normal" - assert model.readonly_property == model["readonlyProperty"] == "readonly" - assert model.inner_model.normal_property == model.inner_model["normalProperty"] == "normal" - assert model.inner_model.readonly_property == model.inner_model["readonlyProperty"] == "readonly" - - assert model.as_dict(exclude_readonly=True) == { - "normalProperty": "normal", - "innerModel": {"normalProperty": "normal"}, - } - assert json.loads(json.dumps(model, cls=SdkJSONEncoder)) == value - - model["normalProperty"] = "setWithDict" - model["readonlyProperty"] = "setWithDict" - model.inner_model["normalProperty"] = "setWithDict" - model.inner_model["readonlyProperty"] = "setWithDict" - - assert model.normal_property == model["normalProperty"] == "setWithDict" - assert model.readonly_property == model["readonlyProperty"] == "setWithDict" - assert model.inner_model.normal_property == model.inner_model["normalProperty"] == "setWithDict" - assert model.inner_model.readonly_property == model.inner_model["readonlyProperty"] == "setWithDict" - assert model.as_dict(exclude_readonly=True) == { - "normalProperty": "setWithDict", - "innerModel": {"normalProperty": "setWithDict"}, - } - assert json.loads(json.dumps(model, cls=SdkJSONEncoder)) == { - "normalProperty": "setWithDict", - "readonlyProperty": "setWithDict", - "innerModel": { - "normalProperty": "setWithDict", - "readonlyProperty": "setWithDict", - }, - } - - -def test_incorrect_initialization(): - class MyModel(Model): - id: int = rest_field() - field: str = rest_field() - - @overload - def __init__( - self, - *, - id: int, - field: str, - ): ... - - @overload - def __init__(self, mapping: Mapping[str, Any], /): ... - - def __init__(self, *args, **kwargs): - super().__init__(*args, **kwargs) - - with pytest.raises(TypeError): - MyModel(1, "field") - - with pytest.raises(TypeError): - MyModel(id=1, field="field", unknown="me") - - -def test_serialization_initialization_and_setting(): - serialized_datetime = "9999-12-31T23:59:59.999000Z" - parsed_datetime = isodate.parse_datetime(serialized_datetime) - - # pass in parsed - z = Z(zval=parsed_datetime) - assert z.zval == parsed_datetime - assert z["zval"] == serialized_datetime - - # pass in dict - z = Z({"zval": serialized_datetime}) - assert z.zval == parsed_datetime - assert z["zval"] == serialized_datetime - - # assert setting - serialized_datetime = "2022-12-31T23:59:59.999000Z" - z.zval = isodate.parse_datetime(serialized_datetime) - assert z["zval"] == serialized_datetime - - -def test_copy_of_input(): - class TestModel(Model): - data: List[int] = rest_field() - - @overload - def __init__(self, *, data: List[int]): ... - - @overload - def __init__(self, mapping: Mapping[str, Any], /): ... - - def __init__(self, *args, **kwargs): - super().__init__(*args, **kwargs) - - raw = [1, 2, 3] - m = TestModel(data=raw) - assert not m.data is raw - assert m.data == raw - raw.append(4) - assert m.data == [1, 2, 3] - - -def test_inner_model_custom_serializer(): - class InnerModel(Model): - prop: str = rest_field(type=lambda x: x[::-1]) - - @overload - def __init__(self, *, prop: str): ... - - @overload - def __init__(self, mapping: Mapping[str, Any], /): ... - - def __init__(self, *args, **kwargs): - super().__init__(*args, **kwargs) - - class OuterModel(Model): - innie: InnerModel = rest_field() - - @overload - def __init__(self, *, innie: InnerModel): ... - - @overload - def __init__(self, mapping: Mapping[str, Any], /): ... - - def __init__(self, *args, **kwargs): - super().__init__(*args, **kwargs) - - outer = OuterModel({"innie": {"prop": "hello"}}) - assert outer.innie["prop"] == outer["innie"]["prop"] == "hello" - assert outer.innie.prop == outer["innie"].prop == "olleh" # cspell:disable-line - - -def test_default_value(): - class MyModel(Model): - prop_default_str: str = rest_field(name="propDefaultStr", default="hello") - prop_optional_str: Optional[str] = rest_field(name="propOptionalStr", default=None) - prop_default_int: int = rest_field(name="propDefaultInt", default=1) - prop_optional_int: Optional[int] = rest_field(name="propOptionalInt", default=None) - - @overload - def __init__( - self, - *, - prop_default_str: str = "hello", - prop_optional_str: Optional[str] = "propOptionalStr", - prop_default_int: int = 1, - prop_optional_int: Optional[int] = None, - ): ... - - @overload - def __init__(self, mapping: Mapping[str, Any], /): ... - - def __init__(self, *args, **kwargs): - super().__init__(*args, **kwargs) - - my_model = MyModel() - assert my_model.prop_default_str == my_model["propDefaultStr"] == "hello" - assert my_model.prop_optional_str is my_model["propOptionalStr"] is None - assert my_model.prop_default_int == my_model["propDefaultInt"] == 1 - assert my_model.prop_optional_int is my_model["propOptionalInt"] is None - assert my_model == { - "propDefaultStr": "hello", - "propOptionalStr": None, - "propDefaultInt": 1, - "propOptionalInt": None, - } - - my_model = MyModel(prop_default_str="goodbye") - assert my_model.prop_default_str == my_model["propDefaultStr"] == "goodbye" - assert my_model.prop_optional_str is my_model["propOptionalStr"] is None - assert my_model.prop_default_int == my_model["propDefaultInt"] == 1 - assert my_model.prop_optional_int is my_model["propOptionalInt"] is None - assert my_model == { - "propDefaultStr": "goodbye", - "propOptionalStr": None, - "propDefaultInt": 1, - "propOptionalInt": None, - } - - my_model = MyModel(prop_optional_int=4) - assert my_model.prop_default_str == my_model["propDefaultStr"] == "hello" - assert my_model.prop_optional_str is my_model["propOptionalStr"] is None - assert my_model.prop_default_int == my_model["propDefaultInt"] == 1 - assert my_model.prop_optional_int == my_model["propOptionalInt"] == 4 - assert my_model == { - "propDefaultStr": "hello", - "propOptionalStr": None, - "propDefaultInt": 1, - "propOptionalInt": 4, - } - - my_model = MyModel({"propDefaultInt": 5}) - assert my_model.prop_default_str == my_model["propDefaultStr"] == "hello" - assert my_model.prop_optional_str is my_model["propOptionalStr"] is None - assert my_model.prop_default_int == my_model["propDefaultInt"] == 5 - assert my_model.prop_optional_int is my_model["propOptionalInt"] is None - assert my_model == { - "propDefaultStr": "hello", - "propOptionalStr": None, - "propDefaultInt": 5, - "propOptionalInt": None, - } - - -def test_pass_models_in_dict(): - class Inner(Model): - str_property: str = rest_field(name="strProperty") - - @overload - def __init__( - self, - *, - str_property: str, - ): ... - - @overload - def __init__(self, mapping: Mapping[str, Any], /): ... - - def __init__(self, *args, **kwargs): - super().__init__(*args, **kwargs) - - class Outer(Model): - inner_property: Inner = rest_field(name="innerProperty") - - @overload - def __init__( - self, - *, - inner_property: Inner, - ): ... - - @overload - def __init__(self, mapping: Mapping[str, Any], /): ... - - def __init__(self, *args, **kwargs): - super().__init__(*args, **kwargs) - - def _tests(model: Outer): - assert ( - {"innerProperty": {"strProperty": "hello"}} - == {"innerProperty": Inner(str_property="hello")} - == {"innerProperty": Inner({"strProperty": "hello"})} - == Outer(inner_property=Inner(str_property="hello")) - == Outer(inner_property=Inner({"strProperty": "hello"})) - == Outer({"innerProperty": {"strProperty": "hello"}}) - == Outer({"innerProperty": Inner(str_property="hello")}) - == Outer({"innerProperty": Inner({"strProperty": "hello"})}) - == model - ) - - _tests(Outer(inner_property=Inner(str_property="hello"))) - _tests(Outer(inner_property=Inner({"strProperty": "hello"}))) - _tests(Outer({"innerProperty": {"strProperty": "hello"}})) - _tests(Outer({"innerProperty": Inner(str_property="hello")})) - _tests(Outer({"innerProperty": Inner({"strProperty": "hello"})})) - - -def test_mutability_list(): - class Inner(Model): - str_property: str = rest_field(name="strProperty") - - @overload - def __init__( - self, - *, - str_property: str, - ): ... - - @overload - def __init__(self, mapping: Mapping[str, Any], /): ... - - def __init__(self, *args, **kwargs): - super().__init__(*args, **kwargs) - - class Middle(Model): - inner_property: List[Inner] = rest_field(name="innerProperty") - prop: str = rest_field() - - @overload - def __init__( - self, - *, - inner_property: List[Inner], - prop: str, - ): ... - - @overload - def __init__(self, mapping: Mapping[str, Any], /): ... - - def __init__(self, *args, **kwargs): - super().__init__(*args, **kwargs) - - class Outer(Model): - middle_property: Middle = rest_field(name="middleProperty") - - @overload - def __init__( - self, - *, - middle_property: Model, - ): ... - - @overload - def __init__(self, mapping: Mapping[str, Any], /): ... - - def __init__(self, *args, **kwargs): - super().__init__(*args, **kwargs) - - original_dict = { - "middleProperty": { - "innerProperty": [{"strProperty": "hello"}], - "prop": "original", - } - } - model = Outer(original_dict) - assert model is not original_dict - - # set with dict syntax - assert model.middle_property is model["middleProperty"] - middle_property = model.middle_property - middle_property["prop"] = "new" - assert model["middleProperty"] is model.middle_property is middle_property - assert model["middleProperty"]["prop"] == model.middle_property.prop == "new" - - # set with attr syntax - middle_property.prop = "newest" - assert model["middleProperty"] is model.middle_property is middle_property - assert model["middleProperty"]["prop"] == model.middle_property.prop == "newest" - - # modify innerproperty list - assert model["middleProperty"]["innerProperty"][0] is model.middle_property.inner_property[0] - assert ( - model["middleProperty"]["innerProperty"][0] - is model.middle_property["innerProperty"][0] - is model["middleProperty"].inner_property[0] - is model.middle_property.inner_property[0] - ) - inner_property = model["middleProperty"]["innerProperty"][0] - - # set with dict syntax - inner_property["strProperty"] = "nihao" - assert ( - model["middleProperty"]["innerProperty"][0] - is model.middle_property["innerProperty"][0] - is model["middleProperty"].inner_property[0] - is model.middle_property.inner_property[0] - ) - assert ( - model["middleProperty"]["innerProperty"][0]["strProperty"] - == model.middle_property["innerProperty"][0]["strProperty"] - == model["middleProperty"].inner_property[0]["strProperty"] - == model.middle_property.inner_property[0]["strProperty"] - == model["middleProperty"]["innerProperty"][0].str_property - == model.middle_property["innerProperty"][0].str_property - == model["middleProperty"].inner_property[0].str_property - == model.middle_property.inner_property[0].str_property - == "nihao" - ) - - -def test_mutability_dict(): - class Inner(Model): - str_property: str = rest_field(name="strProperty") - - @overload - def __init__( - self, - *, - str_property: str, - ): ... - - @overload - def __init__(self, mapping: Mapping[str, Any], /): ... - - def __init__(self, *args, **kwargs): - super().__init__(*args, **kwargs) - - class Middle(Model): - inner_property: Dict[str, Inner] = rest_field(name="innerProperty") - prop: str = rest_field() - - @overload - def __init__( - self, - *, - inner_property: Dict[str, Inner], - prop: str, - ): ... - - @overload - def __init__(self, mapping: Mapping[str, Any], /): ... - - def __init__(self, *args, **kwargs): - super().__init__(*args, **kwargs) - - class Outer(Model): - middle_property: Middle = rest_field(name="middleProperty") - - @overload - def __init__( - self, - *, - middle_property: Model, - ): ... - - @overload - def __init__(self, mapping: Mapping[str, Any], /): ... - - def __init__(self, *args, **kwargs): - super().__init__(*args, **kwargs) - - original_dict = { - "middleProperty": { - "innerProperty": {"inner": {"strProperty": "hello"}}, - "prop": "original", - } - } - model = Outer(original_dict) - assert model is not original_dict - - # set with dict syntax - assert model.middle_property is model["middleProperty"] - middle_property = model.middle_property - middle_property["prop"] = "new" - assert model["middleProperty"] is model.middle_property is middle_property - assert ( - model["middleProperty"]["prop"] - == model["middleProperty"].prop - == model.middle_property.prop - == model.middle_property["prop"] - == "new" - ) - - # set with attr syntax - middle_property.prop = "newest" - assert model["middleProperty"] is model.middle_property is middle_property - assert model["middleProperty"]["prop"] == model.middle_property.prop == "newest" - - # modify innerproperty list - assert model["middleProperty"]["innerProperty"]["inner"] is model.middle_property.inner_property["inner"] - assert ( - model["middleProperty"]["innerProperty"]["inner"] - is model.middle_property["innerProperty"]["inner"] - is model["middleProperty"].inner_property["inner"] - is model.middle_property.inner_property["inner"] - ) - inner_property = model["middleProperty"]["innerProperty"]["inner"] - - # set with dict syntax - inner_property["strProperty"] = "nihao" - assert ( - model["middleProperty"]["innerProperty"]["inner"] - is model.middle_property["innerProperty"]["inner"] - is model["middleProperty"].inner_property["inner"] - is model.middle_property.inner_property["inner"] - ) - assert ( - model["middleProperty"]["innerProperty"]["inner"]["strProperty"] - == model.middle_property["innerProperty"]["inner"]["strProperty"] - == model["middleProperty"].inner_property["inner"]["strProperty"] - == model.middle_property.inner_property["inner"]["strProperty"] - == model["middleProperty"]["innerProperty"]["inner"].str_property - == model.middle_property["innerProperty"]["inner"].str_property - == model["middleProperty"].inner_property["inner"].str_property - == model.middle_property.inner_property["inner"].str_property - == "nihao" - ) - - -def test_del_model(): - class TestModel(Model): - x: Optional[int] = rest_field() - - my_dict = {} - my_dict["x"] = None - - assert my_dict["x"] is None - - my_model = TestModel({}) - my_model["x"] = None - - assert my_model["x"] is my_model.x is None - - my_model = TestModel({"x": 7}) - my_model.x = None - - assert "x" not in my_model - assert my_model.x is None - - with pytest.raises(KeyError): - del my_model["x"] - my_model.x = 8 - - del my_model["x"] - assert "x" not in my_model - assert my_model.x is my_model.get("x") is None - - with pytest.raises(AttributeError): - del my_model.x - my_model.x = None - assert "x" not in my_model - assert my_model.x is my_model.get("x") is None - - -def test_pop_model(): - class Inner(Model): - str_property: str = rest_field(name="strProperty") - - @overload - def __init__( - self, - *, - str_property: str, - ): ... - - @overload - def __init__(self, mapping: Mapping[str, Any], /): ... - - def __init__(self, *args, **kwargs): - super().__init__(*args, **kwargs) - - class Middle(Model): - inner_property: Dict[str, Inner] = rest_field(name="innerProperty") - prop: str = rest_field() - - @overload - def __init__( - self, - *, - inner_property: Dict[str, Inner], - prop: str, - ): ... - - @overload - def __init__(self, mapping: Mapping[str, Any], /): ... - - def __init__(self, *args, **kwargs): - super().__init__(*args, **kwargs) - - class Outer(Model): - middle_property: Middle = rest_field(name="middleProperty") - - @overload - def __init__( - self, - *, - middle_property: Model, - ): ... - - @overload - def __init__(self, mapping: Mapping[str, Any], /): ... - - def __init__(self, *args, **kwargs): - super().__init__(*args, **kwargs) - - original_dict = { - "middleProperty": { - "innerProperty": {"inner": {"strProperty": "hello"}}, - "prop": "original", - } - } - model_dict = Outer(original_dict) # model we will access with dict syntax - model_attr = Outer(original_dict) # model we will access with attr syntax - - assert model_dict is not original_dict is not model_attr - assert ( - original_dict["middleProperty"]["innerProperty"]["inner"].pop("strProperty") - == model_dict["middleProperty"]["innerProperty"]["inner"].pop("strProperty") - == model_attr.middle_property.inner_property["inner"].pop("strProperty") - == "hello" - ) - - with pytest.raises(KeyError): - original_dict["middleProperty"]["innerProperty"]["inner"].pop("strProperty") - with pytest.raises(KeyError): - model_dict["middleProperty"]["innerProperty"]["inner"].pop("strProperty") - with pytest.raises(KeyError): - model_attr.middle_property.inner_property["inner"].pop("strProperty") - - -def test_contains(): - class ParentA(Model): - a_prop: str = rest_field(name="aProp") - - @overload - def __init__( - self, - *, - a_prop: str, - ): ... - - @overload - def __init__(self, mapping: Mapping[str, Any], /): ... - - def __init__(self, *args, **kwargs): - super().__init__(*args, **kwargs) - - class ParentB(Model): - b_prop: str = rest_field(name="bProp") - - @overload - def __init__( - self, - *, - b_prop: str, - ): ... - - @overload - def __init__(self, mapping: Mapping[str, Any], /): ... - - def __init__(self, *args, **kwargs): - super().__init__(*args, **kwargs) - - class ChildC(ParentA, ParentB): - c_prop: str = rest_field(name="cProp") - - @overload - def __init__( - self, - *, - a_prop: str, - b_prop: str, - c_prop: str, - ): ... - - @overload - def __init__(self, mapping: Mapping[str, Any], /): ... - - def __init__(self, *args, **kwargs): - super().__init__(*args, **kwargs) - - parent_a_dict = {"aProp": "a"} - assert "aProp" in parent_a_dict - - parent_a = ParentA(parent_a_dict) - assert "aProp" in parent_a - assert not "a_prop" in parent_a - - parent_a.a_prop = None # clear it out - assert "aProp" not in parent_a - - parent_b_dict = {"bProp": "b"} - assert "bProp" in parent_b_dict - - parent_b = ParentB(parent_b_dict) - assert "bProp" in parent_b - assert "b_prop" not in parent_b - - parent_b.b_prop = None # clear it out - assert "bProp" not in parent_b - - props = ["aProp", "bProp", "cProp"] - child_c_dict = {"aProp": "a", "bProp": "b", "cProp": "c"} - assert all(p for p in props if p in child_c_dict) - - child_c = ChildC(child_c_dict) - assert all(p for p in props if p in child_c) - assert not any(p for p in ["a_prop", "b_prop", "c_prop"] if p in child_c) - - child_c.a_prop = None - child_c.b_prop = None - child_c.c_prop = None - - assert not any(p for p in props if p in child_c) - - -def test_iter(): - dict_response = { - "platformUpdateDomainCount": 5, - "platformFaultDomainCount": 3, - "virtualMachines": [], - } - assert isinstance(iter(dict_response), Iterable) - model = BasicResource(dict_response) - assert isinstance(iter(model), Iterable) - - assert ( - list(iter(dict_response)) - == list(iter(model)) - == ["platformUpdateDomainCount", "platformFaultDomainCount", "virtualMachines"] - ) - - -def test_len(): - dict_response = { - "platformUpdateDomainCount": 5, - "platformFaultDomainCount": 3, - "virtualMachines": [], - } - model = BasicResource(dict_response) - assert len(dict_response) == len(model) == 3 - - dict_response.pop("platformUpdateDomainCount") - model.pop("platformUpdateDomainCount") - assert len(dict_response) == len(model) == 2 - - -def test_keys(): - class Inner(Model): - str_prop: str = rest_field(name="strProp") - - class Outer(Model): - inner_prop: Inner = rest_field(name="innerProp") - - outer_dict = {"innerProp": {"strProp": "hello"}} - outer = Outer(outer_dict) - assert outer.keys() == outer_dict.keys() - outer_dict["newProp"] = "hello" - outer["newProp"] = "hello" - - assert outer.keys() == outer_dict.keys() - - outer_dict.pop("newProp") - outer.pop("newProp") - assert outer_dict.keys() == outer.keys() - - -def test_values(): - class Inner(Model): - str_prop: str = rest_field(name="strProp") - - class Outer(Model): - inner_prop: Inner = rest_field(name="innerProp") - - outer_dict = {"innerProp": {"strProp": "hello"}} - outer = Outer(outer_dict) - - assert list(outer.values()) == list(outer_dict.values()) - assert len(outer.values()) == len(outer_dict.values()) == 1 - assert list(outer.values())[0]["strProp"] == list(outer_dict.values())[0]["strProp"] == "hello" - - outer_dict["innerProp"]["strProp"] = "goodbye" - outer.inner_prop.str_prop = "goodbye" - - assert list(outer.inner_prop.values()) == list(outer_dict["innerProp"].values()) - - -def test_items(): - class Inner(Model): - str_prop: str = rest_field(name="strProp") - - class Outer(Model): - inner_prop: Inner = rest_field(name="innerProp") - - outer_dict = {"innerProp": {"strProp": "hello"}} - outer = Outer(outer_dict) - - assert list(outer.items()) == list(outer_dict.items()) - - outer_dict["innerProp"]["strProp"] = "goodbye" - outer.inner_prop.str_prop = "goodbye" - - assert list(outer.inner_prop.items()) == list(outer_dict["innerProp"].items()) - - outer_dict["newProp"] = "bonjour" - outer["newProp"] = "bonjour" - - assert list(outer.items()) == list(outer_dict.items()) - - -def test_get(): - class MyModel(Model): - prop: str = rest_field() - rest_prop: str = rest_field(name="restProp") - - my_dict = {"prop": "hello", "restProp": "bonjour"} - my_model = MyModel(my_dict) - - assert my_dict.get("prop") == my_model.get("prop") == "hello" - my_dict["prop"] = "nihao" - my_model.prop = "nihao" - - assert my_dict.get("prop") == my_model.get("prop") == "nihao" - - my_dict["restProp"] = "buongiorno" - my_model.rest_prop = "buongiorno" - - assert my_dict.get("restProp") == my_model.get("restProp") == "buongiorno" - assert my_dict.get("rest_prop") is None # attr case should not work here - - my_dict["newProp"] = "i'm new" - my_model["newProp"] = "i'm new" - - assert my_dict.get("newProp") == my_model.get("newProp") == "i'm new" - assert my_dict.get("nonexistent") is my_model.get("nonexistent") is None - - assert my_dict.get("nonexistent", 0) == my_model.get("nonexistent", 0) == 0 - - -def test_pop(): - class MyModel(Model): - prop: str = rest_field() - rest_prop: str = rest_field(name="restProp") - - my_dict = {"prop": "hello", "restProp": "bonjour"} - my_model = MyModel(my_dict) - - assert my_dict.pop("prop") == my_model.pop("prop") == "hello" - with pytest.raises(KeyError): - my_dict.pop("prop") - with pytest.raises(KeyError): - my_model.pop("prop") - - my_dict["prop"] = "nihao" - my_model.prop = "nihao" - - assert my_dict.pop("prop") == my_model.pop("prop") == "nihao" - - with pytest.raises(KeyError): - my_dict.pop("prop") - with pytest.raises(KeyError): - my_model.pop("prop") - - my_dict["restProp"] = "buongiorno" - my_model.rest_prop = "buongiorno" - - assert my_dict.pop("restProp") == my_model.pop("restProp") == "buongiorno" - with pytest.raises(KeyError): - my_dict.pop("rest_prop") # attr case should not work here - - my_dict["newProp"] = "i'm new" - my_model["newProp"] = "i'm new" - - assert my_dict.pop("newProp") == my_model.pop("newProp") == "i'm new" - assert my_dict.pop("nonexistent", 0) == my_model.pop("nonexistent", 0) == 0 - - -def test_popitem(): - class ModelA(Model): - a_str_prop: str = rest_field(name="aStrProp") - - class ModelB(Model): - b_str_prop: str = rest_field(name="bStrProp") - - class ModelC(Model): - c_str_prop: str = rest_field(name="cStrProp") - - class MainModel(Model): - a_prop: ModelA = rest_field(name="aProp") - b_prop: ModelB = rest_field(name="bProp") - c_prop: ModelC = rest_field(name="cProp") - - my_dict = { - "aProp": {"aStrProp": "a"}, - "bProp": {"bStrProp": "b"}, - "cProp": {"cStrProp": "c"}, - } - - def _tests(my_dict: Dict[str, Any], my_model: MainModel): - my_dict = copy.deepcopy(my_dict) # so we don't get rid of the dict each time we run tests - - # pop c prop - dict_popitem = my_dict.popitem() - model_popitem = my_model.popitem() - assert dict_popitem[0] == model_popitem[0] == "cProp" - assert dict_popitem[1]["cStrProp"] == model_popitem[1]["cStrProp"] == model_popitem[1].c_str_prop == "c" - - # pop b prop - dict_popitem = my_dict.popitem() - model_popitem = my_model.popitem() - assert dict_popitem[0] == model_popitem[0] == "bProp" - assert dict_popitem[1]["bStrProp"] == model_popitem[1]["bStrProp"] == model_popitem[1].b_str_prop == "b" - - # pop a prop - dict_popitem = my_dict.popitem() - model_popitem = my_model.popitem() - assert dict_popitem[0] == model_popitem[0] == "aProp" - assert dict_popitem[1]["aStrProp"] == model_popitem[1]["aStrProp"] == model_popitem[1].a_str_prop == "a" - - with pytest.raises(KeyError): - my_dict.popitem() - - with pytest.raises(KeyError): - my_model.popitem() - - _tests(my_dict, MainModel(my_dict)) - _tests( - my_dict, - MainModel( - a_prop=ModelA(a_str_prop="a"), - b_prop=ModelB(b_str_prop="b"), - c_prop=ModelC(c_str_prop="c"), - ), - ) - - -def test_clear(): - class ModelA(Model): - a_str_prop: str = rest_field(name="aStrProp") - - class ModelB(Model): - b_str_prop: str = rest_field(name="bStrProp") - - class ModelC(Model): - c_str_prop: str = rest_field(name="cStrProp") - - class MainModel(Model): - a_prop: ModelA = rest_field(name="aProp") - b_prop: ModelB = rest_field(name="bProp") - c_prop: ModelC = rest_field(name="cProp") - - my_dict = { - "aProp": {"aStrProp": "a"}, - "bProp": {"bStrProp": "b"}, - "cProp": {"cStrProp": "c"}, - } - - def _tests(my_dict: Dict[str, Any], my_model: MainModel): - my_dict = copy.deepcopy(my_dict) # so we don't get rid of the dict each time we run tests - - assert my_dict["aProp"] == my_model.a_prop == my_model["aProp"] == {"aStrProp": "a"} - my_dict.clear() - my_model.clear() - assert my_dict == my_model == {} - - assert my_model.a_prop is None - assert my_model.b_prop is None - assert my_model.c_prop is None - - my_dict.clear() - my_model.clear() - assert my_dict == my_model == {} - - _tests(my_dict, MainModel(my_dict)) - _tests( - my_dict, - MainModel( - a_prop=ModelA(a_str_prop="a"), - b_prop=ModelB(b_str_prop="b"), - c_prop=ModelC(c_str_prop="c"), - ), - ) - - -def test_update(): - class ModelA(Model): - a_str_prop: str = rest_field(name="aStrProp") - - class ModelB(Model): - b_str_prop: str = rest_field(name="bStrProp") - - class ModelC(Model): - c_str_prop: str = rest_field(name="cStrProp") - - class MainModel(Model): - a_prop: ModelA = rest_field(name="aProp") - b_prop: ModelB = rest_field(name="bProp") - c_prop: ModelC = rest_field(name="cProp") - - my_dict = { - "aProp": {"aStrProp": "a"}, - "bProp": {"bStrProp": "b"}, - "cProp": {"cStrProp": "c"}, - } - - def _tests(my_dict: Dict[str, Any], my_model: MainModel): - my_dict = copy.deepcopy(my_dict) # so we don't get rid of the dict each time we run tests - - assert my_dict["aProp"] == my_model.a_prop == my_model["aProp"] == {"aStrProp": "a"} - my_dict.update({"aProp": {"aStrProp": "newA"}}) - my_model.a_prop.update({"aStrProp": "newA"}) - assert my_dict["aProp"] == my_model.a_prop == my_model["aProp"] == {"aStrProp": "newA"} - - my_dict["bProp"].update({"newBProp": "hello"}) - my_model.b_prop.update({"newBProp": "hello"}) - - assert my_dict["bProp"] == my_model.b_prop == my_model["bProp"] == {"bStrProp": "b", "newBProp": "hello"} - - my_dict.update({"dProp": "hello"}) - my_model.update({"dProp": "hello"}) - - assert my_dict["dProp"] == my_model["dProp"] == "hello" - - _tests(my_dict, MainModel(my_dict)) - _tests( - my_dict, - MainModel( - a_prop=ModelA(a_str_prop="a"), - b_prop=ModelB(b_str_prop="b"), - c_prop=ModelC(c_str_prop="c"), - ), - ) - - -def test_setdefault(): - class Inner(Model): - str_prop: str = rest_field(name="strProp", default="modelDefault") - - class Outer(Model): - inner_prop: Inner = rest_field(name="innerProp") - - og_dict = {"innerProp": {}} - og_dict["innerProp"].setdefault("strProp", "actualDefault") - og_model = Outer(og_dict) - og_model.inner_prop.setdefault("strProp", "actualDefault") - - assert og_dict["innerProp"] == og_model["innerProp"] == og_model.inner_prop == {"strProp": "actualDefault"} - - assert ( - og_dict["innerProp"].setdefault("strProp") - == og_model["innerProp"].setdefault("strProp") - == og_model.inner_prop.setdefault("strProp") - == "actualDefault" - ) - - assert og_dict.setdefault("newProp") is og_model.setdefault("newProp") is None - assert og_dict["newProp"] is og_model["newProp"] is None - - -def test_repr(): - class ModelA(Model): - a_str_prop: str = rest_field(name="aStrProp") - - class ModelB(Model): - b_str_prop: str = rest_field(name="bStrProp") - - class ModelC(Model): - c_str_prop: str = rest_field(name="cStrProp") - - class MainModel(Model): - a_prop: ModelA = rest_field(name="aProp") - b_prop: ModelB = rest_field(name="bProp") - c_prop: ModelC = rest_field(name="cProp") - - my_dict = { - "aProp": {"aStrProp": "a"}, - "bProp": {"bStrProp": "b"}, - "cProp": {"cStrProp": "c"}, - } - - assert repr(my_dict) == repr(MainModel(my_dict)) - - -##### REWRITE BODY COMPLEX INTO THIS FILE ##### - - -def test_complex_basic(): - class Basic(Model): - id: Optional[int] = rest_field(default=None) - name: Optional[str] = rest_field(default=None) - color: Optional[Literal["cyan", "Magenta", "YELLOW", "blacK"]] = rest_field(default=None) - - @overload - def __init__( - self, - *, - id: Optional[int] = None, - name: Optional[str] = None, - color: Optional[Literal["cyan", "Magenta", "YELLOW", "blacK"]] = None, - ): ... - - @overload - def __init__(self, mapping: Mapping[str, Any], /): ... - - def __init__(self, *args, **kwargs): - super().__init__(*args, **kwargs) - - basic = Basic(id=2, name="abc", color="Magenta") - assert basic == {"id": 2, "name": "abc", "color": "Magenta"} - - basic.id = 3 - basic.name = "new_name" - basic.color = "blacK" - - assert basic == {"id": 3, "name": "new_name", "color": "blacK"} - - basic["id"] = 4 - basic["name"] = "newest_name" - basic["color"] = "YELLOW" - - assert basic == {"id": 4, "name": "newest_name", "color": "YELLOW"} - - -def test_complex_boolean_wrapper(): - class BooleanWrapper(Model): - field_true: Optional[bool] = rest_field(default=None) - field_false: Optional[bool] = rest_field(default=None) - - @overload - def __init__( - self, - *, - field_true: Optional[bool] = None, - field_false: Optional[bool] = None, - ): ... - - @overload - def __init__(self, mapping: Mapping[str, Any], /): ... - - def __init__(self, *args, **kwargs): - super().__init__(*args, **kwargs) - - bool_model = BooleanWrapper(field_true=True, field_false=False) - assert bool_model == {"field_true": True, "field_false": False} - bool_model.field_true = False - bool_model.field_false = True - assert bool_model == {"field_true": False, "field_false": True} - - bool_model["field_true"] = True - bool_model["field_false"] = False - assert bool_model == {"field_true": True, "field_false": False} - - -def test_complex_byte_wrapper(): - class ByteWrapper(Model): - default: Optional[bytes] = rest_field(default=None) - base64: Optional[bytes] = rest_field(default=None, format="base64") - base64url: Optional[bytes] = rest_field(default=None, format="base64url") - list_base64: Optional[List[bytes]] = rest_field(default=None, format="base64") - map_base64url: Optional[Dict[str, bytes]] = rest_field(default=None, format="base64url") - - @overload - def __init__( - self, - *, - default: Optional[bytes] = None, - base64: Optional[bytes] = None, - base64url: Optional[bytes] = None, - list_base64: Optional[List[bytes]] = None, - map_base64url: Optional[Dict[str, bytes]] = None, - ): ... - - @overload - def __init__(self, mapping: Mapping[str, Any], /): ... - - def __init__(self, *args, **kwargs): - super().__init__(*args, **kwargs) - - byte_string = bytes("test", "utf-8") - mod = ByteWrapper( - default=byte_string, - base64=byte_string, - base64url=byte_string, - list_base64=[byte_string, byte_string], - map_base64url={"key1": byte_string, "key2": byte_string}, - ) - decoded = "dGVzdA==" - decoded_urlsafe = "dGVzdA" - - def _tests(mod: ByteWrapper): - assert mod == { - "default": decoded, - "base64": decoded, - "base64url": decoded_urlsafe, - "list_base64": [decoded, decoded], - "map_base64url": {"key1": decoded_urlsafe, "key2": decoded_urlsafe}, - } - assert mod.default == byte_string - assert mod.base64 == byte_string - assert mod.base64url == byte_string - assert mod.list_base64 == [byte_string, byte_string] - assert mod.map_base64url == {"key1": byte_string, "key2": byte_string} - assert mod["default"] == decoded - assert mod["base64"] == decoded - assert mod["base64url"] == decoded_urlsafe - assert mod["list_base64"] == [decoded, decoded] - assert mod["map_base64url"] == { - "key1": decoded_urlsafe, - "key2": decoded_urlsafe, - } - - _tests(mod) - mod.default = byte_string - mod.base64 = byte_string - mod.base64url = byte_string - mod.list_base64 = [byte_string, byte_string] - mod.map_base64url = {"key1": byte_string, "key2": byte_string} - _tests(mod) - mod["default"] = decoded - mod["base64"] = decoded - mod["base64url"] = decoded_urlsafe - mod["list_base64"] = [decoded, decoded] - mod["map_base64url"] = {"key1": decoded_urlsafe, "key2": decoded_urlsafe} - _tests(mod) - - -def test_complex_byte_array_wrapper(): - class ByteArrayWrapper(Model): - default: Optional[bytearray] = rest_field(default=None) - base64: Optional[bytearray] = rest_field(default=None, format="base64") - base64url: Optional[bytearray] = rest_field(default=None, format="base64url") - list_base64: Optional[List[bytearray]] = rest_field(default=None, format="base64") - map_base64url: Optional[Dict[str, bytearray]] = rest_field(default=None, format="base64url") - - @overload - def __init__( - self, - *, - default: Optional[bytearray] = None, - base64: Optional[bytearray] = None, - base64url: Optional[bytearray] = None, - list_base64: Optional[List[bytearray]] = None, - map_base64url: Optional[Dict[str, bytearray]] = None, - ): ... - - @overload - def __init__(self, mapping: Mapping[str, Any], /): ... - - def __init__(self, *args, **kwargs): - super().__init__(*args, **kwargs) - - byte_array = bytearray("test".encode("utf-8")) - decoded = "dGVzdA==" - decoded_urlsafe = "dGVzdA" - - def _tests(model: ByteArrayWrapper): - assert model == { - "default": decoded, - "base64": decoded, - "base64url": decoded_urlsafe, - "list_base64": [decoded, decoded], - "map_base64url": {"key1": decoded_urlsafe, "key2": decoded_urlsafe}, - } - assert model.default == byte_array - assert model.base64 == byte_array - assert model.base64url == byte_array - assert model.list_base64 == [byte_array, byte_array] - assert model.map_base64url == {"key1": byte_array, "key2": byte_array} - assert model["default"] == decoded - assert model["base64"] == decoded - assert model["base64url"] == decoded_urlsafe - assert model["list_base64"] == [decoded, decoded] - assert model["map_base64url"] == { - "key1": decoded_urlsafe, - "key2": decoded_urlsafe, - } - - _tests( - ByteArrayWrapper( - default=byte_array, - base64=byte_array, - base64url=byte_array, - list_base64=[byte_array, byte_array], - map_base64url={"key1": byte_array, "key2": byte_array}, - ) - ) - _tests( - ByteArrayWrapper( - { - "default": decoded, - "base64": decoded, - "base64url": decoded_urlsafe, - "list_base64": [decoded, decoded], - "map_base64url": {"key1": decoded_urlsafe, "key2": decoded_urlsafe}, - } - ) - ) - - -def test_complex_datetime_wrapper(): - class DatetimeWrapper(Model): - default: datetime.datetime = rest_field(default=None) - rfc3339: datetime.datetime = rest_field(default=None, format="rfc3339") - rfc7231: datetime.datetime = rest_field(default=None, format="rfc7231") - unix: datetime.datetime = rest_field(default=None, format="unix-timestamp") - list_rfc3339: List[datetime.datetime] = rest_field(default=None, format="rfc3339") - dict_rfc7231: Dict[str, datetime.datetime] = rest_field(default=None, format="rfc7231") - - @overload - def __init__( - self, - *, - default: Optional[datetime.datetime] = None, - rfc3339: Optional[datetime.datetime] = None, - rfc7231: Optional[datetime.datetime] = None, - unix: Optional[datetime.datetime] = None, - list_rfc3339: Optional[List[datetime.datetime]] = None, - dict_rfc7231: Optional[Dict[str, datetime.datetime]] = None, - ): ... - - @overload - def __init__(self, mapping: Mapping[str, Any], /): ... - - def __init__(self, *args, **kwargs): - super().__init__(*args, **kwargs) - - rfc3339 = "2023-06-27T06:11:09Z" - rfc7231 = "Tue, 27 Jun 2023 06:11:09 GMT" - unix = 1687846269 - dt = datetime.datetime(2023, 6, 27, 6, 11, 9, tzinfo=datetime.timezone.utc) - - def _tests(model: DatetimeWrapper): - assert model["default"] == rfc3339 - assert model["rfc3339"] == rfc3339 - assert model["rfc7231"] == rfc7231 - assert model["unix"] == unix - assert model["list_rfc3339"] == [rfc3339, rfc3339] - assert model["dict_rfc7231"] == {"key1": rfc7231, "key2": rfc7231} - assert model.default == model.rfc3339 == model.rfc7231 == model.unix == dt - assert model.list_rfc3339 == [dt, dt] - assert model.dict_rfc7231 == {"key1": dt, "key2": dt} - - _tests( - DatetimeWrapper( - default=dt, - rfc3339=dt, - rfc7231=dt, - unix=dt, - list_rfc3339=[dt, dt], - dict_rfc7231={"key1": dt, "key2": dt}, - ) - ) - _tests( - DatetimeWrapper( - { - "default": rfc3339, - "rfc3339": rfc3339, - "rfc7231": rfc7231, - "unix": unix, - "list_rfc3339": [rfc3339, rfc3339], - "dict_rfc7231": {"key1": rfc7231, "key2": rfc7231}, - } - ) - ) - - -def test_complex_date_wrapper(): - class DateWrapper(Model): - field: datetime.date = rest_field(default=None) - leap: datetime.date = rest_field(default=None) - - @overload - def __init__( - self, - *, - field: Optional[datetime.date] = None, - leap: Optional[datetime.date] = None, - ): ... - - @overload - def __init__(self, mapping: Mapping[str, Any], /): ... - - def __init__(self, *args, **kwargs): - super().__init__(*args, **kwargs) - - field = "0001-01-01" - leap = "2016-02-29" - - def _tests(model: DateWrapper): - assert model.field == isodate.parse_date(field) - assert model["field"] == field - - assert model.leap == isodate.parse_date(leap) - assert model["leap"] == leap - - model.field = isodate.parse_date(leap) - assert model.field == isodate.parse_date(leap) - assert model["field"] == leap - - model["field"] = field - assert model.field == isodate.parse_date(field) - assert model["field"] == field - - _tests(DateWrapper({"field": field, "leap": leap})) - _tests(DateWrapper(field=isodate.parse_date(field), leap=isodate.parse_date(leap))) - - -class DictionaryWrapper(Model): - default_program: Dict[str, str] = rest_field(name="defaultProgram", default=None) - - @overload - def __init__( - self, - *, - default_program: Optional[Dict[str, str]] = None, - ): ... - - @overload - def __init__(self, mapping: Mapping[str, Any], /): ... - - def __init__(self, *args, **kwargs): - super().__init__(*args, **kwargs) - - -default_program = { - "txt": "notepad", - "bmp": "mspaint", - "xls": "excel", - "exe": "", - "": None, -} - - -@pytest.mark.parametrize( - "model", - [ - DictionaryWrapper({"defaultProgram": default_program}), - DictionaryWrapper(default_program=default_program), - ], -) -def test_complex_dictionary_wrapper(model: DictionaryWrapper): - assert model == {"defaultProgram": default_program} - assert model.default_program == model["defaultProgram"] == default_program - - -@pytest.mark.parametrize( - "model", - [DictionaryWrapper({"defaultProgram": {}}), DictionaryWrapper(default_program={})], -) -def test_complex_dictionary_wrapper_empty(model: DictionaryWrapper): - assert model == {"defaultProgram": {}} - assert model.default_program == model["defaultProgram"] == {} - - -@pytest.mark.parametrize( - "model", - [ - DictionaryWrapper({"defaultProgram": None}), - DictionaryWrapper(default_program=None), - ], -) -def test_complex_dictionary_wrapper_none(model: DictionaryWrapper): - assert model == {"defaultProgram": None} - assert model.default_program is None - - -class ArrayWrapper(Model): - array: Optional[List[str]] = rest_field(default=None) - - @overload - def __init__( - self, - *, - array: Optional[List[str]] = None, - ): ... - - @overload - def __init__(self, mapping: Mapping[str, Any], /): ... - - def __init__(self, *args, **kwargs): - super().__init__(*args, **kwargs) - - -array_value = [ - "1, 2, 3, 4", - "", - None, - "&S#$(*Y", - "The quick brown fox jumps over the lazy dog", -] - - -@pytest.mark.parametrize("model", [ArrayWrapper(array=array_value), ArrayWrapper({"array": array_value})]) -def test_complex_array_wrapper(model: ArrayWrapper): - assert model == {"array": array_value} - assert model.array == model["array"] == array_value - - model.array = None - with pytest.raises(KeyError): - model["array"] - assert model.array is None - - model["array"] = [1, 2, 3, 4, 5] - assert model.array == ["1", "2", "3", "4", "5"] - assert model["array"] == ["1", "2", "3", "4", "5"] - - -@pytest.mark.parametrize("model", [ArrayWrapper(array=[]), ArrayWrapper({"array": []})]) -def test_complex_array_wrapper_empty(model: ArrayWrapper): - assert model == {"array": []} - assert model.array == model["array"] == [] - - model.array = ["bonjour"] - assert model.array == model["array"] == ["bonjour"] - - -@pytest.mark.parametrize("model", [ArrayWrapper(array=None), ArrayWrapper({"array": None})]) -def test_complex_array_wrapper_none(model: ArrayWrapper): - assert model == {"array": None} - assert model.array is model["array"] is None - - model.array = ["bonjour"] - assert model.array == model["array"] == ["bonjour"] - - -class PetComplex(Model): - id: Optional[int] = rest_field(default=None) - name: Optional[str] = rest_field(default=None) - - @overload - def __init__( - self, - *, - id: Optional[int] = None, - name: Optional[str] = None, - ): ... - - @overload - def __init__(self, mapping: Mapping[str, Any], /): ... - - def __init__(self, *args, **kwargs): - super().__init__(*args, **kwargs) - - -class DogComplex(PetComplex): - food: Optional[str] = rest_field(default=None) - - @overload - def __init__( - self, - *, - id: Optional[int] = None, - name: Optional[str] = None, - food: Optional[str] = None, - ): ... - - @overload - def __init__(self, mapping: Mapping[str, Any], /): ... - - def __init__(self, *args, **kwargs): - super().__init__(*args, **kwargs) - - -class CatComplex(PetComplex): - color: Optional[str] = rest_field(default=None) - hates: Optional[List[DogComplex]] = rest_field(default=None) - - @overload - def __init__( - self, - *, - id: Optional[int] = None, - name: Optional[str] = None, - food: Optional[str] = None, - color: Optional[str] = None, - hates: Optional[List[DogComplex]] = None, - ): ... - - @overload - def __init__(self, mapping: Mapping[str, Any], /): ... - - def __init__(self, *args, **kwargs): - super().__init__(*args, **kwargs) - - -@pytest.mark.parametrize( - "model", - [ - CatComplex( - id=2, - name="Siamese", - hates=[ - DogComplex(id=1, name="Potato", food="tomato"), - DogComplex(id=-1, name="Tomato", food="french fries"), - ], - ), - CatComplex( - id=2, - name="Siamese", - hates=[ - DogComplex(id=1, name="Potato", food="tomato"), - {"id": -1, "name": "Tomato", "food": "french fries"}, - ], - ), - CatComplex( - id=2, - name="Siamese", - hates=[ - {"id": 1, "name": "Potato", "food": "tomato"}, - {"id": -1, "name": "Tomato", "food": "french fries"}, - ], - ), - ], -) -def test_complex_inheritance(model): - assert model.id == model["id"] == 2 - assert model.name == model["name"] == "Siamese" - assert model.hates - assert model.hates[1] == model["hates"][1] == {"id": -1, "name": "Tomato", "food": "french fries"} - model["breed"] = "persian" - model["color"] = "green" - with pytest.raises(AttributeError): - model.breed - assert model == { - "id": 2, - "name": "Siamese", - "color": "green", - "breed": "persian", - "hates": [ - DogComplex(id=1, name="Potato", food="tomato"), - DogComplex(id=-1, name="Tomato", food="french fries"), - ], - } - - -def test_required_prop_not_passed(): - class ModelWithRequiredProperty(Model): - required_property: int = rest_field(name="requiredProperty") - - @overload - def __init__( - self, - *, - required_property: int, - ): ... - - @overload - def __init__(self, mapping: Mapping[str, Any], /): ... - - def __init__(self, *args, **kwargs): - super().__init__(*args, **kwargs) - - model = ModelWithRequiredProperty() - assert model.required_property is None - with pytest.raises(KeyError): - model["requiredProperty"] - - model = ModelWithRequiredProperty({}) - assert model.required_property is None - with pytest.raises(KeyError): - model["requiredProperty"] - - -def test_null_serialization(core_library): - dict_response = { - "name": "it's me!", - "listOfMe": [ - { - "name": "it's me!", - } - ], - "dictOfMe": { - "me": { - "name": "it's me!", - } - }, - "dictOfListOfMe": { - "many mes": [ - { - "name": "it's me!", - } - ] - }, - "listOfDictOfMe": None, - } - model = RecursiveModel(dict_response) - assert json.loads(json.dumps(model, cls=SdkJSONEncoder)) == dict_response - - assert model.as_dict() == dict_response - - model.list_of_me = core_library.serialization.NULL - model.dict_of_me = None - model.list_of_dict_of_me = [ - { - "me": { - "name": "it's me!", - } - } - ] - model.dict_of_list_of_me["many mes"][0].list_of_me = core_library.serialization.NULL - model.dict_of_list_of_me["many mes"][0].dict_of_me = None - model.list_of_dict_of_me[0]["me"].list_of_me = core_library.serialization.NULL - model.list_of_dict_of_me[0]["me"].dict_of_me = None - - assert json.loads(json.dumps(model, cls=SdkJSONEncoder)) == { - "name": "it's me!", - "listOfMe": None, - "dictOfListOfMe": { - "many mes": [ - { - "name": "it's me!", - "listOfMe": None, - } - ] - }, - "listOfDictOfMe": [ - { - "me": { - "name": "it's me!", - "listOfMe": None, - } - } - ], - } - - assert model.as_dict() == { - "name": "it's me!", - "listOfMe": None, - "dictOfListOfMe": { - "many mes": [ - { - "name": "it's me!", - "listOfMe": None, - } - ] - }, - "listOfDictOfMe": [ - { - "me": { - "name": "it's me!", - "listOfMe": None, - } - } - ], - } - - -class UnionBaseModel(Model): - name: str = rest_field() - - @overload - def __init__(self, *, name: str): ... - - @overload - def __init__(self, mapping: Mapping[str, Any]): ... - - def __init__(self, *args: Any, **kwargs: Any) -> None: - super().__init__(*args, **kwargs) - - -class UnionModel1(UnionBaseModel): - prop1: int = rest_field() - - @overload - def __init__(self, *, name: str, prop1: int): ... - - @overload - def __init__(self, mapping: Mapping[str, Any]): ... - - def __init__(self, *args: Any, **kwargs: Any) -> None: - super().__init__(*args, **kwargs) - - -class UnionModel2(UnionBaseModel): - prop2: int = rest_field() - - @overload - def __init__(self, *, name: str, prop2: int): ... - - @overload - def __init__(self, mapping: Mapping[str, Any]): ... - - def __init__(self, *args: Any, **kwargs: Any) -> None: - super().__init__(*args, **kwargs) - - -MyNamedUnion = Union["UnionModel1", "UnionModel2"] - - -class ModelWithNamedUnionProperty(Model): - named_union: "MyNamedUnion" = rest_field(name="namedUnion") - - @overload - def __init__(self, *, named_union: "MyNamedUnion"): ... - - @overload - def __init__(self, mapping: Mapping[str, Any]): ... - - def __init__(self, *args: Any, **kwargs: Any) -> None: - super().__init__(*args, **kwargs) - - -class ModelWithSimpleUnionProperty(Model): - simple_union: Union[int, List[int]] = rest_field(name="simpleUnion") - - @overload - def __init__(self, *, simple_union: Union[int, List[int]]): ... - - @overload - def __init__(self, mapping: Mapping[str, Any]): ... - - def __init__(self, *args: Any, **kwargs: Any) -> None: - super().__init__(*args, **kwargs) - - -def test_union(): - simple = ModelWithSimpleUnionProperty(simple_union=1) - assert simple.simple_union == simple["simpleUnion"] == 1 - simple = ModelWithSimpleUnionProperty(simple_union=[1, 2]) - assert simple.simple_union == simple["simpleUnion"] == [1, 2] - named = ModelWithNamedUnionProperty() - assert not _is_model(named.named_union) - named.named_union = UnionModel1(name="model1", prop1=1) - assert _is_model(named.named_union) - assert named.named_union == named["namedUnion"] == {"name": "model1", "prop1": 1} - named = ModelWithNamedUnionProperty(named_union=UnionModel2(name="model2", prop2=2)) - assert named.named_union == named["namedUnion"] == {"name": "model2", "prop2": 2} - named = ModelWithNamedUnionProperty({"namedUnion": {"name": "model2", "prop2": 2}}) - assert named.named_union == named["namedUnion"] == {"name": "model2", "prop2": 2} - - -def test_as_dict(): - class CatComplex(PetComplex): - color: Optional[str] = rest_field(default=None) - hates: Optional[List[DogComplex]] = rest_field(default=None, visibility=["read"]) - - @overload - def __init__( - self, - *, - id: Optional[int] = None, - name: Optional[str] = None, - food: Optional[str] = None, - color: Optional[str] = None, - hates: Optional[List[DogComplex]] = None, - ): ... - - @overload - def __init__(self, mapping: Mapping[str, Any], /): ... - - def __init__(self, *args, **kwargs): - super().__init__(*args, **kwargs) - - model = CatComplex( - id=2, - name="Siamese", - hates=[ - DogComplex(id=1, name="Potato", food="tomato"), - DogComplex(id=-1, name="Tomato", food="french fries"), - ], - ) - assert model.as_dict(exclude_readonly=True) == { - "id": 2, - "name": "Siamese", - "color": None, - } - - -class Fish(Model): - __mapping__: Dict[str, Model] = {} - age: int = rest_field() - kind: Literal[None] = rest_discriminator(name="kind") - - @overload - def __init__( - self, - *, - age: int, - ): ... - - @overload - def __init__(self, mapping: Mapping[str, Any]): ... - - def __init__(self, *args: Any, **kwargs: Any) -> None: - super().__init__(*args, **kwargs) - self.kind: Literal[None] = None - - -class Shark(Fish, discriminator="shark"): - __mapping__: Dict[str, Model] = {} - kind: Literal["shark"] = rest_discriminator(name="kind") - sharktype: Literal[None] = rest_discriminator(name="sharktype") - - @overload - def __init__( - self, - *, - age: int, - ): ... - - @overload - def __init__(self, mapping: Mapping[str, Any]): ... - - def __init__(self, *args: Any, **kwargs: Any) -> None: - super().__init__(*args, **kwargs) - self.kind: Literal["shark"] = "shark" - self.sharktype: Literal[None] = None - - -class GoblinShark(Shark, discriminator="goblin"): - sharktype: Literal["goblin"] = rest_discriminator(name="sharktype") - - @overload - def __init__( - self, - *, - age: int, - ): ... - - @overload - def __init__(self, mapping: Mapping[str, Any]): ... - - def __init__(self, *args: Any, **kwargs: Any) -> None: - super().__init__(*args, **kwargs) - self.sharktype: Literal["goblin"] = "goblin" - - -class Salmon(Fish, discriminator="salmon"): - kind: Literal["salmon"] = rest_discriminator(name="kind") - friends: Optional[List["Fish"]] = rest_field() - hate: Optional[Dict[str, "Fish"]] = rest_field() - partner: Optional["Fish"] = rest_field() - - @overload - def __init__( - self, - *, - age: int, - friends: Optional[List["Fish"]] = None, - hate: Optional[Dict[str, "Fish"]] = None, - partner: Optional["Fish"] = None, - ): ... - - @overload - def __init__(self, mapping: Mapping[str, Any]): ... - - def __init__(self, *args: Any, **kwargs: Any) -> None: - super().__init__(*args, **kwargs) - self.kind: Literal["salmon"] = "salmon" - - -class SawShark(Shark, discriminator="saw"): - sharktype: Literal["saw"] = rest_discriminator(name="sharktype") - - @overload - def __init__( - self, - *, - age: int, - ): ... - - @overload - def __init__(self, mapping: Mapping[str, Any]): ... - - def __init__(self, *args: Any, **kwargs: Any) -> None: - super().__init__(*args, **kwargs) - self.sharktype: Literal["saw"] = "saw" - - -def test_discriminator(): - input = { - "age": 1, - "kind": "salmon", - "partner": { - "age": 2, - "kind": "shark", - "sharktype": "saw", - }, - "friends": [ - { - "age": 2, - "kind": "salmon", - "partner": { - "age": 3, - "kind": "salmon", - }, - "hate": { - "key1": { - "age": 4, - "kind": "salmon", - }, - "key2": { - "age": 2, - "kind": "shark", - "sharktype": "goblin", - }, - }, - }, - { - "age": 3, - "kind": "shark", - "sharktype": "goblin", - }, - ], - "hate": { - "key3": { - "age": 3, - "kind": "shark", - "sharktype": "saw", - }, - "key4": { - "age": 2, - "kind": "salmon", - "friends": [ - { - "age": 1, - "kind": "salmon", - }, - { - "age": 4, - "kind": "shark", - "sharktype": "goblin", - }, - ], - }, - }, - } - - model = Salmon(input) - assert model == input - assert model.partner.age == 2 - assert model.partner == SawShark(age=2) - assert model.friends[0].hate["key2"] == GoblinShark(age=2) - - -def test_body_bytes_format(): - assert json.dumps(bytes("test", "utf-8"), cls=SdkJSONEncoder) == '"dGVzdA=="' - assert json.dumps(bytearray("test", "utf-8"), cls=SdkJSONEncoder) == '"dGVzdA=="' - assert json.dumps(bytes("test", "utf-8"), cls=SdkJSONEncoder, format="base64") == '"dGVzdA=="' - assert json.dumps(bytes("test", "utf-8"), cls=SdkJSONEncoder, format="base64url") == '"dGVzdA"' - assert json.dumps(bytearray("test", "utf-8"), cls=SdkJSONEncoder, format="base64") == '"dGVzdA=="' - assert json.dumps(bytearray("test", "utf-8"), cls=SdkJSONEncoder, format="base64url") == '"dGVzdA"' - - assert ( - json.dumps([bytes("test", "utf-8"), bytes("test", "utf-8")], cls=SdkJSONEncoder) == '["dGVzdA==", "dGVzdA=="]' - ) - assert ( - json.dumps([bytearray("test", "utf-8"), bytearray("test", "utf-8")], cls=SdkJSONEncoder) - == '["dGVzdA==", "dGVzdA=="]' - ) - assert ( - json.dumps( - [bytes("test", "utf-8"), bytes("test", "utf-8")], - cls=SdkJSONEncoder, - format="base64", - ) - == '["dGVzdA==", "dGVzdA=="]' - ) - assert ( - json.dumps( - [bytes("test", "utf-8"), bytes("test", "utf-8")], - cls=SdkJSONEncoder, - format="base64url", - ) - == '["dGVzdA", "dGVzdA"]' - ) - assert ( - json.dumps( - [bytearray("test", "utf-8"), bytearray("test", "utf-8")], - cls=SdkJSONEncoder, - format="base64", - ) - == '["dGVzdA==", "dGVzdA=="]' - ) - assert ( - json.dumps( - [bytearray("test", "utf-8"), bytearray("test", "utf-8")], - cls=SdkJSONEncoder, - format="base64url", - ) - == '["dGVzdA", "dGVzdA"]' - ) - - assert ( - json.dumps( - {"a": bytes("test", "utf-8"), "b": bytes("test", "utf-8")}, - cls=SdkJSONEncoder, - ) - == '{"a": "dGVzdA==", "b": "dGVzdA=="}' - ) - assert ( - json.dumps( - {"a": bytearray("test", "utf-8"), "b": bytearray("test", "utf-8")}, - cls=SdkJSONEncoder, - ) - == '{"a": "dGVzdA==", "b": "dGVzdA=="}' - ) - assert ( - json.dumps( - {"a": bytes("test", "utf-8"), "b": bytes("test", "utf-8")}, - cls=SdkJSONEncoder, - format="base64", - ) - == '{"a": "dGVzdA==", "b": "dGVzdA=="}' - ) - assert ( - json.dumps( - {"a": bytes("test", "utf-8"), "b": bytes("test", "utf-8")}, - cls=SdkJSONEncoder, - format="base64url", - ) - == '{"a": "dGVzdA", "b": "dGVzdA"}' - ) - assert ( - json.dumps( - {"a": bytearray("test", "utf-8"), "b": bytearray("test", "utf-8")}, - cls=SdkJSONEncoder, - format="base64", - ) - == '{"a": "dGVzdA==", "b": "dGVzdA=="}' - ) - assert ( - json.dumps( - {"a": bytearray("test", "utf-8"), "b": bytearray("test", "utf-8")}, - cls=SdkJSONEncoder, - format="base64url", - ) - == '{"a": "dGVzdA", "b": "dGVzdA"}' - ) - - -def test_decimal_deserialization(): - class DecimalModel(Model): - decimal_value: decimal.Decimal = rest_field(name="decimalValue") - - @overload - def __init__(self, *, decimal_value: decimal.Decimal): ... - - @overload - def __init__(self, mapping: Mapping[str, Any], /): ... - - def __init__(self, *args, **kwargs): - super().__init__(*args, **kwargs) - - model = DecimalModel({"decimalValue": 0.33333}) - assert model["decimalValue"] == 0.33333 - assert model.decimal_value == decimal.Decimal("0.33333") - - class BaseModel(Model): - my_prop: DecimalModel = rest_field(name="myProp") - - model = BaseModel({"myProp": {"decimalValue": 0.33333}}) - assert isinstance(model.my_prop, DecimalModel) - assert model.my_prop["decimalValue"] == model["myProp"]["decimalValue"] == 0.33333 - assert model.my_prop.decimal_value == decimal.Decimal("0.33333") - - -def test_decimal_serialization(): - assert json.dumps(decimal.Decimal("0.33333"), cls=SdkJSONEncoder) == "0.33333" - assert ( - json.dumps([decimal.Decimal("0.33333"), decimal.Decimal("0.33333")], cls=SdkJSONEncoder) == "[0.33333, 0.33333]" - ) - assert ( - json.dumps( - {"a": decimal.Decimal("0.33333"), "b": decimal.Decimal("0.33333")}, - cls=SdkJSONEncoder, - ) - == '{"a": 0.33333, "b": 0.33333}' - ) - - -def test_int_as_str_deserialization(): - class IntAsStrModel(Model): - int_as_str_value: int = rest_field(name="intAsStrValue", format="str") - - model = IntAsStrModel({"intAsStrValue": "123"}) - assert model["intAsStrValue"] == "123" - assert model.int_as_str_value == 123 - - class BaseModel(Model): - my_prop: IntAsStrModel = rest_field(name="myProp") - - model = BaseModel({"myProp": {"intAsStrValue": "123"}}) - assert isinstance(model.my_prop, IntAsStrModel) - assert model.my_prop["intAsStrValue"] == model["myProp"]["intAsStrValue"] == "123" - assert model.my_prop.int_as_str_value == 123 - - -def test_deserialize(): - expected = {"name": "name", "role": "role"} - result = _deserialize(JSON, expected) - assert result == expected - - -def test_enum_deserialization(): - class MyEnum(Enum): - A = "a" - B = "b" - - class ModelWithEnumProperty(Model): - enum_property: Union[str, MyEnum] = rest_field(name="enumProperty") - enum_property_optional: Optional[Union[str, MyEnum]] = rest_field(name="enumPropertyOptional") - enum_property_optional_none: Optional[Union[str, MyEnum]] = rest_field(name="enumPropertyOptionalNone") - - raw_input = { - "enumProperty": "a", - "enumPropertyOptional": "b", - "enumPropertyOptionalNone": None, - } - - def check_func(target: ModelWithEnumProperty): - assert target.enum_property == MyEnum.A - assert target["enumProperty"] == "a" - assert isinstance(target.enum_property, Enum) - assert isinstance(target["enumProperty"], str) - - assert target.enum_property_optional == MyEnum.B - assert target["enumPropertyOptional"] == "b" - assert isinstance(target.enum_property_optional, Enum) - assert isinstance(target["enumPropertyOptional"], str) - - assert target.enum_property_optional_none is None - assert target["enumPropertyOptionalNone"] is None - - model = ModelWithEnumProperty(raw_input) - check_func(model) - - result = _deserialize(List[ModelWithEnumProperty], [raw_input]) - for item in result: - check_func(item) - - -def test_not_mutating_original_dict(): - class MyInnerModel(Model): - property: str = rest_field() - - class MyModel(Model): - property: MyInnerModel = rest_field() - - origin = {"property": {"property": "hello"}} - - dpg_model = MyModel(origin) - assert dpg_model["property"]["property"] == "hello" - - origin["property"]["property"] = "world" - assert dpg_model["property"]["property"] == "hello" - - -def test_model_init_io(): - class BytesModel(Model): - property: bytes = rest_field() - - JPG = Path(__file__).parent.parent / "data/image.jpg" - with open(JPG, "rb") as f: - b = BytesModel({"property": f}) - assert b.property == f - assert b["property"] == f - with open(JPG, "rb") as f: - b = BytesModel(property=f) - assert b.property == f - assert b["property"] == f - - -def test_additional_properties_serialization(): - value = { - "name": "test", - "modelProp": {"name": "test"}, - "stringProp": "string", - "intProp": 1, - "floatProp": 1.0, - "boolProp": True, - "listProp": [1, 2, 3], - "dictProp": {"key": "value"}, - "noneProp": None, - "datetimeProp": "2023-06-27T06:11:09Z", - "durationProp": "P1D", - } - - class NormalModel(Model): - prop: str = rest_field(name="name") - - class AdditionalPropertiesModel(Model): - name: str = rest_field(name="name") - - model = AdditionalPropertiesModel(name="test") - prop = NormalModel(prop="test") - model["modelProp"] = prop - model["stringProp"] = "string" - model["intProp"] = 1 - model["floatProp"] = 1.0 - model["boolProp"] = True - model["listProp"] = [1, 2, 3] - model["dictProp"] = {"key": "value"} - model["noneProp"] = None - model["datetimeProp"] = datetime.datetime(2023, 6, 27, 6, 11, 9, tzinfo=datetime.timezone.utc) - model["durationProp"] = datetime.timedelta(days=1) - - assert json.loads(json.dumps(model, cls=SdkJSONEncoder)) == value diff --git a/packages/typespec-python/test/generic_mock_api_tests/unittests/test_model_base_xml_serialization.py b/packages/typespec-python/test/generic_mock_api_tests/unittests/test_model_base_xml_serialization.py deleted file mode 100644 index 78912e305b1..00000000000 --- a/packages/typespec-python/test/generic_mock_api_tests/unittests/test_model_base_xml_serialization.py +++ /dev/null @@ -1,1001 +0,0 @@ -# ------------------------------------ -# Copyright (c) Microsoft Corporation. -# Licensed under the MIT License. -# ------------------------------------ -import xml.etree.ElementTree as ET - -from typing import ( - List, - Literal, - Dict, -) - -from specialwords._utils.model_base import ( - _get_element, - Model, - rest_field, - rest_discriminator, - _deserialize_xml, -) - - -def assert_xml_equals(x1, x2): - ET.dump(x1) - ET.dump(x2) - - assert x1.tag == x2.tag - assert (x1.text or "").strip() == (x2.text or "").strip() - # assert x1.tail == x2.tail # Swagger does not change tail - assert x1.attrib == x2.attrib - assert len(x1) == len(x2) - for c1, c2 in zip(x1, x2): - assert_xml_equals(c1, c2) - - -class TestXmlDeserialization: - def test_basic(self): - """Test an ultra basic XML.""" - basic_xml = """ - - 12 - - 12.34 - - true - - test - - """ - - class XmlModel(Model): - int_field: int = rest_field(name="int", xml={"name": "Int"}) - empty_int: int = rest_field(name="empty_int", xml={"name": "EmptyInt"}) - float_field: float = rest_field(name="float", xml={"name": "Float"}) - empty_float: float = rest_field(name="empty_float", xml={"name": "EmptyFloat"}) - bool_field: bool = rest_field(name="bool", xml={"name": "Bool"}) - empty_bool: bool = rest_field(name="empty_bool", xml={"name": "EmptyBool"}) - string: str = rest_field(name="string", xml={"name": "String"}) - empty_string: str = rest_field(name="empty_string", xml={"name": "EmptyString"}) - not_set: str = rest_field(name="not_set", xml={"name": "NotSet"}) - country: str = rest_field(name="country", xml={"name": "country", "attribute": True}) - - def __init__(self, *args, **kwargs): - super().__init__(*args, **kwargs) - - _xml = {"name": "Data"} - - result = _deserialize_xml(XmlModel, basic_xml) - - assert result.int_field == 12 - assert result.empty_int is None - assert result.float_field == 12.34 - assert result.empty_float is None - assert result.bool_field is True - assert result.empty_bool is None - assert result.string == "test" - assert result.country == "france" - assert result.empty_string == "" - assert result.not_set is None - - def test_basic_unicode(self): - """Test a XML with unicode.""" - basic_xml = """ - """ - - class XmlModel(Model): - language: str = rest_field(name="language", xml={"name": "language", "attribute": True}) - - def __init__(self, *args, **kwargs): - super().__init__(*args, **kwargs) - - _xml = {"name": "Data"} - - result = _deserialize_xml(XmlModel, basic_xml) - - assert result.language == "français" - - def test_basic_text(self): - """Test a XML with unicode.""" - basic_xml = """ - I am text""" - - class XmlModel(Model): - language: str = rest_field(name="language", xml={"name": "language", "attribute": True}) - content: str = rest_field(name="content", xml={"name": "content", "text": True}) - - def __init__(self, *args, **kwargs): - super().__init__(*args, **kwargs) - - _xml = {"name": "Data"} - - result = _deserialize_xml(XmlModel, basic_xml) - - assert result.language == "english" - assert result.content == "I am text" - - def test_dict_type(self): - """Test dict type.""" - basic_xml = """ - - - value1 - value2 - - """ - - class XmlModel(Model): - metadata: Dict[str, str] = rest_field(name="Metadata", xml={"name": "Metadata"}) - - def __init__(self, *args, **kwargs): - super().__init__(*args, **kwargs) - - _xml = {"name": "Data"} - - result = _deserialize_xml(XmlModel, basic_xml) - - assert len(result.metadata) == 2 - assert result.metadata["Key1"] == "value1" - assert result.metadata["Key2"] == "value2" - - def test_basic_empty_list(self): - """Test an basic XML with an empty node.""" - basic_xml = """ - - - """ - - class XmlModel(Model): - age: List[str] = rest_field(name="age", xml={"name": "Age"}) - - def __init__(self, *args, **kwargs): - super().__init__(*args, **kwargs) - - _xml = {"name": "Data"} - - result = _deserialize_xml(XmlModel, basic_xml) - assert result.age == [] - - def test_basic_empty_list_unwrapped(self): - """Test an basic XML with an empty node.""" - basic_xml = """ - """ - - class XmlModel(Model): - age: List[str] = rest_field(name="age", xml={"name": "Age", "unwrapped": True}) - - def __init__(self, *args, **kwargs): - super().__init__(*args, **kwargs) - - _xml = {"name": "Data"} - - result = _deserialize_xml(XmlModel, basic_xml) - assert result.age is None - - def test_list_wrapped_items_name_basic_types(self): - """Test XML list and wrap, items is basic type and there is itemsName.""" - - basic_xml = """ - - - granny - fuji - - """ - - class AppleBarrel(Model): - good_apples: List[str] = rest_field(name="GoodApples", xml={"name": "GoodApples", "itemsName": "Apple"}) - - def __init__(self, *args, **kwargs): - super().__init__(*args, **kwargs) - - _xml = {"name": "AppleBarrel"} - - result = _deserialize_xml(AppleBarrel, basic_xml) - assert result.good_apples == ["granny", "fuji"] - - def test_list_not_wrapped_items_name_basic_types(self): - """Test XML list and no wrap, items is basic type and there is itemsName.""" - - basic_xml = """ - - granny - fuji - """ - - class AppleBarrel(Model): - good_apples: List[str] = rest_field( - name="GoodApples", - xml={"name": "GoodApples", "unwrapped": True, "itemsName": "Apple"}, - ) - - def __init__(self, *args, **kwargs): - super().__init__(*args, **kwargs) - - _xml = {"name": "AppleBarrel"} - - result = _deserialize_xml(AppleBarrel, basic_xml) - assert result.good_apples == ["granny", "fuji"] - - def test_list_wrapped_items_name_complex_types(self): - """Test XML list and wrap, items is ref and there is itemsName.""" - - basic_xml = """ - - - - - - """ - - class Apple(Model): - name: str = rest_field(name="name", xml={"name": "name", "attribute": True}) - - def __init__(self, *args, **kwargs): - super().__init__(*args, **kwargs) - - _xml = {"name": "Apple"} - - class AppleBarrel(Model): - good_apples: List[Apple] = rest_field(name="GoodApples", xml={"name": "GoodApples", "itemsName": "Apple"}) - - def __init__(self, *args, **kwargs): - super().__init__(*args, **kwargs) - - _xml = {"name": "AppleBarrel"} - - result = _deserialize_xml(AppleBarrel, basic_xml) - assert [apple.name for apple in result.good_apples] == ["granny", "fuji"] - - def test_list_not_wrapped_items_name_complex_types(self): - """Test XML list and wrap, items is ref and there is itemsName.""" - - basic_xml = """ - - - - """ - - class Apple(Model): - name: str = rest_field(name="name", xml={"name": "name", "attribute": True}) - - def __init__(self, *args, **kwargs): - super().__init__(*args, **kwargs) - - _xml = {"name": "Apple"} - - class AppleBarrel(Model): - good_apples: List[Apple] = rest_field( - name="GoodApples", - xml={"name": "GoodApples", "unwrapped": True, "itemsName": "Apple"}, - ) - - def __init__(self, *args, **kwargs): - super().__init__(*args, **kwargs) - - _xml = {"name": "AppleBarrel"} - - result = _deserialize_xml(AppleBarrel, basic_xml) - assert [apple.name for apple in result.good_apples] == ["granny", "fuji"] - - def test_list_not_wrapped_items_name_complex_types(self): - """Test XML list and wrap, items is ref and there is itemsName.""" - - basic_xml = """ - - - - """ - - class Apple(Model): - name: str = rest_field(name="name", xml={"name": "name", "attribute": True}) - - def __init__(self, *args, **kwargs): - super().__init__(*args, **kwargs) - - _xml = {"name": "Apple"} - - class AppleBarrel(Model): - good_apples: List[Apple] = rest_field( - name="GoodApples", - xml={"name": "GoodApples", "unwrapped": True, "itemsName": "Apple"}, - ) - - def __init__(self, *args, **kwargs): - super().__init__(*args, **kwargs) - - _xml = {"name": "AppleBarrel"} - - result = _deserialize_xml(AppleBarrel, basic_xml) - assert [apple.name for apple in result.good_apples] == ["granny", "fuji"] - - def test_basic_additional_properties(self): - """Test additional properties.""" - basic_xml = """ - - text - - a - b - c - - - a - b - - """ - - class XmlModel(Model): - name: str = rest_field(name="name", xml={"name": "Name"}) - - def __init__(self, *args, **kwargs): - super().__init__(*args, **kwargs) - - _xml = {"name": "Data"} - - result = _deserialize_xml(XmlModel, basic_xml) - - assert result.name is None - assert result["add1"] == "text" - assert result["add2"] == ["a", "b", "c"] - assert result["add3"] == {"a": "a", "b": "b"} - - def test_basic_namespace(self): - """Test an ultra basic XML.""" - basic_xml = """ - - 37 - """ - - class XmlModel(Model): - age: int = rest_field( - name="age", - xml={ - "name": "Age", - "prefix": "fictional", - "ns": "http://characters.example.com", - }, - ) - - def __init__(self, *args, **kwargs): - super().__init__(*args, **kwargs) - - _xml = {"name": "Data"} - - result = _deserialize_xml(XmlModel, basic_xml) - assert result.age == 37 - - def test_complex_namespace(self): - """Test recursive namespace.""" - basic_xml = """ - - - lmazuel - - - - testpolicy - - - - 12 - - """ - - class QueueDescriptionResponseAuthor(Model): - name: str = rest_field(name="name", xml={"ns": "http://www.w3.org/2005/Atom"}) - - def __init__(self, *args, **kwargs): - super().__init__(*args, **kwargs) - - _xml = {"ns": "http://www.w3.org/2005/Atom"} - - class AuthorizationRule(Model): - type: str = rest_field( - name="type", - xml={ - "attribute": True, - "prefix": "i", - "ns": "http://www.w3.org/2001/XMLSchema-instance", - }, - ) - key_name: str = rest_field( - name="KeyName", - xml={"ns": "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect"}, - ) - - def __init__(self, *args, **kwargs): - super().__init__(*args, **kwargs) - - _xml = {"ns": "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect"} - - class MessageCountDetails(Model): - active_message_count: int = rest_field( - name="ActiveMessageCount", - xml={ - "prefix": "d2p1", - "ns": "http://schemas.microsoft.com/netservices/2011/06/servicebus", - }, - ) - - def __init__(self, *args, **kwargs): - super().__init__(*args, **kwargs) - - _xml = { - "name": "CountDetails", - "ns": "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect", - } - - class XmlRoot(Model): - author: QueueDescriptionResponseAuthor = rest_field(name="author") - authorization_rules: List[AuthorizationRule] = rest_field( - name="AuthorizationRules", - xml={ - "ns": "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect", - }, - ) - message_count_details: MessageCountDetails = rest_field( - name="MessageCountDetails", - xml={ - "ns": "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect", - }, - ) - - def __init__(self, *args, **kwargs): - super().__init__(*args, **kwargs) - - _xml = {"name": "entry", "ns": "http://www.w3.org/2005/Atom"} - - result = _deserialize_xml(XmlRoot, basic_xml) - - assert result.author.name == "lmazuel" - assert result.authorization_rules[0].key_name == "testpolicy" - assert result.authorization_rules[0].type == "SharedAccessAuthorizationRule" - assert result.message_count_details.active_message_count == 12 - - def test_polymorphic_deserialization(self): - basic_xml = """ - - - 12 - - """ - - class RuleFilter(Model): - __mapping__: Dict[str, Model] = {} - type: Literal[None] = rest_discriminator( - name="type", - xml={ - "attribute": True, - "prefix": "xsi", - "ns": "http://www.w3.org/2001/XMLSchema-instance", - }, - ) - - def __init__(self, *args, **kwargs): - super().__init__(*args, **kwargs) - self.type: Literal[None] = None - - _xml = {"name": "Filter"} - - class CorrelationFilter(RuleFilter): - type: Literal["CorrelationFilter"] = rest_discriminator( - name="type", - xml={ - "attribute": True, - "prefix": "xsi", - "ns": "http://www.w3.org/2001/XMLSchema-instance", - }, - ) - correlation_id: int = rest_field(name="CorrelationId") - - def __init__(self, *args, **kwargs): - super().__init__(*args, **kwargs) - self.type: Literal["CorrelationFilter"] = "CorrelationFilter" - - class SqlFilter(RuleFilter): - type: Literal["SqlFilter"] = rest_discriminator( - name="type", - xml={ - "attribute": True, - "prefix": "xsi", - "ns": "http://www.w3.org/2001/XMLSchema-instance", - }, - ) - - def __init__(self, *args, **kwargs): - super().__init__(*args, **kwargs) - self.type: Literal["SqlFilter"] = "SqlFilter" - - class XmlRoot(Model): - filter: RuleFilter = rest_field(name="Filter") - - def __init__(self, *args, **kwargs): - super().__init__(*args, **kwargs) - - _xml = {"name": "entry"} - - result = _deserialize_xml(XmlRoot, basic_xml) - - assert isinstance(result.filter, CorrelationFilter) - assert result.filter.correlation_id == 12 - - -class TestXmlSerialization: - def test_basic(self): - """Test an ultra basic XML.""" - basic_xml = ET.fromstring( - """ - - 37 - """ - ) - - class XmlModel(Model): - age: int = rest_field(xml={"name": "Age"}) - country: str = rest_field(xml={"name": "country", "attribute": True}) - - def __init__(self, *args, **kwargs): - super().__init__(*args, **kwargs) - - _xml = {"name": "Data"} - - xml_model = XmlModel(age=37, country="france") - assert_xml_equals(_get_element(xml_model), basic_xml) - - def test_basic_unicode(self): - """Test a XML with unicode.""" - basic_xml = ET.fromstring( - """ - """.encode( - "utf-8" - ) - ) - - class XmlModel(Model): - language: str = rest_field(xml={"name": "language", "attribute": True}) - - def __init__(self, *args, **kwargs): - super().__init__(*args, **kwargs) - - _xml = {"name": "Data"} - - xml_model = XmlModel(language="français") - assert_xml_equals(_get_element(xml_model), basic_xml) - - def test_nested_unicode(self): - class XmlModel(Model): - message_text: str = rest_field(name="MessageText", xml={"name": "MessageText"}) - - def __init__(self, *args, **kwargs): - super().__init__(*args, **kwargs) - - _xml = {"name": "Message"} - - xml_model_no_unicode = XmlModel(message_text="message1") - xml_element = _get_element(xml_model_no_unicode) - xml_content = ET.tostring(xml_element, encoding="utf8") - assert ( - xml_content - == b"\nmessage1" - ) - - xml_model_with_unicode = XmlModel(message_text="message1㚈") - xml_element = _get_element(xml_model_with_unicode) - xml_content = ET.tostring(xml_element, encoding="utf8") - assert ( - xml_content - == b"\nmessage1\xe3\x9a\x88" - ) - - def test_type_basic(self): - """Test basic types.""" - basic_xml = ET.fromstring( - """ - - 37 - true - """ - ) - - class XmlModel(Model): - age: int = rest_field(name="age", xml={"name": "Age"}) - enabled: bool = rest_field(name="enabled", xml={"name": "Enabled"}) - - def __init__(self, *args, **kwargs): - super().__init__(*args, **kwargs) - - _xml = {"name": "Data"} - - xml_model = XmlModel(age=37, enabled=True) - assert_xml_equals(_get_element(xml_model), basic_xml) - - def test_basic_text(self): - """Test a XML with unicode.""" - basic_xml = ET.fromstring( - """ - I am text""" - ) - - class XmlModel(Model): - language: str = rest_field(name="language", xml={"name": "language", "attribute": True}) - content: str = rest_field(name="content", xml={"text": True}) - - def __init__(self, *args, **kwargs): - super().__init__(*args, **kwargs) - - _xml = {"name": "Data"} - - xml_model = XmlModel(language="english", content="I am text") - assert_xml_equals(_get_element(xml_model), basic_xml) - - def test_dict_type(self): - """Test dict type.""" - basic_xml = ET.fromstring( - """ - - - value1 - value2 - - """ - ) - - class XmlModel(Model): - metadata: Dict[str, str] = rest_field(name="Metadata", xml={"name": "Metadata"}) - - def __init__(self, *args, **kwargs): - super().__init__(*args, **kwargs) - - _xml = {"name": "Data"} - - xml_model = XmlModel( - metadata={ - "Key1": "value1", - "Key2": "value2", - } - ) - assert_xml_equals(_get_element(xml_model), basic_xml) - - def test_additional_properties(self): - """Test additional properties.""" - basic_xml = ET.fromstring( - """ - - test - text - - a - b - c - - - a - b - - """ - ) - - class XmlModel(Model): - name: str = rest_field(name="name", xml={"name": "Name"}) - - def __init__(self, *args, **kwargs): - super().__init__(*args, **kwargs) - - _xml = {"name": "Data"} - - xml_model = XmlModel( - { - "name": "test", - "add1": "text", - "add2": ["a", "b", "c"], - "add3": {"a": "a", "b": "b"}, - } - ) - assert_xml_equals(_get_element(xml_model), basic_xml) - - def test_list_wrapped_basic_types(self): - """Test XML list and wrap, items is basic type and there is no itemsName.""" - - basic_xml = ET.fromstring( - """ - - - granny - fuji - - """ - ) - - class AppleBarrel(Model): - good_apples: List[str] = rest_field(name="GoodApples", xml={"name": "GoodApples"}) - - def __init__(self, *args, **kwargs): - super().__init__(*args, **kwargs) - - _xml = {"name": "AppleBarrel"} - - xml_model = AppleBarrel(good_apples=["granny", "fuji"]) - assert_xml_equals(_get_element(xml_model), basic_xml) - - def test_list_not_wrapped_basic_types(self): - """Test XML list and no wrap, items is basic type and there is no itemsName.""" - - basic_xml = ET.fromstring( - """ - - granny - fuji - """ - ) - - class AppleBarrel(Model): - good_apples: List[str] = rest_field(name="GoodApples", xml={"name": "GoodApples", "unwrapped": True}) - - def __init__(self, *args, **kwargs): - super().__init__(*args, **kwargs) - - _xml = {"name": "AppleBarrel"} - - xml_model = AppleBarrel(good_apples=["granny", "fuji"]) - assert_xml_equals(_get_element(xml_model), basic_xml) - - def test_list_wrapped_basic_types_items_name(self): - """Test XML list and wrap, items is basic type and itemsName.""" - - basic_xml = ET.fromstring( - """ - - - granny - fuji - - """ - ) - - class AppleBarrel(Model): - good_apples: List[str] = rest_field(name="GoodApples", xml={"name": "GoodApples", "itemsName": "string"}) - - def __init__(self, *args, **kwargs): - super().__init__(*args, **kwargs) - - _xml = {"name": "AppleBarrel"} - - xml_model = AppleBarrel(good_apples=["granny", "fuji"]) - assert_xml_equals(_get_element(xml_model), basic_xml) - - def test_list_not_wrapped_basic_types_items_name(self): - """Test XML list and no wrap, items is basic type and itemsName.""" - - basic_xml = ET.fromstring( - """ - - granny - fuji - """ - ) - - class AppleBarrel(Model): - good_apples: List[str] = rest_field( - name="GoodApples", - xml={"name": "GoodApples", "unwrapped": True, "itemsName": "string"}, - ) - - def __init__(self, *args, **kwargs): - super().__init__(*args, **kwargs) - - _xml = {"name": "AppleBarrel"} - - xml_model = AppleBarrel(good_apples=["granny", "fuji"]) - assert_xml_equals(_get_element(xml_model), basic_xml) - - def test_list_wrapped_complex_types(self): - """Test XML list and wrap, items is ref.""" - - basic_xml = ET.fromstring( - """ - - - - - - """ - ) - - class Apple(Model): - name: str = rest_field(name="name", xml={"name": "name", "attribute": True}) - - def __init__(self, *args, **kwargs): - super().__init__(*args, **kwargs) - - _xml = {"name": "Apple"} - - class AppleBarrel(Model): - good_apples: List[Apple] = rest_field(name="GoodApples", xml={"name": "GoodApples"}) - - def __init__(self, *args, **kwargs): - super().__init__(*args, **kwargs) - - _xml = {"name": "AppleBarrel"} - - test = AppleBarrel({"GoodApples": [{"name": "granny"}, {"name": "fuji"}]}) - xml_model = AppleBarrel(good_apples=[Apple(name="granny"), Apple(name="fuji")]) - assert_xml_equals(_get_element(xml_model), basic_xml) - - def test_list_not_wrapped_complex_types(self): - """Test XML list and wrap, items is ref.""" - - basic_xml = ET.fromstring( - """ - - - - """ - ) - - class Apple(Model): - name: str = rest_field(name="name", xml={"name": "name", "attribute": True}) - - def __init__(self, *args, **kwargs): - super().__init__(*args, **kwargs) - - _xml = {"name": "Apple"} - - class AppleBarrel(Model): - good_apples: List[Apple] = rest_field(name="GoodApples", xml={"name": "GoodApples", "unwrapped": True}) - - def __init__(self, *args, **kwargs): - super().__init__(*args, **kwargs) - - xml_model = AppleBarrel(good_apples=[Apple(name="granny"), Apple(name="fuji")]) - assert_xml_equals(_get_element(xml_model), basic_xml) - - def test_two_complex_same_type(self): - """Two different attribute are same type""" - - basic_xml = ET.fromstring( - """ - - - - """ - ) - - class Apple(Model): - name: str = rest_field(name="name", xml={"name": "name", "attribute": True}) - - def __init__(self, *args, **kwargs): - super().__init__(*args, **kwargs) - - _xml = {"name": "Apple"} - - class AppleBarrel(Model): - eu_apple: Apple = rest_field(name="EuropeanApple", xml={"name": "EuropeanApple"}) - us_apple: Apple = rest_field(name="USAApple", xml={"name": "USAApple"}) - - def __init__(self, *args, **kwargs): - super().__init__(*args, **kwargs) - - xml_model = AppleBarrel( - eu_apple=Apple(name="granny"), - us_apple=Apple(name="fuji"), - ) - assert_xml_equals(_get_element(xml_model), basic_xml) - - def test_basic_namespace(self): - """Test an ultra basic XML.""" - basic_xml = ET.fromstring( - """ - - 37 - """ - ) - - class XmlModel(Model): - age: int = rest_field( - name="age", - xml={ - "name": "Age", - "prefix": "fictional", - "ns": "http://characters.example.com", - }, - ) - - def __init__(self, *args, **kwargs): - super().__init__(*args, **kwargs) - - _xml = {"name": "Data"} - - xml_model = XmlModel( - age=37, - ) - assert_xml_equals(_get_element(xml_model), basic_xml) - - def test_complex_namespace(self): - """Test recursive namespace.""" - basic_xml = ET.fromstring( - """ - - - lmazuel - - - - testpolicy - - - - 12 - - """ - ) - - class QueueDescriptionResponseAuthor(Model): - name: str = rest_field(name="name", xml={"ns": "http://www.w3.org/2005/Atom"}) - - def __init__(self, *args, **kwargs): - super().__init__(*args, **kwargs) - - _xml = {"ns": "http://www.w3.org/2005/Atom"} - - class AuthorizationRule(Model): - type: str = rest_field( - name="type", - xml={ - "attribute": True, - "prefix": "i", - "ns": "http://www.w3.org/2001/XMLSchema-instance", - }, - ) - key_name: str = rest_field( - name="KeyName", - xml={"ns": "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect"}, - ) - - def __init__(self, *args, **kwargs): - super().__init__(*args, **kwargs) - - _xml = {"ns": "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect"} - - class MessageCountDetails(Model): - active_message_count: int = rest_field( - name="ActiveMessageCount", - xml={ - "prefix": "d2p1", - "ns": "http://schemas.microsoft.com/netservices/2011/06/servicebus", - }, - ) - - def __init__(self, *args, **kwargs): - super().__init__(*args, **kwargs) - - _xml = { - "name": "CountDetails", - "ns": "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect", - } - - class XmlRoot(Model): - author: QueueDescriptionResponseAuthor = rest_field(name="author") - authorization_rules: List[AuthorizationRule] = rest_field( - name="AuthorizationRules", - xml={ - "ns": "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect", - }, - ) - message_count_details: MessageCountDetails = rest_field( - name="MessageCountDetails", - xml={ - "ns": "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect", - }, - ) - - def __init__(self, *args, **kwargs): - super().__init__(*args, **kwargs) - - _xml = {"name": "entry", "ns": "http://www.w3.org/2005/Atom"} - - xml_model = XmlRoot( - author=QueueDescriptionResponseAuthor(name="lmazuel"), - authorization_rules=[AuthorizationRule(type="SharedAccessAuthorizationRule", key_name="testpolicy")], - message_count_details=MessageCountDetails(active_message_count=12), - ) - assert_xml_equals(_get_element(xml_model), basic_xml) diff --git a/packages/typespec-python/test/generic_mock_api_tests/unittests/test_parse_pyproject.py b/packages/typespec-python/test/generic_mock_api_tests/unittests/test_parse_pyproject.py index 0cf56d17185..78b873e2020 100644 --- a/packages/typespec-python/test/generic_mock_api_tests/unittests/test_parse_pyproject.py +++ b/packages/typespec-python/test/generic_mock_api_tests/unittests/test_parse_pyproject.py @@ -1,5 +1,3 @@ -import importlib.metadata -import importlib.util from pathlib import Path from typing import Dict, Any diff --git a/packages/typespec-python/test/unbranded/generated/authentication-api-key/authentication/apikey/_utils/model_base.py b/packages/typespec-python/test/unbranded/generated/authentication-api-key/authentication/apikey/_utils/model_base.py index c52d928e423..ca800653fd8 100644 --- a/packages/typespec-python/test/unbranded/generated/authentication-api-key/authentication/apikey/_utils/model_base.py +++ b/packages/typespec-python/test/unbranded/generated/authentication-api-key/authentication/apikey/_utils/model_base.py @@ -624,6 +624,9 @@ def __init__(self, *args: typing.Any, **kwargs: typing.Any) -> None: if len(items) > 0: existed_attr_keys.append(xml_name) dict_to_pass[rf._rest_name] = _deserialize(rf._type, items) + elif not rf._is_optional: + existed_attr_keys.append(xml_name) + dict_to_pass[rf._rest_name] = [] continue # text element is primitive type @@ -885,6 +888,8 @@ def _get_deserialize_callable_from_annotation( # pylint: disable=too-many-retur # is it optional? try: if any(a is _NONE_TYPE for a in annotation.__args__): # pyright: ignore + if rf: + rf._is_optional = True if len(annotation.__args__) <= 2: # pyright: ignore if_obj_deserializer = _get_deserialize_callable_from_annotation( next(a for a in annotation.__args__ if a is not _NONE_TYPE), module, rf # pyright: ignore @@ -1043,6 +1048,7 @@ def _failsafe_deserialize_xml( return None +# pylint: disable=too-many-instance-attributes class _RestField: def __init__( self, @@ -1062,6 +1068,7 @@ def __init__( self._is_discriminator = is_discriminator self._visibility = visibility self._is_model = False + self._is_optional = False self._default = default self._format = format self._is_multipart_file_input = is_multipart_file_input diff --git a/packages/typespec-python/test/unbranded/generated/authentication-http-custom/authentication/http/custom/_utils/model_base.py b/packages/typespec-python/test/unbranded/generated/authentication-http-custom/authentication/http/custom/_utils/model_base.py index c52d928e423..ca800653fd8 100644 --- a/packages/typespec-python/test/unbranded/generated/authentication-http-custom/authentication/http/custom/_utils/model_base.py +++ b/packages/typespec-python/test/unbranded/generated/authentication-http-custom/authentication/http/custom/_utils/model_base.py @@ -624,6 +624,9 @@ def __init__(self, *args: typing.Any, **kwargs: typing.Any) -> None: if len(items) > 0: existed_attr_keys.append(xml_name) dict_to_pass[rf._rest_name] = _deserialize(rf._type, items) + elif not rf._is_optional: + existed_attr_keys.append(xml_name) + dict_to_pass[rf._rest_name] = [] continue # text element is primitive type @@ -885,6 +888,8 @@ def _get_deserialize_callable_from_annotation( # pylint: disable=too-many-retur # is it optional? try: if any(a is _NONE_TYPE for a in annotation.__args__): # pyright: ignore + if rf: + rf._is_optional = True if len(annotation.__args__) <= 2: # pyright: ignore if_obj_deserializer = _get_deserialize_callable_from_annotation( next(a for a in annotation.__args__ if a is not _NONE_TYPE), module, rf # pyright: ignore @@ -1043,6 +1048,7 @@ def _failsafe_deserialize_xml( return None +# pylint: disable=too-many-instance-attributes class _RestField: def __init__( self, @@ -1062,6 +1068,7 @@ def __init__( self._is_discriminator = is_discriminator self._visibility = visibility self._is_model = False + self._is_optional = False self._default = default self._format = format self._is_multipart_file_input = is_multipart_file_input diff --git a/packages/typespec-python/test/unbranded/generated/authentication-noauth-union/authentication/noauth/union/_utils/model_base.py b/packages/typespec-python/test/unbranded/generated/authentication-noauth-union/authentication/noauth/union/_utils/model_base.py index c52d928e423..ca800653fd8 100644 --- a/packages/typespec-python/test/unbranded/generated/authentication-noauth-union/authentication/noauth/union/_utils/model_base.py +++ b/packages/typespec-python/test/unbranded/generated/authentication-noauth-union/authentication/noauth/union/_utils/model_base.py @@ -624,6 +624,9 @@ def __init__(self, *args: typing.Any, **kwargs: typing.Any) -> None: if len(items) > 0: existed_attr_keys.append(xml_name) dict_to_pass[rf._rest_name] = _deserialize(rf._type, items) + elif not rf._is_optional: + existed_attr_keys.append(xml_name) + dict_to_pass[rf._rest_name] = [] continue # text element is primitive type @@ -885,6 +888,8 @@ def _get_deserialize_callable_from_annotation( # pylint: disable=too-many-retur # is it optional? try: if any(a is _NONE_TYPE for a in annotation.__args__): # pyright: ignore + if rf: + rf._is_optional = True if len(annotation.__args__) <= 2: # pyright: ignore if_obj_deserializer = _get_deserialize_callable_from_annotation( next(a for a in annotation.__args__ if a is not _NONE_TYPE), module, rf # pyright: ignore @@ -1043,6 +1048,7 @@ def _failsafe_deserialize_xml( return None +# pylint: disable=too-many-instance-attributes class _RestField: def __init__( self, @@ -1062,6 +1068,7 @@ def __init__( self._is_discriminator = is_discriminator self._visibility = visibility self._is_model = False + self._is_optional = False self._default = default self._format = format self._is_multipart_file_input = is_multipart_file_input diff --git a/packages/typespec-python/test/unbranded/generated/authentication-oauth2/authentication/oauth2/_utils/model_base.py b/packages/typespec-python/test/unbranded/generated/authentication-oauth2/authentication/oauth2/_utils/model_base.py index c52d928e423..ca800653fd8 100644 --- a/packages/typespec-python/test/unbranded/generated/authentication-oauth2/authentication/oauth2/_utils/model_base.py +++ b/packages/typespec-python/test/unbranded/generated/authentication-oauth2/authentication/oauth2/_utils/model_base.py @@ -624,6 +624,9 @@ def __init__(self, *args: typing.Any, **kwargs: typing.Any) -> None: if len(items) > 0: existed_attr_keys.append(xml_name) dict_to_pass[rf._rest_name] = _deserialize(rf._type, items) + elif not rf._is_optional: + existed_attr_keys.append(xml_name) + dict_to_pass[rf._rest_name] = [] continue # text element is primitive type @@ -885,6 +888,8 @@ def _get_deserialize_callable_from_annotation( # pylint: disable=too-many-retur # is it optional? try: if any(a is _NONE_TYPE for a in annotation.__args__): # pyright: ignore + if rf: + rf._is_optional = True if len(annotation.__args__) <= 2: # pyright: ignore if_obj_deserializer = _get_deserialize_callable_from_annotation( next(a for a in annotation.__args__ if a is not _NONE_TYPE), module, rf # pyright: ignore @@ -1043,6 +1048,7 @@ def _failsafe_deserialize_xml( return None +# pylint: disable=too-many-instance-attributes class _RestField: def __init__( self, @@ -1062,6 +1068,7 @@ def __init__( self._is_discriminator = is_discriminator self._visibility = visibility self._is_model = False + self._is_optional = False self._default = default self._format = format self._is_multipart_file_input = is_multipart_file_input diff --git a/packages/typespec-python/test/unbranded/generated/authentication-union/authentication/union/_utils/model_base.py b/packages/typespec-python/test/unbranded/generated/authentication-union/authentication/union/_utils/model_base.py index c52d928e423..ca800653fd8 100644 --- a/packages/typespec-python/test/unbranded/generated/authentication-union/authentication/union/_utils/model_base.py +++ b/packages/typespec-python/test/unbranded/generated/authentication-union/authentication/union/_utils/model_base.py @@ -624,6 +624,9 @@ def __init__(self, *args: typing.Any, **kwargs: typing.Any) -> None: if len(items) > 0: existed_attr_keys.append(xml_name) dict_to_pass[rf._rest_name] = _deserialize(rf._type, items) + elif not rf._is_optional: + existed_attr_keys.append(xml_name) + dict_to_pass[rf._rest_name] = [] continue # text element is primitive type @@ -885,6 +888,8 @@ def _get_deserialize_callable_from_annotation( # pylint: disable=too-many-retur # is it optional? try: if any(a is _NONE_TYPE for a in annotation.__args__): # pyright: ignore + if rf: + rf._is_optional = True if len(annotation.__args__) <= 2: # pyright: ignore if_obj_deserializer = _get_deserialize_callable_from_annotation( next(a for a in annotation.__args__ if a is not _NONE_TYPE), module, rf # pyright: ignore @@ -1043,6 +1048,7 @@ def _failsafe_deserialize_xml( return None +# pylint: disable=too-many-instance-attributes class _RestField: def __init__( self, @@ -1062,6 +1068,7 @@ def __init__( self._is_discriminator = is_discriminator self._visibility = visibility self._is_model = False + self._is_optional = False self._default = default self._format = format self._is_multipart_file_input = is_multipart_file_input diff --git a/packages/typespec-python/test/unbranded/generated/encode-array/encode/array/_utils/model_base.py b/packages/typespec-python/test/unbranded/generated/encode-array/encode/array/_utils/model_base.py index c52d928e423..ca800653fd8 100644 --- a/packages/typespec-python/test/unbranded/generated/encode-array/encode/array/_utils/model_base.py +++ b/packages/typespec-python/test/unbranded/generated/encode-array/encode/array/_utils/model_base.py @@ -624,6 +624,9 @@ def __init__(self, *args: typing.Any, **kwargs: typing.Any) -> None: if len(items) > 0: existed_attr_keys.append(xml_name) dict_to_pass[rf._rest_name] = _deserialize(rf._type, items) + elif not rf._is_optional: + existed_attr_keys.append(xml_name) + dict_to_pass[rf._rest_name] = [] continue # text element is primitive type @@ -885,6 +888,8 @@ def _get_deserialize_callable_from_annotation( # pylint: disable=too-many-retur # is it optional? try: if any(a is _NONE_TYPE for a in annotation.__args__): # pyright: ignore + if rf: + rf._is_optional = True if len(annotation.__args__) <= 2: # pyright: ignore if_obj_deserializer = _get_deserialize_callable_from_annotation( next(a for a in annotation.__args__ if a is not _NONE_TYPE), module, rf # pyright: ignore @@ -1043,6 +1048,7 @@ def _failsafe_deserialize_xml( return None +# pylint: disable=too-many-instance-attributes class _RestField: def __init__( self, @@ -1062,6 +1068,7 @@ def __init__( self._is_discriminator = is_discriminator self._visibility = visibility self._is_model = False + self._is_optional = False self._default = default self._format = format self._is_multipart_file_input = is_multipart_file_input diff --git a/packages/typespec-python/test/unbranded/generated/encode-bytes/encode/bytes/_utils/model_base.py b/packages/typespec-python/test/unbranded/generated/encode-bytes/encode/bytes/_utils/model_base.py index c52d928e423..ca800653fd8 100644 --- a/packages/typespec-python/test/unbranded/generated/encode-bytes/encode/bytes/_utils/model_base.py +++ b/packages/typespec-python/test/unbranded/generated/encode-bytes/encode/bytes/_utils/model_base.py @@ -624,6 +624,9 @@ def __init__(self, *args: typing.Any, **kwargs: typing.Any) -> None: if len(items) > 0: existed_attr_keys.append(xml_name) dict_to_pass[rf._rest_name] = _deserialize(rf._type, items) + elif not rf._is_optional: + existed_attr_keys.append(xml_name) + dict_to_pass[rf._rest_name] = [] continue # text element is primitive type @@ -885,6 +888,8 @@ def _get_deserialize_callable_from_annotation( # pylint: disable=too-many-retur # is it optional? try: if any(a is _NONE_TYPE for a in annotation.__args__): # pyright: ignore + if rf: + rf._is_optional = True if len(annotation.__args__) <= 2: # pyright: ignore if_obj_deserializer = _get_deserialize_callable_from_annotation( next(a for a in annotation.__args__ if a is not _NONE_TYPE), module, rf # pyright: ignore @@ -1043,6 +1048,7 @@ def _failsafe_deserialize_xml( return None +# pylint: disable=too-many-instance-attributes class _RestField: def __init__( self, @@ -1062,6 +1068,7 @@ def __init__( self._is_discriminator = is_discriminator self._visibility = visibility self._is_model = False + self._is_optional = False self._default = default self._format = format self._is_multipart_file_input = is_multipart_file_input diff --git a/packages/typespec-python/test/unbranded/generated/encode-datetime/encode/datetime/_utils/model_base.py b/packages/typespec-python/test/unbranded/generated/encode-datetime/encode/datetime/_utils/model_base.py index c52d928e423..ca800653fd8 100644 --- a/packages/typespec-python/test/unbranded/generated/encode-datetime/encode/datetime/_utils/model_base.py +++ b/packages/typespec-python/test/unbranded/generated/encode-datetime/encode/datetime/_utils/model_base.py @@ -624,6 +624,9 @@ def __init__(self, *args: typing.Any, **kwargs: typing.Any) -> None: if len(items) > 0: existed_attr_keys.append(xml_name) dict_to_pass[rf._rest_name] = _deserialize(rf._type, items) + elif not rf._is_optional: + existed_attr_keys.append(xml_name) + dict_to_pass[rf._rest_name] = [] continue # text element is primitive type @@ -885,6 +888,8 @@ def _get_deserialize_callable_from_annotation( # pylint: disable=too-many-retur # is it optional? try: if any(a is _NONE_TYPE for a in annotation.__args__): # pyright: ignore + if rf: + rf._is_optional = True if len(annotation.__args__) <= 2: # pyright: ignore if_obj_deserializer = _get_deserialize_callable_from_annotation( next(a for a in annotation.__args__ if a is not _NONE_TYPE), module, rf # pyright: ignore @@ -1043,6 +1048,7 @@ def _failsafe_deserialize_xml( return None +# pylint: disable=too-many-instance-attributes class _RestField: def __init__( self, @@ -1062,6 +1068,7 @@ def __init__( self._is_discriminator = is_discriminator self._visibility = visibility self._is_model = False + self._is_optional = False self._default = default self._format = format self._is_multipart_file_input = is_multipart_file_input diff --git a/packages/typespec-python/test/unbranded/generated/encode-duration/encode/duration/_utils/model_base.py b/packages/typespec-python/test/unbranded/generated/encode-duration/encode/duration/_utils/model_base.py index c52d928e423..ca800653fd8 100644 --- a/packages/typespec-python/test/unbranded/generated/encode-duration/encode/duration/_utils/model_base.py +++ b/packages/typespec-python/test/unbranded/generated/encode-duration/encode/duration/_utils/model_base.py @@ -624,6 +624,9 @@ def __init__(self, *args: typing.Any, **kwargs: typing.Any) -> None: if len(items) > 0: existed_attr_keys.append(xml_name) dict_to_pass[rf._rest_name] = _deserialize(rf._type, items) + elif not rf._is_optional: + existed_attr_keys.append(xml_name) + dict_to_pass[rf._rest_name] = [] continue # text element is primitive type @@ -885,6 +888,8 @@ def _get_deserialize_callable_from_annotation( # pylint: disable=too-many-retur # is it optional? try: if any(a is _NONE_TYPE for a in annotation.__args__): # pyright: ignore + if rf: + rf._is_optional = True if len(annotation.__args__) <= 2: # pyright: ignore if_obj_deserializer = _get_deserialize_callable_from_annotation( next(a for a in annotation.__args__ if a is not _NONE_TYPE), module, rf # pyright: ignore @@ -1043,6 +1048,7 @@ def _failsafe_deserialize_xml( return None +# pylint: disable=too-many-instance-attributes class _RestField: def __init__( self, @@ -1062,6 +1068,7 @@ def __init__( self._is_discriminator = is_discriminator self._visibility = visibility self._is_model = False + self._is_optional = False self._default = default self._format = format self._is_multipart_file_input = is_multipart_file_input diff --git a/packages/typespec-python/test/unbranded/generated/encode-numeric/encode/numeric/_utils/model_base.py b/packages/typespec-python/test/unbranded/generated/encode-numeric/encode/numeric/_utils/model_base.py index c52d928e423..ca800653fd8 100644 --- a/packages/typespec-python/test/unbranded/generated/encode-numeric/encode/numeric/_utils/model_base.py +++ b/packages/typespec-python/test/unbranded/generated/encode-numeric/encode/numeric/_utils/model_base.py @@ -624,6 +624,9 @@ def __init__(self, *args: typing.Any, **kwargs: typing.Any) -> None: if len(items) > 0: existed_attr_keys.append(xml_name) dict_to_pass[rf._rest_name] = _deserialize(rf._type, items) + elif not rf._is_optional: + existed_attr_keys.append(xml_name) + dict_to_pass[rf._rest_name] = [] continue # text element is primitive type @@ -885,6 +888,8 @@ def _get_deserialize_callable_from_annotation( # pylint: disable=too-many-retur # is it optional? try: if any(a is _NONE_TYPE for a in annotation.__args__): # pyright: ignore + if rf: + rf._is_optional = True if len(annotation.__args__) <= 2: # pyright: ignore if_obj_deserializer = _get_deserialize_callable_from_annotation( next(a for a in annotation.__args__ if a is not _NONE_TYPE), module, rf # pyright: ignore @@ -1043,6 +1048,7 @@ def _failsafe_deserialize_xml( return None +# pylint: disable=too-many-instance-attributes class _RestField: def __init__( self, @@ -1062,6 +1068,7 @@ def __init__( self._is_discriminator = is_discriminator self._visibility = visibility self._is_model = False + self._is_optional = False self._default = default self._format = format self._is_multipart_file_input = is_multipart_file_input diff --git a/packages/typespec-python/test/unbranded/generated/generation-subdir/generation/subdir/_generated/_utils/model_base.py b/packages/typespec-python/test/unbranded/generated/generation-subdir/generation/subdir/_generated/_utils/model_base.py index c52d928e423..ca800653fd8 100644 --- a/packages/typespec-python/test/unbranded/generated/generation-subdir/generation/subdir/_generated/_utils/model_base.py +++ b/packages/typespec-python/test/unbranded/generated/generation-subdir/generation/subdir/_generated/_utils/model_base.py @@ -624,6 +624,9 @@ def __init__(self, *args: typing.Any, **kwargs: typing.Any) -> None: if len(items) > 0: existed_attr_keys.append(xml_name) dict_to_pass[rf._rest_name] = _deserialize(rf._type, items) + elif not rf._is_optional: + existed_attr_keys.append(xml_name) + dict_to_pass[rf._rest_name] = [] continue # text element is primitive type @@ -885,6 +888,8 @@ def _get_deserialize_callable_from_annotation( # pylint: disable=too-many-retur # is it optional? try: if any(a is _NONE_TYPE for a in annotation.__args__): # pyright: ignore + if rf: + rf._is_optional = True if len(annotation.__args__) <= 2: # pyright: ignore if_obj_deserializer = _get_deserialize_callable_from_annotation( next(a for a in annotation.__args__ if a is not _NONE_TYPE), module, rf # pyright: ignore @@ -1043,6 +1048,7 @@ def _failsafe_deserialize_xml( return None +# pylint: disable=too-many-instance-attributes class _RestField: def __init__( self, @@ -1062,6 +1068,7 @@ def __init__( self._is_discriminator = is_discriminator self._visibility = visibility self._is_model = False + self._is_optional = False self._default = default self._format = format self._is_multipart_file_input = is_multipart_file_input diff --git a/packages/typespec-python/test/unbranded/generated/headasbooleanfalse/headasbooleanfalse/_utils/model_base.py b/packages/typespec-python/test/unbranded/generated/headasbooleanfalse/headasbooleanfalse/_utils/model_base.py index c52d928e423..ca800653fd8 100644 --- a/packages/typespec-python/test/unbranded/generated/headasbooleanfalse/headasbooleanfalse/_utils/model_base.py +++ b/packages/typespec-python/test/unbranded/generated/headasbooleanfalse/headasbooleanfalse/_utils/model_base.py @@ -624,6 +624,9 @@ def __init__(self, *args: typing.Any, **kwargs: typing.Any) -> None: if len(items) > 0: existed_attr_keys.append(xml_name) dict_to_pass[rf._rest_name] = _deserialize(rf._type, items) + elif not rf._is_optional: + existed_attr_keys.append(xml_name) + dict_to_pass[rf._rest_name] = [] continue # text element is primitive type @@ -885,6 +888,8 @@ def _get_deserialize_callable_from_annotation( # pylint: disable=too-many-retur # is it optional? try: if any(a is _NONE_TYPE for a in annotation.__args__): # pyright: ignore + if rf: + rf._is_optional = True if len(annotation.__args__) <= 2: # pyright: ignore if_obj_deserializer = _get_deserialize_callable_from_annotation( next(a for a in annotation.__args__ if a is not _NONE_TYPE), module, rf # pyright: ignore @@ -1043,6 +1048,7 @@ def _failsafe_deserialize_xml( return None +# pylint: disable=too-many-instance-attributes class _RestField: def __init__( self, @@ -1062,6 +1068,7 @@ def __init__( self._is_discriminator = is_discriminator self._visibility = visibility self._is_model = False + self._is_optional = False self._default = default self._format = format self._is_multipart_file_input = is_multipart_file_input diff --git a/packages/typespec-python/test/unbranded/generated/headasbooleantrue/headasbooleantrue/_utils/model_base.py b/packages/typespec-python/test/unbranded/generated/headasbooleantrue/headasbooleantrue/_utils/model_base.py index c52d928e423..ca800653fd8 100644 --- a/packages/typespec-python/test/unbranded/generated/headasbooleantrue/headasbooleantrue/_utils/model_base.py +++ b/packages/typespec-python/test/unbranded/generated/headasbooleantrue/headasbooleantrue/_utils/model_base.py @@ -624,6 +624,9 @@ def __init__(self, *args: typing.Any, **kwargs: typing.Any) -> None: if len(items) > 0: existed_attr_keys.append(xml_name) dict_to_pass[rf._rest_name] = _deserialize(rf._type, items) + elif not rf._is_optional: + existed_attr_keys.append(xml_name) + dict_to_pass[rf._rest_name] = [] continue # text element is primitive type @@ -885,6 +888,8 @@ def _get_deserialize_callable_from_annotation( # pylint: disable=too-many-retur # is it optional? try: if any(a is _NONE_TYPE for a in annotation.__args__): # pyright: ignore + if rf: + rf._is_optional = True if len(annotation.__args__) <= 2: # pyright: ignore if_obj_deserializer = _get_deserialize_callable_from_annotation( next(a for a in annotation.__args__ if a is not _NONE_TYPE), module, rf # pyright: ignore @@ -1043,6 +1048,7 @@ def _failsafe_deserialize_xml( return None +# pylint: disable=too-many-instance-attributes class _RestField: def __init__( self, @@ -1062,6 +1068,7 @@ def __init__( self._is_discriminator = is_discriminator self._visibility = visibility self._is_model = False + self._is_optional = False self._default = default self._format = format self._is_multipart_file_input = is_multipart_file_input diff --git a/packages/typespec-python/test/unbranded/generated/parameters-basic/parameters/basic/_utils/model_base.py b/packages/typespec-python/test/unbranded/generated/parameters-basic/parameters/basic/_utils/model_base.py index c52d928e423..ca800653fd8 100644 --- a/packages/typespec-python/test/unbranded/generated/parameters-basic/parameters/basic/_utils/model_base.py +++ b/packages/typespec-python/test/unbranded/generated/parameters-basic/parameters/basic/_utils/model_base.py @@ -624,6 +624,9 @@ def __init__(self, *args: typing.Any, **kwargs: typing.Any) -> None: if len(items) > 0: existed_attr_keys.append(xml_name) dict_to_pass[rf._rest_name] = _deserialize(rf._type, items) + elif not rf._is_optional: + existed_attr_keys.append(xml_name) + dict_to_pass[rf._rest_name] = [] continue # text element is primitive type @@ -885,6 +888,8 @@ def _get_deserialize_callable_from_annotation( # pylint: disable=too-many-retur # is it optional? try: if any(a is _NONE_TYPE for a in annotation.__args__): # pyright: ignore + if rf: + rf._is_optional = True if len(annotation.__args__) <= 2: # pyright: ignore if_obj_deserializer = _get_deserialize_callable_from_annotation( next(a for a in annotation.__args__ if a is not _NONE_TYPE), module, rf # pyright: ignore @@ -1043,6 +1048,7 @@ def _failsafe_deserialize_xml( return None +# pylint: disable=too-many-instance-attributes class _RestField: def __init__( self, @@ -1062,6 +1068,7 @@ def __init__( self._is_discriminator = is_discriminator self._visibility = visibility self._is_model = False + self._is_optional = False self._default = default self._format = format self._is_multipart_file_input = is_multipart_file_input diff --git a/packages/typespec-python/test/unbranded/generated/parameters-body-optionality/parameters/bodyoptionality/_utils/model_base.py b/packages/typespec-python/test/unbranded/generated/parameters-body-optionality/parameters/bodyoptionality/_utils/model_base.py index c52d928e423..ca800653fd8 100644 --- a/packages/typespec-python/test/unbranded/generated/parameters-body-optionality/parameters/bodyoptionality/_utils/model_base.py +++ b/packages/typespec-python/test/unbranded/generated/parameters-body-optionality/parameters/bodyoptionality/_utils/model_base.py @@ -624,6 +624,9 @@ def __init__(self, *args: typing.Any, **kwargs: typing.Any) -> None: if len(items) > 0: existed_attr_keys.append(xml_name) dict_to_pass[rf._rest_name] = _deserialize(rf._type, items) + elif not rf._is_optional: + existed_attr_keys.append(xml_name) + dict_to_pass[rf._rest_name] = [] continue # text element is primitive type @@ -885,6 +888,8 @@ def _get_deserialize_callable_from_annotation( # pylint: disable=too-many-retur # is it optional? try: if any(a is _NONE_TYPE for a in annotation.__args__): # pyright: ignore + if rf: + rf._is_optional = True if len(annotation.__args__) <= 2: # pyright: ignore if_obj_deserializer = _get_deserialize_callable_from_annotation( next(a for a in annotation.__args__ if a is not _NONE_TYPE), module, rf # pyright: ignore @@ -1043,6 +1048,7 @@ def _failsafe_deserialize_xml( return None +# pylint: disable=too-many-instance-attributes class _RestField: def __init__( self, @@ -1062,6 +1068,7 @@ def __init__( self._is_discriminator = is_discriminator self._visibility = visibility self._is_model = False + self._is_optional = False self._default = default self._format = format self._is_multipart_file_input = is_multipart_file_input diff --git a/packages/typespec-python/test/unbranded/generated/parameters-collection-format/parameters/collectionformat/_utils/model_base.py b/packages/typespec-python/test/unbranded/generated/parameters-collection-format/parameters/collectionformat/_utils/model_base.py index c52d928e423..ca800653fd8 100644 --- a/packages/typespec-python/test/unbranded/generated/parameters-collection-format/parameters/collectionformat/_utils/model_base.py +++ b/packages/typespec-python/test/unbranded/generated/parameters-collection-format/parameters/collectionformat/_utils/model_base.py @@ -624,6 +624,9 @@ def __init__(self, *args: typing.Any, **kwargs: typing.Any) -> None: if len(items) > 0: existed_attr_keys.append(xml_name) dict_to_pass[rf._rest_name] = _deserialize(rf._type, items) + elif not rf._is_optional: + existed_attr_keys.append(xml_name) + dict_to_pass[rf._rest_name] = [] continue # text element is primitive type @@ -885,6 +888,8 @@ def _get_deserialize_callable_from_annotation( # pylint: disable=too-many-retur # is it optional? try: if any(a is _NONE_TYPE for a in annotation.__args__): # pyright: ignore + if rf: + rf._is_optional = True if len(annotation.__args__) <= 2: # pyright: ignore if_obj_deserializer = _get_deserialize_callable_from_annotation( next(a for a in annotation.__args__ if a is not _NONE_TYPE), module, rf # pyright: ignore @@ -1043,6 +1048,7 @@ def _failsafe_deserialize_xml( return None +# pylint: disable=too-many-instance-attributes class _RestField: def __init__( self, @@ -1062,6 +1068,7 @@ def __init__( self._is_discriminator = is_discriminator self._visibility = visibility self._is_model = False + self._is_optional = False self._default = default self._format = format self._is_multipart_file_input = is_multipart_file_input diff --git a/packages/typespec-python/test/unbranded/generated/parameters-path/parameters/path/_utils/model_base.py b/packages/typespec-python/test/unbranded/generated/parameters-path/parameters/path/_utils/model_base.py index c52d928e423..ca800653fd8 100644 --- a/packages/typespec-python/test/unbranded/generated/parameters-path/parameters/path/_utils/model_base.py +++ b/packages/typespec-python/test/unbranded/generated/parameters-path/parameters/path/_utils/model_base.py @@ -624,6 +624,9 @@ def __init__(self, *args: typing.Any, **kwargs: typing.Any) -> None: if len(items) > 0: existed_attr_keys.append(xml_name) dict_to_pass[rf._rest_name] = _deserialize(rf._type, items) + elif not rf._is_optional: + existed_attr_keys.append(xml_name) + dict_to_pass[rf._rest_name] = [] continue # text element is primitive type @@ -885,6 +888,8 @@ def _get_deserialize_callable_from_annotation( # pylint: disable=too-many-retur # is it optional? try: if any(a is _NONE_TYPE for a in annotation.__args__): # pyright: ignore + if rf: + rf._is_optional = True if len(annotation.__args__) <= 2: # pyright: ignore if_obj_deserializer = _get_deserialize_callable_from_annotation( next(a for a in annotation.__args__ if a is not _NONE_TYPE), module, rf # pyright: ignore @@ -1043,6 +1048,7 @@ def _failsafe_deserialize_xml( return None +# pylint: disable=too-many-instance-attributes class _RestField: def __init__( self, @@ -1062,6 +1068,7 @@ def __init__( self._is_discriminator = is_discriminator self._visibility = visibility self._is_model = False + self._is_optional = False self._default = default self._format = format self._is_multipart_file_input = is_multipart_file_input diff --git a/packages/typespec-python/test/unbranded/generated/parameters-query/parameters/query/_utils/model_base.py b/packages/typespec-python/test/unbranded/generated/parameters-query/parameters/query/_utils/model_base.py index c52d928e423..ca800653fd8 100644 --- a/packages/typespec-python/test/unbranded/generated/parameters-query/parameters/query/_utils/model_base.py +++ b/packages/typespec-python/test/unbranded/generated/parameters-query/parameters/query/_utils/model_base.py @@ -624,6 +624,9 @@ def __init__(self, *args: typing.Any, **kwargs: typing.Any) -> None: if len(items) > 0: existed_attr_keys.append(xml_name) dict_to_pass[rf._rest_name] = _deserialize(rf._type, items) + elif not rf._is_optional: + existed_attr_keys.append(xml_name) + dict_to_pass[rf._rest_name] = [] continue # text element is primitive type @@ -885,6 +888,8 @@ def _get_deserialize_callable_from_annotation( # pylint: disable=too-many-retur # is it optional? try: if any(a is _NONE_TYPE for a in annotation.__args__): # pyright: ignore + if rf: + rf._is_optional = True if len(annotation.__args__) <= 2: # pyright: ignore if_obj_deserializer = _get_deserialize_callable_from_annotation( next(a for a in annotation.__args__ if a is not _NONE_TYPE), module, rf # pyright: ignore @@ -1043,6 +1048,7 @@ def _failsafe_deserialize_xml( return None +# pylint: disable=too-many-instance-attributes class _RestField: def __init__( self, @@ -1062,6 +1068,7 @@ def __init__( self._is_discriminator = is_discriminator self._visibility = visibility self._is_model = False + self._is_optional = False self._default = default self._format = format self._is_multipart_file_input = is_multipart_file_input diff --git a/packages/typespec-python/test/unbranded/generated/parameters-spread/parameters/spread/_utils/model_base.py b/packages/typespec-python/test/unbranded/generated/parameters-spread/parameters/spread/_utils/model_base.py index c52d928e423..ca800653fd8 100644 --- a/packages/typespec-python/test/unbranded/generated/parameters-spread/parameters/spread/_utils/model_base.py +++ b/packages/typespec-python/test/unbranded/generated/parameters-spread/parameters/spread/_utils/model_base.py @@ -624,6 +624,9 @@ def __init__(self, *args: typing.Any, **kwargs: typing.Any) -> None: if len(items) > 0: existed_attr_keys.append(xml_name) dict_to_pass[rf._rest_name] = _deserialize(rf._type, items) + elif not rf._is_optional: + existed_attr_keys.append(xml_name) + dict_to_pass[rf._rest_name] = [] continue # text element is primitive type @@ -885,6 +888,8 @@ def _get_deserialize_callable_from_annotation( # pylint: disable=too-many-retur # is it optional? try: if any(a is _NONE_TYPE for a in annotation.__args__): # pyright: ignore + if rf: + rf._is_optional = True if len(annotation.__args__) <= 2: # pyright: ignore if_obj_deserializer = _get_deserialize_callable_from_annotation( next(a for a in annotation.__args__ if a is not _NONE_TYPE), module, rf # pyright: ignore @@ -1043,6 +1048,7 @@ def _failsafe_deserialize_xml( return None +# pylint: disable=too-many-instance-attributes class _RestField: def __init__( self, @@ -1062,6 +1068,7 @@ def __init__( self._is_discriminator = is_discriminator self._visibility = visibility self._is_model = False + self._is_optional = False self._default = default self._format = format self._is_multipart_file_input = is_multipart_file_input diff --git a/packages/typespec-python/test/unbranded/generated/payload-content-negotiation/payload/contentnegotiation/_utils/model_base.py b/packages/typespec-python/test/unbranded/generated/payload-content-negotiation/payload/contentnegotiation/_utils/model_base.py index c52d928e423..ca800653fd8 100644 --- a/packages/typespec-python/test/unbranded/generated/payload-content-negotiation/payload/contentnegotiation/_utils/model_base.py +++ b/packages/typespec-python/test/unbranded/generated/payload-content-negotiation/payload/contentnegotiation/_utils/model_base.py @@ -624,6 +624,9 @@ def __init__(self, *args: typing.Any, **kwargs: typing.Any) -> None: if len(items) > 0: existed_attr_keys.append(xml_name) dict_to_pass[rf._rest_name] = _deserialize(rf._type, items) + elif not rf._is_optional: + existed_attr_keys.append(xml_name) + dict_to_pass[rf._rest_name] = [] continue # text element is primitive type @@ -885,6 +888,8 @@ def _get_deserialize_callable_from_annotation( # pylint: disable=too-many-retur # is it optional? try: if any(a is _NONE_TYPE for a in annotation.__args__): # pyright: ignore + if rf: + rf._is_optional = True if len(annotation.__args__) <= 2: # pyright: ignore if_obj_deserializer = _get_deserialize_callable_from_annotation( next(a for a in annotation.__args__ if a is not _NONE_TYPE), module, rf # pyright: ignore @@ -1043,6 +1048,7 @@ def _failsafe_deserialize_xml( return None +# pylint: disable=too-many-instance-attributes class _RestField: def __init__( self, @@ -1062,6 +1068,7 @@ def __init__( self._is_discriminator = is_discriminator self._visibility = visibility self._is_model = False + self._is_optional = False self._default = default self._format = format self._is_multipart_file_input = is_multipart_file_input diff --git a/packages/typespec-python/test/unbranded/generated/payload-json-merge-patch/payload/jsonmergepatch/_utils/model_base.py b/packages/typespec-python/test/unbranded/generated/payload-json-merge-patch/payload/jsonmergepatch/_utils/model_base.py index c52d928e423..ca800653fd8 100644 --- a/packages/typespec-python/test/unbranded/generated/payload-json-merge-patch/payload/jsonmergepatch/_utils/model_base.py +++ b/packages/typespec-python/test/unbranded/generated/payload-json-merge-patch/payload/jsonmergepatch/_utils/model_base.py @@ -624,6 +624,9 @@ def __init__(self, *args: typing.Any, **kwargs: typing.Any) -> None: if len(items) > 0: existed_attr_keys.append(xml_name) dict_to_pass[rf._rest_name] = _deserialize(rf._type, items) + elif not rf._is_optional: + existed_attr_keys.append(xml_name) + dict_to_pass[rf._rest_name] = [] continue # text element is primitive type @@ -885,6 +888,8 @@ def _get_deserialize_callable_from_annotation( # pylint: disable=too-many-retur # is it optional? try: if any(a is _NONE_TYPE for a in annotation.__args__): # pyright: ignore + if rf: + rf._is_optional = True if len(annotation.__args__) <= 2: # pyright: ignore if_obj_deserializer = _get_deserialize_callable_from_annotation( next(a for a in annotation.__args__ if a is not _NONE_TYPE), module, rf # pyright: ignore @@ -1043,6 +1048,7 @@ def _failsafe_deserialize_xml( return None +# pylint: disable=too-many-instance-attributes class _RestField: def __init__( self, @@ -1062,6 +1068,7 @@ def __init__( self._is_discriminator = is_discriminator self._visibility = visibility self._is_model = False + self._is_optional = False self._default = default self._format = format self._is_multipart_file_input = is_multipart_file_input diff --git a/packages/typespec-python/test/unbranded/generated/payload-media-type/payload/mediatype/_utils/model_base.py b/packages/typespec-python/test/unbranded/generated/payload-media-type/payload/mediatype/_utils/model_base.py index c52d928e423..ca800653fd8 100644 --- a/packages/typespec-python/test/unbranded/generated/payload-media-type/payload/mediatype/_utils/model_base.py +++ b/packages/typespec-python/test/unbranded/generated/payload-media-type/payload/mediatype/_utils/model_base.py @@ -624,6 +624,9 @@ def __init__(self, *args: typing.Any, **kwargs: typing.Any) -> None: if len(items) > 0: existed_attr_keys.append(xml_name) dict_to_pass[rf._rest_name] = _deserialize(rf._type, items) + elif not rf._is_optional: + existed_attr_keys.append(xml_name) + dict_to_pass[rf._rest_name] = [] continue # text element is primitive type @@ -885,6 +888,8 @@ def _get_deserialize_callable_from_annotation( # pylint: disable=too-many-retur # is it optional? try: if any(a is _NONE_TYPE for a in annotation.__args__): # pyright: ignore + if rf: + rf._is_optional = True if len(annotation.__args__) <= 2: # pyright: ignore if_obj_deserializer = _get_deserialize_callable_from_annotation( next(a for a in annotation.__args__ if a is not _NONE_TYPE), module, rf # pyright: ignore @@ -1043,6 +1048,7 @@ def _failsafe_deserialize_xml( return None +# pylint: disable=too-many-instance-attributes class _RestField: def __init__( self, @@ -1062,6 +1068,7 @@ def __init__( self._is_discriminator = is_discriminator self._visibility = visibility self._is_model = False + self._is_optional = False self._default = default self._format = format self._is_multipart_file_input = is_multipart_file_input diff --git a/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/_utils/model_base.py b/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/_utils/model_base.py index c52d928e423..ca800653fd8 100644 --- a/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/_utils/model_base.py +++ b/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/_utils/model_base.py @@ -624,6 +624,9 @@ def __init__(self, *args: typing.Any, **kwargs: typing.Any) -> None: if len(items) > 0: existed_attr_keys.append(xml_name) dict_to_pass[rf._rest_name] = _deserialize(rf._type, items) + elif not rf._is_optional: + existed_attr_keys.append(xml_name) + dict_to_pass[rf._rest_name] = [] continue # text element is primitive type @@ -885,6 +888,8 @@ def _get_deserialize_callable_from_annotation( # pylint: disable=too-many-retur # is it optional? try: if any(a is _NONE_TYPE for a in annotation.__args__): # pyright: ignore + if rf: + rf._is_optional = True if len(annotation.__args__) <= 2: # pyright: ignore if_obj_deserializer = _get_deserialize_callable_from_annotation( next(a for a in annotation.__args__ if a is not _NONE_TYPE), module, rf # pyright: ignore @@ -1043,6 +1048,7 @@ def _failsafe_deserialize_xml( return None +# pylint: disable=too-many-instance-attributes class _RestField: def __init__( self, @@ -1062,6 +1068,7 @@ def __init__( self._is_discriminator = is_discriminator self._visibility = visibility self._is_model = False + self._is_optional = False self._default = default self._format = format self._is_multipart_file_input = is_multipart_file_input diff --git a/packages/typespec-python/test/unbranded/generated/payload-pageable/payload/pageable/_utils/model_base.py b/packages/typespec-python/test/unbranded/generated/payload-pageable/payload/pageable/_utils/model_base.py index c52d928e423..ca800653fd8 100644 --- a/packages/typespec-python/test/unbranded/generated/payload-pageable/payload/pageable/_utils/model_base.py +++ b/packages/typespec-python/test/unbranded/generated/payload-pageable/payload/pageable/_utils/model_base.py @@ -624,6 +624,9 @@ def __init__(self, *args: typing.Any, **kwargs: typing.Any) -> None: if len(items) > 0: existed_attr_keys.append(xml_name) dict_to_pass[rf._rest_name] = _deserialize(rf._type, items) + elif not rf._is_optional: + existed_attr_keys.append(xml_name) + dict_to_pass[rf._rest_name] = [] continue # text element is primitive type @@ -885,6 +888,8 @@ def _get_deserialize_callable_from_annotation( # pylint: disable=too-many-retur # is it optional? try: if any(a is _NONE_TYPE for a in annotation.__args__): # pyright: ignore + if rf: + rf._is_optional = True if len(annotation.__args__) <= 2: # pyright: ignore if_obj_deserializer = _get_deserialize_callable_from_annotation( next(a for a in annotation.__args__ if a is not _NONE_TYPE), module, rf # pyright: ignore @@ -1043,6 +1048,7 @@ def _failsafe_deserialize_xml( return None +# pylint: disable=too-many-instance-attributes class _RestField: def __init__( self, @@ -1062,6 +1068,7 @@ def __init__( self._is_discriminator = is_discriminator self._visibility = visibility self._is_model = False + self._is_optional = False self._default = default self._format = format self._is_multipart_file_input = is_multipart_file_input diff --git a/packages/typespec-python/test/unbranded/generated/payload-xml/payload/xml/_utils/model_base.py b/packages/typespec-python/test/unbranded/generated/payload-xml/payload/xml/_utils/model_base.py index 7199d1d1dce..c62373f9db9 100644 --- a/packages/typespec-python/test/unbranded/generated/payload-xml/payload/xml/_utils/model_base.py +++ b/packages/typespec-python/test/unbranded/generated/payload-xml/payload/xml/_utils/model_base.py @@ -624,6 +624,9 @@ def __init__(self, *args: typing.Any, **kwargs: typing.Any) -> None: if len(items) > 0: existed_attr_keys.append(xml_name) dict_to_pass[rf._rest_name] = _deserialize(rf._type, items) + elif not rf._is_optional: + existed_attr_keys.append(xml_name) + dict_to_pass[rf._rest_name] = [] continue # text element is primitive type @@ -899,6 +902,8 @@ def _get_deserialize_callable_from_annotation( # pylint: disable=too-many-retur # is it optional? try: if any(a is _NONE_TYPE for a in annotation.__args__): # pyright: ignore + if rf: + rf._is_optional = True if len(annotation.__args__) <= 2: # pyright: ignore if_obj_deserializer = _get_deserialize_callable_from_annotation( next(a for a in annotation.__args__ if a is not _NONE_TYPE), module, rf # pyright: ignore @@ -1078,6 +1083,7 @@ def __init__( self._is_discriminator = is_discriminator self._visibility = visibility self._is_model = False + self._is_optional = False self._default = default self._format = format self._is_multipart_file_input = is_multipart_file_input diff --git a/packages/typespec-python/test/unbranded/generated/response-status-code-range/response/statuscoderange/_utils/model_base.py b/packages/typespec-python/test/unbranded/generated/response-status-code-range/response/statuscoderange/_utils/model_base.py index c52d928e423..ca800653fd8 100644 --- a/packages/typespec-python/test/unbranded/generated/response-status-code-range/response/statuscoderange/_utils/model_base.py +++ b/packages/typespec-python/test/unbranded/generated/response-status-code-range/response/statuscoderange/_utils/model_base.py @@ -624,6 +624,9 @@ def __init__(self, *args: typing.Any, **kwargs: typing.Any) -> None: if len(items) > 0: existed_attr_keys.append(xml_name) dict_to_pass[rf._rest_name] = _deserialize(rf._type, items) + elif not rf._is_optional: + existed_attr_keys.append(xml_name) + dict_to_pass[rf._rest_name] = [] continue # text element is primitive type @@ -885,6 +888,8 @@ def _get_deserialize_callable_from_annotation( # pylint: disable=too-many-retur # is it optional? try: if any(a is _NONE_TYPE for a in annotation.__args__): # pyright: ignore + if rf: + rf._is_optional = True if len(annotation.__args__) <= 2: # pyright: ignore if_obj_deserializer = _get_deserialize_callable_from_annotation( next(a for a in annotation.__args__ if a is not _NONE_TYPE), module, rf # pyright: ignore @@ -1043,6 +1048,7 @@ def _failsafe_deserialize_xml( return None +# pylint: disable=too-many-instance-attributes class _RestField: def __init__( self, @@ -1062,6 +1068,7 @@ def __init__( self._is_discriminator = is_discriminator self._visibility = visibility self._is_model = False + self._is_optional = False self._default = default self._format = format self._is_multipart_file_input = is_multipart_file_input diff --git a/packages/typespec-python/test/unbranded/generated/routes/routes/_utils/model_base.py b/packages/typespec-python/test/unbranded/generated/routes/routes/_utils/model_base.py index c52d928e423..ca800653fd8 100644 --- a/packages/typespec-python/test/unbranded/generated/routes/routes/_utils/model_base.py +++ b/packages/typespec-python/test/unbranded/generated/routes/routes/_utils/model_base.py @@ -624,6 +624,9 @@ def __init__(self, *args: typing.Any, **kwargs: typing.Any) -> None: if len(items) > 0: existed_attr_keys.append(xml_name) dict_to_pass[rf._rest_name] = _deserialize(rf._type, items) + elif not rf._is_optional: + existed_attr_keys.append(xml_name) + dict_to_pass[rf._rest_name] = [] continue # text element is primitive type @@ -885,6 +888,8 @@ def _get_deserialize_callable_from_annotation( # pylint: disable=too-many-retur # is it optional? try: if any(a is _NONE_TYPE for a in annotation.__args__): # pyright: ignore + if rf: + rf._is_optional = True if len(annotation.__args__) <= 2: # pyright: ignore if_obj_deserializer = _get_deserialize_callable_from_annotation( next(a for a in annotation.__args__ if a is not _NONE_TYPE), module, rf # pyright: ignore @@ -1043,6 +1048,7 @@ def _failsafe_deserialize_xml( return None +# pylint: disable=too-many-instance-attributes class _RestField: def __init__( self, @@ -1062,6 +1068,7 @@ def __init__( self._is_discriminator = is_discriminator self._visibility = visibility self._is_model = False + self._is_optional = False self._default = default self._format = format self._is_multipart_file_input = is_multipart_file_input diff --git a/packages/typespec-python/test/unbranded/generated/serialization-encoded-name-json/serialization/encodedname/json/_utils/model_base.py b/packages/typespec-python/test/unbranded/generated/serialization-encoded-name-json/serialization/encodedname/json/_utils/model_base.py index c52d928e423..ca800653fd8 100644 --- a/packages/typespec-python/test/unbranded/generated/serialization-encoded-name-json/serialization/encodedname/json/_utils/model_base.py +++ b/packages/typespec-python/test/unbranded/generated/serialization-encoded-name-json/serialization/encodedname/json/_utils/model_base.py @@ -624,6 +624,9 @@ def __init__(self, *args: typing.Any, **kwargs: typing.Any) -> None: if len(items) > 0: existed_attr_keys.append(xml_name) dict_to_pass[rf._rest_name] = _deserialize(rf._type, items) + elif not rf._is_optional: + existed_attr_keys.append(xml_name) + dict_to_pass[rf._rest_name] = [] continue # text element is primitive type @@ -885,6 +888,8 @@ def _get_deserialize_callable_from_annotation( # pylint: disable=too-many-retur # is it optional? try: if any(a is _NONE_TYPE for a in annotation.__args__): # pyright: ignore + if rf: + rf._is_optional = True if len(annotation.__args__) <= 2: # pyright: ignore if_obj_deserializer = _get_deserialize_callable_from_annotation( next(a for a in annotation.__args__ if a is not _NONE_TYPE), module, rf # pyright: ignore @@ -1043,6 +1048,7 @@ def _failsafe_deserialize_xml( return None +# pylint: disable=too-many-instance-attributes class _RestField: def __init__( self, @@ -1062,6 +1068,7 @@ def __init__( self._is_discriminator = is_discriminator self._visibility = visibility self._is_model = False + self._is_optional = False self._default = default self._format = format self._is_multipart_file_input = is_multipart_file_input diff --git a/packages/typespec-python/test/unbranded/generated/server-endpoint-not-defined/server/endpoint/notdefined/_utils/model_base.py b/packages/typespec-python/test/unbranded/generated/server-endpoint-not-defined/server/endpoint/notdefined/_utils/model_base.py index c52d928e423..ca800653fd8 100644 --- a/packages/typespec-python/test/unbranded/generated/server-endpoint-not-defined/server/endpoint/notdefined/_utils/model_base.py +++ b/packages/typespec-python/test/unbranded/generated/server-endpoint-not-defined/server/endpoint/notdefined/_utils/model_base.py @@ -624,6 +624,9 @@ def __init__(self, *args: typing.Any, **kwargs: typing.Any) -> None: if len(items) > 0: existed_attr_keys.append(xml_name) dict_to_pass[rf._rest_name] = _deserialize(rf._type, items) + elif not rf._is_optional: + existed_attr_keys.append(xml_name) + dict_to_pass[rf._rest_name] = [] continue # text element is primitive type @@ -885,6 +888,8 @@ def _get_deserialize_callable_from_annotation( # pylint: disable=too-many-retur # is it optional? try: if any(a is _NONE_TYPE for a in annotation.__args__): # pyright: ignore + if rf: + rf._is_optional = True if len(annotation.__args__) <= 2: # pyright: ignore if_obj_deserializer = _get_deserialize_callable_from_annotation( next(a for a in annotation.__args__ if a is not _NONE_TYPE), module, rf # pyright: ignore @@ -1043,6 +1048,7 @@ def _failsafe_deserialize_xml( return None +# pylint: disable=too-many-instance-attributes class _RestField: def __init__( self, @@ -1062,6 +1068,7 @@ def __init__( self._is_discriminator = is_discriminator self._visibility = visibility self._is_model = False + self._is_optional = False self._default = default self._format = format self._is_multipart_file_input = is_multipart_file_input diff --git a/packages/typespec-python/test/unbranded/generated/server-path-multiple/server/path/multiple/_utils/model_base.py b/packages/typespec-python/test/unbranded/generated/server-path-multiple/server/path/multiple/_utils/model_base.py index c52d928e423..ca800653fd8 100644 --- a/packages/typespec-python/test/unbranded/generated/server-path-multiple/server/path/multiple/_utils/model_base.py +++ b/packages/typespec-python/test/unbranded/generated/server-path-multiple/server/path/multiple/_utils/model_base.py @@ -624,6 +624,9 @@ def __init__(self, *args: typing.Any, **kwargs: typing.Any) -> None: if len(items) > 0: existed_attr_keys.append(xml_name) dict_to_pass[rf._rest_name] = _deserialize(rf._type, items) + elif not rf._is_optional: + existed_attr_keys.append(xml_name) + dict_to_pass[rf._rest_name] = [] continue # text element is primitive type @@ -885,6 +888,8 @@ def _get_deserialize_callable_from_annotation( # pylint: disable=too-many-retur # is it optional? try: if any(a is _NONE_TYPE for a in annotation.__args__): # pyright: ignore + if rf: + rf._is_optional = True if len(annotation.__args__) <= 2: # pyright: ignore if_obj_deserializer = _get_deserialize_callable_from_annotation( next(a for a in annotation.__args__ if a is not _NONE_TYPE), module, rf # pyright: ignore @@ -1043,6 +1048,7 @@ def _failsafe_deserialize_xml( return None +# pylint: disable=too-many-instance-attributes class _RestField: def __init__( self, @@ -1062,6 +1068,7 @@ def __init__( self._is_discriminator = is_discriminator self._visibility = visibility self._is_model = False + self._is_optional = False self._default = default self._format = format self._is_multipart_file_input = is_multipart_file_input diff --git a/packages/typespec-python/test/unbranded/generated/server-path-single/server/path/single/_utils/model_base.py b/packages/typespec-python/test/unbranded/generated/server-path-single/server/path/single/_utils/model_base.py index c52d928e423..ca800653fd8 100644 --- a/packages/typespec-python/test/unbranded/generated/server-path-single/server/path/single/_utils/model_base.py +++ b/packages/typespec-python/test/unbranded/generated/server-path-single/server/path/single/_utils/model_base.py @@ -624,6 +624,9 @@ def __init__(self, *args: typing.Any, **kwargs: typing.Any) -> None: if len(items) > 0: existed_attr_keys.append(xml_name) dict_to_pass[rf._rest_name] = _deserialize(rf._type, items) + elif not rf._is_optional: + existed_attr_keys.append(xml_name) + dict_to_pass[rf._rest_name] = [] continue # text element is primitive type @@ -885,6 +888,8 @@ def _get_deserialize_callable_from_annotation( # pylint: disable=too-many-retur # is it optional? try: if any(a is _NONE_TYPE for a in annotation.__args__): # pyright: ignore + if rf: + rf._is_optional = True if len(annotation.__args__) <= 2: # pyright: ignore if_obj_deserializer = _get_deserialize_callable_from_annotation( next(a for a in annotation.__args__ if a is not _NONE_TYPE), module, rf # pyright: ignore @@ -1043,6 +1048,7 @@ def _failsafe_deserialize_xml( return None +# pylint: disable=too-many-instance-attributes class _RestField: def __init__( self, @@ -1062,6 +1068,7 @@ def __init__( self._is_discriminator = is_discriminator self._visibility = visibility self._is_model = False + self._is_optional = False self._default = default self._format = format self._is_multipart_file_input = is_multipart_file_input diff --git a/packages/typespec-python/test/unbranded/generated/server-versions-not-versioned/server/versions/notversioned/_utils/model_base.py b/packages/typespec-python/test/unbranded/generated/server-versions-not-versioned/server/versions/notversioned/_utils/model_base.py index c52d928e423..ca800653fd8 100644 --- a/packages/typespec-python/test/unbranded/generated/server-versions-not-versioned/server/versions/notversioned/_utils/model_base.py +++ b/packages/typespec-python/test/unbranded/generated/server-versions-not-versioned/server/versions/notversioned/_utils/model_base.py @@ -624,6 +624,9 @@ def __init__(self, *args: typing.Any, **kwargs: typing.Any) -> None: if len(items) > 0: existed_attr_keys.append(xml_name) dict_to_pass[rf._rest_name] = _deserialize(rf._type, items) + elif not rf._is_optional: + existed_attr_keys.append(xml_name) + dict_to_pass[rf._rest_name] = [] continue # text element is primitive type @@ -885,6 +888,8 @@ def _get_deserialize_callable_from_annotation( # pylint: disable=too-many-retur # is it optional? try: if any(a is _NONE_TYPE for a in annotation.__args__): # pyright: ignore + if rf: + rf._is_optional = True if len(annotation.__args__) <= 2: # pyright: ignore if_obj_deserializer = _get_deserialize_callable_from_annotation( next(a for a in annotation.__args__ if a is not _NONE_TYPE), module, rf # pyright: ignore @@ -1043,6 +1048,7 @@ def _failsafe_deserialize_xml( return None +# pylint: disable=too-many-instance-attributes class _RestField: def __init__( self, @@ -1062,6 +1068,7 @@ def __init__( self._is_discriminator = is_discriminator self._visibility = visibility self._is_model = False + self._is_optional = False self._default = default self._format = format self._is_multipart_file_input = is_multipart_file_input diff --git a/packages/typespec-python/test/unbranded/generated/server-versions-versioned/server/versions/versioned/_utils/model_base.py b/packages/typespec-python/test/unbranded/generated/server-versions-versioned/server/versions/versioned/_utils/model_base.py index c52d928e423..ca800653fd8 100644 --- a/packages/typespec-python/test/unbranded/generated/server-versions-versioned/server/versions/versioned/_utils/model_base.py +++ b/packages/typespec-python/test/unbranded/generated/server-versions-versioned/server/versions/versioned/_utils/model_base.py @@ -624,6 +624,9 @@ def __init__(self, *args: typing.Any, **kwargs: typing.Any) -> None: if len(items) > 0: existed_attr_keys.append(xml_name) dict_to_pass[rf._rest_name] = _deserialize(rf._type, items) + elif not rf._is_optional: + existed_attr_keys.append(xml_name) + dict_to_pass[rf._rest_name] = [] continue # text element is primitive type @@ -885,6 +888,8 @@ def _get_deserialize_callable_from_annotation( # pylint: disable=too-many-retur # is it optional? try: if any(a is _NONE_TYPE for a in annotation.__args__): # pyright: ignore + if rf: + rf._is_optional = True if len(annotation.__args__) <= 2: # pyright: ignore if_obj_deserializer = _get_deserialize_callable_from_annotation( next(a for a in annotation.__args__ if a is not _NONE_TYPE), module, rf # pyright: ignore @@ -1043,6 +1048,7 @@ def _failsafe_deserialize_xml( return None +# pylint: disable=too-many-instance-attributes class _RestField: def __init__( self, @@ -1062,6 +1068,7 @@ def __init__( self._is_discriminator = is_discriminator self._visibility = visibility self._is_model = False + self._is_optional = False self._default = default self._format = format self._is_multipart_file_input = is_multipart_file_input diff --git a/packages/typespec-python/test/unbranded/generated/setuppy-authentication-union/setuppy/authentication/union/_utils/model_base.py b/packages/typespec-python/test/unbranded/generated/setuppy-authentication-union/setuppy/authentication/union/_utils/model_base.py index c52d928e423..ca800653fd8 100644 --- a/packages/typespec-python/test/unbranded/generated/setuppy-authentication-union/setuppy/authentication/union/_utils/model_base.py +++ b/packages/typespec-python/test/unbranded/generated/setuppy-authentication-union/setuppy/authentication/union/_utils/model_base.py @@ -624,6 +624,9 @@ def __init__(self, *args: typing.Any, **kwargs: typing.Any) -> None: if len(items) > 0: existed_attr_keys.append(xml_name) dict_to_pass[rf._rest_name] = _deserialize(rf._type, items) + elif not rf._is_optional: + existed_attr_keys.append(xml_name) + dict_to_pass[rf._rest_name] = [] continue # text element is primitive type @@ -885,6 +888,8 @@ def _get_deserialize_callable_from_annotation( # pylint: disable=too-many-retur # is it optional? try: if any(a is _NONE_TYPE for a in annotation.__args__): # pyright: ignore + if rf: + rf._is_optional = True if len(annotation.__args__) <= 2: # pyright: ignore if_obj_deserializer = _get_deserialize_callable_from_annotation( next(a for a in annotation.__args__ if a is not _NONE_TYPE), module, rf # pyright: ignore @@ -1043,6 +1048,7 @@ def _failsafe_deserialize_xml( return None +# pylint: disable=too-many-instance-attributes class _RestField: def __init__( self, @@ -1062,6 +1068,7 @@ def __init__( self._is_discriminator = is_discriminator self._visibility = visibility self._is_model = False + self._is_optional = False self._default = default self._format = format self._is_multipart_file_input = is_multipart_file_input diff --git a/packages/typespec-python/test/unbranded/generated/special-headers-conditional-request/specialheaders/conditionalrequest/_utils/model_base.py b/packages/typespec-python/test/unbranded/generated/special-headers-conditional-request/specialheaders/conditionalrequest/_utils/model_base.py index c52d928e423..ca800653fd8 100644 --- a/packages/typespec-python/test/unbranded/generated/special-headers-conditional-request/specialheaders/conditionalrequest/_utils/model_base.py +++ b/packages/typespec-python/test/unbranded/generated/special-headers-conditional-request/specialheaders/conditionalrequest/_utils/model_base.py @@ -624,6 +624,9 @@ def __init__(self, *args: typing.Any, **kwargs: typing.Any) -> None: if len(items) > 0: existed_attr_keys.append(xml_name) dict_to_pass[rf._rest_name] = _deserialize(rf._type, items) + elif not rf._is_optional: + existed_attr_keys.append(xml_name) + dict_to_pass[rf._rest_name] = [] continue # text element is primitive type @@ -885,6 +888,8 @@ def _get_deserialize_callable_from_annotation( # pylint: disable=too-many-retur # is it optional? try: if any(a is _NONE_TYPE for a in annotation.__args__): # pyright: ignore + if rf: + rf._is_optional = True if len(annotation.__args__) <= 2: # pyright: ignore if_obj_deserializer = _get_deserialize_callable_from_annotation( next(a for a in annotation.__args__ if a is not _NONE_TYPE), module, rf # pyright: ignore @@ -1043,6 +1048,7 @@ def _failsafe_deserialize_xml( return None +# pylint: disable=too-many-instance-attributes class _RestField: def __init__( self, @@ -1062,6 +1068,7 @@ def __init__( self._is_discriminator = is_discriminator self._visibility = visibility self._is_model = False + self._is_optional = False self._default = default self._format = format self._is_multipart_file_input = is_multipart_file_input diff --git a/packages/typespec-python/test/unbranded/generated/special-headers-repeatability/specialheaders/repeatability/_utils/model_base.py b/packages/typespec-python/test/unbranded/generated/special-headers-repeatability/specialheaders/repeatability/_utils/model_base.py index c52d928e423..ca800653fd8 100644 --- a/packages/typespec-python/test/unbranded/generated/special-headers-repeatability/specialheaders/repeatability/_utils/model_base.py +++ b/packages/typespec-python/test/unbranded/generated/special-headers-repeatability/specialheaders/repeatability/_utils/model_base.py @@ -624,6 +624,9 @@ def __init__(self, *args: typing.Any, **kwargs: typing.Any) -> None: if len(items) > 0: existed_attr_keys.append(xml_name) dict_to_pass[rf._rest_name] = _deserialize(rf._type, items) + elif not rf._is_optional: + existed_attr_keys.append(xml_name) + dict_to_pass[rf._rest_name] = [] continue # text element is primitive type @@ -885,6 +888,8 @@ def _get_deserialize_callable_from_annotation( # pylint: disable=too-many-retur # is it optional? try: if any(a is _NONE_TYPE for a in annotation.__args__): # pyright: ignore + if rf: + rf._is_optional = True if len(annotation.__args__) <= 2: # pyright: ignore if_obj_deserializer = _get_deserialize_callable_from_annotation( next(a for a in annotation.__args__ if a is not _NONE_TYPE), module, rf # pyright: ignore @@ -1043,6 +1048,7 @@ def _failsafe_deserialize_xml( return None +# pylint: disable=too-many-instance-attributes class _RestField: def __init__( self, @@ -1062,6 +1068,7 @@ def __init__( self._is_discriminator = is_discriminator self._visibility = visibility self._is_model = False + self._is_optional = False self._default = default self._format = format self._is_multipart_file_input = is_multipart_file_input diff --git a/packages/typespec-python/test/unbranded/generated/special-words/specialwords/_utils/model_base.py b/packages/typespec-python/test/unbranded/generated/special-words/specialwords/_utils/model_base.py index 7199d1d1dce..c62373f9db9 100644 --- a/packages/typespec-python/test/unbranded/generated/special-words/specialwords/_utils/model_base.py +++ b/packages/typespec-python/test/unbranded/generated/special-words/specialwords/_utils/model_base.py @@ -624,6 +624,9 @@ def __init__(self, *args: typing.Any, **kwargs: typing.Any) -> None: if len(items) > 0: existed_attr_keys.append(xml_name) dict_to_pass[rf._rest_name] = _deserialize(rf._type, items) + elif not rf._is_optional: + existed_attr_keys.append(xml_name) + dict_to_pass[rf._rest_name] = [] continue # text element is primitive type @@ -899,6 +902,8 @@ def _get_deserialize_callable_from_annotation( # pylint: disable=too-many-retur # is it optional? try: if any(a is _NONE_TYPE for a in annotation.__args__): # pyright: ignore + if rf: + rf._is_optional = True if len(annotation.__args__) <= 2: # pyright: ignore if_obj_deserializer = _get_deserialize_callable_from_annotation( next(a for a in annotation.__args__ if a is not _NONE_TYPE), module, rf # pyright: ignore @@ -1078,6 +1083,7 @@ def __init__( self._is_discriminator = is_discriminator self._visibility = visibility self._is_model = False + self._is_optional = False self._default = default self._format = format self._is_multipart_file_input = is_multipart_file_input diff --git a/packages/typespec-python/test/unbranded/generated/specs-documentation/specs/documentation/_utils/model_base.py b/packages/typespec-python/test/unbranded/generated/specs-documentation/specs/documentation/_utils/model_base.py index c52d928e423..ca800653fd8 100644 --- a/packages/typespec-python/test/unbranded/generated/specs-documentation/specs/documentation/_utils/model_base.py +++ b/packages/typespec-python/test/unbranded/generated/specs-documentation/specs/documentation/_utils/model_base.py @@ -624,6 +624,9 @@ def __init__(self, *args: typing.Any, **kwargs: typing.Any) -> None: if len(items) > 0: existed_attr_keys.append(xml_name) dict_to_pass[rf._rest_name] = _deserialize(rf._type, items) + elif not rf._is_optional: + existed_attr_keys.append(xml_name) + dict_to_pass[rf._rest_name] = [] continue # text element is primitive type @@ -885,6 +888,8 @@ def _get_deserialize_callable_from_annotation( # pylint: disable=too-many-retur # is it optional? try: if any(a is _NONE_TYPE for a in annotation.__args__): # pyright: ignore + if rf: + rf._is_optional = True if len(annotation.__args__) <= 2: # pyright: ignore if_obj_deserializer = _get_deserialize_callable_from_annotation( next(a for a in annotation.__args__ if a is not _NONE_TYPE), module, rf # pyright: ignore @@ -1043,6 +1048,7 @@ def _failsafe_deserialize_xml( return None +# pylint: disable=too-many-instance-attributes class _RestField: def __init__( self, @@ -1062,6 +1068,7 @@ def __init__( self._is_discriminator = is_discriminator self._visibility = visibility self._is_model = False + self._is_optional = False self._default = default self._format = format self._is_multipart_file_input = is_multipart_file_input diff --git a/packages/typespec-python/test/unbranded/generated/streaming-jsonl/streaming/jsonl/_utils/model_base.py b/packages/typespec-python/test/unbranded/generated/streaming-jsonl/streaming/jsonl/_utils/model_base.py index c52d928e423..ca800653fd8 100644 --- a/packages/typespec-python/test/unbranded/generated/streaming-jsonl/streaming/jsonl/_utils/model_base.py +++ b/packages/typespec-python/test/unbranded/generated/streaming-jsonl/streaming/jsonl/_utils/model_base.py @@ -624,6 +624,9 @@ def __init__(self, *args: typing.Any, **kwargs: typing.Any) -> None: if len(items) > 0: existed_attr_keys.append(xml_name) dict_to_pass[rf._rest_name] = _deserialize(rf._type, items) + elif not rf._is_optional: + existed_attr_keys.append(xml_name) + dict_to_pass[rf._rest_name] = [] continue # text element is primitive type @@ -885,6 +888,8 @@ def _get_deserialize_callable_from_annotation( # pylint: disable=too-many-retur # is it optional? try: if any(a is _NONE_TYPE for a in annotation.__args__): # pyright: ignore + if rf: + rf._is_optional = True if len(annotation.__args__) <= 2: # pyright: ignore if_obj_deserializer = _get_deserialize_callable_from_annotation( next(a for a in annotation.__args__ if a is not _NONE_TYPE), module, rf # pyright: ignore @@ -1043,6 +1048,7 @@ def _failsafe_deserialize_xml( return None +# pylint: disable=too-many-instance-attributes class _RestField: def __init__( self, @@ -1062,6 +1068,7 @@ def __init__( self._is_discriminator = is_discriminator self._visibility = visibility self._is_model = False + self._is_optional = False self._default = default self._format = format self._is_multipart_file_input = is_multipart_file_input diff --git a/packages/typespec-python/test/unbranded/generated/typetest-array/typetest/array/_utils/model_base.py b/packages/typespec-python/test/unbranded/generated/typetest-array/typetest/array/_utils/model_base.py index c52d928e423..ca800653fd8 100644 --- a/packages/typespec-python/test/unbranded/generated/typetest-array/typetest/array/_utils/model_base.py +++ b/packages/typespec-python/test/unbranded/generated/typetest-array/typetest/array/_utils/model_base.py @@ -624,6 +624,9 @@ def __init__(self, *args: typing.Any, **kwargs: typing.Any) -> None: if len(items) > 0: existed_attr_keys.append(xml_name) dict_to_pass[rf._rest_name] = _deserialize(rf._type, items) + elif not rf._is_optional: + existed_attr_keys.append(xml_name) + dict_to_pass[rf._rest_name] = [] continue # text element is primitive type @@ -885,6 +888,8 @@ def _get_deserialize_callable_from_annotation( # pylint: disable=too-many-retur # is it optional? try: if any(a is _NONE_TYPE for a in annotation.__args__): # pyright: ignore + if rf: + rf._is_optional = True if len(annotation.__args__) <= 2: # pyright: ignore if_obj_deserializer = _get_deserialize_callable_from_annotation( next(a for a in annotation.__args__ if a is not _NONE_TYPE), module, rf # pyright: ignore @@ -1043,6 +1048,7 @@ def _failsafe_deserialize_xml( return None +# pylint: disable=too-many-instance-attributes class _RestField: def __init__( self, @@ -1062,6 +1068,7 @@ def __init__( self._is_discriminator = is_discriminator self._visibility = visibility self._is_model = False + self._is_optional = False self._default = default self._format = format self._is_multipart_file_input = is_multipart_file_input diff --git a/packages/typespec-python/test/unbranded/generated/typetest-dictionary/typetest/dictionary/_utils/model_base.py b/packages/typespec-python/test/unbranded/generated/typetest-dictionary/typetest/dictionary/_utils/model_base.py index c52d928e423..ca800653fd8 100644 --- a/packages/typespec-python/test/unbranded/generated/typetest-dictionary/typetest/dictionary/_utils/model_base.py +++ b/packages/typespec-python/test/unbranded/generated/typetest-dictionary/typetest/dictionary/_utils/model_base.py @@ -624,6 +624,9 @@ def __init__(self, *args: typing.Any, **kwargs: typing.Any) -> None: if len(items) > 0: existed_attr_keys.append(xml_name) dict_to_pass[rf._rest_name] = _deserialize(rf._type, items) + elif not rf._is_optional: + existed_attr_keys.append(xml_name) + dict_to_pass[rf._rest_name] = [] continue # text element is primitive type @@ -885,6 +888,8 @@ def _get_deserialize_callable_from_annotation( # pylint: disable=too-many-retur # is it optional? try: if any(a is _NONE_TYPE for a in annotation.__args__): # pyright: ignore + if rf: + rf._is_optional = True if len(annotation.__args__) <= 2: # pyright: ignore if_obj_deserializer = _get_deserialize_callable_from_annotation( next(a for a in annotation.__args__ if a is not _NONE_TYPE), module, rf # pyright: ignore @@ -1043,6 +1048,7 @@ def _failsafe_deserialize_xml( return None +# pylint: disable=too-many-instance-attributes class _RestField: def __init__( self, @@ -1062,6 +1068,7 @@ def __init__( self._is_discriminator = is_discriminator self._visibility = visibility self._is_model = False + self._is_optional = False self._default = default self._format = format self._is_multipart_file_input = is_multipart_file_input diff --git a/packages/typespec-python/test/unbranded/generated/typetest-discriminatedunion/typetest/discriminatedunion/_utils/model_base.py b/packages/typespec-python/test/unbranded/generated/typetest-discriminatedunion/typetest/discriminatedunion/_utils/model_base.py index c52d928e423..ca800653fd8 100644 --- a/packages/typespec-python/test/unbranded/generated/typetest-discriminatedunion/typetest/discriminatedunion/_utils/model_base.py +++ b/packages/typespec-python/test/unbranded/generated/typetest-discriminatedunion/typetest/discriminatedunion/_utils/model_base.py @@ -624,6 +624,9 @@ def __init__(self, *args: typing.Any, **kwargs: typing.Any) -> None: if len(items) > 0: existed_attr_keys.append(xml_name) dict_to_pass[rf._rest_name] = _deserialize(rf._type, items) + elif not rf._is_optional: + existed_attr_keys.append(xml_name) + dict_to_pass[rf._rest_name] = [] continue # text element is primitive type @@ -885,6 +888,8 @@ def _get_deserialize_callable_from_annotation( # pylint: disable=too-many-retur # is it optional? try: if any(a is _NONE_TYPE for a in annotation.__args__): # pyright: ignore + if rf: + rf._is_optional = True if len(annotation.__args__) <= 2: # pyright: ignore if_obj_deserializer = _get_deserialize_callable_from_annotation( next(a for a in annotation.__args__ if a is not _NONE_TYPE), module, rf # pyright: ignore @@ -1043,6 +1048,7 @@ def _failsafe_deserialize_xml( return None +# pylint: disable=too-many-instance-attributes class _RestField: def __init__( self, @@ -1062,6 +1068,7 @@ def __init__( self._is_discriminator = is_discriminator self._visibility = visibility self._is_model = False + self._is_optional = False self._default = default self._format = format self._is_multipart_file_input = is_multipart_file_input diff --git a/packages/typespec-python/test/unbranded/generated/typetest-enum-extensible/typetest/enum/extensible/_utils/model_base.py b/packages/typespec-python/test/unbranded/generated/typetest-enum-extensible/typetest/enum/extensible/_utils/model_base.py index c52d928e423..ca800653fd8 100644 --- a/packages/typespec-python/test/unbranded/generated/typetest-enum-extensible/typetest/enum/extensible/_utils/model_base.py +++ b/packages/typespec-python/test/unbranded/generated/typetest-enum-extensible/typetest/enum/extensible/_utils/model_base.py @@ -624,6 +624,9 @@ def __init__(self, *args: typing.Any, **kwargs: typing.Any) -> None: if len(items) > 0: existed_attr_keys.append(xml_name) dict_to_pass[rf._rest_name] = _deserialize(rf._type, items) + elif not rf._is_optional: + existed_attr_keys.append(xml_name) + dict_to_pass[rf._rest_name] = [] continue # text element is primitive type @@ -885,6 +888,8 @@ def _get_deserialize_callable_from_annotation( # pylint: disable=too-many-retur # is it optional? try: if any(a is _NONE_TYPE for a in annotation.__args__): # pyright: ignore + if rf: + rf._is_optional = True if len(annotation.__args__) <= 2: # pyright: ignore if_obj_deserializer = _get_deserialize_callable_from_annotation( next(a for a in annotation.__args__ if a is not _NONE_TYPE), module, rf # pyright: ignore @@ -1043,6 +1048,7 @@ def _failsafe_deserialize_xml( return None +# pylint: disable=too-many-instance-attributes class _RestField: def __init__( self, @@ -1062,6 +1068,7 @@ def __init__( self._is_discriminator = is_discriminator self._visibility = visibility self._is_model = False + self._is_optional = False self._default = default self._format = format self._is_multipart_file_input = is_multipart_file_input diff --git a/packages/typespec-python/test/unbranded/generated/typetest-enum-fixed/typetest/enum/fixed/_utils/model_base.py b/packages/typespec-python/test/unbranded/generated/typetest-enum-fixed/typetest/enum/fixed/_utils/model_base.py index c52d928e423..ca800653fd8 100644 --- a/packages/typespec-python/test/unbranded/generated/typetest-enum-fixed/typetest/enum/fixed/_utils/model_base.py +++ b/packages/typespec-python/test/unbranded/generated/typetest-enum-fixed/typetest/enum/fixed/_utils/model_base.py @@ -624,6 +624,9 @@ def __init__(self, *args: typing.Any, **kwargs: typing.Any) -> None: if len(items) > 0: existed_attr_keys.append(xml_name) dict_to_pass[rf._rest_name] = _deserialize(rf._type, items) + elif not rf._is_optional: + existed_attr_keys.append(xml_name) + dict_to_pass[rf._rest_name] = [] continue # text element is primitive type @@ -885,6 +888,8 @@ def _get_deserialize_callable_from_annotation( # pylint: disable=too-many-retur # is it optional? try: if any(a is _NONE_TYPE for a in annotation.__args__): # pyright: ignore + if rf: + rf._is_optional = True if len(annotation.__args__) <= 2: # pyright: ignore if_obj_deserializer = _get_deserialize_callable_from_annotation( next(a for a in annotation.__args__ if a is not _NONE_TYPE), module, rf # pyright: ignore @@ -1043,6 +1048,7 @@ def _failsafe_deserialize_xml( return None +# pylint: disable=too-many-instance-attributes class _RestField: def __init__( self, @@ -1062,6 +1068,7 @@ def __init__( self._is_discriminator = is_discriminator self._visibility = visibility self._is_model = False + self._is_optional = False self._default = default self._format = format self._is_multipart_file_input = is_multipart_file_input diff --git a/packages/typespec-python/test/unbranded/generated/typetest-model-empty/typetest/model/empty/_utils/model_base.py b/packages/typespec-python/test/unbranded/generated/typetest-model-empty/typetest/model/empty/_utils/model_base.py index c52d928e423..ca800653fd8 100644 --- a/packages/typespec-python/test/unbranded/generated/typetest-model-empty/typetest/model/empty/_utils/model_base.py +++ b/packages/typespec-python/test/unbranded/generated/typetest-model-empty/typetest/model/empty/_utils/model_base.py @@ -624,6 +624,9 @@ def __init__(self, *args: typing.Any, **kwargs: typing.Any) -> None: if len(items) > 0: existed_attr_keys.append(xml_name) dict_to_pass[rf._rest_name] = _deserialize(rf._type, items) + elif not rf._is_optional: + existed_attr_keys.append(xml_name) + dict_to_pass[rf._rest_name] = [] continue # text element is primitive type @@ -885,6 +888,8 @@ def _get_deserialize_callable_from_annotation( # pylint: disable=too-many-retur # is it optional? try: if any(a is _NONE_TYPE for a in annotation.__args__): # pyright: ignore + if rf: + rf._is_optional = True if len(annotation.__args__) <= 2: # pyright: ignore if_obj_deserializer = _get_deserialize_callable_from_annotation( next(a for a in annotation.__args__ if a is not _NONE_TYPE), module, rf # pyright: ignore @@ -1043,6 +1048,7 @@ def _failsafe_deserialize_xml( return None +# pylint: disable=too-many-instance-attributes class _RestField: def __init__( self, @@ -1062,6 +1068,7 @@ def __init__( self._is_discriminator = is_discriminator self._visibility = visibility self._is_model = False + self._is_optional = False self._default = default self._format = format self._is_multipart_file_input = is_multipart_file_input diff --git a/packages/typespec-python/test/unbranded/generated/typetest-model-enumdiscriminator/typetest/model/enumdiscriminator/_utils/model_base.py b/packages/typespec-python/test/unbranded/generated/typetest-model-enumdiscriminator/typetest/model/enumdiscriminator/_utils/model_base.py index c52d928e423..ca800653fd8 100644 --- a/packages/typespec-python/test/unbranded/generated/typetest-model-enumdiscriminator/typetest/model/enumdiscriminator/_utils/model_base.py +++ b/packages/typespec-python/test/unbranded/generated/typetest-model-enumdiscriminator/typetest/model/enumdiscriminator/_utils/model_base.py @@ -624,6 +624,9 @@ def __init__(self, *args: typing.Any, **kwargs: typing.Any) -> None: if len(items) > 0: existed_attr_keys.append(xml_name) dict_to_pass[rf._rest_name] = _deserialize(rf._type, items) + elif not rf._is_optional: + existed_attr_keys.append(xml_name) + dict_to_pass[rf._rest_name] = [] continue # text element is primitive type @@ -885,6 +888,8 @@ def _get_deserialize_callable_from_annotation( # pylint: disable=too-many-retur # is it optional? try: if any(a is _NONE_TYPE for a in annotation.__args__): # pyright: ignore + if rf: + rf._is_optional = True if len(annotation.__args__) <= 2: # pyright: ignore if_obj_deserializer = _get_deserialize_callable_from_annotation( next(a for a in annotation.__args__ if a is not _NONE_TYPE), module, rf # pyright: ignore @@ -1043,6 +1048,7 @@ def _failsafe_deserialize_xml( return None +# pylint: disable=too-many-instance-attributes class _RestField: def __init__( self, @@ -1062,6 +1068,7 @@ def __init__( self._is_discriminator = is_discriminator self._visibility = visibility self._is_model = False + self._is_optional = False self._default = default self._format = format self._is_multipart_file_input = is_multipart_file_input diff --git a/packages/typespec-python/test/unbranded/generated/typetest-model-nesteddiscriminator/typetest/model/nesteddiscriminator/_utils/model_base.py b/packages/typespec-python/test/unbranded/generated/typetest-model-nesteddiscriminator/typetest/model/nesteddiscriminator/_utils/model_base.py index c52d928e423..ca800653fd8 100644 --- a/packages/typespec-python/test/unbranded/generated/typetest-model-nesteddiscriminator/typetest/model/nesteddiscriminator/_utils/model_base.py +++ b/packages/typespec-python/test/unbranded/generated/typetest-model-nesteddiscriminator/typetest/model/nesteddiscriminator/_utils/model_base.py @@ -624,6 +624,9 @@ def __init__(self, *args: typing.Any, **kwargs: typing.Any) -> None: if len(items) > 0: existed_attr_keys.append(xml_name) dict_to_pass[rf._rest_name] = _deserialize(rf._type, items) + elif not rf._is_optional: + existed_attr_keys.append(xml_name) + dict_to_pass[rf._rest_name] = [] continue # text element is primitive type @@ -885,6 +888,8 @@ def _get_deserialize_callable_from_annotation( # pylint: disable=too-many-retur # is it optional? try: if any(a is _NONE_TYPE for a in annotation.__args__): # pyright: ignore + if rf: + rf._is_optional = True if len(annotation.__args__) <= 2: # pyright: ignore if_obj_deserializer = _get_deserialize_callable_from_annotation( next(a for a in annotation.__args__ if a is not _NONE_TYPE), module, rf # pyright: ignore @@ -1043,6 +1048,7 @@ def _failsafe_deserialize_xml( return None +# pylint: disable=too-many-instance-attributes class _RestField: def __init__( self, @@ -1062,6 +1068,7 @@ def __init__( self._is_discriminator = is_discriminator self._visibility = visibility self._is_model = False + self._is_optional = False self._default = default self._format = format self._is_multipart_file_input = is_multipart_file_input diff --git a/packages/typespec-python/test/unbranded/generated/typetest-model-notdiscriminated/typetest/model/notdiscriminated/_utils/model_base.py b/packages/typespec-python/test/unbranded/generated/typetest-model-notdiscriminated/typetest/model/notdiscriminated/_utils/model_base.py index c52d928e423..ca800653fd8 100644 --- a/packages/typespec-python/test/unbranded/generated/typetest-model-notdiscriminated/typetest/model/notdiscriminated/_utils/model_base.py +++ b/packages/typespec-python/test/unbranded/generated/typetest-model-notdiscriminated/typetest/model/notdiscriminated/_utils/model_base.py @@ -624,6 +624,9 @@ def __init__(self, *args: typing.Any, **kwargs: typing.Any) -> None: if len(items) > 0: existed_attr_keys.append(xml_name) dict_to_pass[rf._rest_name] = _deserialize(rf._type, items) + elif not rf._is_optional: + existed_attr_keys.append(xml_name) + dict_to_pass[rf._rest_name] = [] continue # text element is primitive type @@ -885,6 +888,8 @@ def _get_deserialize_callable_from_annotation( # pylint: disable=too-many-retur # is it optional? try: if any(a is _NONE_TYPE for a in annotation.__args__): # pyright: ignore + if rf: + rf._is_optional = True if len(annotation.__args__) <= 2: # pyright: ignore if_obj_deserializer = _get_deserialize_callable_from_annotation( next(a for a in annotation.__args__ if a is not _NONE_TYPE), module, rf # pyright: ignore @@ -1043,6 +1048,7 @@ def _failsafe_deserialize_xml( return None +# pylint: disable=too-many-instance-attributes class _RestField: def __init__( self, @@ -1062,6 +1068,7 @@ def __init__( self._is_discriminator = is_discriminator self._visibility = visibility self._is_model = False + self._is_optional = False self._default = default self._format = format self._is_multipart_file_input = is_multipart_file_input diff --git a/packages/typespec-python/test/unbranded/generated/typetest-model-recursive/typetest/model/recursive/_utils/model_base.py b/packages/typespec-python/test/unbranded/generated/typetest-model-recursive/typetest/model/recursive/_utils/model_base.py index c52d928e423..ca800653fd8 100644 --- a/packages/typespec-python/test/unbranded/generated/typetest-model-recursive/typetest/model/recursive/_utils/model_base.py +++ b/packages/typespec-python/test/unbranded/generated/typetest-model-recursive/typetest/model/recursive/_utils/model_base.py @@ -624,6 +624,9 @@ def __init__(self, *args: typing.Any, **kwargs: typing.Any) -> None: if len(items) > 0: existed_attr_keys.append(xml_name) dict_to_pass[rf._rest_name] = _deserialize(rf._type, items) + elif not rf._is_optional: + existed_attr_keys.append(xml_name) + dict_to_pass[rf._rest_name] = [] continue # text element is primitive type @@ -885,6 +888,8 @@ def _get_deserialize_callable_from_annotation( # pylint: disable=too-many-retur # is it optional? try: if any(a is _NONE_TYPE for a in annotation.__args__): # pyright: ignore + if rf: + rf._is_optional = True if len(annotation.__args__) <= 2: # pyright: ignore if_obj_deserializer = _get_deserialize_callable_from_annotation( next(a for a in annotation.__args__ if a is not _NONE_TYPE), module, rf # pyright: ignore @@ -1043,6 +1048,7 @@ def _failsafe_deserialize_xml( return None +# pylint: disable=too-many-instance-attributes class _RestField: def __init__( self, @@ -1062,6 +1068,7 @@ def __init__( self._is_discriminator = is_discriminator self._visibility = visibility self._is_model = False + self._is_optional = False self._default = default self._format = format self._is_multipart_file_input = is_multipart_file_input diff --git a/packages/typespec-python/test/unbranded/generated/typetest-model-singlediscriminator/typetest/model/singlediscriminator/_utils/model_base.py b/packages/typespec-python/test/unbranded/generated/typetest-model-singlediscriminator/typetest/model/singlediscriminator/_utils/model_base.py index c52d928e423..ca800653fd8 100644 --- a/packages/typespec-python/test/unbranded/generated/typetest-model-singlediscriminator/typetest/model/singlediscriminator/_utils/model_base.py +++ b/packages/typespec-python/test/unbranded/generated/typetest-model-singlediscriminator/typetest/model/singlediscriminator/_utils/model_base.py @@ -624,6 +624,9 @@ def __init__(self, *args: typing.Any, **kwargs: typing.Any) -> None: if len(items) > 0: existed_attr_keys.append(xml_name) dict_to_pass[rf._rest_name] = _deserialize(rf._type, items) + elif not rf._is_optional: + existed_attr_keys.append(xml_name) + dict_to_pass[rf._rest_name] = [] continue # text element is primitive type @@ -885,6 +888,8 @@ def _get_deserialize_callable_from_annotation( # pylint: disable=too-many-retur # is it optional? try: if any(a is _NONE_TYPE for a in annotation.__args__): # pyright: ignore + if rf: + rf._is_optional = True if len(annotation.__args__) <= 2: # pyright: ignore if_obj_deserializer = _get_deserialize_callable_from_annotation( next(a for a in annotation.__args__ if a is not _NONE_TYPE), module, rf # pyright: ignore @@ -1043,6 +1048,7 @@ def _failsafe_deserialize_xml( return None +# pylint: disable=too-many-instance-attributes class _RestField: def __init__( self, @@ -1062,6 +1068,7 @@ def __init__( self._is_discriminator = is_discriminator self._visibility = visibility self._is_model = False + self._is_optional = False self._default = default self._format = format self._is_multipart_file_input = is_multipart_file_input diff --git a/packages/typespec-python/test/unbranded/generated/typetest-model-usage/typetest/model/usage/_utils/model_base.py b/packages/typespec-python/test/unbranded/generated/typetest-model-usage/typetest/model/usage/_utils/model_base.py index c52d928e423..ca800653fd8 100644 --- a/packages/typespec-python/test/unbranded/generated/typetest-model-usage/typetest/model/usage/_utils/model_base.py +++ b/packages/typespec-python/test/unbranded/generated/typetest-model-usage/typetest/model/usage/_utils/model_base.py @@ -624,6 +624,9 @@ def __init__(self, *args: typing.Any, **kwargs: typing.Any) -> None: if len(items) > 0: existed_attr_keys.append(xml_name) dict_to_pass[rf._rest_name] = _deserialize(rf._type, items) + elif not rf._is_optional: + existed_attr_keys.append(xml_name) + dict_to_pass[rf._rest_name] = [] continue # text element is primitive type @@ -885,6 +888,8 @@ def _get_deserialize_callable_from_annotation( # pylint: disable=too-many-retur # is it optional? try: if any(a is _NONE_TYPE for a in annotation.__args__): # pyright: ignore + if rf: + rf._is_optional = True if len(annotation.__args__) <= 2: # pyright: ignore if_obj_deserializer = _get_deserialize_callable_from_annotation( next(a for a in annotation.__args__ if a is not _NONE_TYPE), module, rf # pyright: ignore @@ -1043,6 +1048,7 @@ def _failsafe_deserialize_xml( return None +# pylint: disable=too-many-instance-attributes class _RestField: def __init__( self, @@ -1062,6 +1068,7 @@ def __init__( self._is_discriminator = is_discriminator self._visibility = visibility self._is_model = False + self._is_optional = False self._default = default self._format = format self._is_multipart_file_input = is_multipart_file_input diff --git a/packages/typespec-python/test/unbranded/generated/typetest-model-visibility/typetest/model/visibility/_utils/model_base.py b/packages/typespec-python/test/unbranded/generated/typetest-model-visibility/typetest/model/visibility/_utils/model_base.py index c52d928e423..ca800653fd8 100644 --- a/packages/typespec-python/test/unbranded/generated/typetest-model-visibility/typetest/model/visibility/_utils/model_base.py +++ b/packages/typespec-python/test/unbranded/generated/typetest-model-visibility/typetest/model/visibility/_utils/model_base.py @@ -624,6 +624,9 @@ def __init__(self, *args: typing.Any, **kwargs: typing.Any) -> None: if len(items) > 0: existed_attr_keys.append(xml_name) dict_to_pass[rf._rest_name] = _deserialize(rf._type, items) + elif not rf._is_optional: + existed_attr_keys.append(xml_name) + dict_to_pass[rf._rest_name] = [] continue # text element is primitive type @@ -885,6 +888,8 @@ def _get_deserialize_callable_from_annotation( # pylint: disable=too-many-retur # is it optional? try: if any(a is _NONE_TYPE for a in annotation.__args__): # pyright: ignore + if rf: + rf._is_optional = True if len(annotation.__args__) <= 2: # pyright: ignore if_obj_deserializer = _get_deserialize_callable_from_annotation( next(a for a in annotation.__args__ if a is not _NONE_TYPE), module, rf # pyright: ignore @@ -1043,6 +1048,7 @@ def _failsafe_deserialize_xml( return None +# pylint: disable=too-many-instance-attributes class _RestField: def __init__( self, @@ -1062,6 +1068,7 @@ def __init__( self._is_discriminator = is_discriminator self._visibility = visibility self._is_model = False + self._is_optional = False self._default = default self._format = format self._is_multipart_file_input = is_multipart_file_input diff --git a/packages/typespec-python/test/unbranded/generated/typetest-property-additionalproperties/typetest/property/additionalproperties/_utils/model_base.py b/packages/typespec-python/test/unbranded/generated/typetest-property-additionalproperties/typetest/property/additionalproperties/_utils/model_base.py index c52d928e423..ca800653fd8 100644 --- a/packages/typespec-python/test/unbranded/generated/typetest-property-additionalproperties/typetest/property/additionalproperties/_utils/model_base.py +++ b/packages/typespec-python/test/unbranded/generated/typetest-property-additionalproperties/typetest/property/additionalproperties/_utils/model_base.py @@ -624,6 +624,9 @@ def __init__(self, *args: typing.Any, **kwargs: typing.Any) -> None: if len(items) > 0: existed_attr_keys.append(xml_name) dict_to_pass[rf._rest_name] = _deserialize(rf._type, items) + elif not rf._is_optional: + existed_attr_keys.append(xml_name) + dict_to_pass[rf._rest_name] = [] continue # text element is primitive type @@ -885,6 +888,8 @@ def _get_deserialize_callable_from_annotation( # pylint: disable=too-many-retur # is it optional? try: if any(a is _NONE_TYPE for a in annotation.__args__): # pyright: ignore + if rf: + rf._is_optional = True if len(annotation.__args__) <= 2: # pyright: ignore if_obj_deserializer = _get_deserialize_callable_from_annotation( next(a for a in annotation.__args__ if a is not _NONE_TYPE), module, rf # pyright: ignore @@ -1043,6 +1048,7 @@ def _failsafe_deserialize_xml( return None +# pylint: disable=too-many-instance-attributes class _RestField: def __init__( self, @@ -1062,6 +1068,7 @@ def __init__( self._is_discriminator = is_discriminator self._visibility = visibility self._is_model = False + self._is_optional = False self._default = default self._format = format self._is_multipart_file_input = is_multipart_file_input diff --git a/packages/typespec-python/test/unbranded/generated/typetest-property-nullable/typetest/property/nullable/_utils/model_base.py b/packages/typespec-python/test/unbranded/generated/typetest-property-nullable/typetest/property/nullable/_utils/model_base.py index c52d928e423..ca800653fd8 100644 --- a/packages/typespec-python/test/unbranded/generated/typetest-property-nullable/typetest/property/nullable/_utils/model_base.py +++ b/packages/typespec-python/test/unbranded/generated/typetest-property-nullable/typetest/property/nullable/_utils/model_base.py @@ -624,6 +624,9 @@ def __init__(self, *args: typing.Any, **kwargs: typing.Any) -> None: if len(items) > 0: existed_attr_keys.append(xml_name) dict_to_pass[rf._rest_name] = _deserialize(rf._type, items) + elif not rf._is_optional: + existed_attr_keys.append(xml_name) + dict_to_pass[rf._rest_name] = [] continue # text element is primitive type @@ -885,6 +888,8 @@ def _get_deserialize_callable_from_annotation( # pylint: disable=too-many-retur # is it optional? try: if any(a is _NONE_TYPE for a in annotation.__args__): # pyright: ignore + if rf: + rf._is_optional = True if len(annotation.__args__) <= 2: # pyright: ignore if_obj_deserializer = _get_deserialize_callable_from_annotation( next(a for a in annotation.__args__ if a is not _NONE_TYPE), module, rf # pyright: ignore @@ -1043,6 +1048,7 @@ def _failsafe_deserialize_xml( return None +# pylint: disable=too-many-instance-attributes class _RestField: def __init__( self, @@ -1062,6 +1068,7 @@ def __init__( self._is_discriminator = is_discriminator self._visibility = visibility self._is_model = False + self._is_optional = False self._default = default self._format = format self._is_multipart_file_input = is_multipart_file_input diff --git a/packages/typespec-python/test/unbranded/generated/typetest-property-optional/typetest/property/optional/_utils/model_base.py b/packages/typespec-python/test/unbranded/generated/typetest-property-optional/typetest/property/optional/_utils/model_base.py index c52d928e423..ca800653fd8 100644 --- a/packages/typespec-python/test/unbranded/generated/typetest-property-optional/typetest/property/optional/_utils/model_base.py +++ b/packages/typespec-python/test/unbranded/generated/typetest-property-optional/typetest/property/optional/_utils/model_base.py @@ -624,6 +624,9 @@ def __init__(self, *args: typing.Any, **kwargs: typing.Any) -> None: if len(items) > 0: existed_attr_keys.append(xml_name) dict_to_pass[rf._rest_name] = _deserialize(rf._type, items) + elif not rf._is_optional: + existed_attr_keys.append(xml_name) + dict_to_pass[rf._rest_name] = [] continue # text element is primitive type @@ -885,6 +888,8 @@ def _get_deserialize_callable_from_annotation( # pylint: disable=too-many-retur # is it optional? try: if any(a is _NONE_TYPE for a in annotation.__args__): # pyright: ignore + if rf: + rf._is_optional = True if len(annotation.__args__) <= 2: # pyright: ignore if_obj_deserializer = _get_deserialize_callable_from_annotation( next(a for a in annotation.__args__ if a is not _NONE_TYPE), module, rf # pyright: ignore @@ -1043,6 +1048,7 @@ def _failsafe_deserialize_xml( return None +# pylint: disable=too-many-instance-attributes class _RestField: def __init__( self, @@ -1062,6 +1068,7 @@ def __init__( self._is_discriminator = is_discriminator self._visibility = visibility self._is_model = False + self._is_optional = False self._default = default self._format = format self._is_multipart_file_input = is_multipart_file_input diff --git a/packages/typespec-python/test/unbranded/generated/typetest-property-valuetypes/typetest/property/valuetypes/_utils/model_base.py b/packages/typespec-python/test/unbranded/generated/typetest-property-valuetypes/typetest/property/valuetypes/_utils/model_base.py index c52d928e423..ca800653fd8 100644 --- a/packages/typespec-python/test/unbranded/generated/typetest-property-valuetypes/typetest/property/valuetypes/_utils/model_base.py +++ b/packages/typespec-python/test/unbranded/generated/typetest-property-valuetypes/typetest/property/valuetypes/_utils/model_base.py @@ -624,6 +624,9 @@ def __init__(self, *args: typing.Any, **kwargs: typing.Any) -> None: if len(items) > 0: existed_attr_keys.append(xml_name) dict_to_pass[rf._rest_name] = _deserialize(rf._type, items) + elif not rf._is_optional: + existed_attr_keys.append(xml_name) + dict_to_pass[rf._rest_name] = [] continue # text element is primitive type @@ -885,6 +888,8 @@ def _get_deserialize_callable_from_annotation( # pylint: disable=too-many-retur # is it optional? try: if any(a is _NONE_TYPE for a in annotation.__args__): # pyright: ignore + if rf: + rf._is_optional = True if len(annotation.__args__) <= 2: # pyright: ignore if_obj_deserializer = _get_deserialize_callable_from_annotation( next(a for a in annotation.__args__ if a is not _NONE_TYPE), module, rf # pyright: ignore @@ -1043,6 +1048,7 @@ def _failsafe_deserialize_xml( return None +# pylint: disable=too-many-instance-attributes class _RestField: def __init__( self, @@ -1062,6 +1068,7 @@ def __init__( self._is_discriminator = is_discriminator self._visibility = visibility self._is_model = False + self._is_optional = False self._default = default self._format = format self._is_multipart_file_input = is_multipart_file_input diff --git a/packages/typespec-python/test/unbranded/generated/typetest-scalar/typetest/scalar/_utils/model_base.py b/packages/typespec-python/test/unbranded/generated/typetest-scalar/typetest/scalar/_utils/model_base.py index c52d928e423..ca800653fd8 100644 --- a/packages/typespec-python/test/unbranded/generated/typetest-scalar/typetest/scalar/_utils/model_base.py +++ b/packages/typespec-python/test/unbranded/generated/typetest-scalar/typetest/scalar/_utils/model_base.py @@ -624,6 +624,9 @@ def __init__(self, *args: typing.Any, **kwargs: typing.Any) -> None: if len(items) > 0: existed_attr_keys.append(xml_name) dict_to_pass[rf._rest_name] = _deserialize(rf._type, items) + elif not rf._is_optional: + existed_attr_keys.append(xml_name) + dict_to_pass[rf._rest_name] = [] continue # text element is primitive type @@ -885,6 +888,8 @@ def _get_deserialize_callable_from_annotation( # pylint: disable=too-many-retur # is it optional? try: if any(a is _NONE_TYPE for a in annotation.__args__): # pyright: ignore + if rf: + rf._is_optional = True if len(annotation.__args__) <= 2: # pyright: ignore if_obj_deserializer = _get_deserialize_callable_from_annotation( next(a for a in annotation.__args__ if a is not _NONE_TYPE), module, rf # pyright: ignore @@ -1043,6 +1048,7 @@ def _failsafe_deserialize_xml( return None +# pylint: disable=too-many-instance-attributes class _RestField: def __init__( self, @@ -1062,6 +1068,7 @@ def __init__( self._is_discriminator = is_discriminator self._visibility = visibility self._is_model = False + self._is_optional = False self._default = default self._format = format self._is_multipart_file_input = is_multipart_file_input diff --git a/packages/typespec-python/test/unbranded/generated/typetest-union/typetest/union/_utils/model_base.py b/packages/typespec-python/test/unbranded/generated/typetest-union/typetest/union/_utils/model_base.py index c52d928e423..ca800653fd8 100644 --- a/packages/typespec-python/test/unbranded/generated/typetest-union/typetest/union/_utils/model_base.py +++ b/packages/typespec-python/test/unbranded/generated/typetest-union/typetest/union/_utils/model_base.py @@ -624,6 +624,9 @@ def __init__(self, *args: typing.Any, **kwargs: typing.Any) -> None: if len(items) > 0: existed_attr_keys.append(xml_name) dict_to_pass[rf._rest_name] = _deserialize(rf._type, items) + elif not rf._is_optional: + existed_attr_keys.append(xml_name) + dict_to_pass[rf._rest_name] = [] continue # text element is primitive type @@ -885,6 +888,8 @@ def _get_deserialize_callable_from_annotation( # pylint: disable=too-many-retur # is it optional? try: if any(a is _NONE_TYPE for a in annotation.__args__): # pyright: ignore + if rf: + rf._is_optional = True if len(annotation.__args__) <= 2: # pyright: ignore if_obj_deserializer = _get_deserialize_callable_from_annotation( next(a for a in annotation.__args__ if a is not _NONE_TYPE), module, rf # pyright: ignore @@ -1043,6 +1048,7 @@ def _failsafe_deserialize_xml( return None +# pylint: disable=too-many-instance-attributes class _RestField: def __init__( self, @@ -1062,6 +1068,7 @@ def __init__( self._is_discriminator = is_discriminator self._visibility = visibility self._is_model = False + self._is_optional = False self._default = default self._format = format self._is_multipart_file_input = is_multipart_file_input diff --git a/packages/typespec-python/test/unbranded/generated/versioning-added/versioning/added/_utils/model_base.py b/packages/typespec-python/test/unbranded/generated/versioning-added/versioning/added/_utils/model_base.py index c52d928e423..ca800653fd8 100644 --- a/packages/typespec-python/test/unbranded/generated/versioning-added/versioning/added/_utils/model_base.py +++ b/packages/typespec-python/test/unbranded/generated/versioning-added/versioning/added/_utils/model_base.py @@ -624,6 +624,9 @@ def __init__(self, *args: typing.Any, **kwargs: typing.Any) -> None: if len(items) > 0: existed_attr_keys.append(xml_name) dict_to_pass[rf._rest_name] = _deserialize(rf._type, items) + elif not rf._is_optional: + existed_attr_keys.append(xml_name) + dict_to_pass[rf._rest_name] = [] continue # text element is primitive type @@ -885,6 +888,8 @@ def _get_deserialize_callable_from_annotation( # pylint: disable=too-many-retur # is it optional? try: if any(a is _NONE_TYPE for a in annotation.__args__): # pyright: ignore + if rf: + rf._is_optional = True if len(annotation.__args__) <= 2: # pyright: ignore if_obj_deserializer = _get_deserialize_callable_from_annotation( next(a for a in annotation.__args__ if a is not _NONE_TYPE), module, rf # pyright: ignore @@ -1043,6 +1048,7 @@ def _failsafe_deserialize_xml( return None +# pylint: disable=too-many-instance-attributes class _RestField: def __init__( self, @@ -1062,6 +1068,7 @@ def __init__( self._is_discriminator = is_discriminator self._visibility = visibility self._is_model = False + self._is_optional = False self._default = default self._format = format self._is_multipart_file_input = is_multipart_file_input diff --git a/packages/typespec-python/test/unbranded/generated/versioning-madeoptional/versioning/madeoptional/_utils/model_base.py b/packages/typespec-python/test/unbranded/generated/versioning-madeoptional/versioning/madeoptional/_utils/model_base.py index c52d928e423..ca800653fd8 100644 --- a/packages/typespec-python/test/unbranded/generated/versioning-madeoptional/versioning/madeoptional/_utils/model_base.py +++ b/packages/typespec-python/test/unbranded/generated/versioning-madeoptional/versioning/madeoptional/_utils/model_base.py @@ -624,6 +624,9 @@ def __init__(self, *args: typing.Any, **kwargs: typing.Any) -> None: if len(items) > 0: existed_attr_keys.append(xml_name) dict_to_pass[rf._rest_name] = _deserialize(rf._type, items) + elif not rf._is_optional: + existed_attr_keys.append(xml_name) + dict_to_pass[rf._rest_name] = [] continue # text element is primitive type @@ -885,6 +888,8 @@ def _get_deserialize_callable_from_annotation( # pylint: disable=too-many-retur # is it optional? try: if any(a is _NONE_TYPE for a in annotation.__args__): # pyright: ignore + if rf: + rf._is_optional = True if len(annotation.__args__) <= 2: # pyright: ignore if_obj_deserializer = _get_deserialize_callable_from_annotation( next(a for a in annotation.__args__ if a is not _NONE_TYPE), module, rf # pyright: ignore @@ -1043,6 +1048,7 @@ def _failsafe_deserialize_xml( return None +# pylint: disable=too-many-instance-attributes class _RestField: def __init__( self, @@ -1062,6 +1068,7 @@ def __init__( self._is_discriminator = is_discriminator self._visibility = visibility self._is_model = False + self._is_optional = False self._default = default self._format = format self._is_multipart_file_input = is_multipart_file_input diff --git a/packages/typespec-python/test/unbranded/generated/versioning-removed/versioning/removed/_utils/model_base.py b/packages/typespec-python/test/unbranded/generated/versioning-removed/versioning/removed/_utils/model_base.py index c52d928e423..ca800653fd8 100644 --- a/packages/typespec-python/test/unbranded/generated/versioning-removed/versioning/removed/_utils/model_base.py +++ b/packages/typespec-python/test/unbranded/generated/versioning-removed/versioning/removed/_utils/model_base.py @@ -624,6 +624,9 @@ def __init__(self, *args: typing.Any, **kwargs: typing.Any) -> None: if len(items) > 0: existed_attr_keys.append(xml_name) dict_to_pass[rf._rest_name] = _deserialize(rf._type, items) + elif not rf._is_optional: + existed_attr_keys.append(xml_name) + dict_to_pass[rf._rest_name] = [] continue # text element is primitive type @@ -885,6 +888,8 @@ def _get_deserialize_callable_from_annotation( # pylint: disable=too-many-retur # is it optional? try: if any(a is _NONE_TYPE for a in annotation.__args__): # pyright: ignore + if rf: + rf._is_optional = True if len(annotation.__args__) <= 2: # pyright: ignore if_obj_deserializer = _get_deserialize_callable_from_annotation( next(a for a in annotation.__args__ if a is not _NONE_TYPE), module, rf # pyright: ignore @@ -1043,6 +1048,7 @@ def _failsafe_deserialize_xml( return None +# pylint: disable=too-many-instance-attributes class _RestField: def __init__( self, @@ -1062,6 +1068,7 @@ def __init__( self._is_discriminator = is_discriminator self._visibility = visibility self._is_model = False + self._is_optional = False self._default = default self._format = format self._is_multipart_file_input = is_multipart_file_input diff --git a/packages/typespec-python/test/unbranded/generated/versioning-renamedfrom/versioning/renamedfrom/_utils/model_base.py b/packages/typespec-python/test/unbranded/generated/versioning-renamedfrom/versioning/renamedfrom/_utils/model_base.py index c52d928e423..ca800653fd8 100644 --- a/packages/typespec-python/test/unbranded/generated/versioning-renamedfrom/versioning/renamedfrom/_utils/model_base.py +++ b/packages/typespec-python/test/unbranded/generated/versioning-renamedfrom/versioning/renamedfrom/_utils/model_base.py @@ -624,6 +624,9 @@ def __init__(self, *args: typing.Any, **kwargs: typing.Any) -> None: if len(items) > 0: existed_attr_keys.append(xml_name) dict_to_pass[rf._rest_name] = _deserialize(rf._type, items) + elif not rf._is_optional: + existed_attr_keys.append(xml_name) + dict_to_pass[rf._rest_name] = [] continue # text element is primitive type @@ -885,6 +888,8 @@ def _get_deserialize_callable_from_annotation( # pylint: disable=too-many-retur # is it optional? try: if any(a is _NONE_TYPE for a in annotation.__args__): # pyright: ignore + if rf: + rf._is_optional = True if len(annotation.__args__) <= 2: # pyright: ignore if_obj_deserializer = _get_deserialize_callable_from_annotation( next(a for a in annotation.__args__ if a is not _NONE_TYPE), module, rf # pyright: ignore @@ -1043,6 +1048,7 @@ def _failsafe_deserialize_xml( return None +# pylint: disable=too-many-instance-attributes class _RestField: def __init__( self, @@ -1062,6 +1068,7 @@ def __init__( self._is_discriminator = is_discriminator self._visibility = visibility self._is_model = False + self._is_optional = False self._default = default self._format = format self._is_multipart_file_input = is_multipart_file_input diff --git a/packages/typespec-python/test/unbranded/generated/versioning-returntypechangedfrom/versioning/returntypechangedfrom/_utils/model_base.py b/packages/typespec-python/test/unbranded/generated/versioning-returntypechangedfrom/versioning/returntypechangedfrom/_utils/model_base.py index c52d928e423..ca800653fd8 100644 --- a/packages/typespec-python/test/unbranded/generated/versioning-returntypechangedfrom/versioning/returntypechangedfrom/_utils/model_base.py +++ b/packages/typespec-python/test/unbranded/generated/versioning-returntypechangedfrom/versioning/returntypechangedfrom/_utils/model_base.py @@ -624,6 +624,9 @@ def __init__(self, *args: typing.Any, **kwargs: typing.Any) -> None: if len(items) > 0: existed_attr_keys.append(xml_name) dict_to_pass[rf._rest_name] = _deserialize(rf._type, items) + elif not rf._is_optional: + existed_attr_keys.append(xml_name) + dict_to_pass[rf._rest_name] = [] continue # text element is primitive type @@ -885,6 +888,8 @@ def _get_deserialize_callable_from_annotation( # pylint: disable=too-many-retur # is it optional? try: if any(a is _NONE_TYPE for a in annotation.__args__): # pyright: ignore + if rf: + rf._is_optional = True if len(annotation.__args__) <= 2: # pyright: ignore if_obj_deserializer = _get_deserialize_callable_from_annotation( next(a for a in annotation.__args__ if a is not _NONE_TYPE), module, rf # pyright: ignore @@ -1043,6 +1048,7 @@ def _failsafe_deserialize_xml( return None +# pylint: disable=too-many-instance-attributes class _RestField: def __init__( self, @@ -1062,6 +1068,7 @@ def __init__( self._is_discriminator = is_discriminator self._visibility = visibility self._is_model = False + self._is_optional = False self._default = default self._format = format self._is_multipart_file_input = is_multipart_file_input diff --git a/packages/typespec-python/test/unbranded/generated/versioning-typechangedfrom/versioning/typechangedfrom/_utils/model_base.py b/packages/typespec-python/test/unbranded/generated/versioning-typechangedfrom/versioning/typechangedfrom/_utils/model_base.py index c52d928e423..ca800653fd8 100644 --- a/packages/typespec-python/test/unbranded/generated/versioning-typechangedfrom/versioning/typechangedfrom/_utils/model_base.py +++ b/packages/typespec-python/test/unbranded/generated/versioning-typechangedfrom/versioning/typechangedfrom/_utils/model_base.py @@ -624,6 +624,9 @@ def __init__(self, *args: typing.Any, **kwargs: typing.Any) -> None: if len(items) > 0: existed_attr_keys.append(xml_name) dict_to_pass[rf._rest_name] = _deserialize(rf._type, items) + elif not rf._is_optional: + existed_attr_keys.append(xml_name) + dict_to_pass[rf._rest_name] = [] continue # text element is primitive type @@ -885,6 +888,8 @@ def _get_deserialize_callable_from_annotation( # pylint: disable=too-many-retur # is it optional? try: if any(a is _NONE_TYPE for a in annotation.__args__): # pyright: ignore + if rf: + rf._is_optional = True if len(annotation.__args__) <= 2: # pyright: ignore if_obj_deserializer = _get_deserialize_callable_from_annotation( next(a for a in annotation.__args__ if a is not _NONE_TYPE), module, rf # pyright: ignore @@ -1043,6 +1048,7 @@ def _failsafe_deserialize_xml( return None +# pylint: disable=too-many-instance-attributes class _RestField: def __init__( self, @@ -1062,6 +1068,7 @@ def __init__( self._is_discriminator = is_discriminator self._visibility = visibility self._is_model = False + self._is_optional = False self._default = default self._format = format self._is_multipart_file_input = is_multipart_file_input diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 1350b14c041..f367cbfbff2 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -60,8 +60,8 @@ importers: specifier: ~1.0.2 version: 1.0.2 '@typespec/http-client-python': - specifier: https://artprodcus3.artifacts.visualstudio.com/A0fb41ef4-5012-48a9-bf39-4ee3de03ee35/29ec6040-b234-4e31-b139-33dc4287b756/_apis/artifact/cGlwZWxpbmVhcnRpZmFjdDovL2F6dXJlLXNkay9wcm9qZWN0SWQvMjllYzYwNDAtYjIzNC00ZTMxLWIxMzktMzNkYzQyODdiNzU2L2J1aWxkSWQvNTk1Mzk0MS9hcnRpZmFjdE5hbWUvYnVpbGRfYXJ0aWZhY3RzX3B5dGhvbg2/content?format=file&subPath=%2Fpackages%2Ftypespec-http-client-python-0.27.2.tgz - version: https://artprodcus3.artifacts.visualstudio.com/A0fb41ef4-5012-48a9-bf39-4ee3de03ee35/29ec6040-b234-4e31-b139-33dc4287b756/_apis/artifact/cGlwZWxpbmVhcnRpZmFjdDovL2F6dXJlLXNkay9wcm9qZWN0SWQvMjllYzYwNDAtYjIzNC00ZTMxLWIxMzktMzNkYzQyODdiNzU2L2J1aWxkSWQvNTk1Mzk0MS9hcnRpZmFjdE5hbWUvYnVpbGRfYXJ0aWZhY3RzX3B5dGhvbg2/content?format=file&subPath=%2Fpackages%2Ftypespec-http-client-python-0.27.2.tgz(sjuqmbhka3ctg7d4p66zqqaix4) + specifier: https://artprodcus3.artifacts.visualstudio.com/A0fb41ef4-5012-48a9-bf39-4ee3de03ee35/29ec6040-b234-4e31-b139-33dc4287b756/_apis/artifact/cGlwZWxpbmVhcnRpZmFjdDovL2F6dXJlLXNkay9wcm9qZWN0SWQvMjllYzYwNDAtYjIzNC00ZTMxLWIxMzktMzNkYzQyODdiNzU2L2J1aWxkSWQvNTk3MDY3MS9hcnRpZmFjdE5hbWUvYnVpbGRfYXJ0aWZhY3RzX3B5dGhvbg2/content?format=file&subPath=%2Fpackages%2Ftypespec-http-client-python-0.27.2.tgz + version: https://artprodcus3.artifacts.visualstudio.com/A0fb41ef4-5012-48a9-bf39-4ee3de03ee35/29ec6040-b234-4e31-b139-33dc4287b756/_apis/artifact/cGlwZWxpbmVhcnRpZmFjdDovL2F6dXJlLXNkay9wcm9qZWN0SWQvMjllYzYwNDAtYjIzNC00ZTMxLWIxMzktMzNkYzQyODdiNzU2L2J1aWxkSWQvNTk3MDY3MS9hcnRpZmFjdE5hbWUvYnVpbGRfYXJ0aWZhY3RzX3B5dGhvbg2/content?format=file&subPath=%2Fpackages%2Ftypespec-http-client-python-0.27.2.tgz(sjuqmbhka3ctg7d4p66zqqaix4) fs-extra: specifier: ~11.2.0 version: 11.2.0 @@ -82,8 +82,8 @@ importers: packages/typespec-python: dependencies: '@typespec/http-client-python': - specifier: https://artprodcus3.artifacts.visualstudio.com/A0fb41ef4-5012-48a9-bf39-4ee3de03ee35/29ec6040-b234-4e31-b139-33dc4287b756/_apis/artifact/cGlwZWxpbmVhcnRpZmFjdDovL2F6dXJlLXNkay9wcm9qZWN0SWQvMjllYzYwNDAtYjIzNC00ZTMxLWIxMzktMzNkYzQyODdiNzU2L2J1aWxkSWQvNTk1Mzk0MS9hcnRpZmFjdE5hbWUvYnVpbGRfYXJ0aWZhY3RzX3B5dGhvbg2/content?format=file&subPath=%2Fpackages%2Ftypespec-http-client-python-0.27.2.tgz - version: https://artprodcus3.artifacts.visualstudio.com/A0fb41ef4-5012-48a9-bf39-4ee3de03ee35/29ec6040-b234-4e31-b139-33dc4287b756/_apis/artifact/cGlwZWxpbmVhcnRpZmFjdDovL2F6dXJlLXNkay9wcm9qZWN0SWQvMjllYzYwNDAtYjIzNC00ZTMxLWIxMzktMzNkYzQyODdiNzU2L2J1aWxkSWQvNTk1Mzk0MS9hcnRpZmFjdE5hbWUvYnVpbGRfYXJ0aWZhY3RzX3B5dGhvbg2/content?format=file&subPath=%2Fpackages%2Ftypespec-http-client-python-0.27.2.tgz(sjuqmbhka3ctg7d4p66zqqaix4) + specifier: https://artprodcus3.artifacts.visualstudio.com/A0fb41ef4-5012-48a9-bf39-4ee3de03ee35/29ec6040-b234-4e31-b139-33dc4287b756/_apis/artifact/cGlwZWxpbmVhcnRpZmFjdDovL2F6dXJlLXNkay9wcm9qZWN0SWQvMjllYzYwNDAtYjIzNC00ZTMxLWIxMzktMzNkYzQyODdiNzU2L2J1aWxkSWQvNTk3MDY3MS9hcnRpZmFjdE5hbWUvYnVpbGRfYXJ0aWZhY3RzX3B5dGhvbg2/content?format=file&subPath=%2Fpackages%2Ftypespec-http-client-python-0.27.2.tgz + version: https://artprodcus3.artifacts.visualstudio.com/A0fb41ef4-5012-48a9-bf39-4ee3de03ee35/29ec6040-b234-4e31-b139-33dc4287b756/_apis/artifact/cGlwZWxpbmVhcnRpZmFjdDovL2F6dXJlLXNkay9wcm9qZWN0SWQvMjllYzYwNDAtYjIzNC00ZTMxLWIxMzktMzNkYzQyODdiNzU2L2J1aWxkSWQvNTk3MDY3MS9hcnRpZmFjdE5hbWUvYnVpbGRfYXJ0aWZhY3RzX3B5dGhvbg2/content?format=file&subPath=%2Fpackages%2Ftypespec-http-client-python-0.27.2.tgz(sjuqmbhka3ctg7d4p66zqqaix4) fs-extra: specifier: ~11.2.0 version: 11.2.0 @@ -1725,8 +1725,8 @@ packages: peerDependencies: '@typespec/compiler': ^1.9.0 - '@typespec/http-client-python@https://artprodcus3.artifacts.visualstudio.com/A0fb41ef4-5012-48a9-bf39-4ee3de03ee35/29ec6040-b234-4e31-b139-33dc4287b756/_apis/artifact/cGlwZWxpbmVhcnRpZmFjdDovL2F6dXJlLXNkay9wcm9qZWN0SWQvMjllYzYwNDAtYjIzNC00ZTMxLWIxMzktMzNkYzQyODdiNzU2L2J1aWxkSWQvNTk1Mzk0MS9hcnRpZmFjdE5hbWUvYnVpbGRfYXJ0aWZhY3RzX3B5dGhvbg2/content?format=file&subPath=%2Fpackages%2Ftypespec-http-client-python-0.27.2.tgz': - resolution: {tarball: https://artprodcus3.artifacts.visualstudio.com/A0fb41ef4-5012-48a9-bf39-4ee3de03ee35/29ec6040-b234-4e31-b139-33dc4287b756/_apis/artifact/cGlwZWxpbmVhcnRpZmFjdDovL2F6dXJlLXNkay9wcm9qZWN0SWQvMjllYzYwNDAtYjIzNC00ZTMxLWIxMzktMzNkYzQyODdiNzU2L2J1aWxkSWQvNTk1Mzk0MS9hcnRpZmFjdE5hbWUvYnVpbGRfYXJ0aWZhY3RzX3B5dGhvbg2/content?format=file&subPath=%2Fpackages%2Ftypespec-http-client-python-0.27.2.tgz} + '@typespec/http-client-python@https://artprodcus3.artifacts.visualstudio.com/A0fb41ef4-5012-48a9-bf39-4ee3de03ee35/29ec6040-b234-4e31-b139-33dc4287b756/_apis/artifact/cGlwZWxpbmVhcnRpZmFjdDovL2F6dXJlLXNkay9wcm9qZWN0SWQvMjllYzYwNDAtYjIzNC00ZTMxLWIxMzktMzNkYzQyODdiNzU2L2J1aWxkSWQvNTk3MDY3MS9hcnRpZmFjdE5hbWUvYnVpbGRfYXJ0aWZhY3RzX3B5dGhvbg2/content?format=file&subPath=%2Fpackages%2Ftypespec-http-client-python-0.27.2.tgz': + resolution: {tarball: https://artprodcus3.artifacts.visualstudio.com/A0fb41ef4-5012-48a9-bf39-4ee3de03ee35/29ec6040-b234-4e31-b139-33dc4287b756/_apis/artifact/cGlwZWxpbmVhcnRpZmFjdDovL2F6dXJlLXNkay9wcm9qZWN0SWQvMjllYzYwNDAtYjIzNC00ZTMxLWIxMzktMzNkYzQyODdiNzU2L2J1aWxkSWQvNTk3MDY3MS9hcnRpZmFjdE5hbWUvYnVpbGRfYXJ0aWZhY3RzX3B5dGhvbg2/content?format=file&subPath=%2Fpackages%2Ftypespec-http-client-python-0.27.2.tgz} version: 0.27.2 engines: {node: '>=20.0.0'} peerDependencies: @@ -6713,7 +6713,7 @@ snapshots: dependencies: '@typespec/compiler': 1.9.0(@types/node@25.0.10) - '@typespec/http-client-python@https://artprodcus3.artifacts.visualstudio.com/A0fb41ef4-5012-48a9-bf39-4ee3de03ee35/29ec6040-b234-4e31-b139-33dc4287b756/_apis/artifact/cGlwZWxpbmVhcnRpZmFjdDovL2F6dXJlLXNkay9wcm9qZWN0SWQvMjllYzYwNDAtYjIzNC00ZTMxLWIxMzktMzNkYzQyODdiNzU2L2J1aWxkSWQvNTk1Mzk0MS9hcnRpZmFjdE5hbWUvYnVpbGRfYXJ0aWZhY3RzX3B5dGhvbg2/content?format=file&subPath=%2Fpackages%2Ftypespec-http-client-python-0.27.2.tgz(sjuqmbhka3ctg7d4p66zqqaix4)': + '@typespec/http-client-python@https://artprodcus3.artifacts.visualstudio.com/A0fb41ef4-5012-48a9-bf39-4ee3de03ee35/29ec6040-b234-4e31-b139-33dc4287b756/_apis/artifact/cGlwZWxpbmVhcnRpZmFjdDovL2F6dXJlLXNkay9wcm9qZWN0SWQvMjllYzYwNDAtYjIzNC00ZTMxLWIxMzktMzNkYzQyODdiNzU2L2J1aWxkSWQvNTk3MDY3MS9hcnRpZmFjdE5hbWUvYnVpbGRfYXJ0aWZhY3RzX3B5dGhvbg2/content?format=file&subPath=%2Fpackages%2Ftypespec-http-client-python-0.27.2.tgz(sjuqmbhka3ctg7d4p66zqqaix4)': dependencies: '@azure-tools/typespec-autorest': 0.65.0(pqg7vsrbtnqcusmn36y4aubeqq) '@azure-tools/typespec-azure-core': 0.65.0(@typespec/compiler@1.9.0(@types/node@25.0.10))(@typespec/http@1.9.1(@typespec/compiler@1.9.0(@types/node@25.0.10))(@typespec/streams@0.79.0(@typespec/compiler@1.9.0(@types/node@25.0.10))))(@typespec/rest@0.79.0(@typespec/compiler@1.9.0(@types/node@25.0.10))(@typespec/http@1.9.1(@typespec/compiler@1.9.0(@types/node@25.0.10))(@typespec/streams@0.79.0(@typespec/compiler@1.9.0(@types/node@25.0.10)))))