From 94e6e3d118e77103a585d630ae5de0dc1049483f Mon Sep 17 00:00:00 2001 From: msyyc <70930885+msyyc@users.noreply.github.com> Date: Tue, 23 Jan 2024 16:29:55 +0800 Subject: [PATCH 01/45] init --- .../autorest/codegen/models/operation.py | 5 + .../codegen/serializers/builder_serializer.py | 4 +- .../codegen/serializers/general_serializer.py | 2 + .../codegen/templates/vendor.py.jinja2 | 21 +++- .../payload/multipart/_vendor.py | 29 ++++- .../multipart/aio/operations/_operations.py | 26 ++--- .../multipart/operations/_operations.py | 26 ++--- .../mock_api_tests/test_payload_multipart.py | 104 ++++++++++++++++++ .../test/azure/requirements.txt | 2 +- .../payload/multipart/_vendor.py | 29 ++++- .../multipart/aio/operations/_operations.py | 26 ++--- .../multipart/operations/_operations.py | 26 ++--- 12 files changed, 234 insertions(+), 66 deletions(-) create mode 100644 packages/typespec-python/test/azure/mock_api_tests/test_payload_multipart.py diff --git a/packages/autorest.python/autorest/codegen/models/operation.py b/packages/autorest.python/autorest/codegen/models/operation.py index fc91f31628b..532958cfcef 100644 --- a/packages/autorest.python/autorest/codegen/models/operation.py +++ b/packages/autorest.python/autorest/codegen/models/operation.py @@ -587,6 +587,11 @@ def imports(self, async_mode: bool, **kwargs: Any) -> FileImport: relative_path, "_model_base", ImportType.LOCAL ) file_import.add_submodule_import("io", "IOBase", ImportType.STDLIB) + file_import.add_submodule_import( + f"{relative_path}_vendor", + "has_file", + ImportType.LOCAL, + ) file_import.add_submodule_import( f"{relative_path}_vendor", "multipart_file", diff --git a/packages/autorest.python/autorest/codegen/serializers/builder_serializer.py b/packages/autorest.python/autorest/codegen/serializers/builder_serializer.py index f85ed95fd58..b74004b80a8 100644 --- a/packages/autorest.python/autorest/codegen/serializers/builder_serializer.py +++ b/packages/autorest.python/autorest/codegen/serializers/builder_serializer.py @@ -759,8 +759,8 @@ def _serialize_body_parameter(self, builder: OperationType) -> List[str]: f" _body = handle_multipart_form_data_model({body_param.client_name})", "else:", f" _body = {body_param.client_name}", - "_files = {k: multipart_file(v) for k, v in _body.items() if isinstance(v, (IOBase, bytes))}", - "_data = {k: multipart_data(v) for k, v in _body.items() if not isinstance(v, (IOBase, bytes))}", + "_files = {k: multipart_file(v) for k, v in _body.items() if has_file(v)}", + "_data = {k: multipart_data(v) for k, v in _body.items() if not has_file(v)}", ] retval: List[str] = [] body_kwarg_name = builder.request_builder.parameters.body_parameter.client_name diff --git a/packages/autorest.python/autorest/codegen/serializers/general_serializer.py b/packages/autorest.python/autorest/codegen/serializers/general_serializer.py index eedcf415726..ca5fe53df70 100644 --- a/packages/autorest.python/autorest/codegen/serializers/general_serializer.py +++ b/packages/autorest.python/autorest/codegen/serializers/general_serializer.py @@ -131,6 +131,8 @@ def serialize_vendor_file(self, clients: List[Client]) -> str: ImportType.SDKCORE, ) if self.code_model.has_form_data: + file_import.add_submodule_import("typing", "List", ImportType.STDLIB) + file_import.add_submodule_import("typing", "Tuple", ImportType.STDLIB) file_import.add_submodule_import("typing", "Union", ImportType.STDLIB) file_import.add_submodule_import("typing", "Any", ImportType.STDLIB) file_import.add_submodule_import("io", "IOBase", ImportType.STDLIB) diff --git a/packages/autorest.python/autorest/codegen/templates/vendor.py.jinja2 b/packages/autorest.python/autorest/codegen/templates/vendor.py.jinja2 index 8fc8c740c3e..86c2f889bca 100644 --- a/packages/autorest.python/autorest/codegen/templates/vendor.py.jinja2 +++ b/packages/autorest.python/autorest/codegen/templates/vendor.py.jinja2 @@ -66,16 +66,31 @@ def prep_if_none_match(etag: Optional[str], match_condition: Optional[MatchCondi return None {% endif %} {% if code_model.has_form_data %} + +# file-like tuple could be `(filename, IO (or bytes))` or `(filename, IO (or bytes), content_type)` +FileType = Union[IOBase, bytes] +FileTuple = Union[Tuple[str, FileType], Tuple[str, FileType, str]] +MultiPartFile = Union[IOBase, bytes, FileTuple] +HandledMultiPartFile = Union[IOBase, FileTuple] + class NamedBytesIO(BytesIO): def __init__(self, name: str, *args, **kwargs): super().__init__(*args, **kwargs) self.name = name -def multipart_file(file: Union[IOBase, bytes]) -> IOBase: - if isinstance(file, IOBase): +def has_file(data: Any) -> bool: + return isinstance(data, (IOBase, bytes)) or (isinstance(data, (list, tuple)) and any(isinstance(f, (IOBase, bytes, tuple)) for f in data)) + +def handle_file(file: Union[IOBase, bytes, FileTuple]) -> IOBase: + if isinstance(file, (IOBase, Tuple)): return file return NamedBytesIO("auto-name-" + str(uuid.uuid4()), file) +def multipart_file(file: Union[MultiPartFile, List[MultiPartFile]]) -> Union[HandledMultiPartFile, List[HandledMultiPartFile]]: + if isinstance(file, list): + return [handle_file(f) for f in file] + return handle_file(file) + def multipart_data(data: Any) -> Any: if isinstance(data, (list, tuple, dict, Model)): return json.dumps(data, cls=SdkJSONEncoder, exclude_readonly=True) @@ -96,7 +111,7 @@ def handle_multipart_form_data_model(body: Model) -> MutableMapping[str, Any]: attr = rest_name_attr.get(rest_name) if attr is not None: raw_value = getattr(body, attr, None) - if isinstance(raw_value, (bytes, IOBase)): + if has_file(raw_value): result[rest_name] = raw_value return result {% endif %} diff --git a/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/_vendor.py b/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/_vendor.py index 03d44e41296..9eaf7d96fc0 100644 --- a/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/_vendor.py +++ b/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/_vendor.py @@ -8,7 +8,7 @@ from io import BytesIO, IOBase import json import sys -from typing import Any, Union +from typing import Any, List, Tuple, Union import uuid from ._model_base import Model, SdkJSONEncoder @@ -19,18 +19,39 @@ from typing import MutableMapping # type: ignore # pylint: disable=ungrouped-imports +# file-like tuple could be `(filename, IO (or bytes))` or `(filename, IO (or bytes), content_type)` +FileType = Union[IOBase, bytes] +FileTuple = Union[Tuple[str, FileType], Tuple[str, FileType, str]] +MultiPartFile = Union[IOBase, bytes, FileTuple] +HandledMultiPartFile = Union[IOBase, FileTuple] + + class NamedBytesIO(BytesIO): def __init__(self, name: str, *args, **kwargs): super().__init__(*args, **kwargs) self.name = name -def multipart_file(file: Union[IOBase, bytes]) -> IOBase: - if isinstance(file, IOBase): +def has_file(data: Any) -> bool: + return isinstance(data, (IOBase, bytes)) or ( + isinstance(data, (list, tuple)) and any(isinstance(f, (IOBase, bytes, tuple)) for f in data) + ) + + +def handle_file(file: Union[IOBase, bytes, FileTuple]) -> IOBase: + if isinstance(file, (IOBase, Tuple)): return file return NamedBytesIO("auto-name-" + str(uuid.uuid4()), file) +def multipart_file( + file: Union[MultiPartFile, List[MultiPartFile]] +) -> Union[HandledMultiPartFile, List[HandledMultiPartFile]]: + if isinstance(file, list): + return [handle_file(f) for f in file] + return handle_file(file) + + def multipart_data(data: Any) -> Any: if isinstance(data, (list, tuple, dict, Model)): return json.dumps(data, cls=SdkJSONEncoder, exclude_readonly=True) @@ -52,6 +73,6 @@ def handle_multipart_form_data_model(body: Model) -> MutableMapping[str, Any]: attr = rest_name_attr.get(rest_name) if attr is not None: raw_value = getattr(body, attr, None) - if isinstance(raw_value, (bytes, IOBase)): + if has_file(raw_value): result[rest_name] = raw_value return result diff --git a/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/aio/operations/_operations.py b/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/aio/operations/_operations.py index d62b74e1c01..dbec435bf15 100644 --- a/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/aio/operations/_operations.py +++ b/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/aio/operations/_operations.py @@ -23,7 +23,7 @@ from azure.core.tracing.decorator_async import distributed_trace_async from ... import _model_base, models as _models -from ..._vendor import handle_multipart_form_data_model, multipart_data, multipart_file +from ..._vendor import handle_multipart_form_data_model, has_file, multipart_data, multipart_file from ...operations._operations import ( build_form_data_basic_request, build_form_data_binary_array_parts_request, @@ -130,8 +130,8 @@ async def basic( # pylint: disable=inconsistent-return-statements _body = handle_multipart_form_data_model(body) else: _body = body - _files = {k: multipart_file(v) for k, v in _body.items() if isinstance(v, (IOBase, bytes))} - _data = {k: multipart_data(v) for k, v in _body.items() if not isinstance(v, (IOBase, bytes))} + _files = {k: multipart_file(v) for k, v in _body.items() if has_file(v)} + _data = {k: multipart_data(v) for k, v in _body.items() if not has_file(v)} _request = build_form_data_basic_request( data=_data, @@ -250,8 +250,8 @@ async def complex( # pylint: disable=inconsistent-return-statements _body = handle_multipart_form_data_model(body) else: _body = body - _files = {k: multipart_file(v) for k, v in _body.items() if isinstance(v, (IOBase, bytes))} - _data = {k: multipart_data(v) for k, v in _body.items() if not isinstance(v, (IOBase, bytes))} + _files = {k: multipart_file(v) for k, v in _body.items() if has_file(v)} + _data = {k: multipart_data(v) for k, v in _body.items() if not has_file(v)} _request = build_form_data_complex_request( data=_data, @@ -352,8 +352,8 @@ async def json_part( # pylint: disable=inconsistent-return-statements _body = handle_multipart_form_data_model(body) else: _body = body - _files = {k: multipart_file(v) for k, v in _body.items() if isinstance(v, (IOBase, bytes))} - _data = {k: multipart_data(v) for k, v in _body.items() if not isinstance(v, (IOBase, bytes))} + _files = {k: multipart_file(v) for k, v in _body.items() if has_file(v)} + _data = {k: multipart_data(v) for k, v in _body.items() if not has_file(v)} _request = build_form_data_json_part_request( data=_data, @@ -456,8 +456,8 @@ async def binary_array_parts( # pylint: disable=inconsistent-return-statements _body = handle_multipart_form_data_model(body) else: _body = body - _files = {k: multipart_file(v) for k, v in _body.items() if isinstance(v, (IOBase, bytes))} - _data = {k: multipart_data(v) for k, v in _body.items() if not isinstance(v, (IOBase, bytes))} + _files = {k: multipart_file(v) for k, v in _body.items() if has_file(v)} + _data = {k: multipart_data(v) for k, v in _body.items() if not has_file(v)} _request = build_form_data_binary_array_parts_request( data=_data, @@ -564,8 +564,8 @@ async def json_array_parts( # pylint: disable=inconsistent-return-statements _body = handle_multipart_form_data_model(body) else: _body = body - _files = {k: multipart_file(v) for k, v in _body.items() if isinstance(v, (IOBase, bytes))} - _data = {k: multipart_data(v) for k, v in _body.items() if not isinstance(v, (IOBase, bytes))} + _files = {k: multipart_file(v) for k, v in _body.items() if has_file(v)} + _data = {k: multipart_data(v) for k, v in _body.items() if not has_file(v)} _request = build_form_data_json_array_parts_request( data=_data, @@ -664,8 +664,8 @@ async def multi_binary_parts( # pylint: disable=inconsistent-return-statements _body = handle_multipart_form_data_model(body) else: _body = body - _files = {k: multipart_file(v) for k, v in _body.items() if isinstance(v, (IOBase, bytes))} - _data = {k: multipart_data(v) for k, v in _body.items() if not isinstance(v, (IOBase, bytes))} + _files = {k: multipart_file(v) for k, v in _body.items() if has_file(v)} + _data = {k: multipart_data(v) for k, v in _body.items() if not has_file(v)} _request = build_form_data_multi_binary_parts_request( data=_data, diff --git a/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/operations/_operations.py b/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/operations/_operations.py index 2ca0678c8e9..ac113f9112b 100644 --- a/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/operations/_operations.py +++ b/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/operations/_operations.py @@ -25,7 +25,7 @@ from .. import _model_base, models as _models from .._serialization import Serializer -from .._vendor import handle_multipart_form_data_model, multipart_data, multipart_file +from .._vendor import handle_multipart_form_data_model, has_file, multipart_data, multipart_file if sys.version_info >= (3, 9): from collections.abc import MutableMapping @@ -181,8 +181,8 @@ def basic( # pylint: disable=inconsistent-return-statements _body = handle_multipart_form_data_model(body) else: _body = body - _files = {k: multipart_file(v) for k, v in _body.items() if isinstance(v, (IOBase, bytes))} - _data = {k: multipart_data(v) for k, v in _body.items() if not isinstance(v, (IOBase, bytes))} + _files = {k: multipart_file(v) for k, v in _body.items() if has_file(v)} + _data = {k: multipart_data(v) for k, v in _body.items() if not has_file(v)} _request = build_form_data_basic_request( data=_data, @@ -301,8 +301,8 @@ def complex( # pylint: disable=inconsistent-return-statements _body = handle_multipart_form_data_model(body) else: _body = body - _files = {k: multipart_file(v) for k, v in _body.items() if isinstance(v, (IOBase, bytes))} - _data = {k: multipart_data(v) for k, v in _body.items() if not isinstance(v, (IOBase, bytes))} + _files = {k: multipart_file(v) for k, v in _body.items() if has_file(v)} + _data = {k: multipart_data(v) for k, v in _body.items() if not has_file(v)} _request = build_form_data_complex_request( data=_data, @@ -403,8 +403,8 @@ def json_part( # pylint: disable=inconsistent-return-statements _body = handle_multipart_form_data_model(body) else: _body = body - _files = {k: multipart_file(v) for k, v in _body.items() if isinstance(v, (IOBase, bytes))} - _data = {k: multipart_data(v) for k, v in _body.items() if not isinstance(v, (IOBase, bytes))} + _files = {k: multipart_file(v) for k, v in _body.items() if has_file(v)} + _data = {k: multipart_data(v) for k, v in _body.items() if not has_file(v)} _request = build_form_data_json_part_request( data=_data, @@ -505,8 +505,8 @@ def binary_array_parts( # pylint: disable=inconsistent-return-statements _body = handle_multipart_form_data_model(body) else: _body = body - _files = {k: multipart_file(v) for k, v in _body.items() if isinstance(v, (IOBase, bytes))} - _data = {k: multipart_data(v) for k, v in _body.items() if not isinstance(v, (IOBase, bytes))} + _files = {k: multipart_file(v) for k, v in _body.items() if has_file(v)} + _data = {k: multipart_data(v) for k, v in _body.items() if not has_file(v)} _request = build_form_data_binary_array_parts_request( data=_data, @@ -611,8 +611,8 @@ def json_array_parts( # pylint: disable=inconsistent-return-statements _body = handle_multipart_form_data_model(body) else: _body = body - _files = {k: multipart_file(v) for k, v in _body.items() if isinstance(v, (IOBase, bytes))} - _data = {k: multipart_data(v) for k, v in _body.items() if not isinstance(v, (IOBase, bytes))} + _files = {k: multipart_file(v) for k, v in _body.items() if has_file(v)} + _data = {k: multipart_data(v) for k, v in _body.items() if not has_file(v)} _request = build_form_data_json_array_parts_request( data=_data, @@ -709,8 +709,8 @@ def multi_binary_parts( # pylint: disable=inconsistent-return-statements _body = handle_multipart_form_data_model(body) else: _body = body - _files = {k: multipart_file(v) for k, v in _body.items() if isinstance(v, (IOBase, bytes))} - _data = {k: multipart_data(v) for k, v in _body.items() if not isinstance(v, (IOBase, bytes))} + _files = {k: multipart_file(v) for k, v in _body.items() if has_file(v)} + _data = {k: multipart_data(v) for k, v in _body.items() if not has_file(v)} _request = build_form_data_multi_binary_parts_request( data=_data, diff --git a/packages/typespec-python/test/azure/mock_api_tests/test_payload_multipart.py b/packages/typespec-python/test/azure/mock_api_tests/test_payload_multipart.py new file mode 100644 index 00000000000..934a844b121 --- /dev/null +++ b/packages/typespec-python/test/azure/mock_api_tests/test_payload_multipart.py @@ -0,0 +1,104 @@ +# ------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for +# license information. +# -------------------------------------------------------------------------- +from typing import Dict, Any +from pathlib import Path +import pytest +from payload.multipart import MultiPartClient, models +from payload.multipart._model_base import Model + +JPG = Path(__file__).parent.parent.parent / "generic_mock_api_tests/data/image.jpg" +PNG = Path(__file__).parent.parent.parent / "generic_mock_api_tests/data/image.png" + + +@pytest.fixture +def client(): + with MultiPartClient(endpoint="http://localhost:3000") as client: + yield client + + +@pytest.mark.parametrize( + "op_name,model_class,data,file", + [ + ( + "binary_array_parts", + models.BinaryArrayPartsRequest, + {"id": "123"}, + {"pictures": [PNG, PNG]}, + ), + ( + "complex", + models.ComplexPartsRequest, + {"id": "123", "previousAddresses": [models.Address(city="Y"), models.Address(city="Z")], "address": models.Address(city="X")}, + {"pictures": [PNG, PNG], "profileImage": JPG}, + ) + ], +) +def test_multi_part(client: MultiPartClient, op_name, model_class, data, file): + file_bytes = lambda p: open(str(p), "rb").read() + op = getattr(client.form_data, op_name) + # test bytes + body = {k: ([file_bytes(vi) for vi in v] if isinstance(v, list) else file_bytes(v)) for k, v in file.items()} + body.update(data) + op(body) + op(model_class(body)) + + # test io + file_io = lambda p: open(str(p), "rb") + body = {k: ([file_io(vi) for vi in v] if isinstance(v, list) else file_io(v)) for k, v in file.items()} + body.update(data) + op(body) + + body = {k: ([file_io(vi) for vi in v] if isinstance(v, list) else file_io(v)) for k, v in file.items()} + body.update(data) + with pytest.raises(TypeError): + # caused by deepcopy when DPG model init + op(model_class(body)) + +# def test_sample_single_file(client: MultiPartClient): +# # Python SDK support several kinds of file format for multipart/form-data and users can choose any of them + +# # 1. bytes +# client.form_data.basic(models.MultiPartRequest(id="123", profile_image=open(str(JPG), "rb").read())) + +# # 2. file io +# client.form_data.basic({"id": "123", "profileImage": open(str(JPG), "rb")}) + +# # 3. file tuple (only set file name) +# client.form_data.basic({"id": "123", "profileImage": ("my_image.jpg", open(str(JPG), "rb"))}) +# # or +# client.form_data.basic({"id": "123", "profileImage": ("my_image.jpg", open(str(JPG), "rb").read())}) + +# # 4. file tuple (set file name and content type) +# client.form_data.basic({"id": "123", "profileImage": ("my_image.jpg", open(str(JPG), "rb"), "image/jpeg")}) +# # or +# client.form_data.basic({"id": "123", "profileImage": ("my_image.jpg", open(str(JPG), "rb").read(), "image/jpeg")}) + +# def test_sample_array_file(client: MultiPartClient): +# # If users want to upload array files for same field name, they can use list, and users can +# # choose any of the above file format for each file. e.g. + +# # List[bytes, io] +# client.form_data.binary_array_parts({"id": "123", "pictures": [open(str(PNG), "rb").read(), open(str(PNG), "rb")]}) + +# # List[bytes, tuple] +# client.form_data.binary_array_parts({ +# "id": "123", +# "pictures": [open(str(PNG), "rb").read(), ("my_image.png", open(str(PNG), "rb"))] +# }) +# # or +# client.form_data.binary_array_parts({ +# "id": "123", +# "pictures": [open(str(PNG), "rb").read(), ("my_image.png", open(str(PNG), "rb"), "image/png")] +# }) +# # List[io, bytes] +# client.form_data.binary_array_parts({"id": "123", "pictures": [open(str(PNG), "rb"), open(str(PNG), "rb").read()]}) + +# # List[tuple, tuple] +# client.form_data.binary_array_parts({ +# "id": "123", +# "pictures": [("my_image1.png", open(str(PNG), "rb"), "image/png"), ("my_image2.png", open(str(PNG), "rb"), "image/png")] +# }) +# # ... diff --git a/packages/typespec-python/test/azure/requirements.txt b/packages/typespec-python/test/azure/requirements.txt index f01619e4bb7..3dee22f5bf9 100644 --- a/packages/typespec-python/test/azure/requirements.txt +++ b/packages/typespec-python/test/azure/requirements.txt @@ -2,7 +2,7 @@ aiohttp;python_full_version>="3.5.2" requests==2.31.0 pytest pytest-asyncio==0.14.0;python_full_version>="3.5.2" -azure-core==1.29.5 +git+https://github.com/Azure/azure-sdk-for-python@multipart-files-array-dev11#subdirectory=sdk/core/azure-core # only for azure -e ./generated/azure-mgmt-spheredpg -e ./generated/azure-mgmt-spheremsrest diff --git a/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/_vendor.py b/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/_vendor.py index c559ea1ec67..5ef15917f86 100644 --- a/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/_vendor.py +++ b/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/_vendor.py @@ -8,7 +8,7 @@ from io import BytesIO, IOBase import json import sys -from typing import Any, Union +from typing import Any, List, Tuple, Union import uuid from ._model_base import Model, SdkJSONEncoder @@ -19,18 +19,39 @@ from typing import MutableMapping # type: ignore # pylint: disable=ungrouped-imports +# file-like tuple could be `(filename, IO (or bytes))` or `(filename, IO (or bytes), content_type)` +FileType = Union[IOBase, bytes] +FileTuple = Union[Tuple[str, FileType], Tuple[str, FileType, str]] +MultiPartFile = Union[IOBase, bytes, FileTuple] +HandledMultiPartFile = Union[IOBase, FileTuple] + + class NamedBytesIO(BytesIO): def __init__(self, name: str, *args, **kwargs): super().__init__(*args, **kwargs) self.name = name -def multipart_file(file: Union[IOBase, bytes]) -> IOBase: - if isinstance(file, IOBase): +def has_file(data: Any) -> bool: + return isinstance(data, (IOBase, bytes)) or ( + isinstance(data, (list, tuple)) and any(isinstance(f, (IOBase, bytes, tuple)) for f in data) + ) + + +def handle_file(file: Union[IOBase, bytes, FileTuple]) -> IOBase: + if isinstance(file, (IOBase, Tuple)): return file return NamedBytesIO("auto-name-" + str(uuid.uuid4()), file) +def multipart_file( + file: Union[MultiPartFile, List[MultiPartFile]] +) -> Union[HandledMultiPartFile, List[HandledMultiPartFile]]: + if isinstance(file, list): + return [handle_file(f) for f in file] + return handle_file(file) + + def multipart_data(data: Any) -> Any: if isinstance(data, (list, tuple, dict, Model)): return json.dumps(data, cls=SdkJSONEncoder, exclude_readonly=True) @@ -52,6 +73,6 @@ def handle_multipart_form_data_model(body: Model) -> MutableMapping[str, Any]: attr = rest_name_attr.get(rest_name) if attr is not None: raw_value = getattr(body, attr, None) - if isinstance(raw_value, (bytes, IOBase)): + if has_file(raw_value): result[rest_name] = raw_value return result diff --git a/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/aio/operations/_operations.py b/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/aio/operations/_operations.py index d3dca59c18e..c6c7412cf53 100644 --- a/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/aio/operations/_operations.py +++ b/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/aio/operations/_operations.py @@ -22,7 +22,7 @@ from corehttp.runtime.pipeline import PipelineResponse from ... import _model_base, models as _models -from ..._vendor import handle_multipart_form_data_model, multipart_data, multipart_file +from ..._vendor import handle_multipart_form_data_model, has_file, multipart_data, multipart_file from ...operations._operations import ( build_form_data_basic_request, build_form_data_binary_array_parts_request, @@ -128,8 +128,8 @@ async def basic( # pylint: disable=inconsistent-return-statements _body = handle_multipart_form_data_model(body) else: _body = body - _files = {k: multipart_file(v) for k, v in _body.items() if isinstance(v, (IOBase, bytes))} - _data = {k: multipart_data(v) for k, v in _body.items() if not isinstance(v, (IOBase, bytes))} + _files = {k: multipart_file(v) for k, v in _body.items() if has_file(v)} + _data = {k: multipart_data(v) for k, v in _body.items() if not has_file(v)} _request = build_form_data_basic_request( data=_data, @@ -247,8 +247,8 @@ async def complex( # pylint: disable=inconsistent-return-statements _body = handle_multipart_form_data_model(body) else: _body = body - _files = {k: multipart_file(v) for k, v in _body.items() if isinstance(v, (IOBase, bytes))} - _data = {k: multipart_data(v) for k, v in _body.items() if not isinstance(v, (IOBase, bytes))} + _files = {k: multipart_file(v) for k, v in _body.items() if has_file(v)} + _data = {k: multipart_data(v) for k, v in _body.items() if not has_file(v)} _request = build_form_data_complex_request( data=_data, @@ -348,8 +348,8 @@ async def json_part( # pylint: disable=inconsistent-return-statements _body = handle_multipart_form_data_model(body) else: _body = body - _files = {k: multipart_file(v) for k, v in _body.items() if isinstance(v, (IOBase, bytes))} - _data = {k: multipart_data(v) for k, v in _body.items() if not isinstance(v, (IOBase, bytes))} + _files = {k: multipart_file(v) for k, v in _body.items() if has_file(v)} + _data = {k: multipart_data(v) for k, v in _body.items() if not has_file(v)} _request = build_form_data_json_part_request( data=_data, @@ -451,8 +451,8 @@ async def binary_array_parts( # pylint: disable=inconsistent-return-statements _body = handle_multipart_form_data_model(body) else: _body = body - _files = {k: multipart_file(v) for k, v in _body.items() if isinstance(v, (IOBase, bytes))} - _data = {k: multipart_data(v) for k, v in _body.items() if not isinstance(v, (IOBase, bytes))} + _files = {k: multipart_file(v) for k, v in _body.items() if has_file(v)} + _data = {k: multipart_data(v) for k, v in _body.items() if not has_file(v)} _request = build_form_data_binary_array_parts_request( data=_data, @@ -558,8 +558,8 @@ async def json_array_parts( # pylint: disable=inconsistent-return-statements _body = handle_multipart_form_data_model(body) else: _body = body - _files = {k: multipart_file(v) for k, v in _body.items() if isinstance(v, (IOBase, bytes))} - _data = {k: multipart_data(v) for k, v in _body.items() if not isinstance(v, (IOBase, bytes))} + _files = {k: multipart_file(v) for k, v in _body.items() if has_file(v)} + _data = {k: multipart_data(v) for k, v in _body.items() if not has_file(v)} _request = build_form_data_json_array_parts_request( data=_data, @@ -657,8 +657,8 @@ async def multi_binary_parts( # pylint: disable=inconsistent-return-statements _body = handle_multipart_form_data_model(body) else: _body = body - _files = {k: multipart_file(v) for k, v in _body.items() if isinstance(v, (IOBase, bytes))} - _data = {k: multipart_data(v) for k, v in _body.items() if not isinstance(v, (IOBase, bytes))} + _files = {k: multipart_file(v) for k, v in _body.items() if has_file(v)} + _data = {k: multipart_data(v) for k, v in _body.items() if not has_file(v)} _request = build_form_data_multi_binary_parts_request( data=_data, diff --git a/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/operations/_operations.py b/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/operations/_operations.py index 4feac538204..8833b8c8582 100644 --- a/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/operations/_operations.py +++ b/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/operations/_operations.py @@ -24,7 +24,7 @@ from .. import _model_base, models as _models from .._serialization import Serializer -from .._vendor import handle_multipart_form_data_model, multipart_data, multipart_file +from .._vendor import handle_multipart_form_data_model, has_file, multipart_data, multipart_file if sys.version_info >= (3, 9): from collections.abc import MutableMapping @@ -179,8 +179,8 @@ def basic( # pylint: disable=inconsistent-return-statements _body = handle_multipart_form_data_model(body) else: _body = body - _files = {k: multipart_file(v) for k, v in _body.items() if isinstance(v, (IOBase, bytes))} - _data = {k: multipart_data(v) for k, v in _body.items() if not isinstance(v, (IOBase, bytes))} + _files = {k: multipart_file(v) for k, v in _body.items() if has_file(v)} + _data = {k: multipart_data(v) for k, v in _body.items() if not has_file(v)} _request = build_form_data_basic_request( data=_data, @@ -298,8 +298,8 @@ def complex( # pylint: disable=inconsistent-return-statements _body = handle_multipart_form_data_model(body) else: _body = body - _files = {k: multipart_file(v) for k, v in _body.items() if isinstance(v, (IOBase, bytes))} - _data = {k: multipart_data(v) for k, v in _body.items() if not isinstance(v, (IOBase, bytes))} + _files = {k: multipart_file(v) for k, v in _body.items() if has_file(v)} + _data = {k: multipart_data(v) for k, v in _body.items() if not has_file(v)} _request = build_form_data_complex_request( data=_data, @@ -399,8 +399,8 @@ def json_part( # pylint: disable=inconsistent-return-statements _body = handle_multipart_form_data_model(body) else: _body = body - _files = {k: multipart_file(v) for k, v in _body.items() if isinstance(v, (IOBase, bytes))} - _data = {k: multipart_data(v) for k, v in _body.items() if not isinstance(v, (IOBase, bytes))} + _files = {k: multipart_file(v) for k, v in _body.items() if has_file(v)} + _data = {k: multipart_data(v) for k, v in _body.items() if not has_file(v)} _request = build_form_data_json_part_request( data=_data, @@ -500,8 +500,8 @@ def binary_array_parts( # pylint: disable=inconsistent-return-statements _body = handle_multipart_form_data_model(body) else: _body = body - _files = {k: multipart_file(v) for k, v in _body.items() if isinstance(v, (IOBase, bytes))} - _data = {k: multipart_data(v) for k, v in _body.items() if not isinstance(v, (IOBase, bytes))} + _files = {k: multipart_file(v) for k, v in _body.items() if has_file(v)} + _data = {k: multipart_data(v) for k, v in _body.items() if not has_file(v)} _request = build_form_data_binary_array_parts_request( data=_data, @@ -605,8 +605,8 @@ def json_array_parts( # pylint: disable=inconsistent-return-statements _body = handle_multipart_form_data_model(body) else: _body = body - _files = {k: multipart_file(v) for k, v in _body.items() if isinstance(v, (IOBase, bytes))} - _data = {k: multipart_data(v) for k, v in _body.items() if not isinstance(v, (IOBase, bytes))} + _files = {k: multipart_file(v) for k, v in _body.items() if has_file(v)} + _data = {k: multipart_data(v) for k, v in _body.items() if not has_file(v)} _request = build_form_data_json_array_parts_request( data=_data, @@ -702,8 +702,8 @@ def multi_binary_parts( # pylint: disable=inconsistent-return-statements _body = handle_multipart_form_data_model(body) else: _body = body - _files = {k: multipart_file(v) for k, v in _body.items() if isinstance(v, (IOBase, bytes))} - _data = {k: multipart_data(v) for k, v in _body.items() if not isinstance(v, (IOBase, bytes))} + _files = {k: multipart_file(v) for k, v in _body.items() if has_file(v)} + _data = {k: multipart_data(v) for k, v in _body.items() if not has_file(v)} _request = build_form_data_multi_binary_parts_request( data=_data, From a45a47c1c284cd4034f8351a930b61065fbf1e10 Mon Sep 17 00:00:00 2001 From: msyyc <70930885+msyyc@users.noreply.github.com> Date: Tue, 23 Jan 2024 17:00:25 +0800 Subject: [PATCH 02/45] rename file --- ..._payload_multipart.py => test_payload_multipart_file_array.py} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename packages/typespec-python/test/azure/mock_api_tests/{test_payload_multipart.py => test_payload_multipart_file_array.py} (100%) diff --git a/packages/typespec-python/test/azure/mock_api_tests/test_payload_multipart.py b/packages/typespec-python/test/azure/mock_api_tests/test_payload_multipart_file_array.py similarity index 100% rename from packages/typespec-python/test/azure/mock_api_tests/test_payload_multipart.py rename to packages/typespec-python/test/azure/mock_api_tests/test_payload_multipart_file_array.py From 575568f05b459613c2607f08c8be1011f483d86a Mon Sep 17 00:00:00 2001 From: msyyc <70930885+msyyc@users.noreply.github.com> Date: Tue, 23 Jan 2024 17:26:39 +0800 Subject: [PATCH 03/45] lint --- packages/autorest.python/autorest/codegen/models/operation.py | 1 - .../autorest/codegen/templates/vendor.py.jinja2 | 4 ++-- .../generated/payload-multipart/payload/multipart/_vendor.py | 4 ++-- .../payload/multipart/aio/operations/_operations.py | 1 - .../payload/multipart/operations/_operations.py | 1 - .../generated/payload-multipart/payload/multipart/_vendor.py | 4 ++-- .../payload/multipart/aio/operations/_operations.py | 1 - .../payload/multipart/operations/_operations.py | 1 - 8 files changed, 6 insertions(+), 11 deletions(-) diff --git a/packages/autorest.python/autorest/codegen/models/operation.py b/packages/autorest.python/autorest/codegen/models/operation.py index 532958cfcef..534f85742c2 100644 --- a/packages/autorest.python/autorest/codegen/models/operation.py +++ b/packages/autorest.python/autorest/codegen/models/operation.py @@ -586,7 +586,6 @@ def imports(self, async_mode: bool, **kwargs: Any) -> FileImport: file_import.add_submodule_import( relative_path, "_model_base", ImportType.LOCAL ) - file_import.add_submodule_import("io", "IOBase", ImportType.STDLIB) file_import.add_submodule_import( f"{relative_path}_vendor", "has_file", diff --git a/packages/autorest.python/autorest/codegen/templates/vendor.py.jinja2 b/packages/autorest.python/autorest/codegen/templates/vendor.py.jinja2 index 86c2f889bca..9c31defae33 100644 --- a/packages/autorest.python/autorest/codegen/templates/vendor.py.jinja2 +++ b/packages/autorest.python/autorest/codegen/templates/vendor.py.jinja2 @@ -81,8 +81,8 @@ class NamedBytesIO(BytesIO): def has_file(data: Any) -> bool: return isinstance(data, (IOBase, bytes)) or (isinstance(data, (list, tuple)) and any(isinstance(f, (IOBase, bytes, tuple)) for f in data)) -def handle_file(file: Union[IOBase, bytes, FileTuple]) -> IOBase: - if isinstance(file, (IOBase, Tuple)): +def handle_file(file: Union[IOBase, bytes, FileTuple]) -> HandledMultiPartFile: + if isinstance(file, (IOBase, tuple)): return file return NamedBytesIO("auto-name-" + str(uuid.uuid4()), file) diff --git a/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/_vendor.py b/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/_vendor.py index 9eaf7d96fc0..1f04e129d0b 100644 --- a/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/_vendor.py +++ b/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/_vendor.py @@ -38,8 +38,8 @@ def has_file(data: Any) -> bool: ) -def handle_file(file: Union[IOBase, bytes, FileTuple]) -> IOBase: - if isinstance(file, (IOBase, Tuple)): +def handle_file(file: Union[IOBase, bytes, FileTuple]) -> HandledMultiPartFile: + if isinstance(file, (IOBase, tuple)): return file return NamedBytesIO("auto-name-" + str(uuid.uuid4()), file) diff --git a/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/aio/operations/_operations.py b/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/aio/operations/_operations.py index dbec435bf15..a9141115191 100644 --- a/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/aio/operations/_operations.py +++ b/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/aio/operations/_operations.py @@ -6,7 +6,6 @@ # Code generated by Microsoft (R) Python Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from io import IOBase import sys from typing import Any, Callable, Dict, Optional, TypeVar, Union, overload diff --git a/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/operations/_operations.py b/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/operations/_operations.py index ac113f9112b..32fa26cb8bd 100644 --- a/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/operations/_operations.py +++ b/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/operations/_operations.py @@ -6,7 +6,6 @@ # Code generated by Microsoft (R) Python Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from io import IOBase import sys from typing import Any, Callable, Dict, Optional, TypeVar, Union, overload diff --git a/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/_vendor.py b/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/_vendor.py index 5ef15917f86..4e08215a6d0 100644 --- a/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/_vendor.py +++ b/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/_vendor.py @@ -38,8 +38,8 @@ def has_file(data: Any) -> bool: ) -def handle_file(file: Union[IOBase, bytes, FileTuple]) -> IOBase: - if isinstance(file, (IOBase, Tuple)): +def handle_file(file: Union[IOBase, bytes, FileTuple]) -> HandledMultiPartFile: + if isinstance(file, (IOBase, tuple)): return file return NamedBytesIO("auto-name-" + str(uuid.uuid4()), file) diff --git a/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/aio/operations/_operations.py b/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/aio/operations/_operations.py index c6c7412cf53..7bac644a4ab 100644 --- a/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/aio/operations/_operations.py +++ b/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/aio/operations/_operations.py @@ -6,7 +6,6 @@ # Code generated by Unbranded (R) Python Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from io import IOBase import sys from typing import Any, Callable, Dict, Optional, TypeVar, Union, overload diff --git a/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/operations/_operations.py b/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/operations/_operations.py index 8833b8c8582..16a47cd6b40 100644 --- a/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/operations/_operations.py +++ b/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/operations/_operations.py @@ -6,7 +6,6 @@ # Code generated by Unbranded (R) Python Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from io import IOBase import sys from typing import Any, Callable, Dict, Optional, TypeVar, Union, overload From b8fd3ff208371c33f1eda98abcff3ce141a886b3 Mon Sep 17 00:00:00 2001 From: msyyc <70930885+msyyc@users.noreply.github.com> Date: Thu, 25 Jan 2024 14:26:40 +0800 Subject: [PATCH 04/45] review --- .../autorest/codegen/models/operation.py | 5 --- .../autorest/codegen/models/parameter.py | 23 +++++++++- .../codegen/serializers/builder_serializer.py | 7 +-- .../codegen/templates/vendor.py.jinja2 | 13 +++--- .../payload/multipart/_vendor.py | 18 +++----- .../multipart/aio/operations/_operations.py | 44 +++++++++++-------- .../multipart/operations/_operations.py | 44 +++++++++++-------- .../payload/multipart/_vendor.py | 18 +++----- .../multipart/aio/operations/_operations.py | 44 +++++++++++-------- .../multipart/operations/_operations.py | 44 +++++++++++-------- 10 files changed, 145 insertions(+), 115 deletions(-) diff --git a/packages/autorest.python/autorest/codegen/models/operation.py b/packages/autorest.python/autorest/codegen/models/operation.py index 534f85742c2..bb8748a4a9c 100644 --- a/packages/autorest.python/autorest/codegen/models/operation.py +++ b/packages/autorest.python/autorest/codegen/models/operation.py @@ -586,11 +586,6 @@ def imports(self, async_mode: bool, **kwargs: Any) -> FileImport: file_import.add_submodule_import( relative_path, "_model_base", ImportType.LOCAL ) - file_import.add_submodule_import( - f"{relative_path}_vendor", - "has_file", - ImportType.LOCAL, - ) file_import.add_submodule_import( f"{relative_path}_vendor", "multipart_file", diff --git a/packages/autorest.python/autorest/codegen/models/parameter.py b/packages/autorest.python/autorest/codegen/models/parameter.py index aab6ad0bb40..66e35a25f99 100644 --- a/packages/autorest.python/autorest/codegen/models/parameter.py +++ b/packages/autorest.python/autorest/codegen/models/parameter.py @@ -23,7 +23,9 @@ from .constant_type import ConstantType from .utils import add_to_description from .combined_type import CombinedType -from .model_type import JSONModelType +from .model_type import JSONModelType, DPGModelType +from .primitive_types import ByteArraySchema +from .list_type import ListType if TYPE_CHECKING: from .code_model import CodeModel @@ -278,6 +280,25 @@ def has_json_model_type(self) -> bool: return self.type.target_model_subtype((JSONModelType,)) is not None return isinstance(self.type, JSONModelType) + @property + def file_properties(self) -> List[str]: + model_type = None + if isinstance(self.type, CombinedType): + model_type = self.type.target_model_subtype((JSONModelType, DPGModelType)) + elif isinstance(self.type, (JSONModelType, DPGModelType)): + model_type = self.type + if model_type is None: + return [] + return [ + prop.wire_name + for prop in model_type.properties + if isinstance(prop.type, ByteArraySchema) + or ( + isinstance(prop.type, ListType) + and isinstance(prop.type.element_type, ByteArraySchema) + ) + ] + @classmethod def from_yaml( cls, yaml_data: Dict[str, Any], code_model: "CodeModel" diff --git a/packages/autorest.python/autorest/codegen/serializers/builder_serializer.py b/packages/autorest.python/autorest/codegen/serializers/builder_serializer.py index b74004b80a8..4df181d302e 100644 --- a/packages/autorest.python/autorest/codegen/serializers/builder_serializer.py +++ b/packages/autorest.python/autorest/codegen/serializers/builder_serializer.py @@ -755,12 +755,13 @@ def _serialize_body_parameter(self, builder: OperationType) -> List[str]: body_param = cast(BodyParameter, builder.parameters.body_parameter) if body_param.is_form_data: return [ + 'file_properties = ["' + '", "'.join(body_param.file_properties) + '"]', f"if isinstance({body_param.client_name}, _model_base.Model):", - f" _body = handle_multipart_form_data_model({body_param.client_name})", + f" _body = handle_multipart_form_data_model({body_param.client_name}, file_properties)", "else:", f" _body = {body_param.client_name}", - "_files = {k: multipart_file(v) for k, v in _body.items() if has_file(v)}", - "_data = {k: multipart_data(v) for k, v in _body.items() if not has_file(v)}", + "_files = {k: multipart_file(v) for k, v in _body.items() if k in file_properties}", + "_data = {k: multipart_data(v) for k, v in _body.items() if k not in file_properties}", ] retval: List[str] = [] body_kwarg_name = builder.request_builder.parameters.body_parameter.client_name diff --git a/packages/autorest.python/autorest/codegen/templates/vendor.py.jinja2 b/packages/autorest.python/autorest/codegen/templates/vendor.py.jinja2 index 9c31defae33..c25a28a3c51 100644 --- a/packages/autorest.python/autorest/codegen/templates/vendor.py.jinja2 +++ b/packages/autorest.python/autorest/codegen/templates/vendor.py.jinja2 @@ -78,9 +78,6 @@ class NamedBytesIO(BytesIO): super().__init__(*args, **kwargs) self.name = name -def has_file(data: Any) -> bool: - return isinstance(data, (IOBase, bytes)) or (isinstance(data, (list, tuple)) and any(isinstance(f, (IOBase, bytes, tuple)) for f in data)) - def handle_file(file: Union[IOBase, bytes, FileTuple]) -> HandledMultiPartFile: if isinstance(file, (IOBase, tuple)): return file @@ -96,12 +93,14 @@ def multipart_data(data: Any) -> Any: return json.dumps(data, cls=SdkJSONEncoder, exclude_readonly=True) return data -def handle_multipart_form_data_model(body: Model) -> MutableMapping[str, Any]: # pylint: disable=unsubscriptable-object +def handle_multipart_form_data_model(body: Model, file_properties: List[str]) -> MutableMapping[str, Any]: # pylint: disable=unsubscriptable-object """handle first layer of model. If its value is bytes or IO, replace it with raw value instead of serialized value. :param body: The model to handle. :type body: ~payload.multipart._model_base.Model + :param file_properties: The properties of the model that are file type. + :type file_properties: list[str] :return: The handled model. :rtype: MutableMapping[str, Any] """ @@ -109,9 +108,7 @@ def handle_multipart_form_data_model(body: Model) -> MutableMapping[str, Any]: rest_name_attr = {v._rest_name: k for k, v in body._attr_to_rest_field.items()} # pylint: disable=protected-access for rest_name in result.keys(): attr = rest_name_attr.get(rest_name) - if attr is not None: - raw_value = getattr(body, attr, None) - if has_file(raw_value): - result[rest_name] = raw_value + if attr is not None and rest_name in file_properties: + result[rest_name] = getattr(body, attr, None) return result {% endif %} diff --git a/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/_vendor.py b/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/_vendor.py index 1f04e129d0b..222a66999ba 100644 --- a/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/_vendor.py +++ b/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/_vendor.py @@ -32,12 +32,6 @@ def __init__(self, name: str, *args, **kwargs): self.name = name -def has_file(data: Any) -> bool: - return isinstance(data, (IOBase, bytes)) or ( - isinstance(data, (list, tuple)) and any(isinstance(f, (IOBase, bytes, tuple)) for f in data) - ) - - def handle_file(file: Union[IOBase, bytes, FileTuple]) -> HandledMultiPartFile: if isinstance(file, (IOBase, tuple)): return file @@ -58,12 +52,16 @@ def multipart_data(data: Any) -> Any: return data -def handle_multipart_form_data_model(body: Model) -> MutableMapping[str, Any]: # pylint: disable=unsubscriptable-object +def handle_multipart_form_data_model( + body: Model, file_properties: List[str] +) -> MutableMapping[str, Any]: # pylint: disable=unsubscriptable-object """handle first layer of model. If its value is bytes or IO, replace it with raw value instead of serialized value. :param body: The model to handle. :type body: ~payload.multipart._model_base.Model + :param file_properties: The properties of the model that are file type. + :type file_properties: list[str] :return: The handled model. :rtype: MutableMapping[str, Any] """ @@ -71,8 +69,6 @@ def handle_multipart_form_data_model(body: Model) -> MutableMapping[str, Any]: rest_name_attr = {v._rest_name: k for k, v in body._attr_to_rest_field.items()} # pylint: disable=protected-access for rest_name in result.keys(): attr = rest_name_attr.get(rest_name) - if attr is not None: - raw_value = getattr(body, attr, None) - if has_file(raw_value): - result[rest_name] = raw_value + if attr is not None and rest_name in file_properties: + result[rest_name] = getattr(body, attr, None) return result diff --git a/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/aio/operations/_operations.py b/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/aio/operations/_operations.py index a9141115191..339aec23362 100644 --- a/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/aio/operations/_operations.py +++ b/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/aio/operations/_operations.py @@ -22,7 +22,7 @@ from azure.core.tracing.decorator_async import distributed_trace_async from ... import _model_base, models as _models -from ..._vendor import handle_multipart_form_data_model, has_file, multipart_data, multipart_file +from ..._vendor import handle_multipart_form_data_model, multipart_data, multipart_file from ...operations._operations import ( build_form_data_basic_request, build_form_data_binary_array_parts_request, @@ -125,12 +125,13 @@ async def basic( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) + file_properties = ["profileImage"] if isinstance(body, _model_base.Model): - _body = handle_multipart_form_data_model(body) + _body = handle_multipart_form_data_model(body, file_properties) else: _body = body - _files = {k: multipart_file(v) for k, v in _body.items() if has_file(v)} - _data = {k: multipart_data(v) for k, v in _body.items() if not has_file(v)} + _files = {k: multipart_file(v) for k, v in _body.items() if k in file_properties} + _data = {k: multipart_data(v) for k, v in _body.items() if k not in file_properties} _request = build_form_data_basic_request( data=_data, @@ -245,12 +246,13 @@ async def complex( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) + file_properties = ["profileImage", "pictures"] if isinstance(body, _model_base.Model): - _body = handle_multipart_form_data_model(body) + _body = handle_multipart_form_data_model(body, file_properties) else: _body = body - _files = {k: multipart_file(v) for k, v in _body.items() if has_file(v)} - _data = {k: multipart_data(v) for k, v in _body.items() if not has_file(v)} + _files = {k: multipart_file(v) for k, v in _body.items() if k in file_properties} + _data = {k: multipart_data(v) for k, v in _body.items() if k not in file_properties} _request = build_form_data_complex_request( data=_data, @@ -347,12 +349,13 @@ async def json_part( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) + file_properties = ["profileImage"] if isinstance(body, _model_base.Model): - _body = handle_multipart_form_data_model(body) + _body = handle_multipart_form_data_model(body, file_properties) else: _body = body - _files = {k: multipart_file(v) for k, v in _body.items() if has_file(v)} - _data = {k: multipart_data(v) for k, v in _body.items() if not has_file(v)} + _files = {k: multipart_file(v) for k, v in _body.items() if k in file_properties} + _data = {k: multipart_data(v) for k, v in _body.items() if k not in file_properties} _request = build_form_data_json_part_request( data=_data, @@ -451,12 +454,13 @@ async def binary_array_parts( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) + file_properties = ["pictures"] if isinstance(body, _model_base.Model): - _body = handle_multipart_form_data_model(body) + _body = handle_multipart_form_data_model(body, file_properties) else: _body = body - _files = {k: multipart_file(v) for k, v in _body.items() if has_file(v)} - _data = {k: multipart_data(v) for k, v in _body.items() if not has_file(v)} + _files = {k: multipart_file(v) for k, v in _body.items() if k in file_properties} + _data = {k: multipart_data(v) for k, v in _body.items() if k not in file_properties} _request = build_form_data_binary_array_parts_request( data=_data, @@ -559,12 +563,13 @@ async def json_array_parts( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) + file_properties = ["profileImage"] if isinstance(body, _model_base.Model): - _body = handle_multipart_form_data_model(body) + _body = handle_multipart_form_data_model(body, file_properties) else: _body = body - _files = {k: multipart_file(v) for k, v in _body.items() if has_file(v)} - _data = {k: multipart_data(v) for k, v in _body.items() if not has_file(v)} + _files = {k: multipart_file(v) for k, v in _body.items() if k in file_properties} + _data = {k: multipart_data(v) for k, v in _body.items() if k not in file_properties} _request = build_form_data_json_array_parts_request( data=_data, @@ -659,12 +664,13 @@ async def multi_binary_parts( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) + file_properties = ["profileImage", "picture"] if isinstance(body, _model_base.Model): - _body = handle_multipart_form_data_model(body) + _body = handle_multipart_form_data_model(body, file_properties) else: _body = body - _files = {k: multipart_file(v) for k, v in _body.items() if has_file(v)} - _data = {k: multipart_data(v) for k, v in _body.items() if not has_file(v)} + _files = {k: multipart_file(v) for k, v in _body.items() if k in file_properties} + _data = {k: multipart_data(v) for k, v in _body.items() if k not in file_properties} _request = build_form_data_multi_binary_parts_request( data=_data, diff --git a/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/operations/_operations.py b/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/operations/_operations.py index 32fa26cb8bd..f01895f4fe6 100644 --- a/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/operations/_operations.py +++ b/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/operations/_operations.py @@ -24,7 +24,7 @@ from .. import _model_base, models as _models from .._serialization import Serializer -from .._vendor import handle_multipart_form_data_model, has_file, multipart_data, multipart_file +from .._vendor import handle_multipart_form_data_model, multipart_data, multipart_file if sys.version_info >= (3, 9): from collections.abc import MutableMapping @@ -176,12 +176,13 @@ def basic( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) + file_properties = ["profileImage"] if isinstance(body, _model_base.Model): - _body = handle_multipart_form_data_model(body) + _body = handle_multipart_form_data_model(body, file_properties) else: _body = body - _files = {k: multipart_file(v) for k, v in _body.items() if has_file(v)} - _data = {k: multipart_data(v) for k, v in _body.items() if not has_file(v)} + _files = {k: multipart_file(v) for k, v in _body.items() if k in file_properties} + _data = {k: multipart_data(v) for k, v in _body.items() if k not in file_properties} _request = build_form_data_basic_request( data=_data, @@ -296,12 +297,13 @@ def complex( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) + file_properties = ["profileImage", "pictures"] if isinstance(body, _model_base.Model): - _body = handle_multipart_form_data_model(body) + _body = handle_multipart_form_data_model(body, file_properties) else: _body = body - _files = {k: multipart_file(v) for k, v in _body.items() if has_file(v)} - _data = {k: multipart_data(v) for k, v in _body.items() if not has_file(v)} + _files = {k: multipart_file(v) for k, v in _body.items() if k in file_properties} + _data = {k: multipart_data(v) for k, v in _body.items() if k not in file_properties} _request = build_form_data_complex_request( data=_data, @@ -398,12 +400,13 @@ def json_part( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) + file_properties = ["profileImage"] if isinstance(body, _model_base.Model): - _body = handle_multipart_form_data_model(body) + _body = handle_multipart_form_data_model(body, file_properties) else: _body = body - _files = {k: multipart_file(v) for k, v in _body.items() if has_file(v)} - _data = {k: multipart_data(v) for k, v in _body.items() if not has_file(v)} + _files = {k: multipart_file(v) for k, v in _body.items() if k in file_properties} + _data = {k: multipart_data(v) for k, v in _body.items() if k not in file_properties} _request = build_form_data_json_part_request( data=_data, @@ -500,12 +503,13 @@ def binary_array_parts( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) + file_properties = ["pictures"] if isinstance(body, _model_base.Model): - _body = handle_multipart_form_data_model(body) + _body = handle_multipart_form_data_model(body, file_properties) else: _body = body - _files = {k: multipart_file(v) for k, v in _body.items() if has_file(v)} - _data = {k: multipart_data(v) for k, v in _body.items() if not has_file(v)} + _files = {k: multipart_file(v) for k, v in _body.items() if k in file_properties} + _data = {k: multipart_data(v) for k, v in _body.items() if k not in file_properties} _request = build_form_data_binary_array_parts_request( data=_data, @@ -606,12 +610,13 @@ def json_array_parts( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) + file_properties = ["profileImage"] if isinstance(body, _model_base.Model): - _body = handle_multipart_form_data_model(body) + _body = handle_multipart_form_data_model(body, file_properties) else: _body = body - _files = {k: multipart_file(v) for k, v in _body.items() if has_file(v)} - _data = {k: multipart_data(v) for k, v in _body.items() if not has_file(v)} + _files = {k: multipart_file(v) for k, v in _body.items() if k in file_properties} + _data = {k: multipart_data(v) for k, v in _body.items() if k not in file_properties} _request = build_form_data_json_array_parts_request( data=_data, @@ -704,12 +709,13 @@ def multi_binary_parts( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) + file_properties = ["profileImage", "picture"] if isinstance(body, _model_base.Model): - _body = handle_multipart_form_data_model(body) + _body = handle_multipart_form_data_model(body, file_properties) else: _body = body - _files = {k: multipart_file(v) for k, v in _body.items() if has_file(v)} - _data = {k: multipart_data(v) for k, v in _body.items() if not has_file(v)} + _files = {k: multipart_file(v) for k, v in _body.items() if k in file_properties} + _data = {k: multipart_data(v) for k, v in _body.items() if k not in file_properties} _request = build_form_data_multi_binary_parts_request( data=_data, diff --git a/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/_vendor.py b/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/_vendor.py index 4e08215a6d0..4931a6de0f9 100644 --- a/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/_vendor.py +++ b/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/_vendor.py @@ -32,12 +32,6 @@ def __init__(self, name: str, *args, **kwargs): self.name = name -def has_file(data: Any) -> bool: - return isinstance(data, (IOBase, bytes)) or ( - isinstance(data, (list, tuple)) and any(isinstance(f, (IOBase, bytes, tuple)) for f in data) - ) - - def handle_file(file: Union[IOBase, bytes, FileTuple]) -> HandledMultiPartFile: if isinstance(file, (IOBase, tuple)): return file @@ -58,12 +52,16 @@ def multipart_data(data: Any) -> Any: return data -def handle_multipart_form_data_model(body: Model) -> MutableMapping[str, Any]: # pylint: disable=unsubscriptable-object +def handle_multipart_form_data_model( + body: Model, file_properties: List[str] +) -> MutableMapping[str, Any]: # pylint: disable=unsubscriptable-object """handle first layer of model. If its value is bytes or IO, replace it with raw value instead of serialized value. :param body: The model to handle. :type body: ~payload.multipart._model_base.Model + :param file_properties: The properties of the model that are file type. + :type file_properties: list[str] :return: The handled model. :rtype: MutableMapping[str, Any] """ @@ -71,8 +69,6 @@ def handle_multipart_form_data_model(body: Model) -> MutableMapping[str, Any]: rest_name_attr = {v._rest_name: k for k, v in body._attr_to_rest_field.items()} # pylint: disable=protected-access for rest_name in result.keys(): attr = rest_name_attr.get(rest_name) - if attr is not None: - raw_value = getattr(body, attr, None) - if has_file(raw_value): - result[rest_name] = raw_value + if attr is not None and rest_name in file_properties: + result[rest_name] = getattr(body, attr, None) return result diff --git a/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/aio/operations/_operations.py b/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/aio/operations/_operations.py index 7bac644a4ab..993837aa7e5 100644 --- a/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/aio/operations/_operations.py +++ b/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/aio/operations/_operations.py @@ -21,7 +21,7 @@ from corehttp.runtime.pipeline import PipelineResponse from ... import _model_base, models as _models -from ..._vendor import handle_multipart_form_data_model, has_file, multipart_data, multipart_file +from ..._vendor import handle_multipart_form_data_model, multipart_data, multipart_file from ...operations._operations import ( build_form_data_basic_request, build_form_data_binary_array_parts_request, @@ -123,12 +123,13 @@ async def basic( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) + file_properties = ["profileImage"] if isinstance(body, _model_base.Model): - _body = handle_multipart_form_data_model(body) + _body = handle_multipart_form_data_model(body, file_properties) else: _body = body - _files = {k: multipart_file(v) for k, v in _body.items() if has_file(v)} - _data = {k: multipart_data(v) for k, v in _body.items() if not has_file(v)} + _files = {k: multipart_file(v) for k, v in _body.items() if k in file_properties} + _data = {k: multipart_data(v) for k, v in _body.items() if k not in file_properties} _request = build_form_data_basic_request( data=_data, @@ -242,12 +243,13 @@ async def complex( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) + file_properties = ["profileImage", "pictures"] if isinstance(body, _model_base.Model): - _body = handle_multipart_form_data_model(body) + _body = handle_multipart_form_data_model(body, file_properties) else: _body = body - _files = {k: multipart_file(v) for k, v in _body.items() if has_file(v)} - _data = {k: multipart_data(v) for k, v in _body.items() if not has_file(v)} + _files = {k: multipart_file(v) for k, v in _body.items() if k in file_properties} + _data = {k: multipart_data(v) for k, v in _body.items() if k not in file_properties} _request = build_form_data_complex_request( data=_data, @@ -343,12 +345,13 @@ async def json_part( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) + file_properties = ["profileImage"] if isinstance(body, _model_base.Model): - _body = handle_multipart_form_data_model(body) + _body = handle_multipart_form_data_model(body, file_properties) else: _body = body - _files = {k: multipart_file(v) for k, v in _body.items() if has_file(v)} - _data = {k: multipart_data(v) for k, v in _body.items() if not has_file(v)} + _files = {k: multipart_file(v) for k, v in _body.items() if k in file_properties} + _data = {k: multipart_data(v) for k, v in _body.items() if k not in file_properties} _request = build_form_data_json_part_request( data=_data, @@ -446,12 +449,13 @@ async def binary_array_parts( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) + file_properties = ["pictures"] if isinstance(body, _model_base.Model): - _body = handle_multipart_form_data_model(body) + _body = handle_multipart_form_data_model(body, file_properties) else: _body = body - _files = {k: multipart_file(v) for k, v in _body.items() if has_file(v)} - _data = {k: multipart_data(v) for k, v in _body.items() if not has_file(v)} + _files = {k: multipart_file(v) for k, v in _body.items() if k in file_properties} + _data = {k: multipart_data(v) for k, v in _body.items() if k not in file_properties} _request = build_form_data_binary_array_parts_request( data=_data, @@ -553,12 +557,13 @@ async def json_array_parts( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) + file_properties = ["profileImage"] if isinstance(body, _model_base.Model): - _body = handle_multipart_form_data_model(body) + _body = handle_multipart_form_data_model(body, file_properties) else: _body = body - _files = {k: multipart_file(v) for k, v in _body.items() if has_file(v)} - _data = {k: multipart_data(v) for k, v in _body.items() if not has_file(v)} + _files = {k: multipart_file(v) for k, v in _body.items() if k in file_properties} + _data = {k: multipart_data(v) for k, v in _body.items() if k not in file_properties} _request = build_form_data_json_array_parts_request( data=_data, @@ -652,12 +657,13 @@ async def multi_binary_parts( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) + file_properties = ["profileImage", "picture"] if isinstance(body, _model_base.Model): - _body = handle_multipart_form_data_model(body) + _body = handle_multipart_form_data_model(body, file_properties) else: _body = body - _files = {k: multipart_file(v) for k, v in _body.items() if has_file(v)} - _data = {k: multipart_data(v) for k, v in _body.items() if not has_file(v)} + _files = {k: multipart_file(v) for k, v in _body.items() if k in file_properties} + _data = {k: multipart_data(v) for k, v in _body.items() if k not in file_properties} _request = build_form_data_multi_binary_parts_request( data=_data, diff --git a/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/operations/_operations.py b/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/operations/_operations.py index 16a47cd6b40..ba300f8f9d4 100644 --- a/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/operations/_operations.py +++ b/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/operations/_operations.py @@ -23,7 +23,7 @@ from .. import _model_base, models as _models from .._serialization import Serializer -from .._vendor import handle_multipart_form_data_model, has_file, multipart_data, multipart_file +from .._vendor import handle_multipart_form_data_model, multipart_data, multipart_file if sys.version_info >= (3, 9): from collections.abc import MutableMapping @@ -174,12 +174,13 @@ def basic( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) + file_properties = ["profileImage"] if isinstance(body, _model_base.Model): - _body = handle_multipart_form_data_model(body) + _body = handle_multipart_form_data_model(body, file_properties) else: _body = body - _files = {k: multipart_file(v) for k, v in _body.items() if has_file(v)} - _data = {k: multipart_data(v) for k, v in _body.items() if not has_file(v)} + _files = {k: multipart_file(v) for k, v in _body.items() if k in file_properties} + _data = {k: multipart_data(v) for k, v in _body.items() if k not in file_properties} _request = build_form_data_basic_request( data=_data, @@ -293,12 +294,13 @@ def complex( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) + file_properties = ["profileImage", "pictures"] if isinstance(body, _model_base.Model): - _body = handle_multipart_form_data_model(body) + _body = handle_multipart_form_data_model(body, file_properties) else: _body = body - _files = {k: multipart_file(v) for k, v in _body.items() if has_file(v)} - _data = {k: multipart_data(v) for k, v in _body.items() if not has_file(v)} + _files = {k: multipart_file(v) for k, v in _body.items() if k in file_properties} + _data = {k: multipart_data(v) for k, v in _body.items() if k not in file_properties} _request = build_form_data_complex_request( data=_data, @@ -394,12 +396,13 @@ def json_part( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) + file_properties = ["profileImage"] if isinstance(body, _model_base.Model): - _body = handle_multipart_form_data_model(body) + _body = handle_multipart_form_data_model(body, file_properties) else: _body = body - _files = {k: multipart_file(v) for k, v in _body.items() if has_file(v)} - _data = {k: multipart_data(v) for k, v in _body.items() if not has_file(v)} + _files = {k: multipart_file(v) for k, v in _body.items() if k in file_properties} + _data = {k: multipart_data(v) for k, v in _body.items() if k not in file_properties} _request = build_form_data_json_part_request( data=_data, @@ -495,12 +498,13 @@ def binary_array_parts( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) + file_properties = ["pictures"] if isinstance(body, _model_base.Model): - _body = handle_multipart_form_data_model(body) + _body = handle_multipart_form_data_model(body, file_properties) else: _body = body - _files = {k: multipart_file(v) for k, v in _body.items() if has_file(v)} - _data = {k: multipart_data(v) for k, v in _body.items() if not has_file(v)} + _files = {k: multipart_file(v) for k, v in _body.items() if k in file_properties} + _data = {k: multipart_data(v) for k, v in _body.items() if k not in file_properties} _request = build_form_data_binary_array_parts_request( data=_data, @@ -600,12 +604,13 @@ def json_array_parts( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) + file_properties = ["profileImage"] if isinstance(body, _model_base.Model): - _body = handle_multipart_form_data_model(body) + _body = handle_multipart_form_data_model(body, file_properties) else: _body = body - _files = {k: multipart_file(v) for k, v in _body.items() if has_file(v)} - _data = {k: multipart_data(v) for k, v in _body.items() if not has_file(v)} + _files = {k: multipart_file(v) for k, v in _body.items() if k in file_properties} + _data = {k: multipart_data(v) for k, v in _body.items() if k not in file_properties} _request = build_form_data_json_array_parts_request( data=_data, @@ -697,12 +702,13 @@ def multi_binary_parts( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) + file_properties = ["profileImage", "picture"] if isinstance(body, _model_base.Model): - _body = handle_multipart_form_data_model(body) + _body = handle_multipart_form_data_model(body, file_properties) else: _body = body - _files = {k: multipart_file(v) for k, v in _body.items() if has_file(v)} - _data = {k: multipart_data(v) for k, v in _body.items() if not has_file(v)} + _files = {k: multipart_file(v) for k, v in _body.items() if k in file_properties} + _data = {k: multipart_data(v) for k, v in _body.items() if k not in file_properties} _request = build_form_data_multi_binary_parts_request( data=_data, From 97932bac230a82206091cf97bf163e68a45182b7 Mon Sep 17 00:00:00 2001 From: msyyc <70930885+msyyc@users.noreply.github.com> Date: Fri, 26 Jan 2024 13:51:06 +0800 Subject: [PATCH 05/45] update --- .../autorest/codegen/models/operation.py | 15 +--- .../codegen/serializers/builder_serializer.py | 8 +- .../codegen/serializers/general_serializer.py | 1 - .../codegen/templates/vendor.py.jinja2 | 43 +++++++---- .../payload/multipart/_vendor.py | 50 ++++++++----- .../multipart/aio/operations/_operations.py | 52 ++----------- .../multipart/operations/_operations.py | 52 ++----------- .../test_payload_multipart_file_array.py | 74 +++++++++---------- .../test/azure/requirements.txt | 2 +- .../test_payload_multipart_async.py | 22 ++++-- .../test_payload_multipart.py | 22 ++++-- .../payload/multipart/_vendor.py | 50 ++++++++----- .../multipart/aio/operations/_operations.py | 52 ++----------- .../multipart/operations/_operations.py | 52 ++----------- 14 files changed, 192 insertions(+), 303 deletions(-) diff --git a/packages/autorest.python/autorest/codegen/models/operation.py b/packages/autorest.python/autorest/codegen/models/operation.py index bb8748a4a9c..9da7b09712f 100644 --- a/packages/autorest.python/autorest/codegen/models/operation.py +++ b/packages/autorest.python/autorest/codegen/models/operation.py @@ -583,22 +583,9 @@ def imports(self, async_mode: bool, **kwargs: Any) -> FileImport: ) file_import.add_import("json", ImportType.STDLIB) else: - file_import.add_submodule_import( - relative_path, "_model_base", ImportType.LOCAL - ) - file_import.add_submodule_import( - f"{relative_path}_vendor", - "multipart_file", - ImportType.LOCAL, - ) - file_import.add_submodule_import( - f"{relative_path}_vendor", - "multipart_data", - ImportType.LOCAL, - ) file_import.add_submodule_import( f"{relative_path}_vendor", - "handle_multipart_form_data_model", + "handle_multipart_form_data_body", ImportType.LOCAL, ) if self.default_error_deserialization or any( diff --git a/packages/autorest.python/autorest/codegen/serializers/builder_serializer.py b/packages/autorest.python/autorest/codegen/serializers/builder_serializer.py index 4df181d302e..3e4d941482e 100644 --- a/packages/autorest.python/autorest/codegen/serializers/builder_serializer.py +++ b/packages/autorest.python/autorest/codegen/serializers/builder_serializer.py @@ -756,12 +756,7 @@ def _serialize_body_parameter(self, builder: OperationType) -> List[str]: if body_param.is_form_data: return [ 'file_properties = ["' + '", "'.join(body_param.file_properties) + '"]', - f"if isinstance({body_param.client_name}, _model_base.Model):", - f" _body = handle_multipart_form_data_model({body_param.client_name}, file_properties)", - "else:", - f" _body = {body_param.client_name}", - "_files = {k: multipart_file(v) for k, v in _body.items() if k in file_properties}", - "_data = {k: multipart_data(v) for k, v in _body.items() if k not in file_properties}", + f"_files = handle_multipart_form_data_body({body_param.client_name}, file_properties)", ] retval: List[str] = [] body_kwarg_name = builder.request_builder.parameters.body_parameter.client_name @@ -978,7 +973,6 @@ def _create_request_builder_call( f"{' # type: ignore' if type_ignore else ''}" ) if request_builder.has_form_data_body: - retval.append(" data=_data,") retval.append(" files=_files,") elif request_builder.overloads: seen_body_params = set() diff --git a/packages/autorest.python/autorest/codegen/serializers/general_serializer.py b/packages/autorest.python/autorest/codegen/serializers/general_serializer.py index ca5fe53df70..2795a3749d6 100644 --- a/packages/autorest.python/autorest/codegen/serializers/general_serializer.py +++ b/packages/autorest.python/autorest/codegen/serializers/general_serializer.py @@ -136,7 +136,6 @@ def serialize_vendor_file(self, clients: List[Client]) -> str: file_import.add_submodule_import("typing", "Union", ImportType.STDLIB) file_import.add_submodule_import("typing", "Any", ImportType.STDLIB) file_import.add_submodule_import("io", "IOBase", ImportType.STDLIB) - file_import.add_submodule_import("io", "BytesIO", ImportType.STDLIB) file_import.add_import("uuid", ImportType.STDLIB) file_import.add_import("json", ImportType.STDLIB) file_import.add_mutable_mapping_import() diff --git a/packages/autorest.python/autorest/codegen/templates/vendor.py.jinja2 b/packages/autorest.python/autorest/codegen/templates/vendor.py.jinja2 index c25a28a3c51..22a6e373b3f 100644 --- a/packages/autorest.python/autorest/codegen/templates/vendor.py.jinja2 +++ b/packages/autorest.python/autorest/codegen/templates/vendor.py.jinja2 @@ -67,38 +67,30 @@ def prep_if_none_match(etag: Optional[str], match_condition: Optional[MatchCondi {% endif %} {% if code_model.has_form_data %} +JSON = MutableMapping[str, Any] # pylint: disable=unsubscriptable-object + # file-like tuple could be `(filename, IO (or bytes))` or `(filename, IO (or bytes), content_type)` FileType = Union[IOBase, bytes] FileTuple = Union[Tuple[str, FileType], Tuple[str, FileType, str]] MultiPartFile = Union[IOBase, bytes, FileTuple] HandledMultiPartFile = Union[IOBase, FileTuple] -class NamedBytesIO(BytesIO): - def __init__(self, name: str, *args, **kwargs): - super().__init__(*args, **kwargs) - self.name = name - -def handle_file(file: Union[IOBase, bytes, FileTuple]) -> HandledMultiPartFile: +def multipart_file(file: MultiPartFile) -> HandledMultiPartFile: if isinstance(file, (IOBase, tuple)): return file - return NamedBytesIO("auto-name-" + str(uuid.uuid4()), file) - -def multipart_file(file: Union[MultiPartFile, List[MultiPartFile]]) -> Union[HandledMultiPartFile, List[HandledMultiPartFile]]: - if isinstance(file, list): - return [handle_file(f) for f in file] - return handle_file(file) + return ("auto-name-" + str(uuid.uuid4()), file) def multipart_data(data: Any) -> Any: if isinstance(data, (list, tuple, dict, Model)): return json.dumps(data, cls=SdkJSONEncoder, exclude_readonly=True) return data -def handle_multipart_form_data_model(body: Model, file_properties: List[str]) -> MutableMapping[str, Any]: # pylint: disable=unsubscriptable-object - """handle first layer of model. +def handle_multipart_form_data_model(body: Model, file_properties: List[str])-> JSON: # pylint: disable=unsubscriptable-object + """handle first layer of model. If its value is bytes or IO, replace it with raw value instead of serialized value. :param body: The model to handle. - :type body: ~payload.multipart._model_base.Model + :type body: ._model_base.Model :param file_properties: The properties of the model that are file type. :type file_properties: list[str] :return: The handled model. @@ -111,4 +103,25 @@ def handle_multipart_form_data_model(body: Model, file_properties: List[str]) -> if attr is not None and rest_name in file_properties: result[rest_name] = getattr(body, attr, None) return result + +def handle_multipart_form_data_body(body: Union[Model, JSON], file_properties: List[str])-> List[Tuple[str, HandledMultiPartFile]]: + """handle multipart form data body. + + :param body: The body to handle. + :type body: ._model_base.Model or dict[str, Any] + :param file_properties: The properties of the model that are file type. + :type file_properties: list[str] + :return: The handled body. + :rtype: list[tuple[str, HandledMultiPartFile]] + """ + _body = handle_multipart_form_data_model(body, file_properties) if isinstance(body, Model) else body + files = [] + for filed_name, value in _body.items(): + if filed_name in file_properties: + if isinstance(value, list): + files.extend([(filed_name, multipart_file(i)) for i in value]) + files.append((filed_name, multipart_file(value))) + else: + files.append((filed_name, multipart_data(value))) + return files {% endif %} diff --git a/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/_vendor.py b/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/_vendor.py index 222a66999ba..df2af9a8793 100644 --- a/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/_vendor.py +++ b/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/_vendor.py @@ -5,7 +5,7 @@ # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from io import BytesIO, IOBase +from io import IOBase import json import sys from typing import Any, List, Tuple, Union @@ -19,6 +19,8 @@ from typing import MutableMapping # type: ignore # pylint: disable=ungrouped-imports +JSON = MutableMapping[str, Any] # pylint: disable=unsubscriptable-object + # file-like tuple could be `(filename, IO (or bytes))` or `(filename, IO (or bytes), content_type)` FileType = Union[IOBase, bytes] FileTuple = Union[Tuple[str, FileType], Tuple[str, FileType, str]] @@ -26,24 +28,10 @@ HandledMultiPartFile = Union[IOBase, FileTuple] -class NamedBytesIO(BytesIO): - def __init__(self, name: str, *args, **kwargs): - super().__init__(*args, **kwargs) - self.name = name - - -def handle_file(file: Union[IOBase, bytes, FileTuple]) -> HandledMultiPartFile: +def multipart_file(file: MultiPartFile) -> HandledMultiPartFile: if isinstance(file, (IOBase, tuple)): return file - return NamedBytesIO("auto-name-" + str(uuid.uuid4()), file) - - -def multipart_file( - file: Union[MultiPartFile, List[MultiPartFile]] -) -> Union[HandledMultiPartFile, List[HandledMultiPartFile]]: - if isinstance(file, list): - return [handle_file(f) for f in file] - return handle_file(file) + return ("auto-name-" + str(uuid.uuid4()), file) def multipart_data(data: Any) -> Any: @@ -54,12 +42,12 @@ def multipart_data(data: Any) -> Any: def handle_multipart_form_data_model( body: Model, file_properties: List[str] -) -> MutableMapping[str, Any]: # pylint: disable=unsubscriptable-object +) -> JSON: # pylint: disable=unsubscriptable-object """handle first layer of model. If its value is bytes or IO, replace it with raw value instead of serialized value. :param body: The model to handle. - :type body: ~payload.multipart._model_base.Model + :type body: ._model_base.Model :param file_properties: The properties of the model that are file type. :type file_properties: list[str] :return: The handled model. @@ -72,3 +60,27 @@ def handle_multipart_form_data_model( if attr is not None and rest_name in file_properties: result[rest_name] = getattr(body, attr, None) return result + + +def handle_multipart_form_data_body( + body: Union[Model, JSON], file_properties: List[str] +) -> List[Tuple[str, HandledMultiPartFile]]: + """handle multipart form data body. + + :param body: The body to handle. + :type body: ._model_base.Model or dict[str, Any] + :param file_properties: The properties of the model that are file type. + :type file_properties: list[str] + :return: The handled body. + :rtype: list[tuple[str, HandledMultiPartFile]] + """ + _body = handle_multipart_form_data_model(body, file_properties) if isinstance(body, Model) else body + files = [] + for filed_name, value in _body.items(): + if filed_name in file_properties: + if isinstance(value, list): + files.extend([(filed_name, multipart_file(i)) for i in value]) + files.append((filed_name, multipart_file(value))) + else: + files.append((filed_name, multipart_data(value))) + return files diff --git a/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/aio/operations/_operations.py b/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/aio/operations/_operations.py index 339aec23362..5745aadfccb 100644 --- a/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/aio/operations/_operations.py +++ b/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/aio/operations/_operations.py @@ -21,8 +21,8 @@ from azure.core.rest import AsyncHttpResponse, HttpRequest from azure.core.tracing.decorator_async import distributed_trace_async -from ... import _model_base, models as _models -from ..._vendor import handle_multipart_form_data_model, multipart_data, multipart_file +from ... import models as _models +from ..._vendor import handle_multipart_form_data_body from ...operations._operations import ( build_form_data_basic_request, build_form_data_binary_array_parts_request, @@ -126,15 +126,9 @@ async def basic( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) file_properties = ["profileImage"] - if isinstance(body, _model_base.Model): - _body = handle_multipart_form_data_model(body, file_properties) - else: - _body = body - _files = {k: multipart_file(v) for k, v in _body.items() if k in file_properties} - _data = {k: multipart_data(v) for k, v in _body.items() if k not in file_properties} + _files = handle_multipart_form_data_body(body, file_properties) _request = build_form_data_basic_request( - data=_data, files=_files, headers=_headers, params=_params, @@ -247,15 +241,9 @@ async def complex( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) file_properties = ["profileImage", "pictures"] - if isinstance(body, _model_base.Model): - _body = handle_multipart_form_data_model(body, file_properties) - else: - _body = body - _files = {k: multipart_file(v) for k, v in _body.items() if k in file_properties} - _data = {k: multipart_data(v) for k, v in _body.items() if k not in file_properties} + _files = handle_multipart_form_data_body(body, file_properties) _request = build_form_data_complex_request( - data=_data, files=_files, headers=_headers, params=_params, @@ -350,15 +338,9 @@ async def json_part( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) file_properties = ["profileImage"] - if isinstance(body, _model_base.Model): - _body = handle_multipart_form_data_model(body, file_properties) - else: - _body = body - _files = {k: multipart_file(v) for k, v in _body.items() if k in file_properties} - _data = {k: multipart_data(v) for k, v in _body.items() if k not in file_properties} + _files = handle_multipart_form_data_body(body, file_properties) _request = build_form_data_json_part_request( - data=_data, files=_files, headers=_headers, params=_params, @@ -455,15 +437,9 @@ async def binary_array_parts( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) file_properties = ["pictures"] - if isinstance(body, _model_base.Model): - _body = handle_multipart_form_data_model(body, file_properties) - else: - _body = body - _files = {k: multipart_file(v) for k, v in _body.items() if k in file_properties} - _data = {k: multipart_data(v) for k, v in _body.items() if k not in file_properties} + _files = handle_multipart_form_data_body(body, file_properties) _request = build_form_data_binary_array_parts_request( - data=_data, files=_files, headers=_headers, params=_params, @@ -564,15 +540,9 @@ async def json_array_parts( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) file_properties = ["profileImage"] - if isinstance(body, _model_base.Model): - _body = handle_multipart_form_data_model(body, file_properties) - else: - _body = body - _files = {k: multipart_file(v) for k, v in _body.items() if k in file_properties} - _data = {k: multipart_data(v) for k, v in _body.items() if k not in file_properties} + _files = handle_multipart_form_data_body(body, file_properties) _request = build_form_data_json_array_parts_request( - data=_data, files=_files, headers=_headers, params=_params, @@ -665,15 +635,9 @@ async def multi_binary_parts( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) file_properties = ["profileImage", "picture"] - if isinstance(body, _model_base.Model): - _body = handle_multipart_form_data_model(body, file_properties) - else: - _body = body - _files = {k: multipart_file(v) for k, v in _body.items() if k in file_properties} - _data = {k: multipart_data(v) for k, v in _body.items() if k not in file_properties} + _files = handle_multipart_form_data_body(body, file_properties) _request = build_form_data_multi_binary_parts_request( - data=_data, files=_files, headers=_headers, params=_params, diff --git a/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/operations/_operations.py b/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/operations/_operations.py index f01895f4fe6..0f5ec7db58e 100644 --- a/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/operations/_operations.py +++ b/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/operations/_operations.py @@ -22,9 +22,9 @@ from azure.core.tracing.decorator import distributed_trace from azure.core.utils import case_insensitive_dict -from .. import _model_base, models as _models +from .. import models as _models from .._serialization import Serializer -from .._vendor import handle_multipart_form_data_model, multipart_data, multipart_file +from .._vendor import handle_multipart_form_data_body if sys.version_info >= (3, 9): from collections.abc import MutableMapping @@ -177,15 +177,9 @@ def basic( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) file_properties = ["profileImage"] - if isinstance(body, _model_base.Model): - _body = handle_multipart_form_data_model(body, file_properties) - else: - _body = body - _files = {k: multipart_file(v) for k, v in _body.items() if k in file_properties} - _data = {k: multipart_data(v) for k, v in _body.items() if k not in file_properties} + _files = handle_multipart_form_data_body(body, file_properties) _request = build_form_data_basic_request( - data=_data, files=_files, headers=_headers, params=_params, @@ -298,15 +292,9 @@ def complex( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) file_properties = ["profileImage", "pictures"] - if isinstance(body, _model_base.Model): - _body = handle_multipart_form_data_model(body, file_properties) - else: - _body = body - _files = {k: multipart_file(v) for k, v in _body.items() if k in file_properties} - _data = {k: multipart_data(v) for k, v in _body.items() if k not in file_properties} + _files = handle_multipart_form_data_body(body, file_properties) _request = build_form_data_complex_request( - data=_data, files=_files, headers=_headers, params=_params, @@ -401,15 +389,9 @@ def json_part( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) file_properties = ["profileImage"] - if isinstance(body, _model_base.Model): - _body = handle_multipart_form_data_model(body, file_properties) - else: - _body = body - _files = {k: multipart_file(v) for k, v in _body.items() if k in file_properties} - _data = {k: multipart_data(v) for k, v in _body.items() if k not in file_properties} + _files = handle_multipart_form_data_body(body, file_properties) _request = build_form_data_json_part_request( - data=_data, files=_files, headers=_headers, params=_params, @@ -504,15 +486,9 @@ def binary_array_parts( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) file_properties = ["pictures"] - if isinstance(body, _model_base.Model): - _body = handle_multipart_form_data_model(body, file_properties) - else: - _body = body - _files = {k: multipart_file(v) for k, v in _body.items() if k in file_properties} - _data = {k: multipart_data(v) for k, v in _body.items() if k not in file_properties} + _files = handle_multipart_form_data_body(body, file_properties) _request = build_form_data_binary_array_parts_request( - data=_data, files=_files, headers=_headers, params=_params, @@ -611,15 +587,9 @@ def json_array_parts( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) file_properties = ["profileImage"] - if isinstance(body, _model_base.Model): - _body = handle_multipart_form_data_model(body, file_properties) - else: - _body = body - _files = {k: multipart_file(v) for k, v in _body.items() if k in file_properties} - _data = {k: multipart_data(v) for k, v in _body.items() if k not in file_properties} + _files = handle_multipart_form_data_body(body, file_properties) _request = build_form_data_json_array_parts_request( - data=_data, files=_files, headers=_headers, params=_params, @@ -710,15 +680,9 @@ def multi_binary_parts( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) file_properties = ["profileImage", "picture"] - if isinstance(body, _model_base.Model): - _body = handle_multipart_form_data_model(body, file_properties) - else: - _body = body - _files = {k: multipart_file(v) for k, v in _body.items() if k in file_properties} - _data = {k: multipart_data(v) for k, v in _body.items() if k not in file_properties} + _files = handle_multipart_form_data_body(body, file_properties) _request = build_form_data_multi_binary_parts_request( - data=_data, files=_files, headers=_headers, params=_params, diff --git a/packages/typespec-python/test/azure/mock_api_tests/test_payload_multipart_file_array.py b/packages/typespec-python/test/azure/mock_api_tests/test_payload_multipart_file_array.py index 934a844b121..35dd233ff88 100644 --- a/packages/typespec-python/test/azure/mock_api_tests/test_payload_multipart_file_array.py +++ b/packages/typespec-python/test/azure/mock_api_tests/test_payload_multipart_file_array.py @@ -19,43 +19,43 @@ def client(): yield client -@pytest.mark.parametrize( - "op_name,model_class,data,file", - [ - ( - "binary_array_parts", - models.BinaryArrayPartsRequest, - {"id": "123"}, - {"pictures": [PNG, PNG]}, - ), - ( - "complex", - models.ComplexPartsRequest, - {"id": "123", "previousAddresses": [models.Address(city="Y"), models.Address(city="Z")], "address": models.Address(city="X")}, - {"pictures": [PNG, PNG], "profileImage": JPG}, - ) - ], -) -def test_multi_part(client: MultiPartClient, op_name, model_class, data, file): - file_bytes = lambda p: open(str(p), "rb").read() - op = getattr(client.form_data, op_name) - # test bytes - body = {k: ([file_bytes(vi) for vi in v] if isinstance(v, list) else file_bytes(v)) for k, v in file.items()} - body.update(data) - op(body) - op(model_class(body)) - - # test io - file_io = lambda p: open(str(p), "rb") - body = {k: ([file_io(vi) for vi in v] if isinstance(v, list) else file_io(v)) for k, v in file.items()} - body.update(data) - op(body) - - body = {k: ([file_io(vi) for vi in v] if isinstance(v, list) else file_io(v)) for k, v in file.items()} - body.update(data) - with pytest.raises(TypeError): - # caused by deepcopy when DPG model init - op(model_class(body)) +# @pytest.mark.parametrize( +# "op_name,model_class,data,file", +# [ +# ( +# "binary_array_parts", +# models.BinaryArrayPartsRequest, +# {"id": "123"}, +# {"pictures": [PNG, PNG]}, +# ), +# ( +# "complex", +# models.ComplexPartsRequest, +# {"id": "123", "previousAddresses": [models.Address(city="Y"), models.Address(city="Z")], "address": models.Address(city="X")}, +# {"pictures": [PNG, PNG], "profileImage": JPG}, +# ) +# ], +# ) +# def test_multi_part(client: MultiPartClient, op_name, model_class, data, file): +# file_bytes = lambda p: open(str(p), "rb").read() +# op = getattr(client.form_data, op_name) +# # test bytes +# body = {k: ([file_bytes(vi) for vi in v] if isinstance(v, list) else file_bytes(v)) for k, v in file.items()} +# body.update(data) +# op(body) +# op(model_class(body)) + +# # test io +# file_io = lambda p: open(str(p), "rb") +# body = {k: ([file_io(vi) for vi in v] if isinstance(v, list) else file_io(v)) for k, v in file.items()} +# body.update(data) +# op(body) + +# body = {k: ([file_io(vi) for vi in v] if isinstance(v, list) else file_io(v)) for k, v in file.items()} +# body.update(data) +# with pytest.raises(TypeError): +# # caused by deepcopy when DPG model init +# op(model_class(body)) # def test_sample_single_file(client: MultiPartClient): # # Python SDK support several kinds of file format for multipart/form-data and users can choose any of them diff --git a/packages/typespec-python/test/azure/requirements.txt b/packages/typespec-python/test/azure/requirements.txt index 3dee22f5bf9..30daf52fb5d 100644 --- a/packages/typespec-python/test/azure/requirements.txt +++ b/packages/typespec-python/test/azure/requirements.txt @@ -2,7 +2,7 @@ aiohttp;python_full_version>="3.5.2" requests==2.31.0 pytest pytest-asyncio==0.14.0;python_full_version>="3.5.2" -git+https://github.com/Azure/azure-sdk-for-python@multipart-files-array-dev11#subdirectory=sdk/core/azure-core +git+https://github.com/iscai-msft/azure-sdk-for-python@multipartSameFileName#subdirectory=sdk/core/azure-core # only for azure -e ./generated/azure-mgmt-spheredpg -e ./generated/azure-mgmt-spheremsrest diff --git a/packages/typespec-python/test/generic_mock_api_tests/asynctests/test_payload_multipart_async.py b/packages/typespec-python/test/generic_mock_api_tests/asynctests/test_payload_multipart_async.py index ea13afb3288..53d664cdd5e 100644 --- a/packages/typespec-python/test/generic_mock_api_tests/asynctests/test_payload_multipart_async.py +++ b/packages/typespec-python/test/generic_mock_api_tests/asynctests/test_payload_multipart_async.py @@ -3,6 +3,7 @@ # Licensed under the MIT License. See License.txt in the project root for # license information. # -------------------------------------------------------------------------- +import uuid from typing import Dict, Any from pathlib import Path import pytest @@ -22,49 +23,56 @@ async def client(): @pytest.mark.asyncio @pytest.mark.parametrize( - "op_name,model_class,data,file", + "op_name,model_class,data,file,file_info", [ - ("basic", models.MultiPartRequest, {"id": "123"}, {"profileImage": JPG}), + ("basic", models.MultiPartRequest, {"id": "123"}, {"profileImage": JPG}, {}), ( "multi_binary_parts", models.MultiBinaryPartsRequest, {}, {"profileImage": JPG, "picture": PNG}, + {} ), ( "multi_binary_parts", models.MultiBinaryPartsRequest, {}, {"profileImage": JPG}, + {} ), ( "json_part", models.JsonPartRequest, {"address": models.Address(city="X")}, {"profileImage": JPG}, + {} ), ( "json_array_parts", models.JsonArrayPartsRequest, {"previousAddresses": [models.Address(city="Y"), models.Address(city="Z")]}, {"profileImage": JPG}, + {} ), ], ) -async def test_multi_part(client: MultiPartClient, op_name, model_class, data, file): +async def test_multi_part(client: MultiPartClient, op_name, model_class, data, file, file_info): + def add_info(file_content): + name = str(uuid.uuid4()) if file_info.get("file_name") is None else file_info.get("file_name") + content_type = "application/octet-stream" if file_info.get("content_type") is None else file_info.get("content_type") + return (name, file_content, content_type) op = getattr(client.form_data, op_name) # test bytes - body = {k: open(str(v), "rb").read() for k, v in file.items()} + body = {k: add_info(open(str(v), "rb").read()) for k, v in file.items()} body.update(data) await op(body) - await op(model_class(body)) # test io - body = {k: open(str(v), "rb") for k, v in file.items()} + body = {k: add_info(open(str(v), "rb")) for k, v in file.items()} body.update(data) await op(body) - body = {k: open(str(v), "rb") for k, v in file.items()} + body = {k: add_info(open(str(v), "rb")) for k, v in file.items()} body.update(data) with pytest.raises(TypeError): # caused by deepcopy when DPG model init diff --git a/packages/typespec-python/test/generic_mock_api_tests/test_payload_multipart.py b/packages/typespec-python/test/generic_mock_api_tests/test_payload_multipart.py index 3219a91a218..e3b0efbccbf 100644 --- a/packages/typespec-python/test/generic_mock_api_tests/test_payload_multipart.py +++ b/packages/typespec-python/test/generic_mock_api_tests/test_payload_multipart.py @@ -3,6 +3,7 @@ # Licensed under the MIT License. See License.txt in the project root for # license information. # -------------------------------------------------------------------------- +import uuid from typing import Dict, Any from pathlib import Path import pytest @@ -20,49 +21,56 @@ def client(): @pytest.mark.parametrize( - "op_name,model_class,data,file", + "op_name,model_class,data,file,file_info", [ - ("basic", models.MultiPartRequest, {"id": "123"}, {"profileImage": JPG}), + ("basic", models.MultiPartRequest, {"id": "123"}, {"profileImage": JPG}, {}), ( "multi_binary_parts", models.MultiBinaryPartsRequest, {}, {"profileImage": JPG, "picture": PNG}, + {} ), ( "multi_binary_parts", models.MultiBinaryPartsRequest, {}, {"profileImage": JPG}, + {} ), ( "json_part", models.JsonPartRequest, {"address": models.Address(city="X")}, {"profileImage": JPG}, + {} ), ( "json_array_parts", models.JsonArrayPartsRequest, {"previousAddresses": [models.Address(city="Y"), models.Address(city="Z")]}, {"profileImage": JPG}, + {} ), ], ) -def test_multi_part(client: MultiPartClient, op_name, model_class, data, file): +def test_multi_part(client: MultiPartClient, op_name, model_class, data, file, file_info): + def add_info(file_content): + name = str(uuid.uuid4()) if file_info.get("file_name") is None else file_info.get("file_name") + content_type = "application/octet-stream" if file_info.get("content_type") is None else file_info.get("content_type") + return (name, file_content, content_type) op = getattr(client.form_data, op_name) # test bytes - body = {k: open(str(v), "rb").read() for k, v in file.items()} + body = {k: add_info(open(str(v), "rb").read()) for k, v in file.items()} body.update(data) op(body) - op(model_class(body)) # test io - body = {k: open(str(v), "rb") for k, v in file.items()} + body = {k: add_info(open(str(v), "rb")) for k, v in file.items()} body.update(data) op(body) - body = {k: open(str(v), "rb") for k, v in file.items()} + body = {k: add_info(open(str(v), "rb")) for k, v in file.items()} body.update(data) with pytest.raises(TypeError): # caused by deepcopy when DPG model init diff --git a/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/_vendor.py b/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/_vendor.py index 4931a6de0f9..1ab8b4172fd 100644 --- a/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/_vendor.py +++ b/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/_vendor.py @@ -5,7 +5,7 @@ # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from io import BytesIO, IOBase +from io import IOBase import json import sys from typing import Any, List, Tuple, Union @@ -19,6 +19,8 @@ from typing import MutableMapping # type: ignore # pylint: disable=ungrouped-imports +JSON = MutableMapping[str, Any] # pylint: disable=unsubscriptable-object + # file-like tuple could be `(filename, IO (or bytes))` or `(filename, IO (or bytes), content_type)` FileType = Union[IOBase, bytes] FileTuple = Union[Tuple[str, FileType], Tuple[str, FileType, str]] @@ -26,24 +28,10 @@ HandledMultiPartFile = Union[IOBase, FileTuple] -class NamedBytesIO(BytesIO): - def __init__(self, name: str, *args, **kwargs): - super().__init__(*args, **kwargs) - self.name = name - - -def handle_file(file: Union[IOBase, bytes, FileTuple]) -> HandledMultiPartFile: +def multipart_file(file: MultiPartFile) -> HandledMultiPartFile: if isinstance(file, (IOBase, tuple)): return file - return NamedBytesIO("auto-name-" + str(uuid.uuid4()), file) - - -def multipart_file( - file: Union[MultiPartFile, List[MultiPartFile]] -) -> Union[HandledMultiPartFile, List[HandledMultiPartFile]]: - if isinstance(file, list): - return [handle_file(f) for f in file] - return handle_file(file) + return ("auto-name-" + str(uuid.uuid4()), file) def multipart_data(data: Any) -> Any: @@ -54,12 +42,12 @@ def multipart_data(data: Any) -> Any: def handle_multipart_form_data_model( body: Model, file_properties: List[str] -) -> MutableMapping[str, Any]: # pylint: disable=unsubscriptable-object +) -> JSON: # pylint: disable=unsubscriptable-object """handle first layer of model. If its value is bytes or IO, replace it with raw value instead of serialized value. :param body: The model to handle. - :type body: ~payload.multipart._model_base.Model + :type body: ._model_base.Model :param file_properties: The properties of the model that are file type. :type file_properties: list[str] :return: The handled model. @@ -72,3 +60,27 @@ def handle_multipart_form_data_model( if attr is not None and rest_name in file_properties: result[rest_name] = getattr(body, attr, None) return result + + +def handle_multipart_form_data_body( + body: Union[Model, JSON], file_properties: List[str] +) -> List[Tuple[str, HandledMultiPartFile]]: + """handle multipart form data body. + + :param body: The body to handle. + :type body: ._model_base.Model or dict[str, Any] + :param file_properties: The properties of the model that are file type. + :type file_properties: list[str] + :return: The handled body. + :rtype: list[tuple[str, HandledMultiPartFile]] + """ + _body = handle_multipart_form_data_model(body, file_properties) if isinstance(body, Model) else body + files = [] + for filed_name, value in _body.items(): + if filed_name in file_properties: + if isinstance(value, list): + files.extend([(filed_name, multipart_file(i)) for i in value]) + files.append((filed_name, multipart_file(value))) + else: + files.append((filed_name, multipart_data(value))) + return files diff --git a/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/aio/operations/_operations.py b/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/aio/operations/_operations.py index 993837aa7e5..103aa3b7892 100644 --- a/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/aio/operations/_operations.py +++ b/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/aio/operations/_operations.py @@ -20,8 +20,8 @@ from corehttp.rest import AsyncHttpResponse, HttpRequest from corehttp.runtime.pipeline import PipelineResponse -from ... import _model_base, models as _models -from ..._vendor import handle_multipart_form_data_model, multipart_data, multipart_file +from ... import models as _models +from ..._vendor import handle_multipart_form_data_body from ...operations._operations import ( build_form_data_basic_request, build_form_data_binary_array_parts_request, @@ -124,15 +124,9 @@ async def basic( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) file_properties = ["profileImage"] - if isinstance(body, _model_base.Model): - _body = handle_multipart_form_data_model(body, file_properties) - else: - _body = body - _files = {k: multipart_file(v) for k, v in _body.items() if k in file_properties} - _data = {k: multipart_data(v) for k, v in _body.items() if k not in file_properties} + _files = handle_multipart_form_data_body(body, file_properties) _request = build_form_data_basic_request( - data=_data, files=_files, headers=_headers, params=_params, @@ -244,15 +238,9 @@ async def complex( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) file_properties = ["profileImage", "pictures"] - if isinstance(body, _model_base.Model): - _body = handle_multipart_form_data_model(body, file_properties) - else: - _body = body - _files = {k: multipart_file(v) for k, v in _body.items() if k in file_properties} - _data = {k: multipart_data(v) for k, v in _body.items() if k not in file_properties} + _files = handle_multipart_form_data_body(body, file_properties) _request = build_form_data_complex_request( - data=_data, files=_files, headers=_headers, params=_params, @@ -346,15 +334,9 @@ async def json_part( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) file_properties = ["profileImage"] - if isinstance(body, _model_base.Model): - _body = handle_multipart_form_data_model(body, file_properties) - else: - _body = body - _files = {k: multipart_file(v) for k, v in _body.items() if k in file_properties} - _data = {k: multipart_data(v) for k, v in _body.items() if k not in file_properties} + _files = handle_multipart_form_data_body(body, file_properties) _request = build_form_data_json_part_request( - data=_data, files=_files, headers=_headers, params=_params, @@ -450,15 +432,9 @@ async def binary_array_parts( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) file_properties = ["pictures"] - if isinstance(body, _model_base.Model): - _body = handle_multipart_form_data_model(body, file_properties) - else: - _body = body - _files = {k: multipart_file(v) for k, v in _body.items() if k in file_properties} - _data = {k: multipart_data(v) for k, v in _body.items() if k not in file_properties} + _files = handle_multipart_form_data_body(body, file_properties) _request = build_form_data_binary_array_parts_request( - data=_data, files=_files, headers=_headers, params=_params, @@ -558,15 +534,9 @@ async def json_array_parts( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) file_properties = ["profileImage"] - if isinstance(body, _model_base.Model): - _body = handle_multipart_form_data_model(body, file_properties) - else: - _body = body - _files = {k: multipart_file(v) for k, v in _body.items() if k in file_properties} - _data = {k: multipart_data(v) for k, v in _body.items() if k not in file_properties} + _files = handle_multipart_form_data_body(body, file_properties) _request = build_form_data_json_array_parts_request( - data=_data, files=_files, headers=_headers, params=_params, @@ -658,15 +628,9 @@ async def multi_binary_parts( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) file_properties = ["profileImage", "picture"] - if isinstance(body, _model_base.Model): - _body = handle_multipart_form_data_model(body, file_properties) - else: - _body = body - _files = {k: multipart_file(v) for k, v in _body.items() if k in file_properties} - _data = {k: multipart_data(v) for k, v in _body.items() if k not in file_properties} + _files = handle_multipart_form_data_body(body, file_properties) _request = build_form_data_multi_binary_parts_request( - data=_data, files=_files, headers=_headers, params=_params, diff --git a/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/operations/_operations.py b/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/operations/_operations.py index ba300f8f9d4..546fe0e0d8b 100644 --- a/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/operations/_operations.py +++ b/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/operations/_operations.py @@ -21,9 +21,9 @@ from corehttp.runtime.pipeline import PipelineResponse from corehttp.utils import case_insensitive_dict -from .. import _model_base, models as _models +from .. import models as _models from .._serialization import Serializer -from .._vendor import handle_multipart_form_data_model, multipart_data, multipart_file +from .._vendor import handle_multipart_form_data_body if sys.version_info >= (3, 9): from collections.abc import MutableMapping @@ -175,15 +175,9 @@ def basic( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) file_properties = ["profileImage"] - if isinstance(body, _model_base.Model): - _body = handle_multipart_form_data_model(body, file_properties) - else: - _body = body - _files = {k: multipart_file(v) for k, v in _body.items() if k in file_properties} - _data = {k: multipart_data(v) for k, v in _body.items() if k not in file_properties} + _files = handle_multipart_form_data_body(body, file_properties) _request = build_form_data_basic_request( - data=_data, files=_files, headers=_headers, params=_params, @@ -295,15 +289,9 @@ def complex( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) file_properties = ["profileImage", "pictures"] - if isinstance(body, _model_base.Model): - _body = handle_multipart_form_data_model(body, file_properties) - else: - _body = body - _files = {k: multipart_file(v) for k, v in _body.items() if k in file_properties} - _data = {k: multipart_data(v) for k, v in _body.items() if k not in file_properties} + _files = handle_multipart_form_data_body(body, file_properties) _request = build_form_data_complex_request( - data=_data, files=_files, headers=_headers, params=_params, @@ -397,15 +385,9 @@ def json_part( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) file_properties = ["profileImage"] - if isinstance(body, _model_base.Model): - _body = handle_multipart_form_data_model(body, file_properties) - else: - _body = body - _files = {k: multipart_file(v) for k, v in _body.items() if k in file_properties} - _data = {k: multipart_data(v) for k, v in _body.items() if k not in file_properties} + _files = handle_multipart_form_data_body(body, file_properties) _request = build_form_data_json_part_request( - data=_data, files=_files, headers=_headers, params=_params, @@ -499,15 +481,9 @@ def binary_array_parts( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) file_properties = ["pictures"] - if isinstance(body, _model_base.Model): - _body = handle_multipart_form_data_model(body, file_properties) - else: - _body = body - _files = {k: multipart_file(v) for k, v in _body.items() if k in file_properties} - _data = {k: multipart_data(v) for k, v in _body.items() if k not in file_properties} + _files = handle_multipart_form_data_body(body, file_properties) _request = build_form_data_binary_array_parts_request( - data=_data, files=_files, headers=_headers, params=_params, @@ -605,15 +581,9 @@ def json_array_parts( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) file_properties = ["profileImage"] - if isinstance(body, _model_base.Model): - _body = handle_multipart_form_data_model(body, file_properties) - else: - _body = body - _files = {k: multipart_file(v) for k, v in _body.items() if k in file_properties} - _data = {k: multipart_data(v) for k, v in _body.items() if k not in file_properties} + _files = handle_multipart_form_data_body(body, file_properties) _request = build_form_data_json_array_parts_request( - data=_data, files=_files, headers=_headers, params=_params, @@ -703,15 +673,9 @@ def multi_binary_parts( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) file_properties = ["profileImage", "picture"] - if isinstance(body, _model_base.Model): - _body = handle_multipart_form_data_model(body, file_properties) - else: - _body = body - _files = {k: multipart_file(v) for k, v in _body.items() if k in file_properties} - _data = {k: multipart_data(v) for k, v in _body.items() if k not in file_properties} + _files = handle_multipart_form_data_body(body, file_properties) _request = build_form_data_multi_binary_parts_request( - data=_data, files=_files, headers=_headers, params=_params, From ca46a17652196fafedad9728033f3bc50463b5f0 Mon Sep 17 00:00:00 2001 From: msyyc <70930885+msyyc@users.noreply.github.com> Date: Fri, 26 Jan 2024 13:54:53 +0800 Subject: [PATCH 06/45] fix cspell --- .../autorest/codegen/templates/vendor.py.jinja2 | 10 +++++----- .../payload-multipart/payload/multipart/_vendor.py | 10 +++++----- .../payload-multipart/payload/multipart/_vendor.py | 10 +++++----- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/packages/autorest.python/autorest/codegen/templates/vendor.py.jinja2 b/packages/autorest.python/autorest/codegen/templates/vendor.py.jinja2 index 22a6e373b3f..4c1ec06b806 100644 --- a/packages/autorest.python/autorest/codegen/templates/vendor.py.jinja2 +++ b/packages/autorest.python/autorest/codegen/templates/vendor.py.jinja2 @@ -116,12 +116,12 @@ def handle_multipart_form_data_body(body: Union[Model, JSON], file_properties: L """ _body = handle_multipart_form_data_model(body, file_properties) if isinstance(body, Model) else body files = [] - for filed_name, value in _body.items(): - if filed_name in file_properties: + for field_name, value in _body.items(): + if field_name in file_properties: if isinstance(value, list): - files.extend([(filed_name, multipart_file(i)) for i in value]) - files.append((filed_name, multipart_file(value))) + files.extend([(field_name, multipart_file(i)) for i in value]) + files.append((field_name, multipart_file(value))) else: - files.append((filed_name, multipart_data(value))) + files.append((field_name, multipart_data(value))) return files {% endif %} diff --git a/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/_vendor.py b/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/_vendor.py index df2af9a8793..cabee5f19ad 100644 --- a/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/_vendor.py +++ b/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/_vendor.py @@ -76,11 +76,11 @@ def handle_multipart_form_data_body( """ _body = handle_multipart_form_data_model(body, file_properties) if isinstance(body, Model) else body files = [] - for filed_name, value in _body.items(): - if filed_name in file_properties: + for field_name, value in _body.items(): + if field_name in file_properties: if isinstance(value, list): - files.extend([(filed_name, multipart_file(i)) for i in value]) - files.append((filed_name, multipart_file(value))) + files.extend([(field_name, multipart_file(i)) for i in value]) + files.append((field_name, multipart_file(value))) else: - files.append((filed_name, multipart_data(value))) + files.append((field_name, multipart_data(value))) return files diff --git a/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/_vendor.py b/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/_vendor.py index 1ab8b4172fd..fd65fc03ac6 100644 --- a/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/_vendor.py +++ b/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/_vendor.py @@ -76,11 +76,11 @@ def handle_multipart_form_data_body( """ _body = handle_multipart_form_data_model(body, file_properties) if isinstance(body, Model) else body files = [] - for filed_name, value in _body.items(): - if filed_name in file_properties: + for field_name, value in _body.items(): + if field_name in file_properties: if isinstance(value, list): - files.extend([(filed_name, multipart_file(i)) for i in value]) - files.append((filed_name, multipart_file(value))) + files.extend([(field_name, multipart_file(i)) for i in value]) + files.append((field_name, multipart_file(value))) else: - files.append((filed_name, multipart_data(value))) + files.append((field_name, multipart_data(value))) return files From fba4a91651b5cce6c8926b6170abd135e790a450 Mon Sep 17 00:00:00 2001 From: msyyc <70930885+msyyc@users.noreply.github.com> Date: Mon, 29 Jan 2024 14:24:15 +0800 Subject: [PATCH 07/45] update test --- .../codegen/templates/vendor.py.jinja2 | 3 +- .../payload/multipart/_vendor.py | 3 +- .../test_payload_multipart_async.py | 96 ++++++++++++ .../mock_api_tests/test_payload_multipart.py | 139 ++++++++++++++++++ .../test_payload_multipart_file_array.py | 104 ------------- .../payload/multipart/_vendor.py | 3 +- 6 files changed, 241 insertions(+), 107 deletions(-) create mode 100644 packages/typespec-python/test/azure/mock_api_tests/asynctests/test_payload_multipart_async.py create mode 100644 packages/typespec-python/test/azure/mock_api_tests/test_payload_multipart.py delete mode 100644 packages/typespec-python/test/azure/mock_api_tests/test_payload_multipart_file_array.py diff --git a/packages/autorest.python/autorest/codegen/templates/vendor.py.jinja2 b/packages/autorest.python/autorest/codegen/templates/vendor.py.jinja2 index 4c1ec06b806..8337d15ac30 100644 --- a/packages/autorest.python/autorest/codegen/templates/vendor.py.jinja2 +++ b/packages/autorest.python/autorest/codegen/templates/vendor.py.jinja2 @@ -120,7 +120,8 @@ def handle_multipart_form_data_body(body: Union[Model, JSON], file_properties: L if field_name in file_properties: if isinstance(value, list): files.extend([(field_name, multipart_file(i)) for i in value]) - files.append((field_name, multipart_file(value))) + else: + files.append((field_name, multipart_file(value))) else: files.append((field_name, multipart_data(value))) return files diff --git a/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/_vendor.py b/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/_vendor.py index cabee5f19ad..6aa7bf1f7b5 100644 --- a/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/_vendor.py +++ b/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/_vendor.py @@ -80,7 +80,8 @@ def handle_multipart_form_data_body( if field_name in file_properties: if isinstance(value, list): files.extend([(field_name, multipart_file(i)) for i in value]) - files.append((field_name, multipart_file(value))) + else: + files.append((field_name, multipart_file(value))) else: files.append((field_name, multipart_data(value))) return files diff --git a/packages/typespec-python/test/azure/mock_api_tests/asynctests/test_payload_multipart_async.py b/packages/typespec-python/test/azure/mock_api_tests/asynctests/test_payload_multipart_async.py new file mode 100644 index 00000000000..f7f84666b03 --- /dev/null +++ b/packages/typespec-python/test/azure/mock_api_tests/asynctests/test_payload_multipart_async.py @@ -0,0 +1,96 @@ +# ------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for +# license information. +# -------------------------------------------------------------------------- +import uuid +from typing import Dict, Any +from pathlib import Path +import pytest +from payload.multipart.aio import MultiPartClient +from payload.multipart import models +from payload.multipart._model_base import Model + +JPG = Path(__file__).parent.parent.parent.parent / "generic_mock_api_tests/data/image.jpg" +PNG = Path(__file__).parent.parent.parent.parent / "generic_mock_api_tests/data/image.png" + + +@pytest.fixture +async def client(): + async with MultiPartClient(endpoint="http://localhost:3000") as client: + yield client + + +@pytest.mark.asyncio +@pytest.mark.parametrize( + "op_name,model_class,data,file,file_info", + [ + ("basic", models.MultiPartRequest, {"id": "123"}, {"profileImage": JPG}, {}), + ( + "multi_binary_parts", + models.MultiBinaryPartsRequest, + {}, + {"profileImage": JPG, "picture": PNG}, + {} + ), + ( + "multi_binary_parts", + models.MultiBinaryPartsRequest, + {}, + {"profileImage": JPG}, + {} + ), + ( + "json_part", + models.JsonPartRequest, + {"address": models.Address(city="X")}, + {"profileImage": JPG}, + {}, + ), + ( + "json_array_parts", + models.JsonArrayPartsRequest, + {"previousAddresses": [models.Address(city="Y"), models.Address(city="Z")]}, + {"profileImage": JPG}, + {}, + ), + ( + "binary_array_parts", + models.BinaryArrayPartsRequest, + {"id": "123"}, + {"pictures": [PNG, PNG]}, + {}, + ), + ( + "complex", + models.ComplexPartsRequest, + {"id": "123", "previousAddresses": [models.Address(city="Y"), models.Address(city="Z")], "address": models.Address(city="X")}, + {"pictures": [PNG, PNG], "profileImage": JPG}, + {}, + ), + ], +) +async def test_multi_part(client: MultiPartClient, op_name, model_class, data, file, file_info): + def add_info(file_path, is_bytes): + file_content = open(str(file_path), "rb").read() if is_bytes else open(str(file_path), "rb") + name = str(uuid.uuid4()) if file_info.get("file_name") is None else file_info.get("file_name") + content_type = "application/octet-stream" if file_info.get("content_type") is None else file_info.get("content_type") + return (name, file_content, content_type) + def convert(is_bytes=False): + files_part = {k: ([add_info(vi, is_bytes) for vi in v] if isinstance(v, list) else add_info(v, is_bytes)) for k, v in file.items()} + files_part.update(data) + return files_part + op = getattr(client.form_data, op_name) + # test bytes (raw dict) + body = convert(True) + await op(body) + + # test io (raw dict) + body = convert() + await op(body) + + # test io (model) + body = convert() + with pytest.raises(TypeError): + # caused by deepcopy when DPG model init + await op(model_class(body)) diff --git a/packages/typespec-python/test/azure/mock_api_tests/test_payload_multipart.py b/packages/typespec-python/test/azure/mock_api_tests/test_payload_multipart.py new file mode 100644 index 00000000000..b64b187b69a --- /dev/null +++ b/packages/typespec-python/test/azure/mock_api_tests/test_payload_multipart.py @@ -0,0 +1,139 @@ +# ------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for +# license information. +# -------------------------------------------------------------------------- +import uuid +from typing import Dict, Any +from pathlib import Path +import pytest +from payload.multipart import MultiPartClient, models +from payload.multipart._model_base import Model + +JPG = Path(__file__).parent.parent.parent / "generic_mock_api_tests/data/image.jpg" +PNG = Path(__file__).parent.parent.parent / "generic_mock_api_tests/data/image.png" + + +@pytest.fixture +def client(): + with MultiPartClient(endpoint="http://localhost:3000") as client: + yield client + + +@pytest.mark.parametrize( + "op_name,model_class,data,file,file_info", + [ + ("basic", models.MultiPartRequest, {"id": "123"}, {"profileImage": JPG}, {}), + ( + "multi_binary_parts", + models.MultiBinaryPartsRequest, + {}, + {"profileImage": JPG, "picture": PNG}, + {} + ), + ( + "multi_binary_parts", + models.MultiBinaryPartsRequest, + {}, + {"profileImage": JPG}, + {} + ), + ( + "json_part", + models.JsonPartRequest, + {"address": models.Address(city="X")}, + {"profileImage": JPG}, + {}, + ), + ( + "json_array_parts", + models.JsonArrayPartsRequest, + {"previousAddresses": [models.Address(city="Y"), models.Address(city="Z")]}, + {"profileImage": JPG}, + {}, + ), + ( + "binary_array_parts", + models.BinaryArrayPartsRequest, + {"id": "123"}, + {"pictures": [PNG, PNG]}, + {}, + ), + ( + "complex", + models.ComplexPartsRequest, + {"id": "123", "previousAddresses": [models.Address(city="Y"), models.Address(city="Z")], "address": models.Address(city="X")}, + {"pictures": [PNG, PNG], "profileImage": JPG}, + {}, + ), + ], +) +def test_multi_part(client: MultiPartClient, op_name, model_class, data, file, file_info): + def add_info(file_path, is_bytes): + file_content = open(str(file_path), "rb").read() if is_bytes else open(str(file_path), "rb") + name = str(uuid.uuid4()) if file_info.get("file_name") is None else file_info.get("file_name") + content_type = "application/octet-stream" if file_info.get("content_type") is None else file_info.get("content_type") + return (name, file_content, content_type) + def convert(is_bytes=False): + files_part = {k: ([add_info(vi, is_bytes) for vi in v] if isinstance(v, list) else add_info(v, is_bytes)) for k, v in file.items()} + files_part.update(data) + return files_part + op = getattr(client.form_data, op_name) + # test bytes (raw dict) + body = convert(True) + op(body) + + # test io (raw dict) + body = convert() + op(body) + + # test io (model) + body = convert() + with pytest.raises(TypeError): + # caused by deepcopy when DPG model init + op(model_class(body)) + +def _test_sample_single_file(client: MultiPartClient): + # Python SDK support several kinds of file format for multipart/form-data and users can choose any of them + # 1. bytes + client.form_data.basic({"id": "123", "profileImage": open(str(PNG), "rb").read()}) + + # 2. file io + client.form_data.basic({"id": "123", "profileImage": open(str(PNG), "rb")}) + + # 3. file tuple (only set file name) + client.form_data.basic({"id": "123", "profileImage": ("my_image.jpg", open(str(JPG), "rb"))}) + # or + client.form_data.basic({"id": "123", "profileImage": ("my_image.jpg", open(str(JPG), "rb").read())}) + + # 4. file tuple (set file name and content type) + client.form_data.basic({"id": "123", "profileImage": ("my_image.jpg", open(str(JPG), "rb"), "image/jpeg")}) + # or + client.form_data.basic({"id": "123", "profileImage": ("my_image.jpg", open(str(JPG), "rb").read(), "image/jpeg")}) + +def _test_sample_array_file(client: MultiPartClient): + # If users want to upload array files for same field name, they can use list, and users can + # choose any of the above file format for each file. e.g. + + # List[bytes, io] + client.form_data.binary_array_parts({"id": "123", "pictures": [open(str(PNG), "rb").read(), open(str(PNG), "rb")]}) + + # List[bytes, tuple] + client.form_data.binary_array_parts({ + "id": "123", + "pictures": [open(str(PNG), "rb").read(), ("my_image.png", open(str(PNG), "rb"))] + }) + # or + client.form_data.binary_array_parts({ + "id": "123", + "pictures": [open(str(PNG), "rb").read(), ("my_image.png", open(str(PNG), "rb"), "image/png")] + }) + # List[io, bytes] + client.form_data.binary_array_parts({"id": "123", "pictures": [open(str(PNG), "rb"), open(str(PNG), "rb").read()]}) + + # List[tuple, tuple] + client.form_data.binary_array_parts({ + "id": "123", + "pictures": [("my_image1.png", open(str(PNG), "rb"), "image/png"), ("my_image2.png", open(str(PNG), "rb"), "image/png")] + }) + # ... diff --git a/packages/typespec-python/test/azure/mock_api_tests/test_payload_multipart_file_array.py b/packages/typespec-python/test/azure/mock_api_tests/test_payload_multipart_file_array.py deleted file mode 100644 index 35dd233ff88..00000000000 --- a/packages/typespec-python/test/azure/mock_api_tests/test_payload_multipart_file_array.py +++ /dev/null @@ -1,104 +0,0 @@ -# ------------------------------------------------------------------------- -# Copyright (c) Microsoft Corporation. All rights reserved. -# Licensed under the MIT License. See License.txt in the project root for -# license information. -# -------------------------------------------------------------------------- -from typing import Dict, Any -from pathlib import Path -import pytest -from payload.multipart import MultiPartClient, models -from payload.multipart._model_base import Model - -JPG = Path(__file__).parent.parent.parent / "generic_mock_api_tests/data/image.jpg" -PNG = Path(__file__).parent.parent.parent / "generic_mock_api_tests/data/image.png" - - -@pytest.fixture -def client(): - with MultiPartClient(endpoint="http://localhost:3000") as client: - yield client - - -# @pytest.mark.parametrize( -# "op_name,model_class,data,file", -# [ -# ( -# "binary_array_parts", -# models.BinaryArrayPartsRequest, -# {"id": "123"}, -# {"pictures": [PNG, PNG]}, -# ), -# ( -# "complex", -# models.ComplexPartsRequest, -# {"id": "123", "previousAddresses": [models.Address(city="Y"), models.Address(city="Z")], "address": models.Address(city="X")}, -# {"pictures": [PNG, PNG], "profileImage": JPG}, -# ) -# ], -# ) -# def test_multi_part(client: MultiPartClient, op_name, model_class, data, file): -# file_bytes = lambda p: open(str(p), "rb").read() -# op = getattr(client.form_data, op_name) -# # test bytes -# body = {k: ([file_bytes(vi) for vi in v] if isinstance(v, list) else file_bytes(v)) for k, v in file.items()} -# body.update(data) -# op(body) -# op(model_class(body)) - -# # test io -# file_io = lambda p: open(str(p), "rb") -# body = {k: ([file_io(vi) for vi in v] if isinstance(v, list) else file_io(v)) for k, v in file.items()} -# body.update(data) -# op(body) - -# body = {k: ([file_io(vi) for vi in v] if isinstance(v, list) else file_io(v)) for k, v in file.items()} -# body.update(data) -# with pytest.raises(TypeError): -# # caused by deepcopy when DPG model init -# op(model_class(body)) - -# def test_sample_single_file(client: MultiPartClient): -# # Python SDK support several kinds of file format for multipart/form-data and users can choose any of them - -# # 1. bytes -# client.form_data.basic(models.MultiPartRequest(id="123", profile_image=open(str(JPG), "rb").read())) - -# # 2. file io -# client.form_data.basic({"id": "123", "profileImage": open(str(JPG), "rb")}) - -# # 3. file tuple (only set file name) -# client.form_data.basic({"id": "123", "profileImage": ("my_image.jpg", open(str(JPG), "rb"))}) -# # or -# client.form_data.basic({"id": "123", "profileImage": ("my_image.jpg", open(str(JPG), "rb").read())}) - -# # 4. file tuple (set file name and content type) -# client.form_data.basic({"id": "123", "profileImage": ("my_image.jpg", open(str(JPG), "rb"), "image/jpeg")}) -# # or -# client.form_data.basic({"id": "123", "profileImage": ("my_image.jpg", open(str(JPG), "rb").read(), "image/jpeg")}) - -# def test_sample_array_file(client: MultiPartClient): -# # If users want to upload array files for same field name, they can use list, and users can -# # choose any of the above file format for each file. e.g. - -# # List[bytes, io] -# client.form_data.binary_array_parts({"id": "123", "pictures": [open(str(PNG), "rb").read(), open(str(PNG), "rb")]}) - -# # List[bytes, tuple] -# client.form_data.binary_array_parts({ -# "id": "123", -# "pictures": [open(str(PNG), "rb").read(), ("my_image.png", open(str(PNG), "rb"))] -# }) -# # or -# client.form_data.binary_array_parts({ -# "id": "123", -# "pictures": [open(str(PNG), "rb").read(), ("my_image.png", open(str(PNG), "rb"), "image/png")] -# }) -# # List[io, bytes] -# client.form_data.binary_array_parts({"id": "123", "pictures": [open(str(PNG), "rb"), open(str(PNG), "rb").read()]}) - -# # List[tuple, tuple] -# client.form_data.binary_array_parts({ -# "id": "123", -# "pictures": [("my_image1.png", open(str(PNG), "rb"), "image/png"), ("my_image2.png", open(str(PNG), "rb"), "image/png")] -# }) -# # ... diff --git a/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/_vendor.py b/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/_vendor.py index fd65fc03ac6..2db14b3de0d 100644 --- a/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/_vendor.py +++ b/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/_vendor.py @@ -80,7 +80,8 @@ def handle_multipart_form_data_body( if field_name in file_properties: if isinstance(value, list): files.extend([(field_name, multipart_file(i)) for i in value]) - files.append((field_name, multipart_file(value))) + else: + files.append((field_name, multipart_file(value))) else: files.append((field_name, multipart_data(value))) return files From f7d4ce63fce5d4510ecc2d1d52e31317c9193cb4 Mon Sep 17 00:00:00 2001 From: msyyc <70930885+msyyc@users.noreply.github.com> Date: Mon, 29 Jan 2024 14:28:21 +0800 Subject: [PATCH 08/45] update test --- .../test_payload_multipart_async.py | 79 ------------------- .../test_payload_multipart.py | 77 ------------------ 2 files changed, 156 deletions(-) delete mode 100644 packages/typespec-python/test/generic_mock_api_tests/asynctests/test_payload_multipart_async.py delete mode 100644 packages/typespec-python/test/generic_mock_api_tests/test_payload_multipart.py diff --git a/packages/typespec-python/test/generic_mock_api_tests/asynctests/test_payload_multipart_async.py b/packages/typespec-python/test/generic_mock_api_tests/asynctests/test_payload_multipart_async.py deleted file mode 100644 index 53d664cdd5e..00000000000 --- a/packages/typespec-python/test/generic_mock_api_tests/asynctests/test_payload_multipart_async.py +++ /dev/null @@ -1,79 +0,0 @@ -# ------------------------------------------------------------------------- -# Copyright (c) Microsoft Corporation. All rights reserved. -# Licensed under the MIT License. See License.txt in the project root for -# license information. -# -------------------------------------------------------------------------- -import uuid -from typing import Dict, Any -from pathlib import Path -import pytest -from payload.multipart.aio import MultiPartClient -from payload.multipart import models -from payload.multipart._model_base import Model - -JPG = Path(__file__).parent.parent / "data/image.jpg" -PNG = Path(__file__).parent.parent / "data/image.png" - - -@pytest.fixture -async def client(): - async with MultiPartClient(endpoint="http://localhost:3000") as client: - yield client - - -@pytest.mark.asyncio -@pytest.mark.parametrize( - "op_name,model_class,data,file,file_info", - [ - ("basic", models.MultiPartRequest, {"id": "123"}, {"profileImage": JPG}, {}), - ( - "multi_binary_parts", - models.MultiBinaryPartsRequest, - {}, - {"profileImage": JPG, "picture": PNG}, - {} - ), - ( - "multi_binary_parts", - models.MultiBinaryPartsRequest, - {}, - {"profileImage": JPG}, - {} - ), - ( - "json_part", - models.JsonPartRequest, - {"address": models.Address(city="X")}, - {"profileImage": JPG}, - {} - ), - ( - "json_array_parts", - models.JsonArrayPartsRequest, - {"previousAddresses": [models.Address(city="Y"), models.Address(city="Z")]}, - {"profileImage": JPG}, - {} - ), - ], -) -async def test_multi_part(client: MultiPartClient, op_name, model_class, data, file, file_info): - def add_info(file_content): - name = str(uuid.uuid4()) if file_info.get("file_name") is None else file_info.get("file_name") - content_type = "application/octet-stream" if file_info.get("content_type") is None else file_info.get("content_type") - return (name, file_content, content_type) - op = getattr(client.form_data, op_name) - # test bytes - body = {k: add_info(open(str(v), "rb").read()) for k, v in file.items()} - body.update(data) - await op(body) - - # test io - body = {k: add_info(open(str(v), "rb")) for k, v in file.items()} - body.update(data) - await op(body) - - body = {k: add_info(open(str(v), "rb")) for k, v in file.items()} - body.update(data) - with pytest.raises(TypeError): - # caused by deepcopy when DPG model init - await op(model_class(body)) diff --git a/packages/typespec-python/test/generic_mock_api_tests/test_payload_multipart.py b/packages/typespec-python/test/generic_mock_api_tests/test_payload_multipart.py deleted file mode 100644 index e3b0efbccbf..00000000000 --- a/packages/typespec-python/test/generic_mock_api_tests/test_payload_multipart.py +++ /dev/null @@ -1,77 +0,0 @@ -# ------------------------------------------------------------------------- -# Copyright (c) Microsoft Corporation. All rights reserved. -# Licensed under the MIT License. See License.txt in the project root for -# license information. -# -------------------------------------------------------------------------- -import uuid -from typing import Dict, Any -from pathlib import Path -import pytest -from payload.multipart import MultiPartClient, models -from payload.multipart._model_base import Model - -JPG = Path(__file__).parent / "data/image.jpg" -PNG = Path(__file__).parent / "data/image.png" - - -@pytest.fixture -def client(): - with MultiPartClient(endpoint="http://localhost:3000") as client: - yield client - - -@pytest.mark.parametrize( - "op_name,model_class,data,file,file_info", - [ - ("basic", models.MultiPartRequest, {"id": "123"}, {"profileImage": JPG}, {}), - ( - "multi_binary_parts", - models.MultiBinaryPartsRequest, - {}, - {"profileImage": JPG, "picture": PNG}, - {} - ), - ( - "multi_binary_parts", - models.MultiBinaryPartsRequest, - {}, - {"profileImage": JPG}, - {} - ), - ( - "json_part", - models.JsonPartRequest, - {"address": models.Address(city="X")}, - {"profileImage": JPG}, - {} - ), - ( - "json_array_parts", - models.JsonArrayPartsRequest, - {"previousAddresses": [models.Address(city="Y"), models.Address(city="Z")]}, - {"profileImage": JPG}, - {} - ), - ], -) -def test_multi_part(client: MultiPartClient, op_name, model_class, data, file, file_info): - def add_info(file_content): - name = str(uuid.uuid4()) if file_info.get("file_name") is None else file_info.get("file_name") - content_type = "application/octet-stream" if file_info.get("content_type") is None else file_info.get("content_type") - return (name, file_content, content_type) - op = getattr(client.form_data, op_name) - # test bytes - body = {k: add_info(open(str(v), "rb").read()) for k, v in file.items()} - body.update(data) - op(body) - - # test io - body = {k: add_info(open(str(v), "rb")) for k, v in file.items()} - body.update(data) - op(body) - - body = {k: add_info(open(str(v), "rb")) for k, v in file.items()} - body.update(data) - with pytest.raises(TypeError): - # caused by deepcopy when DPG model init - op(model_class(body)) From f0eb959b5a46c3d34ad1e233afd0cc5e3a52a4f8 Mon Sep 17 00:00:00 2001 From: iscai-msft Date: Mon, 29 Jan 2024 15:50:05 -0500 Subject: [PATCH 09/45] accept files input, doesn't work --- .../autorest/codegen/models/__init__.py | 4 +- .../autorest/codegen/models/combined_type.py | 4 + .../autorest/codegen/models/model_type.py | 1 + .../autorest/codegen/models/operation.py | 8 -- .../autorest/codegen/models/parameter.py | 55 +------- .../autorest/codegen/models/parameter_list.py | 26 ++-- .../codegen/models/primitive_types.py | 28 ++++ .../autorest/codegen/models/property.py | 6 + .../models/request_builder_parameter.py | 37 ------ .../codegen/serializers/builder_serializer.py | 36 ++--- .../codegen/serializers/general_serializer.py | 12 +- .../codegen/templates/vendor.py.jinja2 | 72 ++-------- packages/typespec-python/package.json | 4 +- packages/typespec-python/src/types.ts | 6 + .../payload/multipart/_vendor.py | 87 ------------ .../multipart/aio/operations/_operations.py | 101 +++++++++----- .../payload/multipart/models/_models.py | 49 +++---- .../multipart/operations/_operations.py | 125 +++++++++++++----- 18 files changed, 270 insertions(+), 391 deletions(-) delete mode 100644 packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/_vendor.py diff --git a/packages/autorest.python/autorest/codegen/models/__init__.py b/packages/autorest.python/autorest/codegen/models/__init__.py index 421774420e7..9f90cadbdf4 100644 --- a/packages/autorest.python/autorest/codegen/models/__init__.py +++ b/packages/autorest.python/autorest/codegen/models/__init__.py @@ -20,6 +20,7 @@ DurationType, IntegerType, FloatType, + MultipartFileType, StringType, TimeType, AnyType, @@ -43,7 +44,6 @@ ParameterLocation, BodyParameter, ParameterDelimeter, - MultipartBodyParameter, ClientParameter, ConfigParameter, ) @@ -115,7 +115,6 @@ "BodyParameter", "RequestBuilderBodyParameter", "ParameterDelimeter", - "MultipartBodyParameter", "CredentialType", "ClientParameter", "ConfigParameter", @@ -150,6 +149,7 @@ "unixtime": UnixTimeType, "credential": StringType, "sdkcore": SdkCoreType, + "multipartfile": MultipartFileType } _LOGGER = logging.getLogger(__name__) diff --git a/packages/autorest.python/autorest/codegen/models/combined_type.py b/packages/autorest.python/autorest/codegen/models/combined_type.py index a0b496d0907..016fe2d1664 100644 --- a/packages/autorest.python/autorest/codegen/models/combined_type.py +++ b/packages/autorest.python/autorest/codegen/models/combined_type.py @@ -78,6 +78,10 @@ def type_definition(self, **kwargs: Any) -> str: # If the inside types has been a Union, peel first and then re-union pattern = re.compile(r"Union\[.*\]") return f'Union[{", ".join(map(lambda x: x[6: -1] if pattern.match(x) else x, inside_types))}]' + + @property + def is_form_data(self) -> bool: + return any(isinstance(t, ModelType) and t.is_form_data for t in self.types) def get_json_template_representation( self, diff --git a/packages/autorest.python/autorest/codegen/models/model_type.py b/packages/autorest.python/autorest/codegen/models/model_type.py index f07059c0f2d..531d865e5d8 100644 --- a/packages/autorest.python/autorest/codegen/models/model_type.py +++ b/packages/autorest.python/autorest/codegen/models/model_type.py @@ -75,6 +75,7 @@ def __init__( self.internal: bool = self.yaml_data.get("internal", False) self.snake_case_name: str = self.yaml_data["snakeCaseName"] self.page_result_model: bool = self.yaml_data.get("pageResultModel", False) + self.is_form_data = any(p.is_form_data for p in self.properties) @property def is_xml(self) -> bool: diff --git a/packages/autorest.python/autorest/codegen/models/operation.py b/packages/autorest.python/autorest/codegen/models/operation.py index 9da7b09712f..bfa540bc5af 100644 --- a/packages/autorest.python/autorest/codegen/models/operation.py +++ b/packages/autorest.python/autorest/codegen/models/operation.py @@ -30,7 +30,6 @@ ) from .parameter import ( BodyParameter, - MultipartBodyParameter, Parameter, ParameterLocation, ) @@ -290,7 +289,6 @@ def has_kwargs_to_pop_with_default( Parameter, RequestBuilderParameter, BodyParameter, - MultipartBodyParameter, ] ], location: ParameterLocation, @@ -582,12 +580,6 @@ def imports(self, async_mode: bool, **kwargs: Any) -> FileImport: ImportType.LOCAL, ) file_import.add_import("json", ImportType.STDLIB) - else: - file_import.add_submodule_import( - f"{relative_path}_vendor", - "handle_multipart_form_data_body", - ImportType.LOCAL, - ) if self.default_error_deserialization or any( r.type for r in self.responses ): diff --git a/packages/autorest.python/autorest/codegen/models/parameter.py b/packages/autorest.python/autorest/codegen/models/parameter.py index 66e35a25f99..7fd2bf63f56 100644 --- a/packages/autorest.python/autorest/codegen/models/parameter.py +++ b/packages/autorest.python/autorest/codegen/models/parameter.py @@ -23,7 +23,7 @@ from .constant_type import ConstantType from .utils import add_to_description from .combined_type import CombinedType -from .model_type import JSONModelType, DPGModelType +from .model_type import JSONModelType, DPGModelType, ModelType from .primitive_types import ByteArraySchema from .list_type import ListType @@ -93,6 +93,7 @@ def __init__( "defaultToUnsetSentinel", False ) self.hide_in_method: bool = self.yaml_data.get("hideInMethod", False) + self.form_data_input = isinstance(self.type, ModelType) and any(p.is_multipart_file for p in self.type.properties) def get_declaration(self, value: Any = None) -> Any: return self.type.get_declaration(value) @@ -247,7 +248,7 @@ class BodyParameter(_ParameterBase): @property def is_form_data(self) -> bool: - return self.default_content_type == "multipart/form-data" + return self.type.is_form_data @property def is_partial_body(self) -> bool: @@ -314,47 +315,6 @@ def from_yaml( "EntryBodyParameterType", bound=Union[BodyParameter, "RequestBuilderBodyParameter"] ) - -class _MultipartBodyParameter(Generic[EntryBodyParameterType], BodyParameter): - """Base class for MultipartBodyParameter and RequestBuilderMultipartBodyParameter""" - - def __init__( - self, - yaml_data: Dict[str, Any], - code_model: "CodeModel", - type: BaseType, - entries: List[EntryBodyParameterType], - ) -> None: - super().__init__(yaml_data, code_model, type) - self.entries = entries - - @property - def in_method_signature(self) -> bool: - # Right now, only legacy generates with multipart bodies - # and legacy generates with the multipart body arguments splatted out - return False - - -class MultipartBodyParameter( - _MultipartBodyParameter[BodyParameter] # pylint: disable=unsubscriptable-object -): - """Multipart body parameter for Operation. Used for files and data input.""" - - @classmethod - def from_yaml( - cls, yaml_data: Dict[str, Any], code_model: "CodeModel" - ) -> "MultipartBodyParameter": - return cls( - yaml_data=yaml_data, - code_model=code_model, - type=code_model.lookup_type(id(yaml_data["type"])), - entries=[ - BodyParameter.from_yaml(entry, code_model) - for entry in yaml_data["entries"] - ], - ) - - class Parameter(_ParameterBase): """Basic Parameter class""" @@ -476,12 +436,3 @@ def method_location(self) -> ParameterMethodLocation: if self.constant: return ParameterMethodLocation.KWARG return ParameterMethodLocation.POSITIONAL - - -def get_body_parameter( - yaml_data: Dict[str, Any], code_model: "CodeModel" -) -> Union[BodyParameter, MultipartBodyParameter]: - """Creates a regular body parameter or Multipart body parameter""" - if yaml_data.get("entries"): - return MultipartBodyParameter.from_yaml(yaml_data, code_model) - return BodyParameter.from_yaml(yaml_data, code_model) diff --git a/packages/autorest.python/autorest/codegen/models/parameter_list.py b/packages/autorest.python/autorest/codegen/models/parameter_list.py index a7a5293ee63..f57e8be91a5 100644 --- a/packages/autorest.python/autorest/codegen/models/parameter_list.py +++ b/packages/autorest.python/autorest/codegen/models/parameter_list.py @@ -22,19 +22,15 @@ from .request_builder_parameter import ( RequestBuilderBodyParameter, - RequestBuilderMultipartBodyParameter, RequestBuilderParameter, - get_request_body_parameter, ) from .parameter import ( - MultipartBodyParameter, ParameterLocation, BodyParameter, Parameter, ParameterMethodLocation, ClientParameter, ConfigParameter, - get_body_parameter, ) ParameterType = TypeVar( @@ -43,10 +39,6 @@ BodyParameterType = TypeVar( "BodyParameterType", bound=Union[BodyParameter, RequestBuilderBodyParameter] ) -RequestBuilderBodyParameterType = Union[ - RequestBuilderBodyParameter, RequestBuilderMultipartBodyParameter -] - if TYPE_CHECKING: from .code_model import CodeModel @@ -314,7 +306,7 @@ def from_yaml(cls, yaml_data: Dict[str, Any], code_model: "CodeModel"): class _ParameterList( _ParameterListBase[ # pylint: disable=unsubscriptable-object - Parameter, Union[MultipartBodyParameter, BodyParameter] + Parameter, BodyParameter ] ): """Base Parameter class for the two operation ParameterLists""" @@ -326,10 +318,10 @@ def parameter_creator() -> Callable[[Dict[str, Any], "CodeModel"], Parameter]: @staticmethod def body_parameter_creator() -> ( Callable[ - [Dict[str, Any], "CodeModel"], Union[MultipartBodyParameter, BodyParameter] + [Dict[str, Any], "CodeModel"], BodyParameter ] ): - return get_body_parameter + return BodyParameter.from_yaml @property def implementation(self) -> str: @@ -348,7 +340,7 @@ class ParameterList(_ParameterList): class _RequestBuilderParameterList( _ParameterListBase[ # pylint: disable=unsubscriptable-object - RequestBuilderParameter, RequestBuilderBodyParameterType + RequestBuilderParameter, RequestBuilderBodyParameter ] ): """_RequestBuilderParameterList is base parameter list for RequestBuilder classes""" @@ -361,9 +353,9 @@ def parameter_creator() -> ( @staticmethod def body_parameter_creator() -> ( - Callable[[Dict[str, Any], "CodeModel"], RequestBuilderBodyParameterType] + Callable[[Dict[str, Any], "CodeModel"], RequestBuilderBodyParameter] ): - return get_request_body_parameter + return RequestBuilderBodyParameter.from_yaml @property def implementation(self) -> str: @@ -372,14 +364,14 @@ def implementation(self) -> str: @property def unsorted_method_params( self, - ) -> List[Union[RequestBuilderParameter, RequestBuilderBodyParameterType]]: + ) -> List[Union[RequestBuilderParameter, RequestBuilderBodyParameter]]: # don't have access to client params in request builder retval = [ p for p in super().unsorted_method_params if not ( p.location == ParameterLocation.BODY - and cast(RequestBuilderBodyParameterType, p).is_partial_body + and cast(RequestBuilderBodyParameter, p).is_partial_body ) ] retval.extend( @@ -400,7 +392,7 @@ def path(self) -> List[RequestBuilderParameter]: @property def constant( self, - ) -> List[Union[RequestBuilderParameter, RequestBuilderBodyParameterType]]: + ) -> List[Union[RequestBuilderParameter, RequestBuilderBodyParameter]]: """All constant parameters""" return [ p for p in super().constant if p.location != ParameterLocation.ENDPOINT_PATH diff --git a/packages/autorest.python/autorest/codegen/models/primitive_types.py b/packages/autorest.python/autorest/codegen/models/primitive_types.py index 9c1d8d29e5d..dddd18e8afc 100644 --- a/packages/autorest.python/autorest/codegen/models/primitive_types.py +++ b/packages/autorest.python/autorest/codegen/models/primitive_types.py @@ -81,6 +81,34 @@ def docstring_type(self, **kwargs: Any) -> str: def instance_check_template(self) -> str: return "isinstance({}, bool)" +class MultipartFileType(PrimitiveType): + def __init__(self, yaml_data: Dict[str, Any], code_model: "CodeModel") -> None: + super().__init__(yaml_data=yaml_data, code_model=code_model) + self.type = "FileType" + + def imports(self, **kwargs: Any) -> FileImport: + file_import = FileImport(self.code_model) + file_import.add_submodule_import(".._vendor", "FileType", ImportType.STDLIB) + return file_import + + @property + def instance_check_template(self) -> str: + return "isinstance({}, FileType)" + + @property + def serialization_type(self) -> str: + return "filetype" + + def docstring_type(self, **kwargs: Any) -> str: + return "filetype" + + def type_annotation(self, **kwargs: Any) -> str: + return "FileType" + + @property + def default_template_representation_declaration(self) -> str: + return self.get_declaration({}) + class BinaryType(PrimitiveType): def __init__(self, yaml_data: Dict[str, Any], code_model: "CodeModel") -> None: diff --git a/packages/autorest.python/autorest/codegen/models/property.py b/packages/autorest.python/autorest/codegen/models/property.py index 7020574a26a..54fc6120160 100644 --- a/packages/autorest.python/autorest/codegen/models/property.py +++ b/packages/autorest.python/autorest/codegen/models/property.py @@ -37,6 +37,7 @@ def __init__( if self.client_default_value is None: self.client_default_value = self.type.client_default_value self.flattened_names: List[str] = yaml_data.get("flattenedNames", []) + self.is_multipart_file: bool = True @property def pylint_disable(self) -> str: @@ -162,6 +163,11 @@ def imports(self, **kwargs) -> FileImport: ImportType.LOCAL, ) return file_import + + @property + def is_form_data(self) -> bool: + from .model_type import ModelType + return isinstance(self.type, ModelType) and self.type.is_form_data @classmethod def from_yaml( diff --git a/packages/autorest.python/autorest/codegen/models/request_builder_parameter.py b/packages/autorest.python/autorest/codegen/models/request_builder_parameter.py index f82f361388d..b980959cafe 100644 --- a/packages/autorest.python/autorest/codegen/models/request_builder_parameter.py +++ b/packages/autorest.python/autorest/codegen/models/request_builder_parameter.py @@ -9,7 +9,6 @@ ParameterMethodLocation, Parameter, BodyParameter, - _MultipartBodyParameter, ) from .base import BaseType from .primitive_types import BinaryType, StringType @@ -66,33 +65,6 @@ def name_in_high_level_operation(self) -> str: return "_json" return "_content" - -class RequestBuilderMultipartBodyParameter( - _MultipartBodyParameter[ # pylint: disable=unsubscriptable-object - RequestBuilderBodyParameter - ] -): - """Multipart body parameter for Request BUilders""" - - @property - def name_in_high_level_operation(self) -> str: - return f"_{self.client_name}" - - @classmethod - def from_yaml( - cls, yaml_data: Dict[str, Any], code_model: "CodeModel" - ) -> "RequestBuilderMultipartBodyParameter": - return cls( - yaml_data=yaml_data, - code_model=code_model, - type=code_model.lookup_type(id(yaml_data["type"])), - entries=[ - RequestBuilderBodyParameter.from_yaml(entry, code_model) - for entry in yaml_data["entries"] - ], - ) - - class RequestBuilderParameter(Parameter): """Basic RequestBuilder Parameter.""" @@ -149,12 +121,3 @@ def name_in_high_level_operation(self) -> str: if self.implementation == "Client": return f"self._config.{self.client_name}" return self.client_name - - -def get_request_body_parameter( - yaml_data: Dict[str, Any], code_model: "CodeModel" -) -> Union[RequestBuilderBodyParameter, RequestBuilderMultipartBodyParameter]: - """Get body parameter for a request builder""" - if yaml_data.get("entries"): - return RequestBuilderMultipartBodyParameter.from_yaml(yaml_data, code_model) - return RequestBuilderBodyParameter.from_yaml(yaml_data, code_model) diff --git a/packages/autorest.python/autorest/codegen/serializers/builder_serializer.py b/packages/autorest.python/autorest/codegen/serializers/builder_serializer.py index 3e4d941482e..56e5eb3de03 100644 --- a/packages/autorest.python/autorest/codegen/serializers/builder_serializer.py +++ b/packages/autorest.python/autorest/codegen/serializers/builder_serializer.py @@ -26,7 +26,6 @@ ParameterMethodLocation, RequestBuilderBodyParameter, OverloadedRequestBuilder, - MultipartBodyParameter, Property, RequestBuilderType, CombinedType, @@ -34,6 +33,7 @@ DPGModelType, ParameterListType, ByteArraySchema, + MultipartFileType, ) from .parameter_serializer import ParameterSerializer, PopKwargType from ..models.parameter_list import ParameterType @@ -204,19 +204,6 @@ def _serialize_json_model_body( retval.append(" }") return retval - -def _serialize_multipart_body(builder: BuilderType) -> List[str]: - retval: List[str] = [] - body_param = cast(MultipartBodyParameter, builder.parameters.body_parameter) - # we have to construct our form data before passing to the request as well - retval.append("# Construct form data") - retval.append(f"_{body_param.client_name} = {{") - for param in body_param.entries: - retval.append(f' "{param.wire_name}": {param.client_name},') - retval.append("}") - return retval - - def _get_json_response_template_to_status_codes( builder: OperationType, ) -> Dict[str, List[str]]: @@ -752,12 +739,17 @@ def _serialize_body_parameter(self, builder: OperationType) -> List[str]: This function serializes the body params that need to be serialized. """ - body_param = cast(BodyParameter, builder.parameters.body_parameter) - if body_param.is_form_data: - return [ - 'file_properties = ["' + '", "'.join(body_param.file_properties) + '"]', - f"_files = handle_multipart_form_data_body({body_param.client_name}, file_properties)", - ] + body_param = builder.parameters.body_parameter + if body_param.form_data_input: + retval = ["_files = []"] + for prop in cast(ModelType, body_param.type).properties: + if isinstance(prop.type, MultipartFileType): + if isinstance(prop.type, ListType): + retval.append(f"_files.extend(self.{prop.client_name})") + else: + # we assume that it's just a single multipart file input + retval.append(f"_files.append(self.{prop.client_name})") + return retval retval: List[str] = [] body_kwarg_name = builder.request_builder.parameters.body_parameter.client_name send_xml = builder.parameters.body_parameter.type.is_xml @@ -810,9 +802,7 @@ def _create_body_parameter( ) -> List[str]: """Create the body parameter before we pass it as either json or content to the request builder""" retval = [] - body_param = cast(BodyParameter, builder.parameters.body_parameter) - if hasattr(body_param, "entries"): - return _serialize_multipart_body(builder) + body_param = builder.parameters.body_parameter body_kwarg_name = builder.request_builder.parameters.body_parameter.client_name body_param_type = body_param.type if isinstance(body_param_type, BinaryType) or ( diff --git a/packages/autorest.python/autorest/codegen/serializers/general_serializer.py b/packages/autorest.python/autorest/codegen/serializers/general_serializer.py index 2795a3749d6..b83ad190f9d 100644 --- a/packages/autorest.python/autorest/codegen/serializers/general_serializer.py +++ b/packages/autorest.python/autorest/codegen/serializers/general_serializer.py @@ -131,18 +131,10 @@ def serialize_vendor_file(self, clients: List[Client]) -> str: ImportType.SDKCORE, ) if self.code_model.has_form_data: - file_import.add_submodule_import("typing", "List", ImportType.STDLIB) + file_import.add_submodule_import("typing", "IO", ImportType.STDLIB) file_import.add_submodule_import("typing", "Tuple", ImportType.STDLIB) file_import.add_submodule_import("typing", "Union", ImportType.STDLIB) - file_import.add_submodule_import("typing", "Any", ImportType.STDLIB) - file_import.add_submodule_import("io", "IOBase", ImportType.STDLIB) - file_import.add_import("uuid", ImportType.STDLIB) - file_import.add_import("json", ImportType.STDLIB) - file_import.add_mutable_mapping_import() - file_import.add_submodule_import("._model_base", "Model", ImportType.LOCAL) - file_import.add_submodule_import( - "._model_base", "SdkJSONEncoder", ImportType.LOCAL - ) + file_import.add_submodule_import("typing", "Optional", ImportType.STDLIB) return template.render( code_model=self.code_model, diff --git a/packages/autorest.python/autorest/codegen/templates/vendor.py.jinja2 b/packages/autorest.python/autorest/codegen/templates/vendor.py.jinja2 index 8337d15ac30..b0c05724577 100644 --- a/packages/autorest.python/autorest/codegen/templates/vendor.py.jinja2 +++ b/packages/autorest.python/autorest/codegen/templates/vendor.py.jinja2 @@ -66,63 +66,17 @@ def prep_if_none_match(etag: Optional[str], match_condition: Optional[MatchCondi return None {% endif %} {% if code_model.has_form_data %} - -JSON = MutableMapping[str, Any] # pylint: disable=unsubscriptable-object - # file-like tuple could be `(filename, IO (or bytes))` or `(filename, IO (or bytes), content_type)` -FileType = Union[IOBase, bytes] -FileTuple = Union[Tuple[str, FileType], Tuple[str, FileType, str]] -MultiPartFile = Union[IOBase, bytes, FileTuple] -HandledMultiPartFile = Union[IOBase, FileTuple] - -def multipart_file(file: MultiPartFile) -> HandledMultiPartFile: - if isinstance(file, (IOBase, tuple)): - return file - return ("auto-name-" + str(uuid.uuid4()), file) - -def multipart_data(data: Any) -> Any: - if isinstance(data, (list, tuple, dict, Model)): - return json.dumps(data, cls=SdkJSONEncoder, exclude_readonly=True) - return data - -def handle_multipart_form_data_model(body: Model, file_properties: List[str])-> JSON: # pylint: disable=unsubscriptable-object - """handle first layer of model. - If its value is bytes or IO, replace it with raw value instead of serialized value. - - :param body: The model to handle. - :type body: ._model_base.Model - :param file_properties: The properties of the model that are file type. - :type file_properties: list[str] - :return: The handled model. - :rtype: MutableMapping[str, Any] - """ - result = body.as_dict() - rest_name_attr = {v._rest_name: k for k, v in body._attr_to_rest_field.items()} # pylint: disable=protected-access - for rest_name in result.keys(): - attr = rest_name_attr.get(rest_name) - if attr is not None and rest_name in file_properties: - result[rest_name] = getattr(body, attr, None) - return result - -def handle_multipart_form_data_body(body: Union[Model, JSON], file_properties: List[str])-> List[Tuple[str, HandledMultiPartFile]]: - """handle multipart form data body. - - :param body: The body to handle. - :type body: ._model_base.Model or dict[str, Any] - :param file_properties: The properties of the model that are file type. - :type file_properties: list[str] - :return: The handled body. - :rtype: list[tuple[str, HandledMultiPartFile]] - """ - _body = handle_multipart_form_data_model(body, file_properties) if isinstance(body, Model) else body - files = [] - for field_name, value in _body.items(): - if field_name in file_properties: - if isinstance(value, list): - files.extend([(field_name, multipart_file(i)) for i in value]) - else: - files.append((field_name, multipart_file(value))) - else: - files.append((field_name, multipart_data(value))) - return files -{% endif %} +FileContent = Union[str, bytes, IO[str], IO[bytes]] + +FileType = Union[ + # file (or bytes) + FileContent, + # (filename, file (or bytes)) + Tuple[Optional[str], FileContent], + # (filename, file (or bytes), content_type) + Tuple[Optional[str], FileContent, Optional[str]], +] + +FilesType = Union[Mapping[str, FileType], Sequence[Tuple[str, FileType]]] +{% endif %} \ No newline at end of file diff --git a/packages/typespec-python/package.json b/packages/typespec-python/package.json index 63633593bdd..4fc49150451 100644 --- a/packages/typespec-python/package.json +++ b/packages/typespec-python/package.json @@ -43,7 +43,7 @@ ], "peerDependencies": { "@azure-tools/typespec-azure-core": ">=0.38.0 <1.0.0", - "@azure-tools/typespec-client-generator-core": ">=0.38.0 <1.0.0", + "@azure-tools/typespec-client-generator-core": "0.39.0-dev.2", "@typespec/compiler": ">=0.52.0 <1.0.0", "@typespec/http": ">=0.52.0 <1.0.0", "@typespec/rest": ">=0.52.0 <1.0.0", @@ -74,7 +74,7 @@ "rimraf": "~5.0.0", "typescript": "~5.1.3", "@azure-tools/typespec-azure-core": "~0.38.0", - "@azure-tools/typespec-client-generator-core": "~0.38.0", + "@azure-tools/typespec-client-generator-core": "0.39.0-dev.2", "@typespec/compiler": "~0.52.0", "@typespec/http": "~0.52.0", "@typespec/rest": "~0.52.0", diff --git a/packages/typespec-python/src/types.ts b/packages/typespec-python/src/types.ts index c13c8e382f4..2ce5ae5fcd7 100644 --- a/packages/typespec-python/src/types.ts +++ b/packages/typespec-python/src/types.ts @@ -335,6 +335,12 @@ const sdkScalarKindToPythonKind: Record = { }; function emitBuiltInType(type: SdkBuiltInType | SdkDurationType | SdkDatetimeType): Record { + if (type.kind === "bytes") { + return getSimpleTypeResult({ + type: "multipartfile", + encode: type.encode, + }) + } if (type.kind === "duration" && type.encode === "seconds") { return getSimpleTypeResult({ type: sdkScalarKindToPythonKind[type.wireType.kind], diff --git a/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/_vendor.py b/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/_vendor.py deleted file mode 100644 index 2db14b3de0d..00000000000 --- a/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/_vendor.py +++ /dev/null @@ -1,87 +0,0 @@ -# -------------------------------------------------------------------------- -# Copyright (c) Unbranded Corporation. All rights reserved. -# Licensed under the MIT License. See License.txt in the project root for license information. -# Code generated by Unbranded (R) Python Code Generator. -# Changes may cause incorrect behavior and will be lost if the code is regenerated. -# -------------------------------------------------------------------------- - -from io import IOBase -import json -import sys -from typing import Any, List, Tuple, Union -import uuid - -from ._model_base import Model, SdkJSONEncoder - -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 - -# file-like tuple could be `(filename, IO (or bytes))` or `(filename, IO (or bytes), content_type)` -FileType = Union[IOBase, bytes] -FileTuple = Union[Tuple[str, FileType], Tuple[str, FileType, str]] -MultiPartFile = Union[IOBase, bytes, FileTuple] -HandledMultiPartFile = Union[IOBase, FileTuple] - - -def multipart_file(file: MultiPartFile) -> HandledMultiPartFile: - if isinstance(file, (IOBase, tuple)): - return file - return ("auto-name-" + str(uuid.uuid4()), file) - - -def multipart_data(data: Any) -> Any: - if isinstance(data, (list, tuple, dict, Model)): - return json.dumps(data, cls=SdkJSONEncoder, exclude_readonly=True) - return data - - -def handle_multipart_form_data_model( - body: Model, file_properties: List[str] -) -> JSON: # pylint: disable=unsubscriptable-object - """handle first layer of model. - If its value is bytes or IO, replace it with raw value instead of serialized value. - - :param body: The model to handle. - :type body: ._model_base.Model - :param file_properties: The properties of the model that are file type. - :type file_properties: list[str] - :return: The handled model. - :rtype: MutableMapping[str, Any] - """ - result = body.as_dict() - rest_name_attr = {v._rest_name: k for k, v in body._attr_to_rest_field.items()} # pylint: disable=protected-access - for rest_name in result.keys(): - attr = rest_name_attr.get(rest_name) - if attr is not None and rest_name in file_properties: - result[rest_name] = getattr(body, attr, None) - return result - - -def handle_multipart_form_data_body( - body: Union[Model, JSON], file_properties: List[str] -) -> List[Tuple[str, HandledMultiPartFile]]: - """handle multipart form data body. - - :param body: The body to handle. - :type body: ._model_base.Model or dict[str, Any] - :param file_properties: The properties of the model that are file type. - :type file_properties: list[str] - :return: The handled body. - :rtype: list[tuple[str, HandledMultiPartFile]] - """ - _body = handle_multipart_form_data_model(body, file_properties) if isinstance(body, Model) else body - files = [] - for field_name, value in _body.items(): - if field_name in file_properties: - if isinstance(value, list): - files.extend([(field_name, multipart_file(i)) for i in value]) - else: - files.append((field_name, multipart_file(value))) - else: - files.append((field_name, multipart_data(value))) - return files diff --git a/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/aio/operations/_operations.py b/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/aio/operations/_operations.py index 103aa3b7892..114cc22fa9e 100644 --- a/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/aio/operations/_operations.py +++ b/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/aio/operations/_operations.py @@ -6,6 +6,7 @@ # Code generated by Unbranded (R) Python Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- +import json import sys from typing import Any, Callable, Dict, Optional, TypeVar, Union, overload @@ -21,7 +22,7 @@ from corehttp.runtime.pipeline import PipelineResponse from ... import models as _models -from ..._vendor import handle_multipart_form_data_body +from ..._model_base import SdkJSONEncoder from ...operations._operations import ( build_form_data_basic_request, build_form_data_binary_array_parts_request, @@ -75,7 +76,7 @@ async def basic( # pylint: disable=inconsistent-return-statements # JSON input template you can fill out and use as your body input. body = { "id": "str", # Required. - "profileImage": bytes("bytes", encoding="utf-8") # Required. + "profileImage": {} # Required. } """ @@ -107,7 +108,7 @@ async def basic( # pylint: disable=inconsistent-return-statements # JSON input template you can fill out and use as your body input. body = { "id": "str", # Required. - "profileImage": bytes("bytes", encoding="utf-8") # Required. + "profileImage": {} # Required. } """ error_map = { @@ -123,11 +124,16 @@ async def basic( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) - file_properties = ["profileImage"] - _files = handle_multipart_form_data_body(body, file_properties) + content_type = content_type or "multipart/form-data" + _content = None + if isinstance(body, _model_base.Model): + _files = [] + _files.append(self.profile_image) + elif isinstance(body, MutableMapping): + _content = body _request = build_form_data_basic_request( - files=_files, + content=_content, headers=_headers, params=_params, ) @@ -171,14 +177,14 @@ async def complex( # pylint: disable=inconsistent-return-statements }, "id": "str", # Required. "pictures": [ - bytes("bytes", encoding="utf-8") # Required. + {} # Required. ], "previousAddresses": [ { "city": "str" # Required. } ], - "profileImage": bytes("bytes", encoding="utf-8") # Required. + "profileImage": {} # Required. } """ @@ -214,14 +220,14 @@ async def complex( # pylint: disable=inconsistent-return-statements }, "id": "str", # Required. "pictures": [ - bytes("bytes", encoding="utf-8") # Required. + {} # Required. ], "previousAddresses": [ { "city": "str" # Required. } ], - "profileImage": bytes("bytes", encoding="utf-8") # Required. + "profileImage": {} # Required. } """ error_map = { @@ -237,11 +243,16 @@ async def complex( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) - file_properties = ["profileImage", "pictures"] - _files = handle_multipart_form_data_body(body, file_properties) + content_type = content_type or "multipart/form-data" + _content = None + if isinstance(body, _model_base.Model): + _files = [] + _files.append(self.profile_image) + elif isinstance(body, MutableMapping): + _content = body _request = build_form_data_complex_request( - files=_files, + content=_content, headers=_headers, params=_params, ) @@ -283,7 +294,7 @@ async def json_part( # pylint: disable=inconsistent-return-statements "address": { "city": "str" # Required. }, - "profileImage": bytes("bytes", encoding="utf-8") # Required. + "profileImage": {} # Required. } """ @@ -317,7 +328,7 @@ async def json_part( # pylint: disable=inconsistent-return-statements "address": { "city": "str" # Required. }, - "profileImage": bytes("bytes", encoding="utf-8") # Required. + "profileImage": {} # Required. } """ error_map = { @@ -333,11 +344,16 @@ async def json_part( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) - file_properties = ["profileImage"] - _files = handle_multipart_form_data_body(body, file_properties) + content_type = content_type or "multipart/form-data" + _content = None + if isinstance(body, _model_base.Model): + _files = [] + _files.append(self.profile_image) + elif isinstance(body, MutableMapping): + _content = body _request = build_form_data_json_part_request( - files=_files, + content=_content, headers=_headers, params=_params, ) @@ -378,7 +394,7 @@ async def binary_array_parts( # pylint: disable=inconsistent-return-statements body = { "id": "str", # Required. "pictures": [ - bytes("bytes", encoding="utf-8") # Required. + {} # Required. ] } """ @@ -414,7 +430,7 @@ async def binary_array_parts( # pylint: disable=inconsistent-return-statements body = { "id": "str", # Required. "pictures": [ - bytes("bytes", encoding="utf-8") # Required. + {} # Required. ] } """ @@ -431,11 +447,15 @@ async def binary_array_parts( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) - file_properties = ["pictures"] - _files = handle_multipart_form_data_body(body, file_properties) + content_type = content_type or "multipart/form-data" + _content = None + if isinstance(body, _model_base.Model): + _files = [] + elif isinstance(body, MutableMapping): + _content = body _request = build_form_data_binary_array_parts_request( - files=_files, + content=_content, headers=_headers, params=_params, ) @@ -479,7 +499,7 @@ async def json_array_parts( # pylint: disable=inconsistent-return-statements "city": "str" # Required. } ], - "profileImage": bytes("bytes", encoding="utf-8") # Required. + "profileImage": {} # Required. } """ @@ -517,7 +537,7 @@ async def json_array_parts( # pylint: disable=inconsistent-return-statements "city": "str" # Required. } ], - "profileImage": bytes("bytes", encoding="utf-8") # Required. + "profileImage": {} # Required. } """ error_map = { @@ -533,11 +553,16 @@ async def json_array_parts( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) - file_properties = ["profileImage"] - _files = handle_multipart_form_data_body(body, file_properties) + content_type = content_type or "multipart/form-data" + _content = None + if isinstance(body, _model_base.Model): + _files = [] + _files.append(self.profile_image) + elif isinstance(body, MutableMapping): + _content = body _request = build_form_data_json_array_parts_request( - files=_files, + content=_content, headers=_headers, params=_params, ) @@ -576,8 +601,8 @@ async def multi_binary_parts( # pylint: disable=inconsistent-return-statements # JSON input template you can fill out and use as your body input. body = { - "profileImage": bytes("bytes", encoding="utf-8"), # Required. - "picture": bytes("bytes", encoding="utf-8") # Optional. + "profileImage": {}, # Required. + "picture": {} # Optional. } """ @@ -610,8 +635,8 @@ async def multi_binary_parts( # pylint: disable=inconsistent-return-statements # JSON input template you can fill out and use as your body input. body = { - "profileImage": bytes("bytes", encoding="utf-8"), # Required. - "picture": bytes("bytes", encoding="utf-8") # Optional. + "profileImage": {}, # Required. + "picture": {} # Optional. } """ error_map = { @@ -627,11 +652,17 @@ async def multi_binary_parts( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) - file_properties = ["profileImage", "picture"] - _files = handle_multipart_form_data_body(body, file_properties) + content_type = content_type or "multipart/form-data" + _content = None + if isinstance(body, _model_base.Model): + _files = [] + _files.append(self.profile_image) + _files.append(self.picture) + elif isinstance(body, MutableMapping): + _content = body _request = build_form_data_multi_binary_parts_request( - files=_files, + content=_content, headers=_headers, params=_params, ) diff --git a/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/models/_models.py b/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/models/_models.py index 3f7009ea407..3370e8e5ee7 100644 --- a/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/models/_models.py +++ b/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/models/_models.py @@ -7,6 +7,7 @@ # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- +from .._vendor import FileType from typing import Any, List, Mapping, Optional, TYPE_CHECKING, overload from .. import _model_base @@ -56,12 +57,12 @@ class BinaryArrayPartsRequest(_model_base.Model): :ivar id: Required. :vartype id: str :ivar pictures: Required. - :vartype pictures: list[bytes] + :vartype pictures: list[filetype] """ id: str = rest_field() """Required.""" - pictures: List[bytes] = rest_field(format="base64") + pictures: List[FileType] = rest_field() """Required.""" @overload @@ -69,7 +70,7 @@ def __init__( self, *, id: str, # pylint: disable=redefined-builtin - pictures: List[bytes], + pictures: List[FileType], ): ... @@ -94,22 +95,22 @@ class ComplexPartsRequest(_model_base.Model): :ivar address: Required. :vartype address: ~payload.multipart.models.Address :ivar profile_image: Required. - :vartype profile_image: bytes + :vartype profile_image: filetype :ivar previous_addresses: Required. :vartype previous_addresses: list[~payload.multipart.models.Address] :ivar pictures: Required. - :vartype pictures: list[bytes] + :vartype pictures: list[filetype] """ id: str = rest_field() """Required.""" address: "_models.Address" = rest_field() """Required.""" - profile_image: bytes = rest_field(name="profileImage", format="base64") + profile_image: FileType = rest_field(name="profileImage") """Required.""" previous_addresses: List["_models.Address"] = rest_field(name="previousAddresses") """Required.""" - pictures: List[bytes] = rest_field(format="base64") + pictures: List[FileType] = rest_field() """Required.""" @overload @@ -118,9 +119,9 @@ def __init__( *, id: str, # pylint: disable=redefined-builtin address: "_models.Address", - profile_image: bytes, + profile_image: FileType, previous_addresses: List["_models.Address"], - pictures: List[bytes], + pictures: List[FileType], ): ... @@ -141,12 +142,12 @@ class JsonArrayPartsRequest(_model_base.Model): All required parameters must be populated in order to send to server. :ivar profile_image: Required. - :vartype profile_image: bytes + :vartype profile_image: filetype :ivar previous_addresses: Required. :vartype previous_addresses: list[~payload.multipart.models.Address] """ - profile_image: bytes = rest_field(name="profileImage", format="base64") + profile_image: FileType = rest_field(name="profileImage") """Required.""" previous_addresses: List["_models.Address"] = rest_field(name="previousAddresses") """Required.""" @@ -155,7 +156,7 @@ class JsonArrayPartsRequest(_model_base.Model): def __init__( self, *, - profile_image: bytes, + profile_image: FileType, previous_addresses: List["_models.Address"], ): ... @@ -179,12 +180,12 @@ class JsonPartRequest(_model_base.Model): :ivar address: Required. :vartype address: ~payload.multipart.models.Address :ivar profile_image: Required. - :vartype profile_image: bytes + :vartype profile_image: filetype """ address: "_models.Address" = rest_field() """Required.""" - profile_image: bytes = rest_field(name="profileImage", format="base64") + profile_image: FileType = rest_field(name="profileImage") """Required.""" @overload @@ -192,7 +193,7 @@ def __init__( self, *, address: "_models.Address", - profile_image: bytes, + profile_image: FileType, ): ... @@ -213,21 +214,21 @@ class MultiBinaryPartsRequest(_model_base.Model): All required parameters must be populated in order to send to server. :ivar profile_image: Required. - :vartype profile_image: bytes + :vartype profile_image: filetype :ivar picture: - :vartype picture: bytes + :vartype picture: filetype """ - profile_image: bytes = rest_field(name="profileImage", format="base64") + profile_image: FileType = rest_field(name="profileImage") """Required.""" - picture: Optional[bytes] = rest_field(format="base64") + picture: Optional[FileType] = rest_field() @overload def __init__( self, *, - profile_image: bytes, - picture: Optional[bytes] = None, + profile_image: FileType, + picture: Optional[FileType] = None, ): ... @@ -250,12 +251,12 @@ class MultiPartRequest(_model_base.Model): :ivar id: Required. :vartype id: str :ivar profile_image: Required. - :vartype profile_image: bytes + :vartype profile_image: filetype """ id: str = rest_field() """Required.""" - profile_image: bytes = rest_field(name="profileImage", format="base64") + profile_image: FileType = rest_field(name="profileImage") """Required.""" @overload @@ -263,7 +264,7 @@ def __init__( self, *, id: str, # pylint: disable=redefined-builtin - profile_image: bytes, + profile_image: FileType, ): ... diff --git a/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/operations/_operations.py b/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/operations/_operations.py index 546fe0e0d8b..f0620ed61f0 100644 --- a/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/operations/_operations.py +++ b/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/operations/_operations.py @@ -6,6 +6,7 @@ # Code generated by Unbranded (R) Python Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- +import json import sys from typing import Any, Callable, Dict, Optional, TypeVar, Union, overload @@ -22,8 +23,8 @@ from corehttp.utils import case_insensitive_dict from .. import models as _models +from .._model_base import SdkJSONEncoder from .._serialization import Serializer -from .._vendor import handle_multipart_form_data_body if sys.version_info >= (3, 9): from collections.abc import MutableMapping @@ -43,6 +44,10 @@ def build_form_data_basic_request(**kwargs: Any) -> HttpRequest: # Construct URL _url = "/multipart/form-data/mixed-parts" + # Construct headers + if content_type is not None: + _headers["content-type"] = _SERIALIZER.header("content_type", content_type, "str") + return HttpRequest(method="POST", url=_url, headers=_headers, **kwargs) @@ -52,6 +57,10 @@ def build_form_data_complex_request(**kwargs: Any) -> HttpRequest: # Construct URL _url = "/multipart/form-data/complex-parts" + # Construct headers + if content_type is not None: + _headers["content-type"] = _SERIALIZER.header("content_type", content_type, "str") + return HttpRequest(method="POST", url=_url, headers=_headers, **kwargs) @@ -61,6 +70,10 @@ def build_form_data_json_part_request(**kwargs: Any) -> HttpRequest: # Construct URL _url = "/multipart/form-data/json-part" + # Construct headers + if content_type is not None: + _headers["content-type"] = _SERIALIZER.header("content_type", content_type, "str") + return HttpRequest(method="POST", url=_url, headers=_headers, **kwargs) @@ -70,6 +83,10 @@ def build_form_data_binary_array_parts_request(**kwargs: Any) -> HttpRequest: # # Construct URL _url = "/multipart/form-data/binary-array-parts" + # Construct headers + if content_type is not None: + _headers["content-type"] = _SERIALIZER.header("content_type", content_type, "str") + return HttpRequest(method="POST", url=_url, headers=_headers, **kwargs) @@ -79,6 +96,10 @@ def build_form_data_json_array_parts_request(**kwargs: Any) -> HttpRequest: # Construct URL _url = "/multipart/form-data/json-array-parts" + # Construct headers + if content_type is not None: + _headers["content-type"] = _SERIALIZER.header("content_type", content_type, "str") + return HttpRequest(method="POST", url=_url, headers=_headers, **kwargs) @@ -88,6 +109,10 @@ def build_form_data_multi_binary_parts_request(**kwargs: Any) -> HttpRequest: # # Construct URL _url = "/multipart/form-data/multi-binary-parts" + # Construct headers + if content_type is not None: + _headers["content-type"] = _SERIALIZER.header("content_type", content_type, "str") + return HttpRequest(method="POST", url=_url, headers=_headers, **kwargs) @@ -126,7 +151,7 @@ def basic( # pylint: disable=inconsistent-return-statements # JSON input template you can fill out and use as your body input. body = { "id": "str", # Required. - "profileImage": bytes("bytes", encoding="utf-8") # Required. + "profileImage": {} # Required. } """ @@ -158,7 +183,7 @@ def basic( # pylint: disable=inconsistent-return-statements # JSON input template you can fill out and use as your body input. body = { "id": "str", # Required. - "profileImage": bytes("bytes", encoding="utf-8") # Required. + "profileImage": {} # Required. } """ error_map = { @@ -174,11 +199,16 @@ def basic( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) - file_properties = ["profileImage"] - _files = handle_multipart_form_data_body(body, file_properties) + content_type = content_type or "multipart/form-data" + _content = None + if isinstance(body, _model_base.Model): + _files = [] + _files.append(self.profile_image) + elif isinstance(body, MutableMapping): + _content = body _request = build_form_data_basic_request( - files=_files, + content=_content, headers=_headers, params=_params, ) @@ -222,14 +252,14 @@ def complex( # pylint: disable=inconsistent-return-statements }, "id": "str", # Required. "pictures": [ - bytes("bytes", encoding="utf-8") # Required. + {} # Required. ], "previousAddresses": [ { "city": "str" # Required. } ], - "profileImage": bytes("bytes", encoding="utf-8") # Required. + "profileImage": {} # Required. } """ @@ -265,14 +295,14 @@ def complex( # pylint: disable=inconsistent-return-statements }, "id": "str", # Required. "pictures": [ - bytes("bytes", encoding="utf-8") # Required. + {} # Required. ], "previousAddresses": [ { "city": "str" # Required. } ], - "profileImage": bytes("bytes", encoding="utf-8") # Required. + "profileImage": {} # Required. } """ error_map = { @@ -288,11 +318,16 @@ def complex( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) - file_properties = ["profileImage", "pictures"] - _files = handle_multipart_form_data_body(body, file_properties) + content_type = content_type or "multipart/form-data" + _content = None + if isinstance(body, _model_base.Model): + _files = [] + _files.append(self.profile_image) + elif isinstance(body, MutableMapping): + _content = body _request = build_form_data_complex_request( - files=_files, + content=_content, headers=_headers, params=_params, ) @@ -334,7 +369,7 @@ def json_part( # pylint: disable=inconsistent-return-statements "address": { "city": "str" # Required. }, - "profileImage": bytes("bytes", encoding="utf-8") # Required. + "profileImage": {} # Required. } """ @@ -368,7 +403,7 @@ def json_part( # pylint: disable=inconsistent-return-statements "address": { "city": "str" # Required. }, - "profileImage": bytes("bytes", encoding="utf-8") # Required. + "profileImage": {} # Required. } """ error_map = { @@ -384,11 +419,16 @@ def json_part( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) - file_properties = ["profileImage"] - _files = handle_multipart_form_data_body(body, file_properties) + content_type = content_type or "multipart/form-data" + _content = None + if isinstance(body, _model_base.Model): + _files = [] + _files.append(self.profile_image) + elif isinstance(body, MutableMapping): + _content = body _request = build_form_data_json_part_request( - files=_files, + content=_content, headers=_headers, params=_params, ) @@ -429,7 +469,7 @@ def binary_array_parts( # pylint: disable=inconsistent-return-statements body = { "id": "str", # Required. "pictures": [ - bytes("bytes", encoding="utf-8") # Required. + {} # Required. ] } """ @@ -463,7 +503,7 @@ def binary_array_parts( # pylint: disable=inconsistent-return-statements body = { "id": "str", # Required. "pictures": [ - bytes("bytes", encoding="utf-8") # Required. + {} # Required. ] } """ @@ -480,11 +520,15 @@ def binary_array_parts( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) - file_properties = ["pictures"] - _files = handle_multipart_form_data_body(body, file_properties) + content_type = content_type or "multipart/form-data" + _content = None + if isinstance(body, _model_base.Model): + _files = [] + elif isinstance(body, MutableMapping): + _content = body _request = build_form_data_binary_array_parts_request( - files=_files, + content=_content, headers=_headers, params=_params, ) @@ -528,7 +572,7 @@ def json_array_parts( # pylint: disable=inconsistent-return-statements "city": "str" # Required. } ], - "profileImage": bytes("bytes", encoding="utf-8") # Required. + "profileImage": {} # Required. } """ @@ -564,7 +608,7 @@ def json_array_parts( # pylint: disable=inconsistent-return-statements "city": "str" # Required. } ], - "profileImage": bytes("bytes", encoding="utf-8") # Required. + "profileImage": {} # Required. } """ error_map = { @@ -580,11 +624,16 @@ def json_array_parts( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) - file_properties = ["profileImage"] - _files = handle_multipart_form_data_body(body, file_properties) + content_type = content_type or "multipart/form-data" + _content = None + if isinstance(body, _model_base.Model): + _files = [] + _files.append(self.profile_image) + elif isinstance(body, MutableMapping): + _content = body _request = build_form_data_json_array_parts_request( - files=_files, + content=_content, headers=_headers, params=_params, ) @@ -623,8 +672,8 @@ def multi_binary_parts( # pylint: disable=inconsistent-return-statements # JSON input template you can fill out and use as your body input. body = { - "profileImage": bytes("bytes", encoding="utf-8"), # Required. - "picture": bytes("bytes", encoding="utf-8") # Optional. + "profileImage": {}, # Required. + "picture": {} # Optional. } """ @@ -655,8 +704,8 @@ def multi_binary_parts( # pylint: disable=inconsistent-return-statements # JSON input template you can fill out and use as your body input. body = { - "profileImage": bytes("bytes", encoding="utf-8"), # Required. - "picture": bytes("bytes", encoding="utf-8") # Optional. + "profileImage": {}, # Required. + "picture": {} # Optional. } """ error_map = { @@ -672,11 +721,17 @@ def multi_binary_parts( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) - file_properties = ["profileImage", "picture"] - _files = handle_multipart_form_data_body(body, file_properties) + content_type = content_type or "multipart/form-data" + _content = None + if isinstance(body, _model_base.Model): + _files = [] + _files.append(self.profile_image) + _files.append(self.picture) + elif isinstance(body, MutableMapping): + _content = body _request = build_form_data_multi_binary_parts_request( - files=_files, + content=_content, headers=_headers, params=_params, ) From 7280ce866a7f92d7835fd1b8a10be0787d2cf131 Mon Sep 17 00:00:00 2001 From: iscai-msft Date: Mon, 29 Jan 2024 18:02:08 -0500 Subject: [PATCH 10/45] don't use unreleased tcgc --- packages/typespec-python/package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/typespec-python/package.json b/packages/typespec-python/package.json index 4fc49150451..63633593bdd 100644 --- a/packages/typespec-python/package.json +++ b/packages/typespec-python/package.json @@ -43,7 +43,7 @@ ], "peerDependencies": { "@azure-tools/typespec-azure-core": ">=0.38.0 <1.0.0", - "@azure-tools/typespec-client-generator-core": "0.39.0-dev.2", + "@azure-tools/typespec-client-generator-core": ">=0.38.0 <1.0.0", "@typespec/compiler": ">=0.52.0 <1.0.0", "@typespec/http": ">=0.52.0 <1.0.0", "@typespec/rest": ">=0.52.0 <1.0.0", @@ -74,7 +74,7 @@ "rimraf": "~5.0.0", "typescript": "~5.1.3", "@azure-tools/typespec-azure-core": "~0.38.0", - "@azure-tools/typespec-client-generator-core": "0.39.0-dev.2", + "@azure-tools/typespec-client-generator-core": "~0.38.0", "@typespec/compiler": "~0.52.0", "@typespec/http": "~0.52.0", "@typespec/rest": "~0.52.0", From 3d78277ec32f4f756967d3a78fa9618190b4b99d Mon Sep 17 00:00:00 2001 From: iscai-msft Date: Tue, 30 Jan 2024 15:46:51 -0500 Subject: [PATCH 11/45] revert test changes to multipart --- .../payload/multipart/_vendor.py | 60 ++----- .../multipart/aio/operations/_operations.py | 59 +++++-- .../multipart/operations/_operations.py | 59 +++++-- .../test/azure/requirements.txt | 2 +- .../test_payload_multipart_async.py | 71 +++++++++ .../test_payload_multipart.py | 69 +++++++++ .../payload/multipart/_vendor.py | 57 +++++++ .../multipart/aio/operations/_operations.py | 122 +++++++-------- .../payload/multipart/models/_models.py | 49 +++--- .../multipart/operations/_operations.py | 146 ++++++++---------- 10 files changed, 449 insertions(+), 245 deletions(-) create mode 100644 packages/typespec-python/test/generic_mock_api_tests/asynctests/test_payload_multipart_async.py create mode 100644 packages/typespec-python/test/generic_mock_api_tests/test_payload_multipart.py create mode 100644 packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/_vendor.py diff --git a/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/_vendor.py b/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/_vendor.py index 6aa7bf1f7b5..03d44e41296 100644 --- a/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/_vendor.py +++ b/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/_vendor.py @@ -5,10 +5,10 @@ # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from io import IOBase +from io import BytesIO, IOBase import json import sys -from typing import Any, List, Tuple, Union +from typing import Any, Union import uuid from ._model_base import Model, SdkJSONEncoder @@ -19,19 +19,16 @@ from typing import MutableMapping # type: ignore # pylint: disable=ungrouped-imports -JSON = MutableMapping[str, Any] # pylint: disable=unsubscriptable-object +class NamedBytesIO(BytesIO): + def __init__(self, name: str, *args, **kwargs): + super().__init__(*args, **kwargs) + self.name = name -# file-like tuple could be `(filename, IO (or bytes))` or `(filename, IO (or bytes), content_type)` -FileType = Union[IOBase, bytes] -FileTuple = Union[Tuple[str, FileType], Tuple[str, FileType, str]] -MultiPartFile = Union[IOBase, bytes, FileTuple] -HandledMultiPartFile = Union[IOBase, FileTuple] - -def multipart_file(file: MultiPartFile) -> HandledMultiPartFile: - if isinstance(file, (IOBase, tuple)): +def multipart_file(file: Union[IOBase, bytes]) -> IOBase: + if isinstance(file, IOBase): return file - return ("auto-name-" + str(uuid.uuid4()), file) + return NamedBytesIO("auto-name-" + str(uuid.uuid4()), file) def multipart_data(data: Any) -> Any: @@ -40,16 +37,12 @@ def multipart_data(data: Any) -> Any: return data -def handle_multipart_form_data_model( - body: Model, file_properties: List[str] -) -> JSON: # pylint: disable=unsubscriptable-object +def handle_multipart_form_data_model(body: Model) -> MutableMapping[str, Any]: # pylint: disable=unsubscriptable-object """handle first layer of model. If its value is bytes or IO, replace it with raw value instead of serialized value. :param body: The model to handle. - :type body: ._model_base.Model - :param file_properties: The properties of the model that are file type. - :type file_properties: list[str] + :type body: ~payload.multipart._model_base.Model :return: The handled model. :rtype: MutableMapping[str, Any] """ @@ -57,31 +50,8 @@ def handle_multipart_form_data_model( rest_name_attr = {v._rest_name: k for k, v in body._attr_to_rest_field.items()} # pylint: disable=protected-access for rest_name in result.keys(): attr = rest_name_attr.get(rest_name) - if attr is not None and rest_name in file_properties: - result[rest_name] = getattr(body, attr, None) + if attr is not None: + raw_value = getattr(body, attr, None) + if isinstance(raw_value, (bytes, IOBase)): + result[rest_name] = raw_value return result - - -def handle_multipart_form_data_body( - body: Union[Model, JSON], file_properties: List[str] -) -> List[Tuple[str, HandledMultiPartFile]]: - """handle multipart form data body. - - :param body: The body to handle. - :type body: ._model_base.Model or dict[str, Any] - :param file_properties: The properties of the model that are file type. - :type file_properties: list[str] - :return: The handled body. - :rtype: list[tuple[str, HandledMultiPartFile]] - """ - _body = handle_multipart_form_data_model(body, file_properties) if isinstance(body, Model) else body - files = [] - for field_name, value in _body.items(): - if field_name in file_properties: - if isinstance(value, list): - files.extend([(field_name, multipart_file(i)) for i in value]) - else: - files.append((field_name, multipart_file(value))) - else: - files.append((field_name, multipart_data(value))) - return files diff --git a/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/aio/operations/_operations.py b/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/aio/operations/_operations.py index 5745aadfccb..d62b74e1c01 100644 --- a/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/aio/operations/_operations.py +++ b/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/aio/operations/_operations.py @@ -6,6 +6,7 @@ # Code generated by Microsoft (R) Python Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- +from io import IOBase import sys from typing import Any, Callable, Dict, Optional, TypeVar, Union, overload @@ -21,8 +22,8 @@ from azure.core.rest import AsyncHttpResponse, HttpRequest from azure.core.tracing.decorator_async import distributed_trace_async -from ... import models as _models -from ..._vendor import handle_multipart_form_data_body +from ... import _model_base, models as _models +from ..._vendor import handle_multipart_form_data_model, multipart_data, multipart_file from ...operations._operations import ( build_form_data_basic_request, build_form_data_binary_array_parts_request, @@ -125,10 +126,15 @@ async def basic( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) - file_properties = ["profileImage"] - _files = handle_multipart_form_data_body(body, file_properties) + if isinstance(body, _model_base.Model): + _body = handle_multipart_form_data_model(body) + else: + _body = body + _files = {k: multipart_file(v) for k, v in _body.items() if isinstance(v, (IOBase, bytes))} + _data = {k: multipart_data(v) for k, v in _body.items() if not isinstance(v, (IOBase, bytes))} _request = build_form_data_basic_request( + data=_data, files=_files, headers=_headers, params=_params, @@ -240,10 +246,15 @@ async def complex( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) - file_properties = ["profileImage", "pictures"] - _files = handle_multipart_form_data_body(body, file_properties) + if isinstance(body, _model_base.Model): + _body = handle_multipart_form_data_model(body) + else: + _body = body + _files = {k: multipart_file(v) for k, v in _body.items() if isinstance(v, (IOBase, bytes))} + _data = {k: multipart_data(v) for k, v in _body.items() if not isinstance(v, (IOBase, bytes))} _request = build_form_data_complex_request( + data=_data, files=_files, headers=_headers, params=_params, @@ -337,10 +348,15 @@ async def json_part( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) - file_properties = ["profileImage"] - _files = handle_multipart_form_data_body(body, file_properties) + if isinstance(body, _model_base.Model): + _body = handle_multipart_form_data_model(body) + else: + _body = body + _files = {k: multipart_file(v) for k, v in _body.items() if isinstance(v, (IOBase, bytes))} + _data = {k: multipart_data(v) for k, v in _body.items() if not isinstance(v, (IOBase, bytes))} _request = build_form_data_json_part_request( + data=_data, files=_files, headers=_headers, params=_params, @@ -436,10 +452,15 @@ async def binary_array_parts( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) - file_properties = ["pictures"] - _files = handle_multipart_form_data_body(body, file_properties) + if isinstance(body, _model_base.Model): + _body = handle_multipart_form_data_model(body) + else: + _body = body + _files = {k: multipart_file(v) for k, v in _body.items() if isinstance(v, (IOBase, bytes))} + _data = {k: multipart_data(v) for k, v in _body.items() if not isinstance(v, (IOBase, bytes))} _request = build_form_data_binary_array_parts_request( + data=_data, files=_files, headers=_headers, params=_params, @@ -539,10 +560,15 @@ async def json_array_parts( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) - file_properties = ["profileImage"] - _files = handle_multipart_form_data_body(body, file_properties) + if isinstance(body, _model_base.Model): + _body = handle_multipart_form_data_model(body) + else: + _body = body + _files = {k: multipart_file(v) for k, v in _body.items() if isinstance(v, (IOBase, bytes))} + _data = {k: multipart_data(v) for k, v in _body.items() if not isinstance(v, (IOBase, bytes))} _request = build_form_data_json_array_parts_request( + data=_data, files=_files, headers=_headers, params=_params, @@ -634,10 +660,15 @@ async def multi_binary_parts( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) - file_properties = ["profileImage", "picture"] - _files = handle_multipart_form_data_body(body, file_properties) + if isinstance(body, _model_base.Model): + _body = handle_multipart_form_data_model(body) + else: + _body = body + _files = {k: multipart_file(v) for k, v in _body.items() if isinstance(v, (IOBase, bytes))} + _data = {k: multipart_data(v) for k, v in _body.items() if not isinstance(v, (IOBase, bytes))} _request = build_form_data_multi_binary_parts_request( + data=_data, files=_files, headers=_headers, params=_params, diff --git a/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/operations/_operations.py b/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/operations/_operations.py index 0f5ec7db58e..2ca0678c8e9 100644 --- a/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/operations/_operations.py +++ b/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/operations/_operations.py @@ -6,6 +6,7 @@ # Code generated by Microsoft (R) Python Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- +from io import IOBase import sys from typing import Any, Callable, Dict, Optional, TypeVar, Union, overload @@ -22,9 +23,9 @@ from azure.core.tracing.decorator import distributed_trace from azure.core.utils import case_insensitive_dict -from .. import models as _models +from .. import _model_base, models as _models from .._serialization import Serializer -from .._vendor import handle_multipart_form_data_body +from .._vendor import handle_multipart_form_data_model, multipart_data, multipart_file if sys.version_info >= (3, 9): from collections.abc import MutableMapping @@ -176,10 +177,15 @@ def basic( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) - file_properties = ["profileImage"] - _files = handle_multipart_form_data_body(body, file_properties) + if isinstance(body, _model_base.Model): + _body = handle_multipart_form_data_model(body) + else: + _body = body + _files = {k: multipart_file(v) for k, v in _body.items() if isinstance(v, (IOBase, bytes))} + _data = {k: multipart_data(v) for k, v in _body.items() if not isinstance(v, (IOBase, bytes))} _request = build_form_data_basic_request( + data=_data, files=_files, headers=_headers, params=_params, @@ -291,10 +297,15 @@ def complex( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) - file_properties = ["profileImage", "pictures"] - _files = handle_multipart_form_data_body(body, file_properties) + if isinstance(body, _model_base.Model): + _body = handle_multipart_form_data_model(body) + else: + _body = body + _files = {k: multipart_file(v) for k, v in _body.items() if isinstance(v, (IOBase, bytes))} + _data = {k: multipart_data(v) for k, v in _body.items() if not isinstance(v, (IOBase, bytes))} _request = build_form_data_complex_request( + data=_data, files=_files, headers=_headers, params=_params, @@ -388,10 +399,15 @@ def json_part( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) - file_properties = ["profileImage"] - _files = handle_multipart_form_data_body(body, file_properties) + if isinstance(body, _model_base.Model): + _body = handle_multipart_form_data_model(body) + else: + _body = body + _files = {k: multipart_file(v) for k, v in _body.items() if isinstance(v, (IOBase, bytes))} + _data = {k: multipart_data(v) for k, v in _body.items() if not isinstance(v, (IOBase, bytes))} _request = build_form_data_json_part_request( + data=_data, files=_files, headers=_headers, params=_params, @@ -485,10 +501,15 @@ def binary_array_parts( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) - file_properties = ["pictures"] - _files = handle_multipart_form_data_body(body, file_properties) + if isinstance(body, _model_base.Model): + _body = handle_multipart_form_data_model(body) + else: + _body = body + _files = {k: multipart_file(v) for k, v in _body.items() if isinstance(v, (IOBase, bytes))} + _data = {k: multipart_data(v) for k, v in _body.items() if not isinstance(v, (IOBase, bytes))} _request = build_form_data_binary_array_parts_request( + data=_data, files=_files, headers=_headers, params=_params, @@ -586,10 +607,15 @@ def json_array_parts( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) - file_properties = ["profileImage"] - _files = handle_multipart_form_data_body(body, file_properties) + if isinstance(body, _model_base.Model): + _body = handle_multipart_form_data_model(body) + else: + _body = body + _files = {k: multipart_file(v) for k, v in _body.items() if isinstance(v, (IOBase, bytes))} + _data = {k: multipart_data(v) for k, v in _body.items() if not isinstance(v, (IOBase, bytes))} _request = build_form_data_json_array_parts_request( + data=_data, files=_files, headers=_headers, params=_params, @@ -679,10 +705,15 @@ def multi_binary_parts( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) - file_properties = ["profileImage", "picture"] - _files = handle_multipart_form_data_body(body, file_properties) + if isinstance(body, _model_base.Model): + _body = handle_multipart_form_data_model(body) + else: + _body = body + _files = {k: multipart_file(v) for k, v in _body.items() if isinstance(v, (IOBase, bytes))} + _data = {k: multipart_data(v) for k, v in _body.items() if not isinstance(v, (IOBase, bytes))} _request = build_form_data_multi_binary_parts_request( + data=_data, files=_files, headers=_headers, params=_params, diff --git a/packages/typespec-python/test/azure/requirements.txt b/packages/typespec-python/test/azure/requirements.txt index 30daf52fb5d..f01619e4bb7 100644 --- a/packages/typespec-python/test/azure/requirements.txt +++ b/packages/typespec-python/test/azure/requirements.txt @@ -2,7 +2,7 @@ aiohttp;python_full_version>="3.5.2" requests==2.31.0 pytest pytest-asyncio==0.14.0;python_full_version>="3.5.2" -git+https://github.com/iscai-msft/azure-sdk-for-python@multipartSameFileName#subdirectory=sdk/core/azure-core +azure-core==1.29.5 # only for azure -e ./generated/azure-mgmt-spheredpg -e ./generated/azure-mgmt-spheremsrest diff --git a/packages/typespec-python/test/generic_mock_api_tests/asynctests/test_payload_multipart_async.py b/packages/typespec-python/test/generic_mock_api_tests/asynctests/test_payload_multipart_async.py new file mode 100644 index 00000000000..ea13afb3288 --- /dev/null +++ b/packages/typespec-python/test/generic_mock_api_tests/asynctests/test_payload_multipart_async.py @@ -0,0 +1,71 @@ +# ------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for +# license information. +# -------------------------------------------------------------------------- +from typing import Dict, Any +from pathlib import Path +import pytest +from payload.multipart.aio import MultiPartClient +from payload.multipart import models +from payload.multipart._model_base import Model + +JPG = Path(__file__).parent.parent / "data/image.jpg" +PNG = Path(__file__).parent.parent / "data/image.png" + + +@pytest.fixture +async def client(): + async with MultiPartClient(endpoint="http://localhost:3000") as client: + yield client + + +@pytest.mark.asyncio +@pytest.mark.parametrize( + "op_name,model_class,data,file", + [ + ("basic", models.MultiPartRequest, {"id": "123"}, {"profileImage": JPG}), + ( + "multi_binary_parts", + models.MultiBinaryPartsRequest, + {}, + {"profileImage": JPG, "picture": PNG}, + ), + ( + "multi_binary_parts", + models.MultiBinaryPartsRequest, + {}, + {"profileImage": JPG}, + ), + ( + "json_part", + models.JsonPartRequest, + {"address": models.Address(city="X")}, + {"profileImage": JPG}, + ), + ( + "json_array_parts", + models.JsonArrayPartsRequest, + {"previousAddresses": [models.Address(city="Y"), models.Address(city="Z")]}, + {"profileImage": JPG}, + ), + ], +) +async def test_multi_part(client: MultiPartClient, op_name, model_class, data, file): + op = getattr(client.form_data, op_name) + # test bytes + body = {k: open(str(v), "rb").read() for k, v in file.items()} + body.update(data) + await op(body) + await op(model_class(body)) + + # test io + body = {k: open(str(v), "rb") for k, v in file.items()} + body.update(data) + await op(body) + + body = {k: open(str(v), "rb") for k, v in file.items()} + body.update(data) + with pytest.raises(TypeError): + # caused by deepcopy when DPG model init + await op(model_class(body)) diff --git a/packages/typespec-python/test/generic_mock_api_tests/test_payload_multipart.py b/packages/typespec-python/test/generic_mock_api_tests/test_payload_multipart.py new file mode 100644 index 00000000000..3219a91a218 --- /dev/null +++ b/packages/typespec-python/test/generic_mock_api_tests/test_payload_multipart.py @@ -0,0 +1,69 @@ +# ------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for +# license information. +# -------------------------------------------------------------------------- +from typing import Dict, Any +from pathlib import Path +import pytest +from payload.multipart import MultiPartClient, models +from payload.multipart._model_base import Model + +JPG = Path(__file__).parent / "data/image.jpg" +PNG = Path(__file__).parent / "data/image.png" + + +@pytest.fixture +def client(): + with MultiPartClient(endpoint="http://localhost:3000") as client: + yield client + + +@pytest.mark.parametrize( + "op_name,model_class,data,file", + [ + ("basic", models.MultiPartRequest, {"id": "123"}, {"profileImage": JPG}), + ( + "multi_binary_parts", + models.MultiBinaryPartsRequest, + {}, + {"profileImage": JPG, "picture": PNG}, + ), + ( + "multi_binary_parts", + models.MultiBinaryPartsRequest, + {}, + {"profileImage": JPG}, + ), + ( + "json_part", + models.JsonPartRequest, + {"address": models.Address(city="X")}, + {"profileImage": JPG}, + ), + ( + "json_array_parts", + models.JsonArrayPartsRequest, + {"previousAddresses": [models.Address(city="Y"), models.Address(city="Z")]}, + {"profileImage": JPG}, + ), + ], +) +def test_multi_part(client: MultiPartClient, op_name, model_class, data, file): + op = getattr(client.form_data, op_name) + # test bytes + body = {k: open(str(v), "rb").read() for k, v in file.items()} + body.update(data) + op(body) + op(model_class(body)) + + # test io + body = {k: open(str(v), "rb") for k, v in file.items()} + body.update(data) + op(body) + + body = {k: open(str(v), "rb") for k, v in file.items()} + body.update(data) + with pytest.raises(TypeError): + # caused by deepcopy when DPG model init + op(model_class(body)) diff --git a/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/_vendor.py b/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/_vendor.py new file mode 100644 index 00000000000..c559ea1ec67 --- /dev/null +++ b/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/_vendor.py @@ -0,0 +1,57 @@ +# -------------------------------------------------------------------------- +# Copyright (c) Unbranded Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for license information. +# Code generated by Unbranded (R) Python Code Generator. +# Changes may cause incorrect behavior and will be lost if the code is regenerated. +# -------------------------------------------------------------------------- + +from io import BytesIO, IOBase +import json +import sys +from typing import Any, Union +import uuid + +from ._model_base import Model, SdkJSONEncoder + +if sys.version_info >= (3, 9): + from collections.abc import MutableMapping +else: + from typing import MutableMapping # type: ignore # pylint: disable=ungrouped-imports + + +class NamedBytesIO(BytesIO): + def __init__(self, name: str, *args, **kwargs): + super().__init__(*args, **kwargs) + self.name = name + + +def multipart_file(file: Union[IOBase, bytes]) -> IOBase: + if isinstance(file, IOBase): + return file + return NamedBytesIO("auto-name-" + str(uuid.uuid4()), file) + + +def multipart_data(data: Any) -> Any: + if isinstance(data, (list, tuple, dict, Model)): + return json.dumps(data, cls=SdkJSONEncoder, exclude_readonly=True) + return data + + +def handle_multipart_form_data_model(body: Model) -> MutableMapping[str, Any]: # pylint: disable=unsubscriptable-object + """handle first layer of model. + If its value is bytes or IO, replace it with raw value instead of serialized value. + + :param body: The model to handle. + :type body: ~payload.multipart._model_base.Model + :return: The handled model. + :rtype: MutableMapping[str, Any] + """ + result = body.as_dict() + rest_name_attr = {v._rest_name: k for k, v in body._attr_to_rest_field.items()} # pylint: disable=protected-access + for rest_name in result.keys(): + attr = rest_name_attr.get(rest_name) + if attr is not None: + raw_value = getattr(body, attr, None) + if isinstance(raw_value, (bytes, IOBase)): + result[rest_name] = raw_value + return result diff --git a/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/aio/operations/_operations.py b/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/aio/operations/_operations.py index 114cc22fa9e..d3dca59c18e 100644 --- a/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/aio/operations/_operations.py +++ b/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/aio/operations/_operations.py @@ -6,7 +6,7 @@ # Code generated by Unbranded (R) Python Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -import json +from io import IOBase import sys from typing import Any, Callable, Dict, Optional, TypeVar, Union, overload @@ -21,8 +21,8 @@ from corehttp.rest import AsyncHttpResponse, HttpRequest from corehttp.runtime.pipeline import PipelineResponse -from ... import models as _models -from ..._model_base import SdkJSONEncoder +from ... import _model_base, models as _models +from ..._vendor import handle_multipart_form_data_model, multipart_data, multipart_file from ...operations._operations import ( build_form_data_basic_request, build_form_data_binary_array_parts_request, @@ -76,7 +76,7 @@ async def basic( # pylint: disable=inconsistent-return-statements # JSON input template you can fill out and use as your body input. body = { "id": "str", # Required. - "profileImage": {} # Required. + "profileImage": bytes("bytes", encoding="utf-8") # Required. } """ @@ -108,7 +108,7 @@ async def basic( # pylint: disable=inconsistent-return-statements # JSON input template you can fill out and use as your body input. body = { "id": "str", # Required. - "profileImage": {} # Required. + "profileImage": bytes("bytes", encoding="utf-8") # Required. } """ error_map = { @@ -124,16 +124,16 @@ async def basic( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) - content_type = content_type or "multipart/form-data" - _content = None if isinstance(body, _model_base.Model): - _files = [] - _files.append(self.profile_image) - elif isinstance(body, MutableMapping): - _content = body + _body = handle_multipart_form_data_model(body) + else: + _body = body + _files = {k: multipart_file(v) for k, v in _body.items() if isinstance(v, (IOBase, bytes))} + _data = {k: multipart_data(v) for k, v in _body.items() if not isinstance(v, (IOBase, bytes))} _request = build_form_data_basic_request( - content=_content, + data=_data, + files=_files, headers=_headers, params=_params, ) @@ -177,14 +177,14 @@ async def complex( # pylint: disable=inconsistent-return-statements }, "id": "str", # Required. "pictures": [ - {} # Required. + bytes("bytes", encoding="utf-8") # Required. ], "previousAddresses": [ { "city": "str" # Required. } ], - "profileImage": {} # Required. + "profileImage": bytes("bytes", encoding="utf-8") # Required. } """ @@ -220,14 +220,14 @@ async def complex( # pylint: disable=inconsistent-return-statements }, "id": "str", # Required. "pictures": [ - {} # Required. + bytes("bytes", encoding="utf-8") # Required. ], "previousAddresses": [ { "city": "str" # Required. } ], - "profileImage": {} # Required. + "profileImage": bytes("bytes", encoding="utf-8") # Required. } """ error_map = { @@ -243,16 +243,16 @@ async def complex( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) - content_type = content_type or "multipart/form-data" - _content = None if isinstance(body, _model_base.Model): - _files = [] - _files.append(self.profile_image) - elif isinstance(body, MutableMapping): - _content = body + _body = handle_multipart_form_data_model(body) + else: + _body = body + _files = {k: multipart_file(v) for k, v in _body.items() if isinstance(v, (IOBase, bytes))} + _data = {k: multipart_data(v) for k, v in _body.items() if not isinstance(v, (IOBase, bytes))} _request = build_form_data_complex_request( - content=_content, + data=_data, + files=_files, headers=_headers, params=_params, ) @@ -294,7 +294,7 @@ async def json_part( # pylint: disable=inconsistent-return-statements "address": { "city": "str" # Required. }, - "profileImage": {} # Required. + "profileImage": bytes("bytes", encoding="utf-8") # Required. } """ @@ -328,7 +328,7 @@ async def json_part( # pylint: disable=inconsistent-return-statements "address": { "city": "str" # Required. }, - "profileImage": {} # Required. + "profileImage": bytes("bytes", encoding="utf-8") # Required. } """ error_map = { @@ -344,16 +344,16 @@ async def json_part( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) - content_type = content_type or "multipart/form-data" - _content = None if isinstance(body, _model_base.Model): - _files = [] - _files.append(self.profile_image) - elif isinstance(body, MutableMapping): - _content = body + _body = handle_multipart_form_data_model(body) + else: + _body = body + _files = {k: multipart_file(v) for k, v in _body.items() if isinstance(v, (IOBase, bytes))} + _data = {k: multipart_data(v) for k, v in _body.items() if not isinstance(v, (IOBase, bytes))} _request = build_form_data_json_part_request( - content=_content, + data=_data, + files=_files, headers=_headers, params=_params, ) @@ -394,7 +394,7 @@ async def binary_array_parts( # pylint: disable=inconsistent-return-statements body = { "id": "str", # Required. "pictures": [ - {} # Required. + bytes("bytes", encoding="utf-8") # Required. ] } """ @@ -430,7 +430,7 @@ async def binary_array_parts( # pylint: disable=inconsistent-return-statements body = { "id": "str", # Required. "pictures": [ - {} # Required. + bytes("bytes", encoding="utf-8") # Required. ] } """ @@ -447,15 +447,16 @@ async def binary_array_parts( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) - content_type = content_type or "multipart/form-data" - _content = None if isinstance(body, _model_base.Model): - _files = [] - elif isinstance(body, MutableMapping): - _content = body + _body = handle_multipart_form_data_model(body) + else: + _body = body + _files = {k: multipart_file(v) for k, v in _body.items() if isinstance(v, (IOBase, bytes))} + _data = {k: multipart_data(v) for k, v in _body.items() if not isinstance(v, (IOBase, bytes))} _request = build_form_data_binary_array_parts_request( - content=_content, + data=_data, + files=_files, headers=_headers, params=_params, ) @@ -499,7 +500,7 @@ async def json_array_parts( # pylint: disable=inconsistent-return-statements "city": "str" # Required. } ], - "profileImage": {} # Required. + "profileImage": bytes("bytes", encoding="utf-8") # Required. } """ @@ -537,7 +538,7 @@ async def json_array_parts( # pylint: disable=inconsistent-return-statements "city": "str" # Required. } ], - "profileImage": {} # Required. + "profileImage": bytes("bytes", encoding="utf-8") # Required. } """ error_map = { @@ -553,16 +554,16 @@ async def json_array_parts( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) - content_type = content_type or "multipart/form-data" - _content = None if isinstance(body, _model_base.Model): - _files = [] - _files.append(self.profile_image) - elif isinstance(body, MutableMapping): - _content = body + _body = handle_multipart_form_data_model(body) + else: + _body = body + _files = {k: multipart_file(v) for k, v in _body.items() if isinstance(v, (IOBase, bytes))} + _data = {k: multipart_data(v) for k, v in _body.items() if not isinstance(v, (IOBase, bytes))} _request = build_form_data_json_array_parts_request( - content=_content, + data=_data, + files=_files, headers=_headers, params=_params, ) @@ -601,8 +602,8 @@ async def multi_binary_parts( # pylint: disable=inconsistent-return-statements # JSON input template you can fill out and use as your body input. body = { - "profileImage": {}, # Required. - "picture": {} # Optional. + "profileImage": bytes("bytes", encoding="utf-8"), # Required. + "picture": bytes("bytes", encoding="utf-8") # Optional. } """ @@ -635,8 +636,8 @@ async def multi_binary_parts( # pylint: disable=inconsistent-return-statements # JSON input template you can fill out and use as your body input. body = { - "profileImage": {}, # Required. - "picture": {} # Optional. + "profileImage": bytes("bytes", encoding="utf-8"), # Required. + "picture": bytes("bytes", encoding="utf-8") # Optional. } """ error_map = { @@ -652,17 +653,16 @@ async def multi_binary_parts( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) - content_type = content_type or "multipart/form-data" - _content = None if isinstance(body, _model_base.Model): - _files = [] - _files.append(self.profile_image) - _files.append(self.picture) - elif isinstance(body, MutableMapping): - _content = body + _body = handle_multipart_form_data_model(body) + else: + _body = body + _files = {k: multipart_file(v) for k, v in _body.items() if isinstance(v, (IOBase, bytes))} + _data = {k: multipart_data(v) for k, v in _body.items() if not isinstance(v, (IOBase, bytes))} _request = build_form_data_multi_binary_parts_request( - content=_content, + data=_data, + files=_files, headers=_headers, params=_params, ) diff --git a/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/models/_models.py b/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/models/_models.py index 3370e8e5ee7..3f7009ea407 100644 --- a/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/models/_models.py +++ b/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/models/_models.py @@ -7,7 +7,6 @@ # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from .._vendor import FileType from typing import Any, List, Mapping, Optional, TYPE_CHECKING, overload from .. import _model_base @@ -57,12 +56,12 @@ class BinaryArrayPartsRequest(_model_base.Model): :ivar id: Required. :vartype id: str :ivar pictures: Required. - :vartype pictures: list[filetype] + :vartype pictures: list[bytes] """ id: str = rest_field() """Required.""" - pictures: List[FileType] = rest_field() + pictures: List[bytes] = rest_field(format="base64") """Required.""" @overload @@ -70,7 +69,7 @@ def __init__( self, *, id: str, # pylint: disable=redefined-builtin - pictures: List[FileType], + pictures: List[bytes], ): ... @@ -95,22 +94,22 @@ class ComplexPartsRequest(_model_base.Model): :ivar address: Required. :vartype address: ~payload.multipart.models.Address :ivar profile_image: Required. - :vartype profile_image: filetype + :vartype profile_image: bytes :ivar previous_addresses: Required. :vartype previous_addresses: list[~payload.multipart.models.Address] :ivar pictures: Required. - :vartype pictures: list[filetype] + :vartype pictures: list[bytes] """ id: str = rest_field() """Required.""" address: "_models.Address" = rest_field() """Required.""" - profile_image: FileType = rest_field(name="profileImage") + profile_image: bytes = rest_field(name="profileImage", format="base64") """Required.""" previous_addresses: List["_models.Address"] = rest_field(name="previousAddresses") """Required.""" - pictures: List[FileType] = rest_field() + pictures: List[bytes] = rest_field(format="base64") """Required.""" @overload @@ -119,9 +118,9 @@ def __init__( *, id: str, # pylint: disable=redefined-builtin address: "_models.Address", - profile_image: FileType, + profile_image: bytes, previous_addresses: List["_models.Address"], - pictures: List[FileType], + pictures: List[bytes], ): ... @@ -142,12 +141,12 @@ class JsonArrayPartsRequest(_model_base.Model): All required parameters must be populated in order to send to server. :ivar profile_image: Required. - :vartype profile_image: filetype + :vartype profile_image: bytes :ivar previous_addresses: Required. :vartype previous_addresses: list[~payload.multipart.models.Address] """ - profile_image: FileType = rest_field(name="profileImage") + profile_image: bytes = rest_field(name="profileImage", format="base64") """Required.""" previous_addresses: List["_models.Address"] = rest_field(name="previousAddresses") """Required.""" @@ -156,7 +155,7 @@ class JsonArrayPartsRequest(_model_base.Model): def __init__( self, *, - profile_image: FileType, + profile_image: bytes, previous_addresses: List["_models.Address"], ): ... @@ -180,12 +179,12 @@ class JsonPartRequest(_model_base.Model): :ivar address: Required. :vartype address: ~payload.multipart.models.Address :ivar profile_image: Required. - :vartype profile_image: filetype + :vartype profile_image: bytes """ address: "_models.Address" = rest_field() """Required.""" - profile_image: FileType = rest_field(name="profileImage") + profile_image: bytes = rest_field(name="profileImage", format="base64") """Required.""" @overload @@ -193,7 +192,7 @@ def __init__( self, *, address: "_models.Address", - profile_image: FileType, + profile_image: bytes, ): ... @@ -214,21 +213,21 @@ class MultiBinaryPartsRequest(_model_base.Model): All required parameters must be populated in order to send to server. :ivar profile_image: Required. - :vartype profile_image: filetype + :vartype profile_image: bytes :ivar picture: - :vartype picture: filetype + :vartype picture: bytes """ - profile_image: FileType = rest_field(name="profileImage") + profile_image: bytes = rest_field(name="profileImage", format="base64") """Required.""" - picture: Optional[FileType] = rest_field() + picture: Optional[bytes] = rest_field(format="base64") @overload def __init__( self, *, - profile_image: FileType, - picture: Optional[FileType] = None, + profile_image: bytes, + picture: Optional[bytes] = None, ): ... @@ -251,12 +250,12 @@ class MultiPartRequest(_model_base.Model): :ivar id: Required. :vartype id: str :ivar profile_image: Required. - :vartype profile_image: filetype + :vartype profile_image: bytes """ id: str = rest_field() """Required.""" - profile_image: FileType = rest_field(name="profileImage") + profile_image: bytes = rest_field(name="profileImage", format="base64") """Required.""" @overload @@ -264,7 +263,7 @@ def __init__( self, *, id: str, # pylint: disable=redefined-builtin - profile_image: FileType, + profile_image: bytes, ): ... diff --git a/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/operations/_operations.py b/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/operations/_operations.py index f0620ed61f0..4feac538204 100644 --- a/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/operations/_operations.py +++ b/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/operations/_operations.py @@ -6,7 +6,7 @@ # Code generated by Unbranded (R) Python Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -import json +from io import IOBase import sys from typing import Any, Callable, Dict, Optional, TypeVar, Union, overload @@ -22,9 +22,9 @@ from corehttp.runtime.pipeline import PipelineResponse from corehttp.utils import case_insensitive_dict -from .. import models as _models -from .._model_base import SdkJSONEncoder +from .. import _model_base, models as _models from .._serialization import Serializer +from .._vendor import handle_multipart_form_data_model, multipart_data, multipart_file if sys.version_info >= (3, 9): from collections.abc import MutableMapping @@ -44,10 +44,6 @@ def build_form_data_basic_request(**kwargs: Any) -> HttpRequest: # Construct URL _url = "/multipart/form-data/mixed-parts" - # Construct headers - if content_type is not None: - _headers["content-type"] = _SERIALIZER.header("content_type", content_type, "str") - return HttpRequest(method="POST", url=_url, headers=_headers, **kwargs) @@ -57,10 +53,6 @@ def build_form_data_complex_request(**kwargs: Any) -> HttpRequest: # Construct URL _url = "/multipart/form-data/complex-parts" - # Construct headers - if content_type is not None: - _headers["content-type"] = _SERIALIZER.header("content_type", content_type, "str") - return HttpRequest(method="POST", url=_url, headers=_headers, **kwargs) @@ -70,10 +62,6 @@ def build_form_data_json_part_request(**kwargs: Any) -> HttpRequest: # Construct URL _url = "/multipart/form-data/json-part" - # Construct headers - if content_type is not None: - _headers["content-type"] = _SERIALIZER.header("content_type", content_type, "str") - return HttpRequest(method="POST", url=_url, headers=_headers, **kwargs) @@ -83,10 +71,6 @@ def build_form_data_binary_array_parts_request(**kwargs: Any) -> HttpRequest: # # Construct URL _url = "/multipart/form-data/binary-array-parts" - # Construct headers - if content_type is not None: - _headers["content-type"] = _SERIALIZER.header("content_type", content_type, "str") - return HttpRequest(method="POST", url=_url, headers=_headers, **kwargs) @@ -96,10 +80,6 @@ def build_form_data_json_array_parts_request(**kwargs: Any) -> HttpRequest: # Construct URL _url = "/multipart/form-data/json-array-parts" - # Construct headers - if content_type is not None: - _headers["content-type"] = _SERIALIZER.header("content_type", content_type, "str") - return HttpRequest(method="POST", url=_url, headers=_headers, **kwargs) @@ -109,10 +89,6 @@ def build_form_data_multi_binary_parts_request(**kwargs: Any) -> HttpRequest: # # Construct URL _url = "/multipart/form-data/multi-binary-parts" - # Construct headers - if content_type is not None: - _headers["content-type"] = _SERIALIZER.header("content_type", content_type, "str") - return HttpRequest(method="POST", url=_url, headers=_headers, **kwargs) @@ -151,7 +127,7 @@ def basic( # pylint: disable=inconsistent-return-statements # JSON input template you can fill out and use as your body input. body = { "id": "str", # Required. - "profileImage": {} # Required. + "profileImage": bytes("bytes", encoding="utf-8") # Required. } """ @@ -183,7 +159,7 @@ def basic( # pylint: disable=inconsistent-return-statements # JSON input template you can fill out and use as your body input. body = { "id": "str", # Required. - "profileImage": {} # Required. + "profileImage": bytes("bytes", encoding="utf-8") # Required. } """ error_map = { @@ -199,16 +175,16 @@ def basic( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) - content_type = content_type or "multipart/form-data" - _content = None if isinstance(body, _model_base.Model): - _files = [] - _files.append(self.profile_image) - elif isinstance(body, MutableMapping): - _content = body + _body = handle_multipart_form_data_model(body) + else: + _body = body + _files = {k: multipart_file(v) for k, v in _body.items() if isinstance(v, (IOBase, bytes))} + _data = {k: multipart_data(v) for k, v in _body.items() if not isinstance(v, (IOBase, bytes))} _request = build_form_data_basic_request( - content=_content, + data=_data, + files=_files, headers=_headers, params=_params, ) @@ -252,14 +228,14 @@ def complex( # pylint: disable=inconsistent-return-statements }, "id": "str", # Required. "pictures": [ - {} # Required. + bytes("bytes", encoding="utf-8") # Required. ], "previousAddresses": [ { "city": "str" # Required. } ], - "profileImage": {} # Required. + "profileImage": bytes("bytes", encoding="utf-8") # Required. } """ @@ -295,14 +271,14 @@ def complex( # pylint: disable=inconsistent-return-statements }, "id": "str", # Required. "pictures": [ - {} # Required. + bytes("bytes", encoding="utf-8") # Required. ], "previousAddresses": [ { "city": "str" # Required. } ], - "profileImage": {} # Required. + "profileImage": bytes("bytes", encoding="utf-8") # Required. } """ error_map = { @@ -318,16 +294,16 @@ def complex( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) - content_type = content_type or "multipart/form-data" - _content = None if isinstance(body, _model_base.Model): - _files = [] - _files.append(self.profile_image) - elif isinstance(body, MutableMapping): - _content = body + _body = handle_multipart_form_data_model(body) + else: + _body = body + _files = {k: multipart_file(v) for k, v in _body.items() if isinstance(v, (IOBase, bytes))} + _data = {k: multipart_data(v) for k, v in _body.items() if not isinstance(v, (IOBase, bytes))} _request = build_form_data_complex_request( - content=_content, + data=_data, + files=_files, headers=_headers, params=_params, ) @@ -369,7 +345,7 @@ def json_part( # pylint: disable=inconsistent-return-statements "address": { "city": "str" # Required. }, - "profileImage": {} # Required. + "profileImage": bytes("bytes", encoding="utf-8") # Required. } """ @@ -403,7 +379,7 @@ def json_part( # pylint: disable=inconsistent-return-statements "address": { "city": "str" # Required. }, - "profileImage": {} # Required. + "profileImage": bytes("bytes", encoding="utf-8") # Required. } """ error_map = { @@ -419,16 +395,16 @@ def json_part( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) - content_type = content_type or "multipart/form-data" - _content = None if isinstance(body, _model_base.Model): - _files = [] - _files.append(self.profile_image) - elif isinstance(body, MutableMapping): - _content = body + _body = handle_multipart_form_data_model(body) + else: + _body = body + _files = {k: multipart_file(v) for k, v in _body.items() if isinstance(v, (IOBase, bytes))} + _data = {k: multipart_data(v) for k, v in _body.items() if not isinstance(v, (IOBase, bytes))} _request = build_form_data_json_part_request( - content=_content, + data=_data, + files=_files, headers=_headers, params=_params, ) @@ -469,7 +445,7 @@ def binary_array_parts( # pylint: disable=inconsistent-return-statements body = { "id": "str", # Required. "pictures": [ - {} # Required. + bytes("bytes", encoding="utf-8") # Required. ] } """ @@ -503,7 +479,7 @@ def binary_array_parts( # pylint: disable=inconsistent-return-statements body = { "id": "str", # Required. "pictures": [ - {} # Required. + bytes("bytes", encoding="utf-8") # Required. ] } """ @@ -520,15 +496,16 @@ def binary_array_parts( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) - content_type = content_type or "multipart/form-data" - _content = None if isinstance(body, _model_base.Model): - _files = [] - elif isinstance(body, MutableMapping): - _content = body + _body = handle_multipart_form_data_model(body) + else: + _body = body + _files = {k: multipart_file(v) for k, v in _body.items() if isinstance(v, (IOBase, bytes))} + _data = {k: multipart_data(v) for k, v in _body.items() if not isinstance(v, (IOBase, bytes))} _request = build_form_data_binary_array_parts_request( - content=_content, + data=_data, + files=_files, headers=_headers, params=_params, ) @@ -572,7 +549,7 @@ def json_array_parts( # pylint: disable=inconsistent-return-statements "city": "str" # Required. } ], - "profileImage": {} # Required. + "profileImage": bytes("bytes", encoding="utf-8") # Required. } """ @@ -608,7 +585,7 @@ def json_array_parts( # pylint: disable=inconsistent-return-statements "city": "str" # Required. } ], - "profileImage": {} # Required. + "profileImage": bytes("bytes", encoding="utf-8") # Required. } """ error_map = { @@ -624,16 +601,16 @@ def json_array_parts( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) - content_type = content_type or "multipart/form-data" - _content = None if isinstance(body, _model_base.Model): - _files = [] - _files.append(self.profile_image) - elif isinstance(body, MutableMapping): - _content = body + _body = handle_multipart_form_data_model(body) + else: + _body = body + _files = {k: multipart_file(v) for k, v in _body.items() if isinstance(v, (IOBase, bytes))} + _data = {k: multipart_data(v) for k, v in _body.items() if not isinstance(v, (IOBase, bytes))} _request = build_form_data_json_array_parts_request( - content=_content, + data=_data, + files=_files, headers=_headers, params=_params, ) @@ -672,8 +649,8 @@ def multi_binary_parts( # pylint: disable=inconsistent-return-statements # JSON input template you can fill out and use as your body input. body = { - "profileImage": {}, # Required. - "picture": {} # Optional. + "profileImage": bytes("bytes", encoding="utf-8"), # Required. + "picture": bytes("bytes", encoding="utf-8") # Optional. } """ @@ -704,8 +681,8 @@ def multi_binary_parts( # pylint: disable=inconsistent-return-statements # JSON input template you can fill out and use as your body input. body = { - "profileImage": {}, # Required. - "picture": {} # Optional. + "profileImage": bytes("bytes", encoding="utf-8"), # Required. + "picture": bytes("bytes", encoding="utf-8") # Optional. } """ error_map = { @@ -721,17 +698,16 @@ def multi_binary_parts( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) - content_type = content_type or "multipart/form-data" - _content = None if isinstance(body, _model_base.Model): - _files = [] - _files.append(self.profile_image) - _files.append(self.picture) - elif isinstance(body, MutableMapping): - _content = body + _body = handle_multipart_form_data_model(body) + else: + _body = body + _files = {k: multipart_file(v) for k, v in _body.items() if isinstance(v, (IOBase, bytes))} + _data = {k: multipart_data(v) for k, v in _body.items() if not isinstance(v, (IOBase, bytes))} _request = build_form_data_multi_binary_parts_request( - content=_content, + data=_data, + files=_files, headers=_headers, params=_params, ) From fbc88e6e28b6057ad07c5541e4a3dd63b6a3f1aa Mon Sep 17 00:00:00 2001 From: iscai-msft Date: Tue, 30 Jan 2024 19:16:46 -0500 Subject: [PATCH 12/45] try to pass payload multipart, waiting on tcgc --- .../autorest/codegen/models/__init__.py | 2 +- .../autorest/codegen/models/base.py | 4 + .../autorest/codegen/models/combined_type.py | 4 +- .../autorest/codegen/models/constant_type.py | 4 + .../codegen/models/dictionary_type.py | 4 + .../autorest/codegen/models/list_type.py | 4 + .../autorest/codegen/models/model_type.py | 14 +- .../autorest/codegen/models/operation.py | 2 +- .../autorest/codegen/models/parameter.py | 3 +- .../codegen/models/primitive_types.py | 6 +- .../autorest/codegen/models/property.py | 3 +- .../codegen/serializers/builder_serializer.py | 22 ++- .../codegen/serializers/general_serializer.py | 2 + .../codegen/serializers/model_serializer.py | 2 + .../codegen/templates/model_base.py.jinja2 | 24 +++- .../autorest/m4reformatter/__init__.py | 7 +- .../autorest/preprocess/__init__.py | 2 - packages/typespec-python/package.json | 4 +- packages/typespec-python/src/types.ts | 7 +- .../payload/multipart/_model_base.py | 26 +++- .../payload/multipart/_vendor.py | 58 ++------ .../multipart/aio/operations/_operations.py | 130 ++++++++++-------- .../payload/multipart/models/_models.py | 59 ++++---- .../multipart/operations/_operations.py | 130 ++++++++++-------- .../test_payload_multipart.py | 2 +- .../payload/multipart/_vendor.py | 58 ++------ .../multipart/aio/operations/_operations.py | 112 +++++++-------- .../payload/multipart/models/_models.py | 51 +++---- .../multipart/operations/_operations.py | 112 +++++++-------- pnpm-lock.yaml | 24 ++-- 30 files changed, 443 insertions(+), 439 deletions(-) diff --git a/packages/autorest.python/autorest/codegen/models/__init__.py b/packages/autorest.python/autorest/codegen/models/__init__.py index 9f90cadbdf4..a7e4af664a6 100644 --- a/packages/autorest.python/autorest/codegen/models/__init__.py +++ b/packages/autorest.python/autorest/codegen/models/__init__.py @@ -149,7 +149,7 @@ "unixtime": UnixTimeType, "credential": StringType, "sdkcore": SdkCoreType, - "multipartfile": MultipartFileType + "multipartFile": MultipartFileType } _LOGGER = logging.getLogger(__name__) diff --git a/packages/autorest.python/autorest/codegen/models/base.py b/packages/autorest.python/autorest/codegen/models/base.py index f29061294e0..1fefc0f1cac 100644 --- a/packages/autorest.python/autorest/codegen/models/base.py +++ b/packages/autorest.python/autorest/codegen/models/base.py @@ -186,3 +186,7 @@ def serialization_constraints(self) -> List[str]: @property def type_description(self) -> str: return self.type_annotation() + + @property + def is_multipart_file(self) -> bool: + return False diff --git a/packages/autorest.python/autorest/codegen/models/combined_type.py b/packages/autorest.python/autorest/codegen/models/combined_type.py index 016fe2d1664..5c0ad8ee7af 100644 --- a/packages/autorest.python/autorest/codegen/models/combined_type.py +++ b/packages/autorest.python/autorest/codegen/models/combined_type.py @@ -80,8 +80,8 @@ def type_definition(self, **kwargs: Any) -> str: return f'Union[{", ".join(map(lambda x: x[6: -1] if pattern.match(x) else x, inside_types))}]' @property - def is_form_data(self) -> bool: - return any(isinstance(t, ModelType) and t.is_form_data for t in self.types) + def is_multipart_file(self) -> bool: + return any(t.is_multipart_file for t in self.types) def get_json_template_representation( self, diff --git a/packages/autorest.python/autorest/codegen/models/constant_type.py b/packages/autorest.python/autorest/codegen/models/constant_type.py index afcb304e6db..eef567fcc60 100644 --- a/packages/autorest.python/autorest/codegen/models/constant_type.py +++ b/packages/autorest.python/autorest/codegen/models/constant_type.py @@ -37,6 +37,10 @@ def __init__( self.value_type = value_type self.value = value + @property + def is_multipart_file(self) -> bool: + return self.value_type.is_multipart_file + def get_declaration(self, value=None): if value and value != self.value: _LOGGER.warning( diff --git a/packages/autorest.python/autorest/codegen/models/dictionary_type.py b/packages/autorest.python/autorest/codegen/models/dictionary_type.py index 0b9423250fc..6fcf3d78d5f 100644 --- a/packages/autorest.python/autorest/codegen/models/dictionary_type.py +++ b/packages/autorest.python/autorest/codegen/models/dictionary_type.py @@ -33,6 +33,10 @@ def __init__( @property def encode(self) -> Optional[str]: return self.element_type.encode if hasattr(self.element_type, "encode") else None # type: ignore + + @property + def is_multipart_file(self) -> bool: + return self.element_type.is_multipart_file @property def serialization_type(self) -> str: diff --git a/packages/autorest.python/autorest/codegen/models/list_type.py b/packages/autorest.python/autorest/codegen/models/list_type.py index ad477f10e4a..9395e3d617f 100644 --- a/packages/autorest.python/autorest/codegen/models/list_type.py +++ b/packages/autorest.python/autorest/codegen/models/list_type.py @@ -25,6 +25,10 @@ def __init__( self.min_items: Optional[int] = yaml_data.get("minItems") self.unique_items: bool = yaml_data.get("uniqueItems", False) + @property + def is_multipart_file(self) -> bool: + return self.element_type.is_multipart_file + @property def encode(self) -> Optional[str]: return self.element_type.encode if hasattr(self.element_type, "encode") else None # type: ignore diff --git a/packages/autorest.python/autorest/codegen/models/model_type.py b/packages/autorest.python/autorest/codegen/models/model_type.py index 531d865e5d8..7df19a80d61 100644 --- a/packages/autorest.python/autorest/codegen/models/model_type.py +++ b/packages/autorest.python/autorest/codegen/models/model_type.py @@ -75,7 +75,10 @@ def __init__( self.internal: bool = self.yaml_data.get("internal", False) self.snake_case_name: str = self.yaml_data["snakeCaseName"] self.page_result_model: bool = self.yaml_data.get("pageResultModel", False) - self.is_form_data = any(p.is_form_data for p in self.properties) + + @property + def is_multipart_file(self) -> bool: + return any(p.is_multipart_file for p in self.properties) @property def is_xml(self) -> bool: @@ -315,6 +318,15 @@ def imports(self, **kwargs: Any) -> FileImport: if kwargs.get("model_typing") else TypingSection.REGULAR, ) + if self.is_multipart_file: + file_import.add_submodule_import( + relative_path, + "_model_base", + ImportType.LOCAL, + typing_section=TypingSection.TYPING + if kwargs.get("model_typing") + else TypingSection.REGULAR, + ) return file_import diff --git a/packages/autorest.python/autorest/codegen/models/operation.py b/packages/autorest.python/autorest/codegen/models/operation.py index bfa540bc5af..b5461fee2b7 100644 --- a/packages/autorest.python/autorest/codegen/models/operation.py +++ b/packages/autorest.python/autorest/codegen/models/operation.py @@ -573,7 +573,7 @@ def imports(self, async_mode: bool, **kwargs: Any) -> FileImport: relative_path = "..." if async_mode else ".." if self.code_model.options["models_mode"] == "dpg": if self.parameters.has_body: - if not self.parameters.body_parameter.is_form_data: + if not self.has_form_data_body: file_import.add_submodule_import( f"{relative_path}_model_base", "SdkJSONEncoder", diff --git a/packages/autorest.python/autorest/codegen/models/parameter.py b/packages/autorest.python/autorest/codegen/models/parameter.py index 7fd2bf63f56..6e789f2d22b 100644 --- a/packages/autorest.python/autorest/codegen/models/parameter.py +++ b/packages/autorest.python/autorest/codegen/models/parameter.py @@ -93,7 +93,6 @@ def __init__( "defaultToUnsetSentinel", False ) self.hide_in_method: bool = self.yaml_data.get("hideInMethod", False) - self.form_data_input = isinstance(self.type, ModelType) and any(p.is_multipart_file for p in self.type.properties) def get_declaration(self, value: Any = None) -> Any: return self.type.get_declaration(value) @@ -248,7 +247,7 @@ class BodyParameter(_ParameterBase): @property def is_form_data(self) -> bool: - return self.type.is_form_data + return self.type.is_multipart_file @property def is_partial_body(self) -> bool: diff --git a/packages/autorest.python/autorest/codegen/models/primitive_types.py b/packages/autorest.python/autorest/codegen/models/primitive_types.py index dddd18e8afc..b0f0eaf915b 100644 --- a/packages/autorest.python/autorest/codegen/models/primitive_types.py +++ b/packages/autorest.python/autorest/codegen/models/primitive_types.py @@ -90,6 +90,10 @@ def imports(self, **kwargs: Any) -> FileImport: file_import = FileImport(self.code_model) file_import.add_submodule_import(".._vendor", "FileType", ImportType.STDLIB) return file_import + + @property + def is_multipart_file(self) -> bool: + return True @property def instance_check_template(self) -> str: @@ -107,7 +111,7 @@ def type_annotation(self, **kwargs: Any) -> str: @property def default_template_representation_declaration(self) -> str: - return self.get_declaration({}) + return self.get_declaration("FileInputType") class BinaryType(PrimitiveType): diff --git a/packages/autorest.python/autorest/codegen/models/property.py b/packages/autorest.python/autorest/codegen/models/property.py index 54fc6120160..44c82e83853 100644 --- a/packages/autorest.python/autorest/codegen/models/property.py +++ b/packages/autorest.python/autorest/codegen/models/property.py @@ -166,8 +166,7 @@ def imports(self, **kwargs) -> FileImport: @property def is_form_data(self) -> bool: - from .model_type import ModelType - return isinstance(self.type, ModelType) and self.type.is_form_data + return self.type.is_multipart_file @classmethod def from_yaml( diff --git a/packages/autorest.python/autorest/codegen/serializers/builder_serializer.py b/packages/autorest.python/autorest/codegen/serializers/builder_serializer.py index 56e5eb3de03..748b8241a5c 100644 --- a/packages/autorest.python/autorest/codegen/serializers/builder_serializer.py +++ b/packages/autorest.python/autorest/codegen/serializers/builder_serializer.py @@ -740,15 +740,24 @@ def _serialize_body_parameter(self, builder: OperationType) -> List[str]: This function serializes the body params that need to be serialized. """ body_param = builder.parameters.body_parameter - if body_param.form_data_input: - retval = ["_files = []"] - for prop in cast(ModelType, body_param.type).properties: - if isinstance(prop.type, MultipartFileType): + if body_param.is_form_data: + retval = [ + f"_body = {body_param.client_name}.as_dict() if isinstance({body_param.client_name}, _model_base.Model) else {body_param.client_name}", + "_files = []", + "_data = {}", + ] + model_type = body_param.type.target_model_subtype((JSONModelType, DPGModelType)) if isinstance(body_param.type, CombinedType) else body_param.type + for prop in model_type.properties: + prop_access = f'_body["{prop.wire_name}"]' + retval.append(f'if _body.get("{prop.wire_name}") is not None:') + if prop.is_form_data: if isinstance(prop.type, ListType): - retval.append(f"_files.extend(self.{prop.client_name})") + retval.append(f' _files.extend([("{prop.wire_name}", _body[i]) for i in {prop_access}])') else: # we assume that it's just a single multipart file input - retval.append(f"_files.append(self.{prop.client_name})") + retval.append(f' _files.append(("{prop.wire_name}", {prop_access}))') + else: + retval.append(f' _data["{prop.wire_name}"] = {prop_access}') return retval retval: List[str] = [] body_kwarg_name = builder.request_builder.parameters.body_parameter.client_name @@ -964,6 +973,7 @@ def _create_request_builder_call( ) if request_builder.has_form_data_body: retval.append(" files=_files,") + retval.append(" data=_data,") elif request_builder.overloads: seen_body_params = set() for overload in request_builder.overloads: diff --git a/packages/autorest.python/autorest/codegen/serializers/general_serializer.py b/packages/autorest.python/autorest/codegen/serializers/general_serializer.py index b83ad190f9d..06f6c1d64e7 100644 --- a/packages/autorest.python/autorest/codegen/serializers/general_serializer.py +++ b/packages/autorest.python/autorest/codegen/serializers/general_serializer.py @@ -135,6 +135,8 @@ def serialize_vendor_file(self, clients: List[Client]) -> str: file_import.add_submodule_import("typing", "Tuple", ImportType.STDLIB) file_import.add_submodule_import("typing", "Union", ImportType.STDLIB) file_import.add_submodule_import("typing", "Optional", ImportType.STDLIB) + file_import.add_submodule_import("typing", "Mapping", ImportType.STDLIB) + file_import.add_submodule_import("typing", "Sequence", ImportType.STDLIB) return template.render( code_model=self.code_model, diff --git a/packages/autorest.python/autorest/codegen/serializers/model_serializer.py b/packages/autorest.python/autorest/codegen/serializers/model_serializer.py index 58c37dd84d5..91adb3d4366 100644 --- a/packages/autorest.python/autorest/codegen/serializers/model_serializer.py +++ b/packages/autorest.python/autorest/codegen/serializers/model_serializer.py @@ -259,6 +259,8 @@ def declare_property(prop: Property) -> str: args.append(f"default={prop.client_default_value_declaration}") if hasattr(prop.type, "encode") and prop.type.encode: # type: ignore args.append(f'format="{prop.type.encode}"') # type: ignore + if prop.is_form_data: + args.append("is_multipart_file=True") field = "rest_discriminator" if prop.is_discriminator else "rest_field" type_ignore = ( diff --git a/packages/autorest.python/autorest/codegen/templates/model_base.py.jinja2 b/packages/autorest.python/autorest/codegen/templates/model_base.py.jinja2 index c5777573fc8..84a9be73a0c 100644 --- a/packages/autorest.python/autorest/codegen/templates/model_base.py.jinja2 +++ b/packages/autorest.python/autorest/codegen/templates/model_base.py.jinja2 @@ -470,7 +470,13 @@ def _get_rest_field( def _create_value(rf: typing.Optional["_RestField"], value: typing.Any) -> typing.Any: - return _deserialize(rf._type, value) if (rf and rf._is_model) else _serialize(value, rf._format if rf else None) + if not rf: + return _serialize(value, None) + if rf._is_multipart_file: + return value + if rf._is_model: + return _deserialize(rf._type, value) + return _serialize(value, rf._format) class Model(_MyMutableMapping): @@ -567,7 +573,12 @@ class Model(_MyMutableMapping): for k, v in self.items(): if exclude_readonly and k in readonly_props: # pyright: ignore[reportUnboundVariable] continue - result[k] = Model._as_dict_value(v, exclude_readonly=exclude_readonly) + is_multipart_file = False + try: + is_multipart_file = next(rf for rf in self._attr_to_rest_field.values() if rf._rest_name == k)._is_multipart_file + except StopIteration: + pass + result[k] = v if is_multipart_file else Model._as_dict_value(v, exclude_readonly=exclude_readonly) return result @staticmethod @@ -575,10 +586,10 @@ class Model(_MyMutableMapping): if v is None or isinstance(v, _Null): return None if isinstance(v, (list, tuple, set)): - return [ + return type(v)( Model._as_dict_value(x, exclude_readonly=exclude_readonly) for x in v - ] + ) if isinstance(v, dict): return { dk: Model._as_dict_value(dv, exclude_readonly=exclude_readonly) @@ -779,6 +790,7 @@ class _RestField: visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, + is_multipart_file: bool = False, ): self._type = type self._rest_name_input = name @@ -788,6 +800,7 @@ class _RestField: self._is_model = False self._default = default self._format = format + self._is_multipart_file = is_multipart_file @property def _rest_name(self) -> str: @@ -833,8 +846,9 @@ def rest_field( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, + is_multipart_file: bool = False, ) -> typing.Any: - return _RestField(name=name, type=type, visibility=visibility, default=default, format=format) + return _RestField(name=name, type=type, visibility=visibility, default=default, format=format, is_multipart_file=is_multipart_file) def rest_discriminator( diff --git a/packages/autorest.python/autorest/m4reformatter/__init__.py b/packages/autorest.python/autorest/m4reformatter/__init__.py index a37d152cfbc..5636fd85457 100644 --- a/packages/autorest.python/autorest/m4reformatter/__init__.py +++ b/packages/autorest.python/autorest/m4reformatter/__init__.py @@ -524,11 +524,8 @@ def _update_operation_helper( body_parameter["type"]["type"] == "combined" if body_parameter else False ) abstract = False - if body_parameter and ( - body_parameter.get("entries") - or len(body_parameter["type"].get("types", [])) > 2 - ): - # this means it's formdata or urlencoded, or there are more than 2 types of body + if body_parameter and len(body_parameter["type"].get("types", [])) > 2: + # this means there are more than 2 types of body abstract = True return { "name": yaml_data["language"]["default"]["name"], diff --git a/packages/autorest.python/autorest/preprocess/__init__.py b/packages/autorest.python/autorest/preprocess/__init__.py index 51d3073af6c..45f0ea2c2d9 100644 --- a/packages/autorest.python/autorest/preprocess/__init__.py +++ b/packages/autorest.python/autorest/preprocess/__init__.py @@ -421,8 +421,6 @@ def update_operation( self.update_parameter(parameter) if yaml_data.get("bodyParameter"): self.update_parameter(yaml_data["bodyParameter"]) - for entry in yaml_data["bodyParameter"].get("entries", []): - self.update_parameter(entry) for overload in yaml_data.get("overloads", []): self.update_operation(code_model, overload, is_overload=True) for response in yaml_data.get("responses", []): diff --git a/packages/typespec-python/package.json b/packages/typespec-python/package.json index 63633593bdd..4fc49150451 100644 --- a/packages/typespec-python/package.json +++ b/packages/typespec-python/package.json @@ -43,7 +43,7 @@ ], "peerDependencies": { "@azure-tools/typespec-azure-core": ">=0.38.0 <1.0.0", - "@azure-tools/typespec-client-generator-core": ">=0.38.0 <1.0.0", + "@azure-tools/typespec-client-generator-core": "0.39.0-dev.2", "@typespec/compiler": ">=0.52.0 <1.0.0", "@typespec/http": ">=0.52.0 <1.0.0", "@typespec/rest": ">=0.52.0 <1.0.0", @@ -74,7 +74,7 @@ "rimraf": "~5.0.0", "typescript": "~5.1.3", "@azure-tools/typespec-azure-core": "~0.38.0", - "@azure-tools/typespec-client-generator-core": "~0.38.0", + "@azure-tools/typespec-client-generator-core": "0.39.0-dev.2", "@typespec/compiler": "~0.52.0", "@typespec/http": "~0.52.0", "@typespec/rest": "~0.52.0", diff --git a/packages/typespec-python/src/types.ts b/packages/typespec-python/src/types.ts index 2ce5ae5fcd7..a939b176786 100644 --- a/packages/typespec-python/src/types.ts +++ b/packages/typespec-python/src/types.ts @@ -86,6 +86,7 @@ export function getType( case "enumvalue": return emitEnumMember(type, emitEnum(type.enumType)); case "bytes": + case "multipartFile": case "boolean": case "date": case "time": @@ -335,12 +336,6 @@ const sdkScalarKindToPythonKind: Record = { }; function emitBuiltInType(type: SdkBuiltInType | SdkDurationType | SdkDatetimeType): Record { - if (type.kind === "bytes") { - return getSimpleTypeResult({ - type: "multipartfile", - encode: type.encode, - }) - } if (type.kind === "duration" && type.encode === "seconds") { return getSimpleTypeResult({ type: sdkScalarKindToPythonKind[type.wireType.kind], diff --git a/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/_model_base.py b/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/_model_base.py index 585ccb0e0f9..01c401e6324 100644 --- a/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/_model_base.py +++ b/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/_model_base.py @@ -462,7 +462,13 @@ def _get_rest_field( def _create_value(rf: typing.Optional["_RestField"], value: typing.Any) -> typing.Any: - return _deserialize(rf._type, value) if (rf and rf._is_model) else _serialize(value, rf._format if rf else None) + if not rf: + return _serialize(value, None) + if rf._is_multipart_file: + return value + if rf._is_model: + return _deserialize(rf._type, value) + return _serialize(value, rf._format) class Model(_MyMutableMapping): @@ -559,7 +565,14 @@ def as_dict(self, *, exclude_readonly: bool = False) -> typing.Dict[str, typing. for k, v in self.items(): if exclude_readonly and k in readonly_props: # pyright: ignore[reportUnboundVariable] continue - result[k] = Model._as_dict_value(v, exclude_readonly=exclude_readonly) + is_multipart_file = False + try: + is_multipart_file = next( + rf for rf in self._attr_to_rest_field.values() if rf._rest_name == k + )._is_multipart_file + except StopIteration: + pass + result[k] = v if is_multipart_file else Model._as_dict_value(v, exclude_readonly=exclude_readonly) return result @staticmethod @@ -567,7 +580,7 @@ def _as_dict_value(v: typing.Any, exclude_readonly: bool = False) -> typing.Any: if v is None or isinstance(v, _Null): return None if isinstance(v, (list, tuple, set)): - return [Model._as_dict_value(x, exclude_readonly=exclude_readonly) for x in v] + return type(v)(Model._as_dict_value(x, exclude_readonly=exclude_readonly) for x in v) if isinstance(v, dict): return {dk: Model._as_dict_value(dv, exclude_readonly=exclude_readonly) for dk, dv in v.items()} return v.as_dict(exclude_readonly=exclude_readonly) if hasattr(v, "as_dict") else v @@ -762,6 +775,7 @@ def __init__( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, + is_multipart_file: bool = False, ): self._type = type self._rest_name_input = name @@ -771,6 +785,7 @@ def __init__( self._is_model = False self._default = default self._format = format + self._is_multipart_file = is_multipart_file @property def _rest_name(self) -> str: @@ -816,8 +831,11 @@ def rest_field( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, + is_multipart_file: bool = False, ) -> typing.Any: - return _RestField(name=name, type=type, visibility=visibility, default=default, format=format) + return _RestField( + name=name, type=type, visibility=visibility, default=default, format=format, is_multipart_file=is_multipart_file + ) def rest_discriminator( diff --git a/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/_vendor.py b/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/_vendor.py index 03d44e41296..cb35847d99a 100644 --- a/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/_vendor.py +++ b/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/_vendor.py @@ -5,53 +5,19 @@ # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from io import BytesIO, IOBase -import json -import sys -from typing import Any, Union -import uuid +from typing import IO, Mapping, Optional, Sequence, Tuple, Union -from ._model_base import Model, SdkJSONEncoder -if sys.version_info >= (3, 9): - from collections.abc import MutableMapping -else: - from typing import MutableMapping # type: ignore # pylint: disable=ungrouped-imports +# file-like tuple could be `(filename, IO (or bytes))` or `(filename, IO (or bytes), content_type)` +FileContent = Union[str, bytes, IO[str], IO[bytes]] +FileType = Union[ + # file (or bytes) + FileContent, + # (filename, file (or bytes)) + Tuple[Optional[str], FileContent], + # (filename, file (or bytes), content_type) + Tuple[Optional[str], FileContent, Optional[str]], +] -class NamedBytesIO(BytesIO): - def __init__(self, name: str, *args, **kwargs): - super().__init__(*args, **kwargs) - self.name = name - - -def multipart_file(file: Union[IOBase, bytes]) -> IOBase: - if isinstance(file, IOBase): - return file - return NamedBytesIO("auto-name-" + str(uuid.uuid4()), file) - - -def multipart_data(data: Any) -> Any: - if isinstance(data, (list, tuple, dict, Model)): - return json.dumps(data, cls=SdkJSONEncoder, exclude_readonly=True) - return data - - -def handle_multipart_form_data_model(body: Model) -> MutableMapping[str, Any]: # pylint: disable=unsubscriptable-object - """handle first layer of model. - If its value is bytes or IO, replace it with raw value instead of serialized value. - - :param body: The model to handle. - :type body: ~payload.multipart._model_base.Model - :return: The handled model. - :rtype: MutableMapping[str, Any] - """ - result = body.as_dict() - rest_name_attr = {v._rest_name: k for k, v in body._attr_to_rest_field.items()} # pylint: disable=protected-access - for rest_name in result.keys(): - attr = rest_name_attr.get(rest_name) - if attr is not None: - raw_value = getattr(body, attr, None) - if isinstance(raw_value, (bytes, IOBase)): - result[rest_name] = raw_value - return result +FilesType = Union[Mapping[str, FileType], Sequence[Tuple[str, FileType]]] diff --git a/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/aio/operations/_operations.py b/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/aio/operations/_operations.py index d62b74e1c01..2c970eb4109 100644 --- a/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/aio/operations/_operations.py +++ b/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/aio/operations/_operations.py @@ -6,7 +6,6 @@ # Code generated by Microsoft (R) Python Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from io import IOBase import sys from typing import Any, Callable, Dict, Optional, TypeVar, Union, overload @@ -23,7 +22,6 @@ from azure.core.tracing.decorator_async import distributed_trace_async from ... import _model_base, models as _models -from ..._vendor import handle_multipart_form_data_model, multipart_data, multipart_file from ...operations._operations import ( build_form_data_basic_request, build_form_data_binary_array_parts_request, @@ -77,7 +75,7 @@ async def basic( # pylint: disable=inconsistent-return-statements # JSON input template you can fill out and use as your body input. body = { "id": "str", # Required. - "profileImage": bytes("bytes", encoding="utf-8") # Required. + "profileImage": FileInputType # Required. } """ @@ -110,7 +108,7 @@ async def basic( # pylint: disable=inconsistent-return-statements # JSON input template you can fill out and use as your body input. body = { "id": "str", # Required. - "profileImage": bytes("bytes", encoding="utf-8") # Required. + "profileImage": FileInputType # Required. } """ error_map = { @@ -126,16 +124,17 @@ async def basic( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) - if isinstance(body, _model_base.Model): - _body = handle_multipart_form_data_model(body) - else: - _body = body - _files = {k: multipart_file(v) for k, v in _body.items() if isinstance(v, (IOBase, bytes))} - _data = {k: multipart_data(v) for k, v in _body.items() if not isinstance(v, (IOBase, bytes))} + _body = body.as_dict() if isinstance(body, _model_base.Model) else body + _files = [] + _data = {} + if _body.get("id") is not None: + _data["id"] = _body["id"] + if _body.get("profileImage") is not None: + _files.append(("profileImage", _body["profileImage"])) _request = build_form_data_basic_request( - data=_data, files=_files, + data=_data, headers=_headers, params=_params, ) @@ -179,14 +178,14 @@ async def complex( # pylint: disable=inconsistent-return-statements }, "id": "str", # Required. "pictures": [ - bytes("bytes", encoding="utf-8") # Required. + FileInputType # Required. ], "previousAddresses": [ { "city": "str" # Required. } ], - "profileImage": bytes("bytes", encoding="utf-8") # Required. + "profileImage": FileInputType # Required. } """ @@ -223,14 +222,14 @@ async def complex( # pylint: disable=inconsistent-return-statements }, "id": "str", # Required. "pictures": [ - bytes("bytes", encoding="utf-8") # Required. + FileInputType # Required. ], "previousAddresses": [ { "city": "str" # Required. } ], - "profileImage": bytes("bytes", encoding="utf-8") # Required. + "profileImage": FileInputType # Required. } """ error_map = { @@ -246,16 +245,23 @@ async def complex( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) - if isinstance(body, _model_base.Model): - _body = handle_multipart_form_data_model(body) - else: - _body = body - _files = {k: multipart_file(v) for k, v in _body.items() if isinstance(v, (IOBase, bytes))} - _data = {k: multipart_data(v) for k, v in _body.items() if not isinstance(v, (IOBase, bytes))} + _body = body.as_dict() if isinstance(body, _model_base.Model) else body + _files = [] + _data = {} + if _body.get("id") is not None: + _data["id"] = _body["id"] + if _body.get("address") is not None: + _files.append(("address", _body["address"])) + if _body.get("profileImage") is not None: + _files.append(("profileImage", _body["profileImage"])) + if _body.get("previousAddresses") is not None: + _files.extend([("previousAddresses", _body[i]) for i in _body["previousAddresses"]]) + if _body.get("pictures") is not None: + _files.extend([("pictures", _body[i]) for i in _body["pictures"]]) _request = build_form_data_complex_request( - data=_data, files=_files, + data=_data, headers=_headers, params=_params, ) @@ -297,7 +303,7 @@ async def json_part( # pylint: disable=inconsistent-return-statements "address": { "city": "str" # Required. }, - "profileImage": bytes("bytes", encoding="utf-8") # Required. + "profileImage": FileInputType # Required. } """ @@ -332,7 +338,7 @@ async def json_part( # pylint: disable=inconsistent-return-statements "address": { "city": "str" # Required. }, - "profileImage": bytes("bytes", encoding="utf-8") # Required. + "profileImage": FileInputType # Required. } """ error_map = { @@ -348,16 +354,17 @@ async def json_part( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) - if isinstance(body, _model_base.Model): - _body = handle_multipart_form_data_model(body) - else: - _body = body - _files = {k: multipart_file(v) for k, v in _body.items() if isinstance(v, (IOBase, bytes))} - _data = {k: multipart_data(v) for k, v in _body.items() if not isinstance(v, (IOBase, bytes))} + _body = body.as_dict() if isinstance(body, _model_base.Model) else body + _files = [] + _data = {} + if _body.get("address") is not None: + _files.append(("address", _body["address"])) + if _body.get("profileImage") is not None: + _files.append(("profileImage", _body["profileImage"])) _request = build_form_data_json_part_request( - data=_data, files=_files, + data=_data, headers=_headers, params=_params, ) @@ -398,7 +405,7 @@ async def binary_array_parts( # pylint: disable=inconsistent-return-statements body = { "id": "str", # Required. "pictures": [ - bytes("bytes", encoding="utf-8") # Required. + FileInputType # Required. ] } """ @@ -435,7 +442,7 @@ async def binary_array_parts( # pylint: disable=inconsistent-return-statements body = { "id": "str", # Required. "pictures": [ - bytes("bytes", encoding="utf-8") # Required. + FileInputType # Required. ] } """ @@ -452,16 +459,17 @@ async def binary_array_parts( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) - if isinstance(body, _model_base.Model): - _body = handle_multipart_form_data_model(body) - else: - _body = body - _files = {k: multipart_file(v) for k, v in _body.items() if isinstance(v, (IOBase, bytes))} - _data = {k: multipart_data(v) for k, v in _body.items() if not isinstance(v, (IOBase, bytes))} + _body = body.as_dict() if isinstance(body, _model_base.Model) else body + _files = [] + _data = {} + if _body.get("id") is not None: + _data["id"] = _body["id"] + if _body.get("pictures") is not None: + _files.extend([("pictures", _body[i]) for i in _body["pictures"]]) _request = build_form_data_binary_array_parts_request( - data=_data, files=_files, + data=_data, headers=_headers, params=_params, ) @@ -505,7 +513,7 @@ async def json_array_parts( # pylint: disable=inconsistent-return-statements "city": "str" # Required. } ], - "profileImage": bytes("bytes", encoding="utf-8") # Required. + "profileImage": FileInputType # Required. } """ @@ -544,7 +552,7 @@ async def json_array_parts( # pylint: disable=inconsistent-return-statements "city": "str" # Required. } ], - "profileImage": bytes("bytes", encoding="utf-8") # Required. + "profileImage": FileInputType # Required. } """ error_map = { @@ -560,16 +568,17 @@ async def json_array_parts( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) - if isinstance(body, _model_base.Model): - _body = handle_multipart_form_data_model(body) - else: - _body = body - _files = {k: multipart_file(v) for k, v in _body.items() if isinstance(v, (IOBase, bytes))} - _data = {k: multipart_data(v) for k, v in _body.items() if not isinstance(v, (IOBase, bytes))} + _body = body.as_dict() if isinstance(body, _model_base.Model) else body + _files = [] + _data = {} + if _body.get("profileImage") is not None: + _files.append(("profileImage", _body["profileImage"])) + if _body.get("previousAddresses") is not None: + _files.extend([("previousAddresses", _body[i]) for i in _body["previousAddresses"]]) _request = build_form_data_json_array_parts_request( - data=_data, files=_files, + data=_data, headers=_headers, params=_params, ) @@ -608,8 +617,8 @@ async def multi_binary_parts( # pylint: disable=inconsistent-return-statements # JSON input template you can fill out and use as your body input. body = { - "profileImage": bytes("bytes", encoding="utf-8"), # Required. - "picture": bytes("bytes", encoding="utf-8") # Optional. + "profileImage": FileInputType, # Required. + "picture": FileInputType # Optional. } """ @@ -643,8 +652,8 @@ async def multi_binary_parts( # pylint: disable=inconsistent-return-statements # JSON input template you can fill out and use as your body input. body = { - "profileImage": bytes("bytes", encoding="utf-8"), # Required. - "picture": bytes("bytes", encoding="utf-8") # Optional. + "profileImage": FileInputType, # Required. + "picture": FileInputType # Optional. } """ error_map = { @@ -660,16 +669,17 @@ async def multi_binary_parts( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) - if isinstance(body, _model_base.Model): - _body = handle_multipart_form_data_model(body) - else: - _body = body - _files = {k: multipart_file(v) for k, v in _body.items() if isinstance(v, (IOBase, bytes))} - _data = {k: multipart_data(v) for k, v in _body.items() if not isinstance(v, (IOBase, bytes))} + _body = body.as_dict() if isinstance(body, _model_base.Model) else body + _files = [] + _data = {} + if _body.get("profileImage") is not None: + _files.append(("profileImage", _body["profileImage"])) + if _body.get("picture") is not None: + _files.append(("picture", _body["picture"])) _request = build_form_data_multi_binary_parts_request( - data=_data, files=_files, + data=_data, headers=_headers, params=_params, ) diff --git a/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/models/_models.py b/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/models/_models.py index efe8f59004e..458d93df55f 100644 --- a/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/models/_models.py +++ b/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/models/_models.py @@ -7,6 +7,7 @@ # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- +from .._vendor import FileType from typing import Any, List, Mapping, Optional, TYPE_CHECKING, overload from .. import _model_base @@ -14,7 +15,7 @@ if TYPE_CHECKING: # pylint: disable=unused-import,ungrouped-imports - from .. import models as _models + from .. import _model_base, models as _models class Address(_model_base.Model): @@ -56,12 +57,12 @@ class BinaryArrayPartsRequest(_model_base.Model): :ivar id: Required. :vartype id: str :ivar pictures: Required. - :vartype pictures: list[bytes] + :vartype pictures: list[filetype] """ id: str = rest_field() """Required.""" - pictures: List[bytes] = rest_field(format="base64") + pictures: List[FileType] = rest_field(is_multipart_file=True) """Required.""" @overload @@ -69,7 +70,7 @@ def __init__( self, *, id: str, # pylint: disable=redefined-builtin - pictures: List[bytes], + pictures: List[FileType], ): ... @@ -94,22 +95,22 @@ class ComplexPartsRequest(_model_base.Model): :ivar address: Required. :vartype address: ~payload.multipart.models.Address :ivar profile_image: Required. - :vartype profile_image: bytes + :vartype profile_image: filetype :ivar previous_addresses: Required. :vartype previous_addresses: list[~payload.multipart.models.Address] :ivar pictures: Required. - :vartype pictures: list[bytes] + :vartype pictures: list[filetype] """ id: str = rest_field() """Required.""" - address: "_models.Address" = rest_field() + address: "_models.Address" = rest_field(is_multipart_file=True) """Required.""" - profile_image: bytes = rest_field(name="profileImage", format="base64") + profile_image: FileType = rest_field(name="profileImage", is_multipart_file=True) """Required.""" - previous_addresses: List["_models.Address"] = rest_field(name="previousAddresses") + previous_addresses: List["_models.Address"] = rest_field(name="previousAddresses", is_multipart_file=True) """Required.""" - pictures: List[bytes] = rest_field(format="base64") + pictures: List[FileType] = rest_field(is_multipart_file=True) """Required.""" @overload @@ -118,9 +119,9 @@ def __init__( *, id: str, # pylint: disable=redefined-builtin address: "_models.Address", - profile_image: bytes, + profile_image: FileType, previous_addresses: List["_models.Address"], - pictures: List[bytes], + pictures: List[FileType], ): ... @@ -141,21 +142,21 @@ class JsonArrayPartsRequest(_model_base.Model): All required parameters must be populated in order to send to server. :ivar profile_image: Required. - :vartype profile_image: bytes + :vartype profile_image: filetype :ivar previous_addresses: Required. :vartype previous_addresses: list[~payload.multipart.models.Address] """ - profile_image: bytes = rest_field(name="profileImage", format="base64") + profile_image: FileType = rest_field(name="profileImage", is_multipart_file=True) """Required.""" - previous_addresses: List["_models.Address"] = rest_field(name="previousAddresses") + previous_addresses: List["_models.Address"] = rest_field(name="previousAddresses", is_multipart_file=True) """Required.""" @overload def __init__( self, *, - profile_image: bytes, + profile_image: FileType, previous_addresses: List["_models.Address"], ): ... @@ -179,12 +180,12 @@ class JsonPartRequest(_model_base.Model): :ivar address: Required. :vartype address: ~payload.multipart.models.Address :ivar profile_image: Required. - :vartype profile_image: bytes + :vartype profile_image: filetype """ - address: "_models.Address" = rest_field() + address: "_models.Address" = rest_field(is_multipart_file=True) """Required.""" - profile_image: bytes = rest_field(name="profileImage", format="base64") + profile_image: FileType = rest_field(name="profileImage", is_multipart_file=True) """Required.""" @overload @@ -192,7 +193,7 @@ def __init__( self, *, address: "_models.Address", - profile_image: bytes, + profile_image: FileType, ): ... @@ -213,21 +214,21 @@ class MultiBinaryPartsRequest(_model_base.Model): All required parameters must be populated in order to send to server. :ivar profile_image: Required. - :vartype profile_image: bytes + :vartype profile_image: filetype :ivar picture: - :vartype picture: bytes + :vartype picture: filetype """ - profile_image: bytes = rest_field(name="profileImage", format="base64") + profile_image: FileType = rest_field(name="profileImage", is_multipart_file=True) """Required.""" - picture: Optional[bytes] = rest_field(format="base64") + picture: Optional[FileType] = rest_field(is_multipart_file=True) @overload def __init__( self, *, - profile_image: bytes, - picture: Optional[bytes] = None, + profile_image: FileType, + picture: Optional[FileType] = None, ): ... @@ -250,12 +251,12 @@ class MultiPartRequest(_model_base.Model): :ivar id: Required. :vartype id: str :ivar profile_image: Required. - :vartype profile_image: bytes + :vartype profile_image: filetype """ id: str = rest_field() """Required.""" - profile_image: bytes = rest_field(name="profileImage", format="base64") + profile_image: FileType = rest_field(name="profileImage", is_multipart_file=True) """Required.""" @overload @@ -263,7 +264,7 @@ def __init__( self, *, id: str, # pylint: disable=redefined-builtin - profile_image: bytes, + profile_image: FileType, ): ... diff --git a/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/operations/_operations.py b/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/operations/_operations.py index 2ca0678c8e9..1ca81268355 100644 --- a/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/operations/_operations.py +++ b/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/operations/_operations.py @@ -6,7 +6,6 @@ # Code generated by Microsoft (R) Python Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from io import IOBase import sys from typing import Any, Callable, Dict, Optional, TypeVar, Union, overload @@ -25,7 +24,6 @@ from .. import _model_base, models as _models from .._serialization import Serializer -from .._vendor import handle_multipart_form_data_model, multipart_data, multipart_file if sys.version_info >= (3, 9): from collections.abc import MutableMapping @@ -128,7 +126,7 @@ def basic( # pylint: disable=inconsistent-return-statements # JSON input template you can fill out and use as your body input. body = { "id": "str", # Required. - "profileImage": bytes("bytes", encoding="utf-8") # Required. + "profileImage": FileInputType # Required. } """ @@ -161,7 +159,7 @@ def basic( # pylint: disable=inconsistent-return-statements # JSON input template you can fill out and use as your body input. body = { "id": "str", # Required. - "profileImage": bytes("bytes", encoding="utf-8") # Required. + "profileImage": FileInputType # Required. } """ error_map = { @@ -177,16 +175,17 @@ def basic( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) - if isinstance(body, _model_base.Model): - _body = handle_multipart_form_data_model(body) - else: - _body = body - _files = {k: multipart_file(v) for k, v in _body.items() if isinstance(v, (IOBase, bytes))} - _data = {k: multipart_data(v) for k, v in _body.items() if not isinstance(v, (IOBase, bytes))} + _body = body.as_dict() if isinstance(body, _model_base.Model) else body + _files = [] + _data = {} + if _body.get("id") is not None: + _data["id"] = _body["id"] + if _body.get("profileImage") is not None: + _files.append(("profileImage", _body["profileImage"])) _request = build_form_data_basic_request( - data=_data, files=_files, + data=_data, headers=_headers, params=_params, ) @@ -230,14 +229,14 @@ def complex( # pylint: disable=inconsistent-return-statements }, "id": "str", # Required. "pictures": [ - bytes("bytes", encoding="utf-8") # Required. + FileInputType # Required. ], "previousAddresses": [ { "city": "str" # Required. } ], - "profileImage": bytes("bytes", encoding="utf-8") # Required. + "profileImage": FileInputType # Required. } """ @@ -274,14 +273,14 @@ def complex( # pylint: disable=inconsistent-return-statements }, "id": "str", # Required. "pictures": [ - bytes("bytes", encoding="utf-8") # Required. + FileInputType # Required. ], "previousAddresses": [ { "city": "str" # Required. } ], - "profileImage": bytes("bytes", encoding="utf-8") # Required. + "profileImage": FileInputType # Required. } """ error_map = { @@ -297,16 +296,23 @@ def complex( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) - if isinstance(body, _model_base.Model): - _body = handle_multipart_form_data_model(body) - else: - _body = body - _files = {k: multipart_file(v) for k, v in _body.items() if isinstance(v, (IOBase, bytes))} - _data = {k: multipart_data(v) for k, v in _body.items() if not isinstance(v, (IOBase, bytes))} + _body = body.as_dict() if isinstance(body, _model_base.Model) else body + _files = [] + _data = {} + if _body.get("id") is not None: + _data["id"] = _body["id"] + if _body.get("address") is not None: + _files.append(("address", _body["address"])) + if _body.get("profileImage") is not None: + _files.append(("profileImage", _body["profileImage"])) + if _body.get("previousAddresses") is not None: + _files.extend([("previousAddresses", _body[i]) for i in _body["previousAddresses"]]) + if _body.get("pictures") is not None: + _files.extend([("pictures", _body[i]) for i in _body["pictures"]]) _request = build_form_data_complex_request( - data=_data, files=_files, + data=_data, headers=_headers, params=_params, ) @@ -348,7 +354,7 @@ def json_part( # pylint: disable=inconsistent-return-statements "address": { "city": "str" # Required. }, - "profileImage": bytes("bytes", encoding="utf-8") # Required. + "profileImage": FileInputType # Required. } """ @@ -383,7 +389,7 @@ def json_part( # pylint: disable=inconsistent-return-statements "address": { "city": "str" # Required. }, - "profileImage": bytes("bytes", encoding="utf-8") # Required. + "profileImage": FileInputType # Required. } """ error_map = { @@ -399,16 +405,17 @@ def json_part( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) - if isinstance(body, _model_base.Model): - _body = handle_multipart_form_data_model(body) - else: - _body = body - _files = {k: multipart_file(v) for k, v in _body.items() if isinstance(v, (IOBase, bytes))} - _data = {k: multipart_data(v) for k, v in _body.items() if not isinstance(v, (IOBase, bytes))} + _body = body.as_dict() if isinstance(body, _model_base.Model) else body + _files = [] + _data = {} + if _body.get("address") is not None: + _files.append(("address", _body["address"])) + if _body.get("profileImage") is not None: + _files.append(("profileImage", _body["profileImage"])) _request = build_form_data_json_part_request( - data=_data, files=_files, + data=_data, headers=_headers, params=_params, ) @@ -449,7 +456,7 @@ def binary_array_parts( # pylint: disable=inconsistent-return-statements body = { "id": "str", # Required. "pictures": [ - bytes("bytes", encoding="utf-8") # Required. + FileInputType # Required. ] } """ @@ -484,7 +491,7 @@ def binary_array_parts( # pylint: disable=inconsistent-return-statements body = { "id": "str", # Required. "pictures": [ - bytes("bytes", encoding="utf-8") # Required. + FileInputType # Required. ] } """ @@ -501,16 +508,17 @@ def binary_array_parts( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) - if isinstance(body, _model_base.Model): - _body = handle_multipart_form_data_model(body) - else: - _body = body - _files = {k: multipart_file(v) for k, v in _body.items() if isinstance(v, (IOBase, bytes))} - _data = {k: multipart_data(v) for k, v in _body.items() if not isinstance(v, (IOBase, bytes))} + _body = body.as_dict() if isinstance(body, _model_base.Model) else body + _files = [] + _data = {} + if _body.get("id") is not None: + _data["id"] = _body["id"] + if _body.get("pictures") is not None: + _files.extend([("pictures", _body[i]) for i in _body["pictures"]]) _request = build_form_data_binary_array_parts_request( - data=_data, files=_files, + data=_data, headers=_headers, params=_params, ) @@ -554,7 +562,7 @@ def json_array_parts( # pylint: disable=inconsistent-return-statements "city": "str" # Required. } ], - "profileImage": bytes("bytes", encoding="utf-8") # Required. + "profileImage": FileInputType # Required. } """ @@ -591,7 +599,7 @@ def json_array_parts( # pylint: disable=inconsistent-return-statements "city": "str" # Required. } ], - "profileImage": bytes("bytes", encoding="utf-8") # Required. + "profileImage": FileInputType # Required. } """ error_map = { @@ -607,16 +615,17 @@ def json_array_parts( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) - if isinstance(body, _model_base.Model): - _body = handle_multipart_form_data_model(body) - else: - _body = body - _files = {k: multipart_file(v) for k, v in _body.items() if isinstance(v, (IOBase, bytes))} - _data = {k: multipart_data(v) for k, v in _body.items() if not isinstance(v, (IOBase, bytes))} + _body = body.as_dict() if isinstance(body, _model_base.Model) else body + _files = [] + _data = {} + if _body.get("profileImage") is not None: + _files.append(("profileImage", _body["profileImage"])) + if _body.get("previousAddresses") is not None: + _files.extend([("previousAddresses", _body[i]) for i in _body["previousAddresses"]]) _request = build_form_data_json_array_parts_request( - data=_data, files=_files, + data=_data, headers=_headers, params=_params, ) @@ -655,8 +664,8 @@ def multi_binary_parts( # pylint: disable=inconsistent-return-statements # JSON input template you can fill out and use as your body input. body = { - "profileImage": bytes("bytes", encoding="utf-8"), # Required. - "picture": bytes("bytes", encoding="utf-8") # Optional. + "profileImage": FileInputType, # Required. + "picture": FileInputType # Optional. } """ @@ -688,8 +697,8 @@ def multi_binary_parts( # pylint: disable=inconsistent-return-statements # JSON input template you can fill out and use as your body input. body = { - "profileImage": bytes("bytes", encoding="utf-8"), # Required. - "picture": bytes("bytes", encoding="utf-8") # Optional. + "profileImage": FileInputType, # Required. + "picture": FileInputType # Optional. } """ error_map = { @@ -705,16 +714,17 @@ def multi_binary_parts( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) - if isinstance(body, _model_base.Model): - _body = handle_multipart_form_data_model(body) - else: - _body = body - _files = {k: multipart_file(v) for k, v in _body.items() if isinstance(v, (IOBase, bytes))} - _data = {k: multipart_data(v) for k, v in _body.items() if not isinstance(v, (IOBase, bytes))} + _body = body.as_dict() if isinstance(body, _model_base.Model) else body + _files = [] + _data = {} + if _body.get("profileImage") is not None: + _files.append(("profileImage", _body["profileImage"])) + if _body.get("picture") is not None: + _files.append(("picture", _body["picture"])) _request = build_form_data_multi_binary_parts_request( - data=_data, files=_files, + data=_data, headers=_headers, params=_params, ) diff --git a/packages/typespec-python/test/generic_mock_api_tests/test_payload_multipart.py b/packages/typespec-python/test/generic_mock_api_tests/test_payload_multipart.py index 3219a91a218..7d4213f9f9c 100644 --- a/packages/typespec-python/test/generic_mock_api_tests/test_payload_multipart.py +++ b/packages/typespec-python/test/generic_mock_api_tests/test_payload_multipart.py @@ -52,7 +52,7 @@ def client(): def test_multi_part(client: MultiPartClient, op_name, model_class, data, file): op = getattr(client.form_data, op_name) # test bytes - body = {k: open(str(v), "rb").read() for k, v in file.items()} + body = {k: ("blob", open(str(v), "rb").read(), "application/octet-stream") for k, v in file.items()} body.update(data) op(body) op(model_class(body)) diff --git a/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/_vendor.py b/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/_vendor.py index c559ea1ec67..3b794024c13 100644 --- a/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/_vendor.py +++ b/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/_vendor.py @@ -5,53 +5,19 @@ # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from io import BytesIO, IOBase -import json -import sys -from typing import Any, Union -import uuid +from typing import IO, Mapping, Optional, Sequence, Tuple, Union -from ._model_base import Model, SdkJSONEncoder -if sys.version_info >= (3, 9): - from collections.abc import MutableMapping -else: - from typing import MutableMapping # type: ignore # pylint: disable=ungrouped-imports +# file-like tuple could be `(filename, IO (or bytes))` or `(filename, IO (or bytes), content_type)` +FileContent = Union[str, bytes, IO[str], IO[bytes]] +FileType = Union[ + # file (or bytes) + FileContent, + # (filename, file (or bytes)) + Tuple[Optional[str], FileContent], + # (filename, file (or bytes), content_type) + Tuple[Optional[str], FileContent, Optional[str]], +] -class NamedBytesIO(BytesIO): - def __init__(self, name: str, *args, **kwargs): - super().__init__(*args, **kwargs) - self.name = name - - -def multipart_file(file: Union[IOBase, bytes]) -> IOBase: - if isinstance(file, IOBase): - return file - return NamedBytesIO("auto-name-" + str(uuid.uuid4()), file) - - -def multipart_data(data: Any) -> Any: - if isinstance(data, (list, tuple, dict, Model)): - return json.dumps(data, cls=SdkJSONEncoder, exclude_readonly=True) - return data - - -def handle_multipart_form_data_model(body: Model) -> MutableMapping[str, Any]: # pylint: disable=unsubscriptable-object - """handle first layer of model. - If its value is bytes or IO, replace it with raw value instead of serialized value. - - :param body: The model to handle. - :type body: ~payload.multipart._model_base.Model - :return: The handled model. - :rtype: MutableMapping[str, Any] - """ - result = body.as_dict() - rest_name_attr = {v._rest_name: k for k, v in body._attr_to_rest_field.items()} # pylint: disable=protected-access - for rest_name in result.keys(): - attr = rest_name_attr.get(rest_name) - if attr is not None: - raw_value = getattr(body, attr, None) - if isinstance(raw_value, (bytes, IOBase)): - result[rest_name] = raw_value - return result +FilesType = Union[Mapping[str, FileType], Sequence[Tuple[str, FileType]]] diff --git a/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/aio/operations/_operations.py b/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/aio/operations/_operations.py index d3dca59c18e..e44ff14414f 100644 --- a/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/aio/operations/_operations.py +++ b/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/aio/operations/_operations.py @@ -6,7 +6,6 @@ # Code generated by Unbranded (R) Python Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from io import IOBase import sys from typing import Any, Callable, Dict, Optional, TypeVar, Union, overload @@ -22,7 +21,6 @@ from corehttp.runtime.pipeline import PipelineResponse from ... import _model_base, models as _models -from ..._vendor import handle_multipart_form_data_model, multipart_data, multipart_file from ...operations._operations import ( build_form_data_basic_request, build_form_data_binary_array_parts_request, @@ -76,7 +74,7 @@ async def basic( # pylint: disable=inconsistent-return-statements # JSON input template you can fill out and use as your body input. body = { "id": "str", # Required. - "profileImage": bytes("bytes", encoding="utf-8") # Required. + "profileImage": FileInputType # Required. } """ @@ -108,7 +106,7 @@ async def basic( # pylint: disable=inconsistent-return-statements # JSON input template you can fill out and use as your body input. body = { "id": "str", # Required. - "profileImage": bytes("bytes", encoding="utf-8") # Required. + "profileImage": FileInputType # Required. } """ error_map = { @@ -124,15 +122,12 @@ async def basic( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) - if isinstance(body, _model_base.Model): - _body = handle_multipart_form_data_model(body) - else: - _body = body - _files = {k: multipart_file(v) for k, v in _body.items() if isinstance(v, (IOBase, bytes))} - _data = {k: multipart_data(v) for k, v in _body.items() if not isinstance(v, (IOBase, bytes))} + _body = body.as_dict() if isinstance(body, _model_base.Model) else body + _files = [] + if _body.get("profileImage") is not None: + _files.append(_body["profileImage"]) _request = build_form_data_basic_request( - data=_data, files=_files, headers=_headers, params=_params, @@ -177,14 +172,14 @@ async def complex( # pylint: disable=inconsistent-return-statements }, "id": "str", # Required. "pictures": [ - bytes("bytes", encoding="utf-8") # Required. + FileInputType # Required. ], "previousAddresses": [ { "city": "str" # Required. } ], - "profileImage": bytes("bytes", encoding="utf-8") # Required. + "profileImage": FileInputType # Required. } """ @@ -220,14 +215,14 @@ async def complex( # pylint: disable=inconsistent-return-statements }, "id": "str", # Required. "pictures": [ - bytes("bytes", encoding="utf-8") # Required. + FileInputType # Required. ], "previousAddresses": [ { "city": "str" # Required. } ], - "profileImage": bytes("bytes", encoding="utf-8") # Required. + "profileImage": FileInputType # Required. } """ error_map = { @@ -243,15 +238,18 @@ async def complex( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) - if isinstance(body, _model_base.Model): - _body = handle_multipart_form_data_model(body) - else: - _body = body - _files = {k: multipart_file(v) for k, v in _body.items() if isinstance(v, (IOBase, bytes))} - _data = {k: multipart_data(v) for k, v in _body.items() if not isinstance(v, (IOBase, bytes))} + _body = body.as_dict() if isinstance(body, _model_base.Model) else body + _files = [] + if _body.get("address") is not None: + _files.append(_body["address"]) + if _body.get("profileImage") is not None: + _files.append(_body["profileImage"]) + if _body.get("previousAddresses") is not None: + _files.extend(_body["previousAddresses"]) + if _body.get("pictures") is not None: + _files.extend(_body["pictures"]) _request = build_form_data_complex_request( - data=_data, files=_files, headers=_headers, params=_params, @@ -294,7 +292,7 @@ async def json_part( # pylint: disable=inconsistent-return-statements "address": { "city": "str" # Required. }, - "profileImage": bytes("bytes", encoding="utf-8") # Required. + "profileImage": FileInputType # Required. } """ @@ -328,7 +326,7 @@ async def json_part( # pylint: disable=inconsistent-return-statements "address": { "city": "str" # Required. }, - "profileImage": bytes("bytes", encoding="utf-8") # Required. + "profileImage": FileInputType # Required. } """ error_map = { @@ -344,15 +342,14 @@ async def json_part( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) - if isinstance(body, _model_base.Model): - _body = handle_multipart_form_data_model(body) - else: - _body = body - _files = {k: multipart_file(v) for k, v in _body.items() if isinstance(v, (IOBase, bytes))} - _data = {k: multipart_data(v) for k, v in _body.items() if not isinstance(v, (IOBase, bytes))} + _body = body.as_dict() if isinstance(body, _model_base.Model) else body + _files = [] + if _body.get("address") is not None: + _files.append(_body["address"]) + if _body.get("profileImage") is not None: + _files.append(_body["profileImage"]) _request = build_form_data_json_part_request( - data=_data, files=_files, headers=_headers, params=_params, @@ -394,7 +391,7 @@ async def binary_array_parts( # pylint: disable=inconsistent-return-statements body = { "id": "str", # Required. "pictures": [ - bytes("bytes", encoding="utf-8") # Required. + FileInputType # Required. ] } """ @@ -430,7 +427,7 @@ async def binary_array_parts( # pylint: disable=inconsistent-return-statements body = { "id": "str", # Required. "pictures": [ - bytes("bytes", encoding="utf-8") # Required. + FileInputType # Required. ] } """ @@ -447,15 +444,12 @@ async def binary_array_parts( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) - if isinstance(body, _model_base.Model): - _body = handle_multipart_form_data_model(body) - else: - _body = body - _files = {k: multipart_file(v) for k, v in _body.items() if isinstance(v, (IOBase, bytes))} - _data = {k: multipart_data(v) for k, v in _body.items() if not isinstance(v, (IOBase, bytes))} + _body = body.as_dict() if isinstance(body, _model_base.Model) else body + _files = [] + if _body.get("pictures") is not None: + _files.extend(_body["pictures"]) _request = build_form_data_binary_array_parts_request( - data=_data, files=_files, headers=_headers, params=_params, @@ -500,7 +494,7 @@ async def json_array_parts( # pylint: disable=inconsistent-return-statements "city": "str" # Required. } ], - "profileImage": bytes("bytes", encoding="utf-8") # Required. + "profileImage": FileInputType # Required. } """ @@ -538,7 +532,7 @@ async def json_array_parts( # pylint: disable=inconsistent-return-statements "city": "str" # Required. } ], - "profileImage": bytes("bytes", encoding="utf-8") # Required. + "profileImage": FileInputType # Required. } """ error_map = { @@ -554,15 +548,14 @@ async def json_array_parts( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) - if isinstance(body, _model_base.Model): - _body = handle_multipart_form_data_model(body) - else: - _body = body - _files = {k: multipart_file(v) for k, v in _body.items() if isinstance(v, (IOBase, bytes))} - _data = {k: multipart_data(v) for k, v in _body.items() if not isinstance(v, (IOBase, bytes))} + _body = body.as_dict() if isinstance(body, _model_base.Model) else body + _files = [] + if _body.get("profileImage") is not None: + _files.append(_body["profileImage"]) + if _body.get("previousAddresses") is not None: + _files.extend(_body["previousAddresses"]) _request = build_form_data_json_array_parts_request( - data=_data, files=_files, headers=_headers, params=_params, @@ -602,8 +595,8 @@ async def multi_binary_parts( # pylint: disable=inconsistent-return-statements # JSON input template you can fill out and use as your body input. body = { - "profileImage": bytes("bytes", encoding="utf-8"), # Required. - "picture": bytes("bytes", encoding="utf-8") # Optional. + "profileImage": FileInputType, # Required. + "picture": FileInputType # Optional. } """ @@ -636,8 +629,8 @@ async def multi_binary_parts( # pylint: disable=inconsistent-return-statements # JSON input template you can fill out and use as your body input. body = { - "profileImage": bytes("bytes", encoding="utf-8"), # Required. - "picture": bytes("bytes", encoding="utf-8") # Optional. + "profileImage": FileInputType, # Required. + "picture": FileInputType # Optional. } """ error_map = { @@ -653,15 +646,14 @@ async def multi_binary_parts( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) - if isinstance(body, _model_base.Model): - _body = handle_multipart_form_data_model(body) - else: - _body = body - _files = {k: multipart_file(v) for k, v in _body.items() if isinstance(v, (IOBase, bytes))} - _data = {k: multipart_data(v) for k, v in _body.items() if not isinstance(v, (IOBase, bytes))} + _body = body.as_dict() if isinstance(body, _model_base.Model) else body + _files = [] + if _body.get("profileImage") is not None: + _files.append(_body["profileImage"]) + if _body.get("picture") is not None: + _files.append(_body["picture"]) _request = build_form_data_multi_binary_parts_request( - data=_data, files=_files, headers=_headers, params=_params, diff --git a/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/models/_models.py b/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/models/_models.py index 3f7009ea407..901955107d2 100644 --- a/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/models/_models.py +++ b/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/models/_models.py @@ -7,6 +7,7 @@ # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- +from .._vendor import FileType from typing import Any, List, Mapping, Optional, TYPE_CHECKING, overload from .. import _model_base @@ -14,7 +15,7 @@ if TYPE_CHECKING: # pylint: disable=unused-import,ungrouped-imports - from .. import models as _models + from .. import _model_base, models as _models class Address(_model_base.Model): @@ -56,12 +57,12 @@ class BinaryArrayPartsRequest(_model_base.Model): :ivar id: Required. :vartype id: str :ivar pictures: Required. - :vartype pictures: list[bytes] + :vartype pictures: list[filetype] """ id: str = rest_field() """Required.""" - pictures: List[bytes] = rest_field(format="base64") + pictures: List[FileType] = rest_field() """Required.""" @overload @@ -69,7 +70,7 @@ def __init__( self, *, id: str, # pylint: disable=redefined-builtin - pictures: List[bytes], + pictures: List[FileType], ): ... @@ -94,22 +95,22 @@ class ComplexPartsRequest(_model_base.Model): :ivar address: Required. :vartype address: ~payload.multipart.models.Address :ivar profile_image: Required. - :vartype profile_image: bytes + :vartype profile_image: filetype :ivar previous_addresses: Required. :vartype previous_addresses: list[~payload.multipart.models.Address] :ivar pictures: Required. - :vartype pictures: list[bytes] + :vartype pictures: list[filetype] """ id: str = rest_field() """Required.""" address: "_models.Address" = rest_field() """Required.""" - profile_image: bytes = rest_field(name="profileImage", format="base64") + profile_image: FileType = rest_field(name="profileImage") """Required.""" previous_addresses: List["_models.Address"] = rest_field(name="previousAddresses") """Required.""" - pictures: List[bytes] = rest_field(format="base64") + pictures: List[FileType] = rest_field() """Required.""" @overload @@ -118,9 +119,9 @@ def __init__( *, id: str, # pylint: disable=redefined-builtin address: "_models.Address", - profile_image: bytes, + profile_image: FileType, previous_addresses: List["_models.Address"], - pictures: List[bytes], + pictures: List[FileType], ): ... @@ -141,12 +142,12 @@ class JsonArrayPartsRequest(_model_base.Model): All required parameters must be populated in order to send to server. :ivar profile_image: Required. - :vartype profile_image: bytes + :vartype profile_image: filetype :ivar previous_addresses: Required. :vartype previous_addresses: list[~payload.multipart.models.Address] """ - profile_image: bytes = rest_field(name="profileImage", format="base64") + profile_image: FileType = rest_field(name="profileImage") """Required.""" previous_addresses: List["_models.Address"] = rest_field(name="previousAddresses") """Required.""" @@ -155,7 +156,7 @@ class JsonArrayPartsRequest(_model_base.Model): def __init__( self, *, - profile_image: bytes, + profile_image: FileType, previous_addresses: List["_models.Address"], ): ... @@ -179,12 +180,12 @@ class JsonPartRequest(_model_base.Model): :ivar address: Required. :vartype address: ~payload.multipart.models.Address :ivar profile_image: Required. - :vartype profile_image: bytes + :vartype profile_image: filetype """ address: "_models.Address" = rest_field() """Required.""" - profile_image: bytes = rest_field(name="profileImage", format="base64") + profile_image: FileType = rest_field(name="profileImage") """Required.""" @overload @@ -192,7 +193,7 @@ def __init__( self, *, address: "_models.Address", - profile_image: bytes, + profile_image: FileType, ): ... @@ -213,21 +214,21 @@ class MultiBinaryPartsRequest(_model_base.Model): All required parameters must be populated in order to send to server. :ivar profile_image: Required. - :vartype profile_image: bytes + :vartype profile_image: filetype :ivar picture: - :vartype picture: bytes + :vartype picture: filetype """ - profile_image: bytes = rest_field(name="profileImage", format="base64") + profile_image: FileType = rest_field(name="profileImage") """Required.""" - picture: Optional[bytes] = rest_field(format="base64") + picture: Optional[FileType] = rest_field() @overload def __init__( self, *, - profile_image: bytes, - picture: Optional[bytes] = None, + profile_image: FileType, + picture: Optional[FileType] = None, ): ... @@ -250,12 +251,12 @@ class MultiPartRequest(_model_base.Model): :ivar id: Required. :vartype id: str :ivar profile_image: Required. - :vartype profile_image: bytes + :vartype profile_image: filetype """ id: str = rest_field() """Required.""" - profile_image: bytes = rest_field(name="profileImage", format="base64") + profile_image: FileType = rest_field(name="profileImage") """Required.""" @overload @@ -263,7 +264,7 @@ def __init__( self, *, id: str, # pylint: disable=redefined-builtin - profile_image: bytes, + profile_image: FileType, ): ... diff --git a/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/operations/_operations.py b/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/operations/_operations.py index 4feac538204..b21ea00266d 100644 --- a/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/operations/_operations.py +++ b/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/operations/_operations.py @@ -6,7 +6,6 @@ # Code generated by Unbranded (R) Python Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from io import IOBase import sys from typing import Any, Callable, Dict, Optional, TypeVar, Union, overload @@ -24,7 +23,6 @@ from .. import _model_base, models as _models from .._serialization import Serializer -from .._vendor import handle_multipart_form_data_model, multipart_data, multipart_file if sys.version_info >= (3, 9): from collections.abc import MutableMapping @@ -127,7 +125,7 @@ def basic( # pylint: disable=inconsistent-return-statements # JSON input template you can fill out and use as your body input. body = { "id": "str", # Required. - "profileImage": bytes("bytes", encoding="utf-8") # Required. + "profileImage": FileInputType # Required. } """ @@ -159,7 +157,7 @@ def basic( # pylint: disable=inconsistent-return-statements # JSON input template you can fill out and use as your body input. body = { "id": "str", # Required. - "profileImage": bytes("bytes", encoding="utf-8") # Required. + "profileImage": FileInputType # Required. } """ error_map = { @@ -175,15 +173,12 @@ def basic( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) - if isinstance(body, _model_base.Model): - _body = handle_multipart_form_data_model(body) - else: - _body = body - _files = {k: multipart_file(v) for k, v in _body.items() if isinstance(v, (IOBase, bytes))} - _data = {k: multipart_data(v) for k, v in _body.items() if not isinstance(v, (IOBase, bytes))} + _body = body.as_dict() if isinstance(body, _model_base.Model) else body + _files = [] + if _body.get("profileImage") is not None: + _files.append(_body["profileImage"]) _request = build_form_data_basic_request( - data=_data, files=_files, headers=_headers, params=_params, @@ -228,14 +223,14 @@ def complex( # pylint: disable=inconsistent-return-statements }, "id": "str", # Required. "pictures": [ - bytes("bytes", encoding="utf-8") # Required. + FileInputType # Required. ], "previousAddresses": [ { "city": "str" # Required. } ], - "profileImage": bytes("bytes", encoding="utf-8") # Required. + "profileImage": FileInputType # Required. } """ @@ -271,14 +266,14 @@ def complex( # pylint: disable=inconsistent-return-statements }, "id": "str", # Required. "pictures": [ - bytes("bytes", encoding="utf-8") # Required. + FileInputType # Required. ], "previousAddresses": [ { "city": "str" # Required. } ], - "profileImage": bytes("bytes", encoding="utf-8") # Required. + "profileImage": FileInputType # Required. } """ error_map = { @@ -294,15 +289,18 @@ def complex( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) - if isinstance(body, _model_base.Model): - _body = handle_multipart_form_data_model(body) - else: - _body = body - _files = {k: multipart_file(v) for k, v in _body.items() if isinstance(v, (IOBase, bytes))} - _data = {k: multipart_data(v) for k, v in _body.items() if not isinstance(v, (IOBase, bytes))} + _body = body.as_dict() if isinstance(body, _model_base.Model) else body + _files = [] + if _body.get("address") is not None: + _files.append(_body["address"]) + if _body.get("profileImage") is not None: + _files.append(_body["profileImage"]) + if _body.get("previousAddresses") is not None: + _files.extend(_body["previousAddresses"]) + if _body.get("pictures") is not None: + _files.extend(_body["pictures"]) _request = build_form_data_complex_request( - data=_data, files=_files, headers=_headers, params=_params, @@ -345,7 +343,7 @@ def json_part( # pylint: disable=inconsistent-return-statements "address": { "city": "str" # Required. }, - "profileImage": bytes("bytes", encoding="utf-8") # Required. + "profileImage": FileInputType # Required. } """ @@ -379,7 +377,7 @@ def json_part( # pylint: disable=inconsistent-return-statements "address": { "city": "str" # Required. }, - "profileImage": bytes("bytes", encoding="utf-8") # Required. + "profileImage": FileInputType # Required. } """ error_map = { @@ -395,15 +393,14 @@ def json_part( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) - if isinstance(body, _model_base.Model): - _body = handle_multipart_form_data_model(body) - else: - _body = body - _files = {k: multipart_file(v) for k, v in _body.items() if isinstance(v, (IOBase, bytes))} - _data = {k: multipart_data(v) for k, v in _body.items() if not isinstance(v, (IOBase, bytes))} + _body = body.as_dict() if isinstance(body, _model_base.Model) else body + _files = [] + if _body.get("address") is not None: + _files.append(_body["address"]) + if _body.get("profileImage") is not None: + _files.append(_body["profileImage"]) _request = build_form_data_json_part_request( - data=_data, files=_files, headers=_headers, params=_params, @@ -445,7 +442,7 @@ def binary_array_parts( # pylint: disable=inconsistent-return-statements body = { "id": "str", # Required. "pictures": [ - bytes("bytes", encoding="utf-8") # Required. + FileInputType # Required. ] } """ @@ -479,7 +476,7 @@ def binary_array_parts( # pylint: disable=inconsistent-return-statements body = { "id": "str", # Required. "pictures": [ - bytes("bytes", encoding="utf-8") # Required. + FileInputType # Required. ] } """ @@ -496,15 +493,12 @@ def binary_array_parts( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) - if isinstance(body, _model_base.Model): - _body = handle_multipart_form_data_model(body) - else: - _body = body - _files = {k: multipart_file(v) for k, v in _body.items() if isinstance(v, (IOBase, bytes))} - _data = {k: multipart_data(v) for k, v in _body.items() if not isinstance(v, (IOBase, bytes))} + _body = body.as_dict() if isinstance(body, _model_base.Model) else body + _files = [] + if _body.get("pictures") is not None: + _files.extend(_body["pictures"]) _request = build_form_data_binary_array_parts_request( - data=_data, files=_files, headers=_headers, params=_params, @@ -549,7 +543,7 @@ def json_array_parts( # pylint: disable=inconsistent-return-statements "city": "str" # Required. } ], - "profileImage": bytes("bytes", encoding="utf-8") # Required. + "profileImage": FileInputType # Required. } """ @@ -585,7 +579,7 @@ def json_array_parts( # pylint: disable=inconsistent-return-statements "city": "str" # Required. } ], - "profileImage": bytes("bytes", encoding="utf-8") # Required. + "profileImage": FileInputType # Required. } """ error_map = { @@ -601,15 +595,14 @@ def json_array_parts( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) - if isinstance(body, _model_base.Model): - _body = handle_multipart_form_data_model(body) - else: - _body = body - _files = {k: multipart_file(v) for k, v in _body.items() if isinstance(v, (IOBase, bytes))} - _data = {k: multipart_data(v) for k, v in _body.items() if not isinstance(v, (IOBase, bytes))} + _body = body.as_dict() if isinstance(body, _model_base.Model) else body + _files = [] + if _body.get("profileImage") is not None: + _files.append(_body["profileImage"]) + if _body.get("previousAddresses") is not None: + _files.extend(_body["previousAddresses"]) _request = build_form_data_json_array_parts_request( - data=_data, files=_files, headers=_headers, params=_params, @@ -649,8 +642,8 @@ def multi_binary_parts( # pylint: disable=inconsistent-return-statements # JSON input template you can fill out and use as your body input. body = { - "profileImage": bytes("bytes", encoding="utf-8"), # Required. - "picture": bytes("bytes", encoding="utf-8") # Optional. + "profileImage": FileInputType, # Required. + "picture": FileInputType # Optional. } """ @@ -681,8 +674,8 @@ def multi_binary_parts( # pylint: disable=inconsistent-return-statements # JSON input template you can fill out and use as your body input. body = { - "profileImage": bytes("bytes", encoding="utf-8"), # Required. - "picture": bytes("bytes", encoding="utf-8") # Optional. + "profileImage": FileInputType, # Required. + "picture": FileInputType # Optional. } """ error_map = { @@ -698,15 +691,14 @@ def multi_binary_parts( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) - if isinstance(body, _model_base.Model): - _body = handle_multipart_form_data_model(body) - else: - _body = body - _files = {k: multipart_file(v) for k, v in _body.items() if isinstance(v, (IOBase, bytes))} - _data = {k: multipart_data(v) for k, v in _body.items() if not isinstance(v, (IOBase, bytes))} + _body = body.as_dict() if isinstance(body, _model_base.Model) else body + _files = [] + if _body.get("profileImage") is not None: + _files.append(_body["profileImage"]) + if _body.get("picture") is not None: + _files.append(_body["picture"]) _request = build_form_data_multi_binary_parts_request( - data=_data, files=_files, headers=_headers, params=_params, diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 739638f9401..e997128d1df 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -1,5 +1,9 @@ lockfileVersion: '6.0' +settings: + autoInstallPeers: true + excludeLinksFromLockfile: false + importers: .: @@ -70,8 +74,8 @@ importers: specifier: '>=0.38.0 <1.0.0' version: 0.38.0(@azure-tools/typespec-autorest@0.38.0)(@azure-tools/typespec-azure-core@0.38.0)(@typespec/compiler@0.52.0)(@typespec/http@0.52.0)(@typespec/openapi@0.52.0)(@typespec/rest@0.52.0)(@typespec/versioning@0.52.0) '@azure-tools/typespec-client-generator-core': - specifier: ~0.38.0 - version: 0.38.0(@typespec/compiler@0.52.0)(@typespec/http@0.52.0)(@typespec/rest@0.52.0)(@typespec/versioning@0.52.0) + specifier: 0.39.0-dev.2 + version: 0.39.0-dev.2(@typespec/compiler@0.52.0)(@typespec/http@0.52.0)(@typespec/rest@0.52.0)(@typespec/versioning@0.52.0) '@types/js-yaml': specifier: ~4.0.5 version: 4.0.5 @@ -360,14 +364,14 @@ packages: '@typespec/versioning': 0.52.0(@typespec/compiler@0.52.0) dev: true - /@azure-tools/typespec-client-generator-core@0.38.0(@typespec/compiler@0.52.0)(@typespec/http@0.52.0)(@typespec/rest@0.52.0)(@typespec/versioning@0.52.0): - resolution: {integrity: sha512-DUDIHJikz3Ai8uPk3vKFoMkkGPUxoD5DbGdwkN/pQxaL6Aze8HV4LGEOGtvaIu0SsGjCX9G3XPAXoBoupYgXbw==} + /@azure-tools/typespec-client-generator-core@0.39.0-dev.2(@typespec/compiler@0.52.0)(@typespec/http@0.52.0)(@typespec/rest@0.52.0)(@typespec/versioning@0.52.0): + resolution: {integrity: sha512-lYjtAKYa82O6VlsSqxbbJ3IPHwe/alWnI57Dbx7KYJjqeEnmk+6aZG9amRTAYGm6EiqVAQnxG6DDW947kZlsIQ==} engines: {node: '>=18.0.0'} peerDependencies: - '@typespec/compiler': ~0.52.0 - '@typespec/http': ~0.52.0 - '@typespec/rest': ~0.52.0 - '@typespec/versioning': ~0.52.0 + '@typespec/compiler': ~0.52.0 || >=0.53.0-dev <0.53.0 + '@typespec/http': ~0.52.0 || >=0.53.0-dev <0.53.0 + '@typespec/rest': ~0.52.0 || >=0.53.0-dev <0.53.0 + '@typespec/versioning': ~0.52.0 || >=0.53.0-dev <0.53.0 dependencies: '@typespec/compiler': 0.52.0 '@typespec/http': 0.52.0(@typespec/compiler@0.52.0) @@ -5433,7 +5437,3 @@ packages: /zod@3.21.4: resolution: {integrity: sha512-m46AKbrzKVzOzs/DZgVnG5H55N1sv1M8qZU3A8RIKbs3mrACDNeIOeilDymVb2HdmP8uwshOCF4uJ8uM9rCqJw==} dev: true - -settings: - autoInstallPeers: true - excludeLinksFromLockfile: false From e72641e807109294779576398c456b3b0ea6850b Mon Sep 17 00:00:00 2001 From: iscai-msft Date: Wed, 31 Jan 2024 14:58:30 -0500 Subject: [PATCH 13/45] can generate list of multipart file types --- .../autorest/codegen/serializers/builder_serializer.py | 2 +- .../payload/multipart/aio/operations/_operations.py | 8 ++++---- .../payload/multipart/operations/_operations.py | 8 ++++---- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/packages/autorest.python/autorest/codegen/serializers/builder_serializer.py b/packages/autorest.python/autorest/codegen/serializers/builder_serializer.py index 748b8241a5c..c999e1ab62f 100644 --- a/packages/autorest.python/autorest/codegen/serializers/builder_serializer.py +++ b/packages/autorest.python/autorest/codegen/serializers/builder_serializer.py @@ -752,7 +752,7 @@ def _serialize_body_parameter(self, builder: OperationType) -> List[str]: retval.append(f'if _body.get("{prop.wire_name}") is not None:') if prop.is_form_data: if isinstance(prop.type, ListType): - retval.append(f' _files.extend([("{prop.wire_name}", _body[i]) for i in {prop_access}])') + retval.append(f' _files.extend([("{prop.wire_name}", {prop.wire_name[0]}) for {prop.wire_name[0]} in {prop_access}])') else: # we assume that it's just a single multipart file input retval.append(f' _files.append(("{prop.wire_name}", {prop_access}))') diff --git a/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/aio/operations/_operations.py b/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/aio/operations/_operations.py index 2c970eb4109..a50dcfeb82d 100644 --- a/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/aio/operations/_operations.py +++ b/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/aio/operations/_operations.py @@ -255,9 +255,9 @@ async def complex( # pylint: disable=inconsistent-return-statements if _body.get("profileImage") is not None: _files.append(("profileImage", _body["profileImage"])) if _body.get("previousAddresses") is not None: - _files.extend([("previousAddresses", _body[i]) for i in _body["previousAddresses"]]) + _files.extend([("previousAddresses", p) for p in _body["previousAddresses"]]) if _body.get("pictures") is not None: - _files.extend([("pictures", _body[i]) for i in _body["pictures"]]) + _files.extend([("pictures", p) for p in _body["pictures"]]) _request = build_form_data_complex_request( files=_files, @@ -465,7 +465,7 @@ async def binary_array_parts( # pylint: disable=inconsistent-return-statements if _body.get("id") is not None: _data["id"] = _body["id"] if _body.get("pictures") is not None: - _files.extend([("pictures", _body[i]) for i in _body["pictures"]]) + _files.extend([("pictures", p) for p in _body["pictures"]]) _request = build_form_data_binary_array_parts_request( files=_files, @@ -574,7 +574,7 @@ async def json_array_parts( # pylint: disable=inconsistent-return-statements if _body.get("profileImage") is not None: _files.append(("profileImage", _body["profileImage"])) if _body.get("previousAddresses") is not None: - _files.extend([("previousAddresses", _body[i]) for i in _body["previousAddresses"]]) + _files.extend([("previousAddresses", p) for p in _body["previousAddresses"]]) _request = build_form_data_json_array_parts_request( files=_files, diff --git a/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/operations/_operations.py b/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/operations/_operations.py index 1ca81268355..5c4eb85ae9d 100644 --- a/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/operations/_operations.py +++ b/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/operations/_operations.py @@ -306,9 +306,9 @@ def complex( # pylint: disable=inconsistent-return-statements if _body.get("profileImage") is not None: _files.append(("profileImage", _body["profileImage"])) if _body.get("previousAddresses") is not None: - _files.extend([("previousAddresses", _body[i]) for i in _body["previousAddresses"]]) + _files.extend([("previousAddresses", p) for p in _body["previousAddresses"]]) if _body.get("pictures") is not None: - _files.extend([("pictures", _body[i]) for i in _body["pictures"]]) + _files.extend([("pictures", p) for p in _body["pictures"]]) _request = build_form_data_complex_request( files=_files, @@ -514,7 +514,7 @@ def binary_array_parts( # pylint: disable=inconsistent-return-statements if _body.get("id") is not None: _data["id"] = _body["id"] if _body.get("pictures") is not None: - _files.extend([("pictures", _body[i]) for i in _body["pictures"]]) + _files.extend([("pictures", p) for p in _body["pictures"]]) _request = build_form_data_binary_array_parts_request( files=_files, @@ -621,7 +621,7 @@ def json_array_parts( # pylint: disable=inconsistent-return-statements if _body.get("profileImage") is not None: _files.append(("profileImage", _body["profileImage"])) if _body.get("previousAddresses") is not None: - _files.extend([("previousAddresses", _body[i]) for i in _body["previousAddresses"]]) + _files.extend([("previousAddresses", p) for p in _body["previousAddresses"]]) _request = build_form_data_json_array_parts_request( files=_files, From 551832992d4fe643904ad7f3b5a4a95396b9c49f Mon Sep 17 00:00:00 2001 From: iscai-msft Date: Wed, 31 Jan 2024 15:41:25 -0500 Subject: [PATCH 14/45] regen --- .../autorest/codegen/models/combined_type.py | 4 +- .../codegen/models/dictionary_type.py | 4 - .../autorest/codegen/models/model_type.py | 4 +- .../autorest/codegen/models/parameter.py | 2 +- .../autorest/codegen/models/property.py | 10 +- .../codegen/serializers/builder_serializer.py | 2 +- .../codegen/serializers/model_serializer.py | 2 +- packages/typespec-python/package.json | 4 +- .../authentication/apikey/_model_base.py | 26 ++- .../authentication/http/custom/_model_base.py | 26 ++- .../authentication/oauth2/_model_base.py | 26 ++- .../authentication/union/_model_base.py | 26 ++- .../core/access/_model_base.py | 26 ++- .../clientgenerator/core/usage/_model_base.py | 26 ++- .../specs/azure/core/basic/_model_base.py | 26 ++- .../azure/core/lro/standard/_model_base.py | 26 ++- .../specs/azure/core/traits/_model_base.py | 26 ++- .../azure/core/traits/models/__init__.py | 3 + .../specs/azure/core/traits/models/_enums.py | 23 +++ .../azure/mgmt/spheredpg/_model_base.py | 26 ++- .../azurecore/lro/rpc/_model_base.py | 26 ++- .../azurecore/lro/rpclegacy/_model_base.py | 26 ++- .../client/structure/service/_model_base.py | 26 ++- .../structure/multiclient/_model_base.py | 26 ++- .../structure/renamedoperation/_model_base.py | 26 ++- .../twooperationgroup/_model_base.py | 26 ++- .../encode-bytes/encode/bytes/_model_base.py | 26 ++- .../encode/datetime/_model_base.py | 26 ++- .../encode/duration/_model_base.py | 26 ++- .../headasbooleanfalse/_model_base.py | 26 ++- .../headasbooleantrue/_model_base.py | 26 ++- .../parameters/bodyoptionality/_model_base.py | 26 ++- .../collectionformat/_model_base.py | 26 ++- .../parameters/spread/_model_base.py | 26 ++- .../payload/contentnegotiation/_model_base.py | 26 ++- .../payload/mediatype/_model_base.py | 26 ++- .../multipart/aio/operations/_operations.py | 146 ++++++++------- .../payload/multipart/models/_models.py | 10 +- .../multipart/operations/_operations.py | 170 +++++++++++------- .../payload/pageable/_model_base.py | 26 ++- .../projection/projectedname/_model_base.py | 26 ++- .../resiliency/srv/driven2/_model_base.py | 26 ++- .../server/path/multiple/_model_base.py | 26 ++- .../server/path/single/_model_base.py | 26 ++- .../versions/notversioned/_model_base.py | 26 ++- .../server/versions/versioned/_model_base.py | 26 ++- .../clientrequestid/_model_base.py | 26 ++- .../conditionalrequest/_model_base.py | 26 ++- .../repeatability/_model_base.py | 26 ++- .../special-words/specialwords/_model_base.py | 26 ++- .../typetest/array/_model_base.py | 26 ++- .../typetest/dictionary/_model_base.py | 26 ++- .../typetest/enum/extensible/_model_base.py | 26 ++- .../typetest/enum/fixed/_model_base.py | 26 ++- .../typetest/model/empty/_model_base.py | 26 ++- .../model/enumdiscriminator/_model_base.py | 26 ++- .../model/nesteddiscriminator/_model_base.py | 26 ++- .../model/notdiscriminated/_model_base.py | 26 ++- .../typetest/model/recursive/_model_base.py | 26 ++- .../model/singlediscriminator/_model_base.py | 26 ++- .../typetest/model/usage/_model_base.py | 26 ++- .../typetest/model/visibility/_model_base.py | 26 ++- .../additionalproperties/_model_base.py | 26 ++- .../typetest/property/nullable/_model_base.py | 26 ++- .../typetest/property/optional/_model_base.py | 26 ++- .../property/valuetypes/_model_base.py | 26 ++- .../typetest/scalar/_model_base.py | 26 ++- .../typetest/union/_model_base.py | 26 ++- .../union/aio/operations/_operations.py | 31 ++-- .../typetest/union/models/__init__.py | 2 + .../typetest/union/models/_enums.py | 7 + .../typetest/union/models/_models.py | 12 +- .../typetest/union/operations/_operations.py | 31 ++-- .../authentication/apikey/_model_base.py | 26 ++- .../authentication/http/custom/_model_base.py | 26 ++- .../authentication/oauth2/_model_base.py | 26 ++- .../authentication/union/_model_base.py | 26 ++- .../client/structure/service/_model_base.py | 26 ++- .../structure/multiclient/_model_base.py | 26 ++- .../structure/renamedoperation/_model_base.py | 26 ++- .../twooperationgroup/_model_base.py | 26 ++- .../encode-bytes/encode/bytes/_model_base.py | 26 ++- .../encode/datetime/_model_base.py | 26 ++- .../encode/duration/_model_base.py | 26 ++- .../headasbooleanfalse/_model_base.py | 26 ++- .../headasbooleantrue/_model_base.py | 26 ++- .../parameters/bodyoptionality/_model_base.py | 26 ++- .../collectionformat/_model_base.py | 26 ++- .../parameters/spread/_model_base.py | 26 ++- .../payload/contentnegotiation/_model_base.py | 26 ++- .../payload/mediatype/_model_base.py | 26 ++- .../payload/multipart/_model_base.py | 26 ++- .../multipart/aio/operations/_operations.py | 128 ++++++++----- .../payload/multipart/models/_models.py | 18 +- .../multipart/operations/_operations.py | 152 +++++++++++----- .../payload/pageable/_model_base.py | 26 ++- .../projection/projectedname/_model_base.py | 26 ++- .../resiliency/srv/driven1/_model_base.py | 26 ++- .../resiliency/srv/driven2/_model_base.py | 26 ++- .../server/path/multiple/_model_base.py | 26 ++- .../server/path/single/_model_base.py | 26 ++- .../versions/notversioned/_model_base.py | 26 ++- .../server/versions/versioned/_model_base.py | 26 ++- .../conditionalrequest/_model_base.py | 26 ++- .../repeatability/_model_base.py | 26 ++- .../special-words/specialwords/_model_base.py | 26 ++- .../typetest/array/_model_base.py | 26 ++- .../typetest/dictionary/_model_base.py | 26 ++- .../typetest/enum/extensible/_model_base.py | 26 ++- .../typetest/enum/fixed/_model_base.py | 26 ++- .../typetest/model/empty/_model_base.py | 26 ++- .../model/enumdiscriminator/_model_base.py | 26 ++- .../model/nesteddiscriminator/_model_base.py | 26 ++- .../model/notdiscriminated/_model_base.py | 26 ++- .../typetest/model/recursive/_model_base.py | 26 ++- .../model/singlediscriminator/_model_base.py | 26 ++- .../typetest/model/usage/_model_base.py | 26 ++- .../typetest/model/visibility/_model_base.py | 26 ++- .../additionalproperties/_model_base.py | 26 ++- .../typetest/property/nullable/_model_base.py | 26 ++- .../typetest/property/optional/_model_base.py | 26 ++- .../property/valuetypes/_model_base.py | 26 ++- .../typetest/scalar/_model_base.py | 26 ++- .../typetest/union/_model_base.py | 26 ++- .../union/aio/operations/_operations.py | 31 ++-- .../typetest/union/models/__init__.py | 2 + .../typetest/union/models/_enums.py | 7 + .../typetest/union/models/_models.py | 12 +- .../typetest/union/operations/_operations.py | 31 ++-- pnpm-lock.yaml | 8 +- 130 files changed, 2804 insertions(+), 730 deletions(-) create mode 100644 packages/typespec-python/test/azure/generated/azure-core-traits/specs/azure/core/traits/models/_enums.py diff --git a/packages/autorest.python/autorest/codegen/models/combined_type.py b/packages/autorest.python/autorest/codegen/models/combined_type.py index 5c0ad8ee7af..f50766e598a 100644 --- a/packages/autorest.python/autorest/codegen/models/combined_type.py +++ b/packages/autorest.python/autorest/codegen/models/combined_type.py @@ -80,8 +80,8 @@ def type_definition(self, **kwargs: Any) -> str: return f'Union[{", ".join(map(lambda x: x[6: -1] if pattern.match(x) else x, inside_types))}]' @property - def is_multipart_file(self) -> bool: - return any(t.is_multipart_file for t in self.types) + def is_form_data(self) -> bool: + return any(t.type == "model" and t.is_form_data for t in self.types) def get_json_template_representation( self, diff --git a/packages/autorest.python/autorest/codegen/models/dictionary_type.py b/packages/autorest.python/autorest/codegen/models/dictionary_type.py index 6fcf3d78d5f..0b9423250fc 100644 --- a/packages/autorest.python/autorest/codegen/models/dictionary_type.py +++ b/packages/autorest.python/autorest/codegen/models/dictionary_type.py @@ -33,10 +33,6 @@ def __init__( @property def encode(self) -> Optional[str]: return self.element_type.encode if hasattr(self.element_type, "encode") else None # type: ignore - - @property - def is_multipart_file(self) -> bool: - return self.element_type.is_multipart_file @property def serialization_type(self) -> str: diff --git a/packages/autorest.python/autorest/codegen/models/model_type.py b/packages/autorest.python/autorest/codegen/models/model_type.py index 7df19a80d61..ba298cdd1a6 100644 --- a/packages/autorest.python/autorest/codegen/models/model_type.py +++ b/packages/autorest.python/autorest/codegen/models/model_type.py @@ -77,7 +77,7 @@ def __init__( self.page_result_model: bool = self.yaml_data.get("pageResultModel", False) @property - def is_multipart_file(self) -> bool: + def is_form_data(self) -> bool: return any(p.is_multipart_file for p in self.properties) @property @@ -318,7 +318,7 @@ def imports(self, **kwargs: Any) -> FileImport: if kwargs.get("model_typing") else TypingSection.REGULAR, ) - if self.is_multipart_file: + if self.is_form_data: file_import.add_submodule_import( relative_path, "_model_base", diff --git a/packages/autorest.python/autorest/codegen/models/parameter.py b/packages/autorest.python/autorest/codegen/models/parameter.py index 6e789f2d22b..054008334de 100644 --- a/packages/autorest.python/autorest/codegen/models/parameter.py +++ b/packages/autorest.python/autorest/codegen/models/parameter.py @@ -247,7 +247,7 @@ class BodyParameter(_ParameterBase): @property def is_form_data(self) -> bool: - return self.type.is_multipart_file + return self.type.type == "model" and self.type.is_form_data @property def is_partial_body(self) -> bool: diff --git a/packages/autorest.python/autorest/codegen/models/property.py b/packages/autorest.python/autorest/codegen/models/property.py index 44c82e83853..ed35f5a796a 100644 --- a/packages/autorest.python/autorest/codegen/models/property.py +++ b/packages/autorest.python/autorest/codegen/models/property.py @@ -37,7 +37,6 @@ def __init__( if self.client_default_value is None: self.client_default_value = self.type.client_default_value self.flattened_names: List[str] = yaml_data.get("flattenedNames", []) - self.is_multipart_file: bool = True @property def pylint_disable(self) -> str: @@ -165,8 +164,13 @@ def imports(self, **kwargs) -> FileImport: return file_import @property - def is_form_data(self) -> bool: - return self.type.is_multipart_file + def is_multipart_file(self) -> bool: + """ + We need to check if the type is a model because this could cause infinite recursion. + The only file values that we consider is either a single mutlipart file type, or a list + of them, so there's no need to check for models + """ + return self.type != "model" and self.type.is_multipart_file # this prevents infinite recursion f @classmethod def from_yaml( diff --git a/packages/autorest.python/autorest/codegen/serializers/builder_serializer.py b/packages/autorest.python/autorest/codegen/serializers/builder_serializer.py index c999e1ab62f..5b78b6f7982 100644 --- a/packages/autorest.python/autorest/codegen/serializers/builder_serializer.py +++ b/packages/autorest.python/autorest/codegen/serializers/builder_serializer.py @@ -750,7 +750,7 @@ def _serialize_body_parameter(self, builder: OperationType) -> List[str]: for prop in model_type.properties: prop_access = f'_body["{prop.wire_name}"]' retval.append(f'if _body.get("{prop.wire_name}") is not None:') - if prop.is_form_data: + if prop.is_multipart_file: if isinstance(prop.type, ListType): retval.append(f' _files.extend([("{prop.wire_name}", {prop.wire_name[0]}) for {prop.wire_name[0]} in {prop_access}])') else: diff --git a/packages/autorest.python/autorest/codegen/serializers/model_serializer.py b/packages/autorest.python/autorest/codegen/serializers/model_serializer.py index 91adb3d4366..5b68366ea91 100644 --- a/packages/autorest.python/autorest/codegen/serializers/model_serializer.py +++ b/packages/autorest.python/autorest/codegen/serializers/model_serializer.py @@ -259,7 +259,7 @@ def declare_property(prop: Property) -> str: args.append(f"default={prop.client_default_value_declaration}") if hasattr(prop.type, "encode") and prop.type.encode: # type: ignore args.append(f'format="{prop.type.encode}"') # type: ignore - if prop.is_form_data: + if prop.is_multipart_file: args.append("is_multipart_file=True") field = "rest_discriminator" if prop.is_discriminator else "rest_field" diff --git a/packages/typespec-python/package.json b/packages/typespec-python/package.json index 4fc49150451..ad872751183 100644 --- a/packages/typespec-python/package.json +++ b/packages/typespec-python/package.json @@ -43,7 +43,7 @@ ], "peerDependencies": { "@azure-tools/typespec-azure-core": ">=0.38.0 <1.0.0", - "@azure-tools/typespec-client-generator-core": "0.39.0-dev.2", + "@azure-tools/typespec-client-generator-core": "0.39.0-dev.3", "@typespec/compiler": ">=0.52.0 <1.0.0", "@typespec/http": ">=0.52.0 <1.0.0", "@typespec/rest": ">=0.52.0 <1.0.0", @@ -74,7 +74,7 @@ "rimraf": "~5.0.0", "typescript": "~5.1.3", "@azure-tools/typespec-azure-core": "~0.38.0", - "@azure-tools/typespec-client-generator-core": "0.39.0-dev.2", + "@azure-tools/typespec-client-generator-core": "0.39.0-dev.3", "@typespec/compiler": "~0.52.0", "@typespec/http": "~0.52.0", "@typespec/rest": "~0.52.0", diff --git a/packages/typespec-python/test/azure/generated/authentication-api-key/authentication/apikey/_model_base.py b/packages/typespec-python/test/azure/generated/authentication-api-key/authentication/apikey/_model_base.py index 585ccb0e0f9..01c401e6324 100644 --- a/packages/typespec-python/test/azure/generated/authentication-api-key/authentication/apikey/_model_base.py +++ b/packages/typespec-python/test/azure/generated/authentication-api-key/authentication/apikey/_model_base.py @@ -462,7 +462,13 @@ def _get_rest_field( def _create_value(rf: typing.Optional["_RestField"], value: typing.Any) -> typing.Any: - return _deserialize(rf._type, value) if (rf and rf._is_model) else _serialize(value, rf._format if rf else None) + if not rf: + return _serialize(value, None) + if rf._is_multipart_file: + return value + if rf._is_model: + return _deserialize(rf._type, value) + return _serialize(value, rf._format) class Model(_MyMutableMapping): @@ -559,7 +565,14 @@ def as_dict(self, *, exclude_readonly: bool = False) -> typing.Dict[str, typing. for k, v in self.items(): if exclude_readonly and k in readonly_props: # pyright: ignore[reportUnboundVariable] continue - result[k] = Model._as_dict_value(v, exclude_readonly=exclude_readonly) + is_multipart_file = False + try: + is_multipart_file = next( + rf for rf in self._attr_to_rest_field.values() if rf._rest_name == k + )._is_multipart_file + except StopIteration: + pass + result[k] = v if is_multipart_file else Model._as_dict_value(v, exclude_readonly=exclude_readonly) return result @staticmethod @@ -567,7 +580,7 @@ def _as_dict_value(v: typing.Any, exclude_readonly: bool = False) -> typing.Any: if v is None or isinstance(v, _Null): return None if isinstance(v, (list, tuple, set)): - return [Model._as_dict_value(x, exclude_readonly=exclude_readonly) for x in v] + return type(v)(Model._as_dict_value(x, exclude_readonly=exclude_readonly) for x in v) if isinstance(v, dict): return {dk: Model._as_dict_value(dv, exclude_readonly=exclude_readonly) for dk, dv in v.items()} return v.as_dict(exclude_readonly=exclude_readonly) if hasattr(v, "as_dict") else v @@ -762,6 +775,7 @@ def __init__( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, + is_multipart_file: bool = False, ): self._type = type self._rest_name_input = name @@ -771,6 +785,7 @@ def __init__( self._is_model = False self._default = default self._format = format + self._is_multipart_file = is_multipart_file @property def _rest_name(self) -> str: @@ -816,8 +831,11 @@ def rest_field( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, + is_multipart_file: bool = False, ) -> typing.Any: - return _RestField(name=name, type=type, visibility=visibility, default=default, format=format) + return _RestField( + name=name, type=type, visibility=visibility, default=default, format=format, is_multipart_file=is_multipart_file + ) def rest_discriminator( diff --git a/packages/typespec-python/test/azure/generated/authentication-http-custom/authentication/http/custom/_model_base.py b/packages/typespec-python/test/azure/generated/authentication-http-custom/authentication/http/custom/_model_base.py index 585ccb0e0f9..01c401e6324 100644 --- a/packages/typespec-python/test/azure/generated/authentication-http-custom/authentication/http/custom/_model_base.py +++ b/packages/typespec-python/test/azure/generated/authentication-http-custom/authentication/http/custom/_model_base.py @@ -462,7 +462,13 @@ def _get_rest_field( def _create_value(rf: typing.Optional["_RestField"], value: typing.Any) -> typing.Any: - return _deserialize(rf._type, value) if (rf and rf._is_model) else _serialize(value, rf._format if rf else None) + if not rf: + return _serialize(value, None) + if rf._is_multipart_file: + return value + if rf._is_model: + return _deserialize(rf._type, value) + return _serialize(value, rf._format) class Model(_MyMutableMapping): @@ -559,7 +565,14 @@ def as_dict(self, *, exclude_readonly: bool = False) -> typing.Dict[str, typing. for k, v in self.items(): if exclude_readonly and k in readonly_props: # pyright: ignore[reportUnboundVariable] continue - result[k] = Model._as_dict_value(v, exclude_readonly=exclude_readonly) + is_multipart_file = False + try: + is_multipart_file = next( + rf for rf in self._attr_to_rest_field.values() if rf._rest_name == k + )._is_multipart_file + except StopIteration: + pass + result[k] = v if is_multipart_file else Model._as_dict_value(v, exclude_readonly=exclude_readonly) return result @staticmethod @@ -567,7 +580,7 @@ def _as_dict_value(v: typing.Any, exclude_readonly: bool = False) -> typing.Any: if v is None or isinstance(v, _Null): return None if isinstance(v, (list, tuple, set)): - return [Model._as_dict_value(x, exclude_readonly=exclude_readonly) for x in v] + return type(v)(Model._as_dict_value(x, exclude_readonly=exclude_readonly) for x in v) if isinstance(v, dict): return {dk: Model._as_dict_value(dv, exclude_readonly=exclude_readonly) for dk, dv in v.items()} return v.as_dict(exclude_readonly=exclude_readonly) if hasattr(v, "as_dict") else v @@ -762,6 +775,7 @@ def __init__( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, + is_multipart_file: bool = False, ): self._type = type self._rest_name_input = name @@ -771,6 +785,7 @@ def __init__( self._is_model = False self._default = default self._format = format + self._is_multipart_file = is_multipart_file @property def _rest_name(self) -> str: @@ -816,8 +831,11 @@ def rest_field( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, + is_multipart_file: bool = False, ) -> typing.Any: - return _RestField(name=name, type=type, visibility=visibility, default=default, format=format) + return _RestField( + name=name, type=type, visibility=visibility, default=default, format=format, is_multipart_file=is_multipart_file + ) def rest_discriminator( diff --git a/packages/typespec-python/test/azure/generated/authentication-oauth2/authentication/oauth2/_model_base.py b/packages/typespec-python/test/azure/generated/authentication-oauth2/authentication/oauth2/_model_base.py index 585ccb0e0f9..01c401e6324 100644 --- a/packages/typespec-python/test/azure/generated/authentication-oauth2/authentication/oauth2/_model_base.py +++ b/packages/typespec-python/test/azure/generated/authentication-oauth2/authentication/oauth2/_model_base.py @@ -462,7 +462,13 @@ def _get_rest_field( def _create_value(rf: typing.Optional["_RestField"], value: typing.Any) -> typing.Any: - return _deserialize(rf._type, value) if (rf and rf._is_model) else _serialize(value, rf._format if rf else None) + if not rf: + return _serialize(value, None) + if rf._is_multipart_file: + return value + if rf._is_model: + return _deserialize(rf._type, value) + return _serialize(value, rf._format) class Model(_MyMutableMapping): @@ -559,7 +565,14 @@ def as_dict(self, *, exclude_readonly: bool = False) -> typing.Dict[str, typing. for k, v in self.items(): if exclude_readonly and k in readonly_props: # pyright: ignore[reportUnboundVariable] continue - result[k] = Model._as_dict_value(v, exclude_readonly=exclude_readonly) + is_multipart_file = False + try: + is_multipart_file = next( + rf for rf in self._attr_to_rest_field.values() if rf._rest_name == k + )._is_multipart_file + except StopIteration: + pass + result[k] = v if is_multipart_file else Model._as_dict_value(v, exclude_readonly=exclude_readonly) return result @staticmethod @@ -567,7 +580,7 @@ def _as_dict_value(v: typing.Any, exclude_readonly: bool = False) -> typing.Any: if v is None or isinstance(v, _Null): return None if isinstance(v, (list, tuple, set)): - return [Model._as_dict_value(x, exclude_readonly=exclude_readonly) for x in v] + return type(v)(Model._as_dict_value(x, exclude_readonly=exclude_readonly) for x in v) if isinstance(v, dict): return {dk: Model._as_dict_value(dv, exclude_readonly=exclude_readonly) for dk, dv in v.items()} return v.as_dict(exclude_readonly=exclude_readonly) if hasattr(v, "as_dict") else v @@ -762,6 +775,7 @@ def __init__( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, + is_multipart_file: bool = False, ): self._type = type self._rest_name_input = name @@ -771,6 +785,7 @@ def __init__( self._is_model = False self._default = default self._format = format + self._is_multipart_file = is_multipart_file @property def _rest_name(self) -> str: @@ -816,8 +831,11 @@ def rest_field( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, + is_multipart_file: bool = False, ) -> typing.Any: - return _RestField(name=name, type=type, visibility=visibility, default=default, format=format) + return _RestField( + name=name, type=type, visibility=visibility, default=default, format=format, is_multipart_file=is_multipart_file + ) def rest_discriminator( diff --git a/packages/typespec-python/test/azure/generated/authentication-union/authentication/union/_model_base.py b/packages/typespec-python/test/azure/generated/authentication-union/authentication/union/_model_base.py index 585ccb0e0f9..01c401e6324 100644 --- a/packages/typespec-python/test/azure/generated/authentication-union/authentication/union/_model_base.py +++ b/packages/typespec-python/test/azure/generated/authentication-union/authentication/union/_model_base.py @@ -462,7 +462,13 @@ def _get_rest_field( def _create_value(rf: typing.Optional["_RestField"], value: typing.Any) -> typing.Any: - return _deserialize(rf._type, value) if (rf and rf._is_model) else _serialize(value, rf._format if rf else None) + if not rf: + return _serialize(value, None) + if rf._is_multipart_file: + return value + if rf._is_model: + return _deserialize(rf._type, value) + return _serialize(value, rf._format) class Model(_MyMutableMapping): @@ -559,7 +565,14 @@ def as_dict(self, *, exclude_readonly: bool = False) -> typing.Dict[str, typing. for k, v in self.items(): if exclude_readonly and k in readonly_props: # pyright: ignore[reportUnboundVariable] continue - result[k] = Model._as_dict_value(v, exclude_readonly=exclude_readonly) + is_multipart_file = False + try: + is_multipart_file = next( + rf for rf in self._attr_to_rest_field.values() if rf._rest_name == k + )._is_multipart_file + except StopIteration: + pass + result[k] = v if is_multipart_file else Model._as_dict_value(v, exclude_readonly=exclude_readonly) return result @staticmethod @@ -567,7 +580,7 @@ def _as_dict_value(v: typing.Any, exclude_readonly: bool = False) -> typing.Any: if v is None or isinstance(v, _Null): return None if isinstance(v, (list, tuple, set)): - return [Model._as_dict_value(x, exclude_readonly=exclude_readonly) for x in v] + return type(v)(Model._as_dict_value(x, exclude_readonly=exclude_readonly) for x in v) if isinstance(v, dict): return {dk: Model._as_dict_value(dv, exclude_readonly=exclude_readonly) for dk, dv in v.items()} return v.as_dict(exclude_readonly=exclude_readonly) if hasattr(v, "as_dict") else v @@ -762,6 +775,7 @@ def __init__( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, + is_multipart_file: bool = False, ): self._type = type self._rest_name_input = name @@ -771,6 +785,7 @@ def __init__( self._is_model = False self._default = default self._format = format + self._is_multipart_file = is_multipart_file @property def _rest_name(self) -> str: @@ -816,8 +831,11 @@ def rest_field( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, + is_multipart_file: bool = False, ) -> typing.Any: - return _RestField(name=name, type=type, visibility=visibility, default=default, format=format) + return _RestField( + name=name, type=type, visibility=visibility, default=default, format=format, is_multipart_file=is_multipart_file + ) def rest_discriminator( diff --git a/packages/typespec-python/test/azure/generated/azure-client-generator-core-access/specs/azure/clientgenerator/core/access/_model_base.py b/packages/typespec-python/test/azure/generated/azure-client-generator-core-access/specs/azure/clientgenerator/core/access/_model_base.py index 585ccb0e0f9..01c401e6324 100644 --- a/packages/typespec-python/test/azure/generated/azure-client-generator-core-access/specs/azure/clientgenerator/core/access/_model_base.py +++ b/packages/typespec-python/test/azure/generated/azure-client-generator-core-access/specs/azure/clientgenerator/core/access/_model_base.py @@ -462,7 +462,13 @@ def _get_rest_field( def _create_value(rf: typing.Optional["_RestField"], value: typing.Any) -> typing.Any: - return _deserialize(rf._type, value) if (rf and rf._is_model) else _serialize(value, rf._format if rf else None) + if not rf: + return _serialize(value, None) + if rf._is_multipart_file: + return value + if rf._is_model: + return _deserialize(rf._type, value) + return _serialize(value, rf._format) class Model(_MyMutableMapping): @@ -559,7 +565,14 @@ def as_dict(self, *, exclude_readonly: bool = False) -> typing.Dict[str, typing. for k, v in self.items(): if exclude_readonly and k in readonly_props: # pyright: ignore[reportUnboundVariable] continue - result[k] = Model._as_dict_value(v, exclude_readonly=exclude_readonly) + is_multipart_file = False + try: + is_multipart_file = next( + rf for rf in self._attr_to_rest_field.values() if rf._rest_name == k + )._is_multipart_file + except StopIteration: + pass + result[k] = v if is_multipart_file else Model._as_dict_value(v, exclude_readonly=exclude_readonly) return result @staticmethod @@ -567,7 +580,7 @@ def _as_dict_value(v: typing.Any, exclude_readonly: bool = False) -> typing.Any: if v is None or isinstance(v, _Null): return None if isinstance(v, (list, tuple, set)): - return [Model._as_dict_value(x, exclude_readonly=exclude_readonly) for x in v] + return type(v)(Model._as_dict_value(x, exclude_readonly=exclude_readonly) for x in v) if isinstance(v, dict): return {dk: Model._as_dict_value(dv, exclude_readonly=exclude_readonly) for dk, dv in v.items()} return v.as_dict(exclude_readonly=exclude_readonly) if hasattr(v, "as_dict") else v @@ -762,6 +775,7 @@ def __init__( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, + is_multipart_file: bool = False, ): self._type = type self._rest_name_input = name @@ -771,6 +785,7 @@ def __init__( self._is_model = False self._default = default self._format = format + self._is_multipart_file = is_multipart_file @property def _rest_name(self) -> str: @@ -816,8 +831,11 @@ def rest_field( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, + is_multipart_file: bool = False, ) -> typing.Any: - return _RestField(name=name, type=type, visibility=visibility, default=default, format=format) + return _RestField( + name=name, type=type, visibility=visibility, default=default, format=format, is_multipart_file=is_multipart_file + ) def rest_discriminator( diff --git a/packages/typespec-python/test/azure/generated/azure-client-generator-core-usage/specs/azure/clientgenerator/core/usage/_model_base.py b/packages/typespec-python/test/azure/generated/azure-client-generator-core-usage/specs/azure/clientgenerator/core/usage/_model_base.py index 585ccb0e0f9..01c401e6324 100644 --- a/packages/typespec-python/test/azure/generated/azure-client-generator-core-usage/specs/azure/clientgenerator/core/usage/_model_base.py +++ b/packages/typespec-python/test/azure/generated/azure-client-generator-core-usage/specs/azure/clientgenerator/core/usage/_model_base.py @@ -462,7 +462,13 @@ def _get_rest_field( def _create_value(rf: typing.Optional["_RestField"], value: typing.Any) -> typing.Any: - return _deserialize(rf._type, value) if (rf and rf._is_model) else _serialize(value, rf._format if rf else None) + if not rf: + return _serialize(value, None) + if rf._is_multipart_file: + return value + if rf._is_model: + return _deserialize(rf._type, value) + return _serialize(value, rf._format) class Model(_MyMutableMapping): @@ -559,7 +565,14 @@ def as_dict(self, *, exclude_readonly: bool = False) -> typing.Dict[str, typing. for k, v in self.items(): if exclude_readonly and k in readonly_props: # pyright: ignore[reportUnboundVariable] continue - result[k] = Model._as_dict_value(v, exclude_readonly=exclude_readonly) + is_multipart_file = False + try: + is_multipart_file = next( + rf for rf in self._attr_to_rest_field.values() if rf._rest_name == k + )._is_multipart_file + except StopIteration: + pass + result[k] = v if is_multipart_file else Model._as_dict_value(v, exclude_readonly=exclude_readonly) return result @staticmethod @@ -567,7 +580,7 @@ def _as_dict_value(v: typing.Any, exclude_readonly: bool = False) -> typing.Any: if v is None or isinstance(v, _Null): return None if isinstance(v, (list, tuple, set)): - return [Model._as_dict_value(x, exclude_readonly=exclude_readonly) for x in v] + return type(v)(Model._as_dict_value(x, exclude_readonly=exclude_readonly) for x in v) if isinstance(v, dict): return {dk: Model._as_dict_value(dv, exclude_readonly=exclude_readonly) for dk, dv in v.items()} return v.as_dict(exclude_readonly=exclude_readonly) if hasattr(v, "as_dict") else v @@ -762,6 +775,7 @@ def __init__( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, + is_multipart_file: bool = False, ): self._type = type self._rest_name_input = name @@ -771,6 +785,7 @@ def __init__( self._is_model = False self._default = default self._format = format + self._is_multipart_file = is_multipart_file @property def _rest_name(self) -> str: @@ -816,8 +831,11 @@ def rest_field( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, + is_multipart_file: bool = False, ) -> typing.Any: - return _RestField(name=name, type=type, visibility=visibility, default=default, format=format) + return _RestField( + name=name, type=type, visibility=visibility, default=default, format=format, is_multipart_file=is_multipart_file + ) def rest_discriminator( diff --git a/packages/typespec-python/test/azure/generated/azure-core-basic/specs/azure/core/basic/_model_base.py b/packages/typespec-python/test/azure/generated/azure-core-basic/specs/azure/core/basic/_model_base.py index 585ccb0e0f9..01c401e6324 100644 --- a/packages/typespec-python/test/azure/generated/azure-core-basic/specs/azure/core/basic/_model_base.py +++ b/packages/typespec-python/test/azure/generated/azure-core-basic/specs/azure/core/basic/_model_base.py @@ -462,7 +462,13 @@ def _get_rest_field( def _create_value(rf: typing.Optional["_RestField"], value: typing.Any) -> typing.Any: - return _deserialize(rf._type, value) if (rf and rf._is_model) else _serialize(value, rf._format if rf else None) + if not rf: + return _serialize(value, None) + if rf._is_multipart_file: + return value + if rf._is_model: + return _deserialize(rf._type, value) + return _serialize(value, rf._format) class Model(_MyMutableMapping): @@ -559,7 +565,14 @@ def as_dict(self, *, exclude_readonly: bool = False) -> typing.Dict[str, typing. for k, v in self.items(): if exclude_readonly and k in readonly_props: # pyright: ignore[reportUnboundVariable] continue - result[k] = Model._as_dict_value(v, exclude_readonly=exclude_readonly) + is_multipart_file = False + try: + is_multipart_file = next( + rf for rf in self._attr_to_rest_field.values() if rf._rest_name == k + )._is_multipart_file + except StopIteration: + pass + result[k] = v if is_multipart_file else Model._as_dict_value(v, exclude_readonly=exclude_readonly) return result @staticmethod @@ -567,7 +580,7 @@ def _as_dict_value(v: typing.Any, exclude_readonly: bool = False) -> typing.Any: if v is None or isinstance(v, _Null): return None if isinstance(v, (list, tuple, set)): - return [Model._as_dict_value(x, exclude_readonly=exclude_readonly) for x in v] + return type(v)(Model._as_dict_value(x, exclude_readonly=exclude_readonly) for x in v) if isinstance(v, dict): return {dk: Model._as_dict_value(dv, exclude_readonly=exclude_readonly) for dk, dv in v.items()} return v.as_dict(exclude_readonly=exclude_readonly) if hasattr(v, "as_dict") else v @@ -762,6 +775,7 @@ def __init__( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, + is_multipart_file: bool = False, ): self._type = type self._rest_name_input = name @@ -771,6 +785,7 @@ def __init__( self._is_model = False self._default = default self._format = format + self._is_multipart_file = is_multipart_file @property def _rest_name(self) -> str: @@ -816,8 +831,11 @@ def rest_field( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, + is_multipart_file: bool = False, ) -> typing.Any: - return _RestField(name=name, type=type, visibility=visibility, default=default, format=format) + return _RestField( + name=name, type=type, visibility=visibility, default=default, format=format, is_multipart_file=is_multipart_file + ) def rest_discriminator( diff --git a/packages/typespec-python/test/azure/generated/azure-core-lro-standard/specs/azure/core/lro/standard/_model_base.py b/packages/typespec-python/test/azure/generated/azure-core-lro-standard/specs/azure/core/lro/standard/_model_base.py index 585ccb0e0f9..01c401e6324 100644 --- a/packages/typespec-python/test/azure/generated/azure-core-lro-standard/specs/azure/core/lro/standard/_model_base.py +++ b/packages/typespec-python/test/azure/generated/azure-core-lro-standard/specs/azure/core/lro/standard/_model_base.py @@ -462,7 +462,13 @@ def _get_rest_field( def _create_value(rf: typing.Optional["_RestField"], value: typing.Any) -> typing.Any: - return _deserialize(rf._type, value) if (rf and rf._is_model) else _serialize(value, rf._format if rf else None) + if not rf: + return _serialize(value, None) + if rf._is_multipart_file: + return value + if rf._is_model: + return _deserialize(rf._type, value) + return _serialize(value, rf._format) class Model(_MyMutableMapping): @@ -559,7 +565,14 @@ def as_dict(self, *, exclude_readonly: bool = False) -> typing.Dict[str, typing. for k, v in self.items(): if exclude_readonly and k in readonly_props: # pyright: ignore[reportUnboundVariable] continue - result[k] = Model._as_dict_value(v, exclude_readonly=exclude_readonly) + is_multipart_file = False + try: + is_multipart_file = next( + rf for rf in self._attr_to_rest_field.values() if rf._rest_name == k + )._is_multipart_file + except StopIteration: + pass + result[k] = v if is_multipart_file else Model._as_dict_value(v, exclude_readonly=exclude_readonly) return result @staticmethod @@ -567,7 +580,7 @@ def _as_dict_value(v: typing.Any, exclude_readonly: bool = False) -> typing.Any: if v is None or isinstance(v, _Null): return None if isinstance(v, (list, tuple, set)): - return [Model._as_dict_value(x, exclude_readonly=exclude_readonly) for x in v] + return type(v)(Model._as_dict_value(x, exclude_readonly=exclude_readonly) for x in v) if isinstance(v, dict): return {dk: Model._as_dict_value(dv, exclude_readonly=exclude_readonly) for dk, dv in v.items()} return v.as_dict(exclude_readonly=exclude_readonly) if hasattr(v, "as_dict") else v @@ -762,6 +775,7 @@ def __init__( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, + is_multipart_file: bool = False, ): self._type = type self._rest_name_input = name @@ -771,6 +785,7 @@ def __init__( self._is_model = False self._default = default self._format = format + self._is_multipart_file = is_multipart_file @property def _rest_name(self) -> str: @@ -816,8 +831,11 @@ def rest_field( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, + is_multipart_file: bool = False, ) -> typing.Any: - return _RestField(name=name, type=type, visibility=visibility, default=default, format=format) + return _RestField( + name=name, type=type, visibility=visibility, default=default, format=format, is_multipart_file=is_multipart_file + ) def rest_discriminator( diff --git a/packages/typespec-python/test/azure/generated/azure-core-traits/specs/azure/core/traits/_model_base.py b/packages/typespec-python/test/azure/generated/azure-core-traits/specs/azure/core/traits/_model_base.py index 585ccb0e0f9..01c401e6324 100644 --- a/packages/typespec-python/test/azure/generated/azure-core-traits/specs/azure/core/traits/_model_base.py +++ b/packages/typespec-python/test/azure/generated/azure-core-traits/specs/azure/core/traits/_model_base.py @@ -462,7 +462,13 @@ def _get_rest_field( def _create_value(rf: typing.Optional["_RestField"], value: typing.Any) -> typing.Any: - return _deserialize(rf._type, value) if (rf and rf._is_model) else _serialize(value, rf._format if rf else None) + if not rf: + return _serialize(value, None) + if rf._is_multipart_file: + return value + if rf._is_model: + return _deserialize(rf._type, value) + return _serialize(value, rf._format) class Model(_MyMutableMapping): @@ -559,7 +565,14 @@ def as_dict(self, *, exclude_readonly: bool = False) -> typing.Dict[str, typing. for k, v in self.items(): if exclude_readonly and k in readonly_props: # pyright: ignore[reportUnboundVariable] continue - result[k] = Model._as_dict_value(v, exclude_readonly=exclude_readonly) + is_multipart_file = False + try: + is_multipart_file = next( + rf for rf in self._attr_to_rest_field.values() if rf._rest_name == k + )._is_multipart_file + except StopIteration: + pass + result[k] = v if is_multipart_file else Model._as_dict_value(v, exclude_readonly=exclude_readonly) return result @staticmethod @@ -567,7 +580,7 @@ def _as_dict_value(v: typing.Any, exclude_readonly: bool = False) -> typing.Any: if v is None or isinstance(v, _Null): return None if isinstance(v, (list, tuple, set)): - return [Model._as_dict_value(x, exclude_readonly=exclude_readonly) for x in v] + return type(v)(Model._as_dict_value(x, exclude_readonly=exclude_readonly) for x in v) if isinstance(v, dict): return {dk: Model._as_dict_value(dv, exclude_readonly=exclude_readonly) for dk, dv in v.items()} return v.as_dict(exclude_readonly=exclude_readonly) if hasattr(v, "as_dict") else v @@ -762,6 +775,7 @@ def __init__( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, + is_multipart_file: bool = False, ): self._type = type self._rest_name_input = name @@ -771,6 +785,7 @@ def __init__( self._is_model = False self._default = default self._format = format + self._is_multipart_file = is_multipart_file @property def _rest_name(self) -> str: @@ -816,8 +831,11 @@ def rest_field( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, + is_multipart_file: bool = False, ) -> typing.Any: - return _RestField(name=name, type=type, visibility=visibility, default=default, format=format) + return _RestField( + name=name, type=type, visibility=visibility, default=default, format=format, is_multipart_file=is_multipart_file + ) def rest_discriminator( diff --git a/packages/typespec-python/test/azure/generated/azure-core-traits/specs/azure/core/traits/models/__init__.py b/packages/typespec-python/test/azure/generated/azure-core-traits/specs/azure/core/traits/models/__init__.py index 7c4acb546f5..00824b8dd69 100644 --- a/packages/typespec-python/test/azure/generated/azure-core-traits/specs/azure/core/traits/models/__init__.py +++ b/packages/typespec-python/test/azure/generated/azure-core-traits/specs/azure/core/traits/models/__init__.py @@ -9,6 +9,8 @@ from ._models import User from ._models import UserActionParam from ._models import UserActionResponse + +from ._enums import RepeatabilityResult from ._patch import __all__ as _patch_all from ._patch import * # pylint: disable=unused-wildcard-import from ._patch import patch_sdk as _patch_sdk @@ -17,6 +19,7 @@ "User", "UserActionParam", "UserActionResponse", + "RepeatabilityResult", ] __all__.extend([p for p in _patch_all if p not in __all__]) _patch_sdk() diff --git a/packages/typespec-python/test/azure/generated/azure-core-traits/specs/azure/core/traits/models/_enums.py b/packages/typespec-python/test/azure/generated/azure-core-traits/specs/azure/core/traits/models/_enums.py new file mode 100644 index 00000000000..1e2417ecdd1 --- /dev/null +++ b/packages/typespec-python/test/azure/generated/azure-core-traits/specs/azure/core/traits/models/_enums.py @@ -0,0 +1,23 @@ +# coding=utf-8 +# -------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for license information. +# Code generated by Microsoft (R) Python Code Generator. +# Changes may cause incorrect behavior and will be lost if the code is regenerated. +# -------------------------------------------------------------------------- + +from enum import Enum +from azure.core import CaseInsensitiveEnumMeta + + +class RepeatabilityResult(str, Enum, metaclass=CaseInsensitiveEnumMeta): + """Repeatability Result header options.""" + + ACCEPTED = "accepted" + """If the request was accepted and the server guarantees that the server state reflects a single + execution of the operation.""" + REJECTED = "rejected" + """If the request was rejected because the combination of Repeatability-First-Sent and + Repeatability-Request-ID were invalid + or because the Repeatability-First-Sent value was outside the range of values held by the + server.""" diff --git a/packages/typespec-python/test/azure/generated/azure-mgmt-spheredpg/azure/mgmt/spheredpg/_model_base.py b/packages/typespec-python/test/azure/generated/azure-mgmt-spheredpg/azure/mgmt/spheredpg/_model_base.py index 585ccb0e0f9..01c401e6324 100644 --- a/packages/typespec-python/test/azure/generated/azure-mgmt-spheredpg/azure/mgmt/spheredpg/_model_base.py +++ b/packages/typespec-python/test/azure/generated/azure-mgmt-spheredpg/azure/mgmt/spheredpg/_model_base.py @@ -462,7 +462,13 @@ def _get_rest_field( def _create_value(rf: typing.Optional["_RestField"], value: typing.Any) -> typing.Any: - return _deserialize(rf._type, value) if (rf and rf._is_model) else _serialize(value, rf._format if rf else None) + if not rf: + return _serialize(value, None) + if rf._is_multipart_file: + return value + if rf._is_model: + return _deserialize(rf._type, value) + return _serialize(value, rf._format) class Model(_MyMutableMapping): @@ -559,7 +565,14 @@ def as_dict(self, *, exclude_readonly: bool = False) -> typing.Dict[str, typing. for k, v in self.items(): if exclude_readonly and k in readonly_props: # pyright: ignore[reportUnboundVariable] continue - result[k] = Model._as_dict_value(v, exclude_readonly=exclude_readonly) + is_multipart_file = False + try: + is_multipart_file = next( + rf for rf in self._attr_to_rest_field.values() if rf._rest_name == k + )._is_multipart_file + except StopIteration: + pass + result[k] = v if is_multipart_file else Model._as_dict_value(v, exclude_readonly=exclude_readonly) return result @staticmethod @@ -567,7 +580,7 @@ def _as_dict_value(v: typing.Any, exclude_readonly: bool = False) -> typing.Any: if v is None or isinstance(v, _Null): return None if isinstance(v, (list, tuple, set)): - return [Model._as_dict_value(x, exclude_readonly=exclude_readonly) for x in v] + return type(v)(Model._as_dict_value(x, exclude_readonly=exclude_readonly) for x in v) if isinstance(v, dict): return {dk: Model._as_dict_value(dv, exclude_readonly=exclude_readonly) for dk, dv in v.items()} return v.as_dict(exclude_readonly=exclude_readonly) if hasattr(v, "as_dict") else v @@ -762,6 +775,7 @@ def __init__( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, + is_multipart_file: bool = False, ): self._type = type self._rest_name_input = name @@ -771,6 +785,7 @@ def __init__( self._is_model = False self._default = default self._format = format + self._is_multipart_file = is_multipart_file @property def _rest_name(self) -> str: @@ -816,8 +831,11 @@ def rest_field( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, + is_multipart_file: bool = False, ) -> typing.Any: - return _RestField(name=name, type=type, visibility=visibility, default=default, format=format) + return _RestField( + name=name, type=type, visibility=visibility, default=default, format=format, is_multipart_file=is_multipart_file + ) def rest_discriminator( diff --git a/packages/typespec-python/test/azure/generated/azurecore-lro-rpc/azurecore/lro/rpc/_model_base.py b/packages/typespec-python/test/azure/generated/azurecore-lro-rpc/azurecore/lro/rpc/_model_base.py index 585ccb0e0f9..01c401e6324 100644 --- a/packages/typespec-python/test/azure/generated/azurecore-lro-rpc/azurecore/lro/rpc/_model_base.py +++ b/packages/typespec-python/test/azure/generated/azurecore-lro-rpc/azurecore/lro/rpc/_model_base.py @@ -462,7 +462,13 @@ def _get_rest_field( def _create_value(rf: typing.Optional["_RestField"], value: typing.Any) -> typing.Any: - return _deserialize(rf._type, value) if (rf and rf._is_model) else _serialize(value, rf._format if rf else None) + if not rf: + return _serialize(value, None) + if rf._is_multipart_file: + return value + if rf._is_model: + return _deserialize(rf._type, value) + return _serialize(value, rf._format) class Model(_MyMutableMapping): @@ -559,7 +565,14 @@ def as_dict(self, *, exclude_readonly: bool = False) -> typing.Dict[str, typing. for k, v in self.items(): if exclude_readonly and k in readonly_props: # pyright: ignore[reportUnboundVariable] continue - result[k] = Model._as_dict_value(v, exclude_readonly=exclude_readonly) + is_multipart_file = False + try: + is_multipart_file = next( + rf for rf in self._attr_to_rest_field.values() if rf._rest_name == k + )._is_multipart_file + except StopIteration: + pass + result[k] = v if is_multipart_file else Model._as_dict_value(v, exclude_readonly=exclude_readonly) return result @staticmethod @@ -567,7 +580,7 @@ def _as_dict_value(v: typing.Any, exclude_readonly: bool = False) -> typing.Any: if v is None or isinstance(v, _Null): return None if isinstance(v, (list, tuple, set)): - return [Model._as_dict_value(x, exclude_readonly=exclude_readonly) for x in v] + return type(v)(Model._as_dict_value(x, exclude_readonly=exclude_readonly) for x in v) if isinstance(v, dict): return {dk: Model._as_dict_value(dv, exclude_readonly=exclude_readonly) for dk, dv in v.items()} return v.as_dict(exclude_readonly=exclude_readonly) if hasattr(v, "as_dict") else v @@ -762,6 +775,7 @@ def __init__( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, + is_multipart_file: bool = False, ): self._type = type self._rest_name_input = name @@ -771,6 +785,7 @@ def __init__( self._is_model = False self._default = default self._format = format + self._is_multipart_file = is_multipart_file @property def _rest_name(self) -> str: @@ -816,8 +831,11 @@ def rest_field( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, + is_multipart_file: bool = False, ) -> typing.Any: - return _RestField(name=name, type=type, visibility=visibility, default=default, format=format) + return _RestField( + name=name, type=type, visibility=visibility, default=default, format=format, is_multipart_file=is_multipart_file + ) def rest_discriminator( diff --git a/packages/typespec-python/test/azure/generated/azurecore-lro-rpclegacy/azurecore/lro/rpclegacy/_model_base.py b/packages/typespec-python/test/azure/generated/azurecore-lro-rpclegacy/azurecore/lro/rpclegacy/_model_base.py index 585ccb0e0f9..01c401e6324 100644 --- a/packages/typespec-python/test/azure/generated/azurecore-lro-rpclegacy/azurecore/lro/rpclegacy/_model_base.py +++ b/packages/typespec-python/test/azure/generated/azurecore-lro-rpclegacy/azurecore/lro/rpclegacy/_model_base.py @@ -462,7 +462,13 @@ def _get_rest_field( def _create_value(rf: typing.Optional["_RestField"], value: typing.Any) -> typing.Any: - return _deserialize(rf._type, value) if (rf and rf._is_model) else _serialize(value, rf._format if rf else None) + if not rf: + return _serialize(value, None) + if rf._is_multipart_file: + return value + if rf._is_model: + return _deserialize(rf._type, value) + return _serialize(value, rf._format) class Model(_MyMutableMapping): @@ -559,7 +565,14 @@ def as_dict(self, *, exclude_readonly: bool = False) -> typing.Dict[str, typing. for k, v in self.items(): if exclude_readonly and k in readonly_props: # pyright: ignore[reportUnboundVariable] continue - result[k] = Model._as_dict_value(v, exclude_readonly=exclude_readonly) + is_multipart_file = False + try: + is_multipart_file = next( + rf for rf in self._attr_to_rest_field.values() if rf._rest_name == k + )._is_multipart_file + except StopIteration: + pass + result[k] = v if is_multipart_file else Model._as_dict_value(v, exclude_readonly=exclude_readonly) return result @staticmethod @@ -567,7 +580,7 @@ def _as_dict_value(v: typing.Any, exclude_readonly: bool = False) -> typing.Any: if v is None or isinstance(v, _Null): return None if isinstance(v, (list, tuple, set)): - return [Model._as_dict_value(x, exclude_readonly=exclude_readonly) for x in v] + return type(v)(Model._as_dict_value(x, exclude_readonly=exclude_readonly) for x in v) if isinstance(v, dict): return {dk: Model._as_dict_value(dv, exclude_readonly=exclude_readonly) for dk, dv in v.items()} return v.as_dict(exclude_readonly=exclude_readonly) if hasattr(v, "as_dict") else v @@ -762,6 +775,7 @@ def __init__( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, + is_multipart_file: bool = False, ): self._type = type self._rest_name_input = name @@ -771,6 +785,7 @@ def __init__( self._is_model = False self._default = default self._format = format + self._is_multipart_file = is_multipart_file @property def _rest_name(self) -> str: @@ -816,8 +831,11 @@ def rest_field( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, + is_multipart_file: bool = False, ) -> typing.Any: - return _RestField(name=name, type=type, visibility=visibility, default=default, format=format) + return _RestField( + name=name, type=type, visibility=visibility, default=default, format=format, is_multipart_file=is_multipart_file + ) def rest_discriminator( diff --git a/packages/typespec-python/test/azure/generated/client-structure-default/client/structure/service/_model_base.py b/packages/typespec-python/test/azure/generated/client-structure-default/client/structure/service/_model_base.py index 585ccb0e0f9..01c401e6324 100644 --- a/packages/typespec-python/test/azure/generated/client-structure-default/client/structure/service/_model_base.py +++ b/packages/typespec-python/test/azure/generated/client-structure-default/client/structure/service/_model_base.py @@ -462,7 +462,13 @@ def _get_rest_field( def _create_value(rf: typing.Optional["_RestField"], value: typing.Any) -> typing.Any: - return _deserialize(rf._type, value) if (rf and rf._is_model) else _serialize(value, rf._format if rf else None) + if not rf: + return _serialize(value, None) + if rf._is_multipart_file: + return value + if rf._is_model: + return _deserialize(rf._type, value) + return _serialize(value, rf._format) class Model(_MyMutableMapping): @@ -559,7 +565,14 @@ def as_dict(self, *, exclude_readonly: bool = False) -> typing.Dict[str, typing. for k, v in self.items(): if exclude_readonly and k in readonly_props: # pyright: ignore[reportUnboundVariable] continue - result[k] = Model._as_dict_value(v, exclude_readonly=exclude_readonly) + is_multipart_file = False + try: + is_multipart_file = next( + rf for rf in self._attr_to_rest_field.values() if rf._rest_name == k + )._is_multipart_file + except StopIteration: + pass + result[k] = v if is_multipart_file else Model._as_dict_value(v, exclude_readonly=exclude_readonly) return result @staticmethod @@ -567,7 +580,7 @@ def _as_dict_value(v: typing.Any, exclude_readonly: bool = False) -> typing.Any: if v is None or isinstance(v, _Null): return None if isinstance(v, (list, tuple, set)): - return [Model._as_dict_value(x, exclude_readonly=exclude_readonly) for x in v] + return type(v)(Model._as_dict_value(x, exclude_readonly=exclude_readonly) for x in v) if isinstance(v, dict): return {dk: Model._as_dict_value(dv, exclude_readonly=exclude_readonly) for dk, dv in v.items()} return v.as_dict(exclude_readonly=exclude_readonly) if hasattr(v, "as_dict") else v @@ -762,6 +775,7 @@ def __init__( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, + is_multipart_file: bool = False, ): self._type = type self._rest_name_input = name @@ -771,6 +785,7 @@ def __init__( self._is_model = False self._default = default self._format = format + self._is_multipart_file = is_multipart_file @property def _rest_name(self) -> str: @@ -816,8 +831,11 @@ def rest_field( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, + is_multipart_file: bool = False, ) -> typing.Any: - return _RestField(name=name, type=type, visibility=visibility, default=default, format=format) + return _RestField( + name=name, type=type, visibility=visibility, default=default, format=format, is_multipart_file=is_multipart_file + ) def rest_discriminator( diff --git a/packages/typespec-python/test/azure/generated/client-structure-multiclient/client/structure/multiclient/_model_base.py b/packages/typespec-python/test/azure/generated/client-structure-multiclient/client/structure/multiclient/_model_base.py index 585ccb0e0f9..01c401e6324 100644 --- a/packages/typespec-python/test/azure/generated/client-structure-multiclient/client/structure/multiclient/_model_base.py +++ b/packages/typespec-python/test/azure/generated/client-structure-multiclient/client/structure/multiclient/_model_base.py @@ -462,7 +462,13 @@ def _get_rest_field( def _create_value(rf: typing.Optional["_RestField"], value: typing.Any) -> typing.Any: - return _deserialize(rf._type, value) if (rf and rf._is_model) else _serialize(value, rf._format if rf else None) + if not rf: + return _serialize(value, None) + if rf._is_multipart_file: + return value + if rf._is_model: + return _deserialize(rf._type, value) + return _serialize(value, rf._format) class Model(_MyMutableMapping): @@ -559,7 +565,14 @@ def as_dict(self, *, exclude_readonly: bool = False) -> typing.Dict[str, typing. for k, v in self.items(): if exclude_readonly and k in readonly_props: # pyright: ignore[reportUnboundVariable] continue - result[k] = Model._as_dict_value(v, exclude_readonly=exclude_readonly) + is_multipart_file = False + try: + is_multipart_file = next( + rf for rf in self._attr_to_rest_field.values() if rf._rest_name == k + )._is_multipart_file + except StopIteration: + pass + result[k] = v if is_multipart_file else Model._as_dict_value(v, exclude_readonly=exclude_readonly) return result @staticmethod @@ -567,7 +580,7 @@ def _as_dict_value(v: typing.Any, exclude_readonly: bool = False) -> typing.Any: if v is None or isinstance(v, _Null): return None if isinstance(v, (list, tuple, set)): - return [Model._as_dict_value(x, exclude_readonly=exclude_readonly) for x in v] + return type(v)(Model._as_dict_value(x, exclude_readonly=exclude_readonly) for x in v) if isinstance(v, dict): return {dk: Model._as_dict_value(dv, exclude_readonly=exclude_readonly) for dk, dv in v.items()} return v.as_dict(exclude_readonly=exclude_readonly) if hasattr(v, "as_dict") else v @@ -762,6 +775,7 @@ def __init__( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, + is_multipart_file: bool = False, ): self._type = type self._rest_name_input = name @@ -771,6 +785,7 @@ def __init__( self._is_model = False self._default = default self._format = format + self._is_multipart_file = is_multipart_file @property def _rest_name(self) -> str: @@ -816,8 +831,11 @@ def rest_field( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, + is_multipart_file: bool = False, ) -> typing.Any: - return _RestField(name=name, type=type, visibility=visibility, default=default, format=format) + return _RestField( + name=name, type=type, visibility=visibility, default=default, format=format, is_multipart_file=is_multipart_file + ) def rest_discriminator( diff --git a/packages/typespec-python/test/azure/generated/client-structure-renamedoperation/client/structure/renamedoperation/_model_base.py b/packages/typespec-python/test/azure/generated/client-structure-renamedoperation/client/structure/renamedoperation/_model_base.py index 585ccb0e0f9..01c401e6324 100644 --- a/packages/typespec-python/test/azure/generated/client-structure-renamedoperation/client/structure/renamedoperation/_model_base.py +++ b/packages/typespec-python/test/azure/generated/client-structure-renamedoperation/client/structure/renamedoperation/_model_base.py @@ -462,7 +462,13 @@ def _get_rest_field( def _create_value(rf: typing.Optional["_RestField"], value: typing.Any) -> typing.Any: - return _deserialize(rf._type, value) if (rf and rf._is_model) else _serialize(value, rf._format if rf else None) + if not rf: + return _serialize(value, None) + if rf._is_multipart_file: + return value + if rf._is_model: + return _deserialize(rf._type, value) + return _serialize(value, rf._format) class Model(_MyMutableMapping): @@ -559,7 +565,14 @@ def as_dict(self, *, exclude_readonly: bool = False) -> typing.Dict[str, typing. for k, v in self.items(): if exclude_readonly and k in readonly_props: # pyright: ignore[reportUnboundVariable] continue - result[k] = Model._as_dict_value(v, exclude_readonly=exclude_readonly) + is_multipart_file = False + try: + is_multipart_file = next( + rf for rf in self._attr_to_rest_field.values() if rf._rest_name == k + )._is_multipart_file + except StopIteration: + pass + result[k] = v if is_multipart_file else Model._as_dict_value(v, exclude_readonly=exclude_readonly) return result @staticmethod @@ -567,7 +580,7 @@ def _as_dict_value(v: typing.Any, exclude_readonly: bool = False) -> typing.Any: if v is None or isinstance(v, _Null): return None if isinstance(v, (list, tuple, set)): - return [Model._as_dict_value(x, exclude_readonly=exclude_readonly) for x in v] + return type(v)(Model._as_dict_value(x, exclude_readonly=exclude_readonly) for x in v) if isinstance(v, dict): return {dk: Model._as_dict_value(dv, exclude_readonly=exclude_readonly) for dk, dv in v.items()} return v.as_dict(exclude_readonly=exclude_readonly) if hasattr(v, "as_dict") else v @@ -762,6 +775,7 @@ def __init__( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, + is_multipart_file: bool = False, ): self._type = type self._rest_name_input = name @@ -771,6 +785,7 @@ def __init__( self._is_model = False self._default = default self._format = format + self._is_multipart_file = is_multipart_file @property def _rest_name(self) -> str: @@ -816,8 +831,11 @@ def rest_field( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, + is_multipart_file: bool = False, ) -> typing.Any: - return _RestField(name=name, type=type, visibility=visibility, default=default, format=format) + return _RestField( + name=name, type=type, visibility=visibility, default=default, format=format, is_multipart_file=is_multipart_file + ) def rest_discriminator( diff --git a/packages/typespec-python/test/azure/generated/client-structure-twooperationgroup/client/structure/twooperationgroup/_model_base.py b/packages/typespec-python/test/azure/generated/client-structure-twooperationgroup/client/structure/twooperationgroup/_model_base.py index 585ccb0e0f9..01c401e6324 100644 --- a/packages/typespec-python/test/azure/generated/client-structure-twooperationgroup/client/structure/twooperationgroup/_model_base.py +++ b/packages/typespec-python/test/azure/generated/client-structure-twooperationgroup/client/structure/twooperationgroup/_model_base.py @@ -462,7 +462,13 @@ def _get_rest_field( def _create_value(rf: typing.Optional["_RestField"], value: typing.Any) -> typing.Any: - return _deserialize(rf._type, value) if (rf and rf._is_model) else _serialize(value, rf._format if rf else None) + if not rf: + return _serialize(value, None) + if rf._is_multipart_file: + return value + if rf._is_model: + return _deserialize(rf._type, value) + return _serialize(value, rf._format) class Model(_MyMutableMapping): @@ -559,7 +565,14 @@ def as_dict(self, *, exclude_readonly: bool = False) -> typing.Dict[str, typing. for k, v in self.items(): if exclude_readonly and k in readonly_props: # pyright: ignore[reportUnboundVariable] continue - result[k] = Model._as_dict_value(v, exclude_readonly=exclude_readonly) + is_multipart_file = False + try: + is_multipart_file = next( + rf for rf in self._attr_to_rest_field.values() if rf._rest_name == k + )._is_multipart_file + except StopIteration: + pass + result[k] = v if is_multipart_file else Model._as_dict_value(v, exclude_readonly=exclude_readonly) return result @staticmethod @@ -567,7 +580,7 @@ def _as_dict_value(v: typing.Any, exclude_readonly: bool = False) -> typing.Any: if v is None or isinstance(v, _Null): return None if isinstance(v, (list, tuple, set)): - return [Model._as_dict_value(x, exclude_readonly=exclude_readonly) for x in v] + return type(v)(Model._as_dict_value(x, exclude_readonly=exclude_readonly) for x in v) if isinstance(v, dict): return {dk: Model._as_dict_value(dv, exclude_readonly=exclude_readonly) for dk, dv in v.items()} return v.as_dict(exclude_readonly=exclude_readonly) if hasattr(v, "as_dict") else v @@ -762,6 +775,7 @@ def __init__( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, + is_multipart_file: bool = False, ): self._type = type self._rest_name_input = name @@ -771,6 +785,7 @@ def __init__( self._is_model = False self._default = default self._format = format + self._is_multipart_file = is_multipart_file @property def _rest_name(self) -> str: @@ -816,8 +831,11 @@ def rest_field( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, + is_multipart_file: bool = False, ) -> typing.Any: - return _RestField(name=name, type=type, visibility=visibility, default=default, format=format) + return _RestField( + name=name, type=type, visibility=visibility, default=default, format=format, is_multipart_file=is_multipart_file + ) def rest_discriminator( diff --git a/packages/typespec-python/test/azure/generated/encode-bytes/encode/bytes/_model_base.py b/packages/typespec-python/test/azure/generated/encode-bytes/encode/bytes/_model_base.py index 585ccb0e0f9..01c401e6324 100644 --- a/packages/typespec-python/test/azure/generated/encode-bytes/encode/bytes/_model_base.py +++ b/packages/typespec-python/test/azure/generated/encode-bytes/encode/bytes/_model_base.py @@ -462,7 +462,13 @@ def _get_rest_field( def _create_value(rf: typing.Optional["_RestField"], value: typing.Any) -> typing.Any: - return _deserialize(rf._type, value) if (rf and rf._is_model) else _serialize(value, rf._format if rf else None) + if not rf: + return _serialize(value, None) + if rf._is_multipart_file: + return value + if rf._is_model: + return _deserialize(rf._type, value) + return _serialize(value, rf._format) class Model(_MyMutableMapping): @@ -559,7 +565,14 @@ def as_dict(self, *, exclude_readonly: bool = False) -> typing.Dict[str, typing. for k, v in self.items(): if exclude_readonly and k in readonly_props: # pyright: ignore[reportUnboundVariable] continue - result[k] = Model._as_dict_value(v, exclude_readonly=exclude_readonly) + is_multipart_file = False + try: + is_multipart_file = next( + rf for rf in self._attr_to_rest_field.values() if rf._rest_name == k + )._is_multipart_file + except StopIteration: + pass + result[k] = v if is_multipart_file else Model._as_dict_value(v, exclude_readonly=exclude_readonly) return result @staticmethod @@ -567,7 +580,7 @@ def _as_dict_value(v: typing.Any, exclude_readonly: bool = False) -> typing.Any: if v is None or isinstance(v, _Null): return None if isinstance(v, (list, tuple, set)): - return [Model._as_dict_value(x, exclude_readonly=exclude_readonly) for x in v] + return type(v)(Model._as_dict_value(x, exclude_readonly=exclude_readonly) for x in v) if isinstance(v, dict): return {dk: Model._as_dict_value(dv, exclude_readonly=exclude_readonly) for dk, dv in v.items()} return v.as_dict(exclude_readonly=exclude_readonly) if hasattr(v, "as_dict") else v @@ -762,6 +775,7 @@ def __init__( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, + is_multipart_file: bool = False, ): self._type = type self._rest_name_input = name @@ -771,6 +785,7 @@ def __init__( self._is_model = False self._default = default self._format = format + self._is_multipart_file = is_multipart_file @property def _rest_name(self) -> str: @@ -816,8 +831,11 @@ def rest_field( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, + is_multipart_file: bool = False, ) -> typing.Any: - return _RestField(name=name, type=type, visibility=visibility, default=default, format=format) + return _RestField( + name=name, type=type, visibility=visibility, default=default, format=format, is_multipart_file=is_multipart_file + ) def rest_discriminator( diff --git a/packages/typespec-python/test/azure/generated/encode-datetime/encode/datetime/_model_base.py b/packages/typespec-python/test/azure/generated/encode-datetime/encode/datetime/_model_base.py index 585ccb0e0f9..01c401e6324 100644 --- a/packages/typespec-python/test/azure/generated/encode-datetime/encode/datetime/_model_base.py +++ b/packages/typespec-python/test/azure/generated/encode-datetime/encode/datetime/_model_base.py @@ -462,7 +462,13 @@ def _get_rest_field( def _create_value(rf: typing.Optional["_RestField"], value: typing.Any) -> typing.Any: - return _deserialize(rf._type, value) if (rf and rf._is_model) else _serialize(value, rf._format if rf else None) + if not rf: + return _serialize(value, None) + if rf._is_multipart_file: + return value + if rf._is_model: + return _deserialize(rf._type, value) + return _serialize(value, rf._format) class Model(_MyMutableMapping): @@ -559,7 +565,14 @@ def as_dict(self, *, exclude_readonly: bool = False) -> typing.Dict[str, typing. for k, v in self.items(): if exclude_readonly and k in readonly_props: # pyright: ignore[reportUnboundVariable] continue - result[k] = Model._as_dict_value(v, exclude_readonly=exclude_readonly) + is_multipart_file = False + try: + is_multipart_file = next( + rf for rf in self._attr_to_rest_field.values() if rf._rest_name == k + )._is_multipart_file + except StopIteration: + pass + result[k] = v if is_multipart_file else Model._as_dict_value(v, exclude_readonly=exclude_readonly) return result @staticmethod @@ -567,7 +580,7 @@ def _as_dict_value(v: typing.Any, exclude_readonly: bool = False) -> typing.Any: if v is None or isinstance(v, _Null): return None if isinstance(v, (list, tuple, set)): - return [Model._as_dict_value(x, exclude_readonly=exclude_readonly) for x in v] + return type(v)(Model._as_dict_value(x, exclude_readonly=exclude_readonly) for x in v) if isinstance(v, dict): return {dk: Model._as_dict_value(dv, exclude_readonly=exclude_readonly) for dk, dv in v.items()} return v.as_dict(exclude_readonly=exclude_readonly) if hasattr(v, "as_dict") else v @@ -762,6 +775,7 @@ def __init__( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, + is_multipart_file: bool = False, ): self._type = type self._rest_name_input = name @@ -771,6 +785,7 @@ def __init__( self._is_model = False self._default = default self._format = format + self._is_multipart_file = is_multipart_file @property def _rest_name(self) -> str: @@ -816,8 +831,11 @@ def rest_field( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, + is_multipart_file: bool = False, ) -> typing.Any: - return _RestField(name=name, type=type, visibility=visibility, default=default, format=format) + return _RestField( + name=name, type=type, visibility=visibility, default=default, format=format, is_multipart_file=is_multipart_file + ) def rest_discriminator( diff --git a/packages/typespec-python/test/azure/generated/encode-duration/encode/duration/_model_base.py b/packages/typespec-python/test/azure/generated/encode-duration/encode/duration/_model_base.py index 585ccb0e0f9..01c401e6324 100644 --- a/packages/typespec-python/test/azure/generated/encode-duration/encode/duration/_model_base.py +++ b/packages/typespec-python/test/azure/generated/encode-duration/encode/duration/_model_base.py @@ -462,7 +462,13 @@ def _get_rest_field( def _create_value(rf: typing.Optional["_RestField"], value: typing.Any) -> typing.Any: - return _deserialize(rf._type, value) if (rf and rf._is_model) else _serialize(value, rf._format if rf else None) + if not rf: + return _serialize(value, None) + if rf._is_multipart_file: + return value + if rf._is_model: + return _deserialize(rf._type, value) + return _serialize(value, rf._format) class Model(_MyMutableMapping): @@ -559,7 +565,14 @@ def as_dict(self, *, exclude_readonly: bool = False) -> typing.Dict[str, typing. for k, v in self.items(): if exclude_readonly and k in readonly_props: # pyright: ignore[reportUnboundVariable] continue - result[k] = Model._as_dict_value(v, exclude_readonly=exclude_readonly) + is_multipart_file = False + try: + is_multipart_file = next( + rf for rf in self._attr_to_rest_field.values() if rf._rest_name == k + )._is_multipart_file + except StopIteration: + pass + result[k] = v if is_multipart_file else Model._as_dict_value(v, exclude_readonly=exclude_readonly) return result @staticmethod @@ -567,7 +580,7 @@ def _as_dict_value(v: typing.Any, exclude_readonly: bool = False) -> typing.Any: if v is None or isinstance(v, _Null): return None if isinstance(v, (list, tuple, set)): - return [Model._as_dict_value(x, exclude_readonly=exclude_readonly) for x in v] + return type(v)(Model._as_dict_value(x, exclude_readonly=exclude_readonly) for x in v) if isinstance(v, dict): return {dk: Model._as_dict_value(dv, exclude_readonly=exclude_readonly) for dk, dv in v.items()} return v.as_dict(exclude_readonly=exclude_readonly) if hasattr(v, "as_dict") else v @@ -762,6 +775,7 @@ def __init__( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, + is_multipart_file: bool = False, ): self._type = type self._rest_name_input = name @@ -771,6 +785,7 @@ def __init__( self._is_model = False self._default = default self._format = format + self._is_multipart_file = is_multipart_file @property def _rest_name(self) -> str: @@ -816,8 +831,11 @@ def rest_field( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, + is_multipart_file: bool = False, ) -> typing.Any: - return _RestField(name=name, type=type, visibility=visibility, default=default, format=format) + return _RestField( + name=name, type=type, visibility=visibility, default=default, format=format, is_multipart_file=is_multipart_file + ) def rest_discriminator( diff --git a/packages/typespec-python/test/azure/generated/headasbooleanfalse/headasbooleanfalse/_model_base.py b/packages/typespec-python/test/azure/generated/headasbooleanfalse/headasbooleanfalse/_model_base.py index 585ccb0e0f9..01c401e6324 100644 --- a/packages/typespec-python/test/azure/generated/headasbooleanfalse/headasbooleanfalse/_model_base.py +++ b/packages/typespec-python/test/azure/generated/headasbooleanfalse/headasbooleanfalse/_model_base.py @@ -462,7 +462,13 @@ def _get_rest_field( def _create_value(rf: typing.Optional["_RestField"], value: typing.Any) -> typing.Any: - return _deserialize(rf._type, value) if (rf and rf._is_model) else _serialize(value, rf._format if rf else None) + if not rf: + return _serialize(value, None) + if rf._is_multipart_file: + return value + if rf._is_model: + return _deserialize(rf._type, value) + return _serialize(value, rf._format) class Model(_MyMutableMapping): @@ -559,7 +565,14 @@ def as_dict(self, *, exclude_readonly: bool = False) -> typing.Dict[str, typing. for k, v in self.items(): if exclude_readonly and k in readonly_props: # pyright: ignore[reportUnboundVariable] continue - result[k] = Model._as_dict_value(v, exclude_readonly=exclude_readonly) + is_multipart_file = False + try: + is_multipart_file = next( + rf for rf in self._attr_to_rest_field.values() if rf._rest_name == k + )._is_multipart_file + except StopIteration: + pass + result[k] = v if is_multipart_file else Model._as_dict_value(v, exclude_readonly=exclude_readonly) return result @staticmethod @@ -567,7 +580,7 @@ def _as_dict_value(v: typing.Any, exclude_readonly: bool = False) -> typing.Any: if v is None or isinstance(v, _Null): return None if isinstance(v, (list, tuple, set)): - return [Model._as_dict_value(x, exclude_readonly=exclude_readonly) for x in v] + return type(v)(Model._as_dict_value(x, exclude_readonly=exclude_readonly) for x in v) if isinstance(v, dict): return {dk: Model._as_dict_value(dv, exclude_readonly=exclude_readonly) for dk, dv in v.items()} return v.as_dict(exclude_readonly=exclude_readonly) if hasattr(v, "as_dict") else v @@ -762,6 +775,7 @@ def __init__( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, + is_multipart_file: bool = False, ): self._type = type self._rest_name_input = name @@ -771,6 +785,7 @@ def __init__( self._is_model = False self._default = default self._format = format + self._is_multipart_file = is_multipart_file @property def _rest_name(self) -> str: @@ -816,8 +831,11 @@ def rest_field( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, + is_multipart_file: bool = False, ) -> typing.Any: - return _RestField(name=name, type=type, visibility=visibility, default=default, format=format) + return _RestField( + name=name, type=type, visibility=visibility, default=default, format=format, is_multipart_file=is_multipart_file + ) def rest_discriminator( diff --git a/packages/typespec-python/test/azure/generated/headasbooleantrue/headasbooleantrue/_model_base.py b/packages/typespec-python/test/azure/generated/headasbooleantrue/headasbooleantrue/_model_base.py index 585ccb0e0f9..01c401e6324 100644 --- a/packages/typespec-python/test/azure/generated/headasbooleantrue/headasbooleantrue/_model_base.py +++ b/packages/typespec-python/test/azure/generated/headasbooleantrue/headasbooleantrue/_model_base.py @@ -462,7 +462,13 @@ def _get_rest_field( def _create_value(rf: typing.Optional["_RestField"], value: typing.Any) -> typing.Any: - return _deserialize(rf._type, value) if (rf and rf._is_model) else _serialize(value, rf._format if rf else None) + if not rf: + return _serialize(value, None) + if rf._is_multipart_file: + return value + if rf._is_model: + return _deserialize(rf._type, value) + return _serialize(value, rf._format) class Model(_MyMutableMapping): @@ -559,7 +565,14 @@ def as_dict(self, *, exclude_readonly: bool = False) -> typing.Dict[str, typing. for k, v in self.items(): if exclude_readonly and k in readonly_props: # pyright: ignore[reportUnboundVariable] continue - result[k] = Model._as_dict_value(v, exclude_readonly=exclude_readonly) + is_multipart_file = False + try: + is_multipart_file = next( + rf for rf in self._attr_to_rest_field.values() if rf._rest_name == k + )._is_multipart_file + except StopIteration: + pass + result[k] = v if is_multipart_file else Model._as_dict_value(v, exclude_readonly=exclude_readonly) return result @staticmethod @@ -567,7 +580,7 @@ def _as_dict_value(v: typing.Any, exclude_readonly: bool = False) -> typing.Any: if v is None or isinstance(v, _Null): return None if isinstance(v, (list, tuple, set)): - return [Model._as_dict_value(x, exclude_readonly=exclude_readonly) for x in v] + return type(v)(Model._as_dict_value(x, exclude_readonly=exclude_readonly) for x in v) if isinstance(v, dict): return {dk: Model._as_dict_value(dv, exclude_readonly=exclude_readonly) for dk, dv in v.items()} return v.as_dict(exclude_readonly=exclude_readonly) if hasattr(v, "as_dict") else v @@ -762,6 +775,7 @@ def __init__( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, + is_multipart_file: bool = False, ): self._type = type self._rest_name_input = name @@ -771,6 +785,7 @@ def __init__( self._is_model = False self._default = default self._format = format + self._is_multipart_file = is_multipart_file @property def _rest_name(self) -> str: @@ -816,8 +831,11 @@ def rest_field( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, + is_multipart_file: bool = False, ) -> typing.Any: - return _RestField(name=name, type=type, visibility=visibility, default=default, format=format) + return _RestField( + name=name, type=type, visibility=visibility, default=default, format=format, is_multipart_file=is_multipart_file + ) def rest_discriminator( diff --git a/packages/typespec-python/test/azure/generated/parameters-body-optionality/parameters/bodyoptionality/_model_base.py b/packages/typespec-python/test/azure/generated/parameters-body-optionality/parameters/bodyoptionality/_model_base.py index 585ccb0e0f9..01c401e6324 100644 --- a/packages/typespec-python/test/azure/generated/parameters-body-optionality/parameters/bodyoptionality/_model_base.py +++ b/packages/typespec-python/test/azure/generated/parameters-body-optionality/parameters/bodyoptionality/_model_base.py @@ -462,7 +462,13 @@ def _get_rest_field( def _create_value(rf: typing.Optional["_RestField"], value: typing.Any) -> typing.Any: - return _deserialize(rf._type, value) if (rf and rf._is_model) else _serialize(value, rf._format if rf else None) + if not rf: + return _serialize(value, None) + if rf._is_multipart_file: + return value + if rf._is_model: + return _deserialize(rf._type, value) + return _serialize(value, rf._format) class Model(_MyMutableMapping): @@ -559,7 +565,14 @@ def as_dict(self, *, exclude_readonly: bool = False) -> typing.Dict[str, typing. for k, v in self.items(): if exclude_readonly and k in readonly_props: # pyright: ignore[reportUnboundVariable] continue - result[k] = Model._as_dict_value(v, exclude_readonly=exclude_readonly) + is_multipart_file = False + try: + is_multipart_file = next( + rf for rf in self._attr_to_rest_field.values() if rf._rest_name == k + )._is_multipart_file + except StopIteration: + pass + result[k] = v if is_multipart_file else Model._as_dict_value(v, exclude_readonly=exclude_readonly) return result @staticmethod @@ -567,7 +580,7 @@ def _as_dict_value(v: typing.Any, exclude_readonly: bool = False) -> typing.Any: if v is None or isinstance(v, _Null): return None if isinstance(v, (list, tuple, set)): - return [Model._as_dict_value(x, exclude_readonly=exclude_readonly) for x in v] + return type(v)(Model._as_dict_value(x, exclude_readonly=exclude_readonly) for x in v) if isinstance(v, dict): return {dk: Model._as_dict_value(dv, exclude_readonly=exclude_readonly) for dk, dv in v.items()} return v.as_dict(exclude_readonly=exclude_readonly) if hasattr(v, "as_dict") else v @@ -762,6 +775,7 @@ def __init__( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, + is_multipart_file: bool = False, ): self._type = type self._rest_name_input = name @@ -771,6 +785,7 @@ def __init__( self._is_model = False self._default = default self._format = format + self._is_multipart_file = is_multipart_file @property def _rest_name(self) -> str: @@ -816,8 +831,11 @@ def rest_field( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, + is_multipart_file: bool = False, ) -> typing.Any: - return _RestField(name=name, type=type, visibility=visibility, default=default, format=format) + return _RestField( + name=name, type=type, visibility=visibility, default=default, format=format, is_multipart_file=is_multipart_file + ) def rest_discriminator( diff --git a/packages/typespec-python/test/azure/generated/parameters-collection-format/parameters/collectionformat/_model_base.py b/packages/typespec-python/test/azure/generated/parameters-collection-format/parameters/collectionformat/_model_base.py index 585ccb0e0f9..01c401e6324 100644 --- a/packages/typespec-python/test/azure/generated/parameters-collection-format/parameters/collectionformat/_model_base.py +++ b/packages/typespec-python/test/azure/generated/parameters-collection-format/parameters/collectionformat/_model_base.py @@ -462,7 +462,13 @@ def _get_rest_field( def _create_value(rf: typing.Optional["_RestField"], value: typing.Any) -> typing.Any: - return _deserialize(rf._type, value) if (rf and rf._is_model) else _serialize(value, rf._format if rf else None) + if not rf: + return _serialize(value, None) + if rf._is_multipart_file: + return value + if rf._is_model: + return _deserialize(rf._type, value) + return _serialize(value, rf._format) class Model(_MyMutableMapping): @@ -559,7 +565,14 @@ def as_dict(self, *, exclude_readonly: bool = False) -> typing.Dict[str, typing. for k, v in self.items(): if exclude_readonly and k in readonly_props: # pyright: ignore[reportUnboundVariable] continue - result[k] = Model._as_dict_value(v, exclude_readonly=exclude_readonly) + is_multipart_file = False + try: + is_multipart_file = next( + rf for rf in self._attr_to_rest_field.values() if rf._rest_name == k + )._is_multipart_file + except StopIteration: + pass + result[k] = v if is_multipart_file else Model._as_dict_value(v, exclude_readonly=exclude_readonly) return result @staticmethod @@ -567,7 +580,7 @@ def _as_dict_value(v: typing.Any, exclude_readonly: bool = False) -> typing.Any: if v is None or isinstance(v, _Null): return None if isinstance(v, (list, tuple, set)): - return [Model._as_dict_value(x, exclude_readonly=exclude_readonly) for x in v] + return type(v)(Model._as_dict_value(x, exclude_readonly=exclude_readonly) for x in v) if isinstance(v, dict): return {dk: Model._as_dict_value(dv, exclude_readonly=exclude_readonly) for dk, dv in v.items()} return v.as_dict(exclude_readonly=exclude_readonly) if hasattr(v, "as_dict") else v @@ -762,6 +775,7 @@ def __init__( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, + is_multipart_file: bool = False, ): self._type = type self._rest_name_input = name @@ -771,6 +785,7 @@ def __init__( self._is_model = False self._default = default self._format = format + self._is_multipart_file = is_multipart_file @property def _rest_name(self) -> str: @@ -816,8 +831,11 @@ def rest_field( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, + is_multipart_file: bool = False, ) -> typing.Any: - return _RestField(name=name, type=type, visibility=visibility, default=default, format=format) + return _RestField( + name=name, type=type, visibility=visibility, default=default, format=format, is_multipart_file=is_multipart_file + ) def rest_discriminator( diff --git a/packages/typespec-python/test/azure/generated/parameters-spread/parameters/spread/_model_base.py b/packages/typespec-python/test/azure/generated/parameters-spread/parameters/spread/_model_base.py index 585ccb0e0f9..01c401e6324 100644 --- a/packages/typespec-python/test/azure/generated/parameters-spread/parameters/spread/_model_base.py +++ b/packages/typespec-python/test/azure/generated/parameters-spread/parameters/spread/_model_base.py @@ -462,7 +462,13 @@ def _get_rest_field( def _create_value(rf: typing.Optional["_RestField"], value: typing.Any) -> typing.Any: - return _deserialize(rf._type, value) if (rf and rf._is_model) else _serialize(value, rf._format if rf else None) + if not rf: + return _serialize(value, None) + if rf._is_multipart_file: + return value + if rf._is_model: + return _deserialize(rf._type, value) + return _serialize(value, rf._format) class Model(_MyMutableMapping): @@ -559,7 +565,14 @@ def as_dict(self, *, exclude_readonly: bool = False) -> typing.Dict[str, typing. for k, v in self.items(): if exclude_readonly and k in readonly_props: # pyright: ignore[reportUnboundVariable] continue - result[k] = Model._as_dict_value(v, exclude_readonly=exclude_readonly) + is_multipart_file = False + try: + is_multipart_file = next( + rf for rf in self._attr_to_rest_field.values() if rf._rest_name == k + )._is_multipart_file + except StopIteration: + pass + result[k] = v if is_multipart_file else Model._as_dict_value(v, exclude_readonly=exclude_readonly) return result @staticmethod @@ -567,7 +580,7 @@ def _as_dict_value(v: typing.Any, exclude_readonly: bool = False) -> typing.Any: if v is None or isinstance(v, _Null): return None if isinstance(v, (list, tuple, set)): - return [Model._as_dict_value(x, exclude_readonly=exclude_readonly) for x in v] + return type(v)(Model._as_dict_value(x, exclude_readonly=exclude_readonly) for x in v) if isinstance(v, dict): return {dk: Model._as_dict_value(dv, exclude_readonly=exclude_readonly) for dk, dv in v.items()} return v.as_dict(exclude_readonly=exclude_readonly) if hasattr(v, "as_dict") else v @@ -762,6 +775,7 @@ def __init__( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, + is_multipart_file: bool = False, ): self._type = type self._rest_name_input = name @@ -771,6 +785,7 @@ def __init__( self._is_model = False self._default = default self._format = format + self._is_multipart_file = is_multipart_file @property def _rest_name(self) -> str: @@ -816,8 +831,11 @@ def rest_field( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, + is_multipart_file: bool = False, ) -> typing.Any: - return _RestField(name=name, type=type, visibility=visibility, default=default, format=format) + return _RestField( + name=name, type=type, visibility=visibility, default=default, format=format, is_multipart_file=is_multipart_file + ) def rest_discriminator( diff --git a/packages/typespec-python/test/azure/generated/payload-content-negotiation/payload/contentnegotiation/_model_base.py b/packages/typespec-python/test/azure/generated/payload-content-negotiation/payload/contentnegotiation/_model_base.py index 585ccb0e0f9..01c401e6324 100644 --- a/packages/typespec-python/test/azure/generated/payload-content-negotiation/payload/contentnegotiation/_model_base.py +++ b/packages/typespec-python/test/azure/generated/payload-content-negotiation/payload/contentnegotiation/_model_base.py @@ -462,7 +462,13 @@ def _get_rest_field( def _create_value(rf: typing.Optional["_RestField"], value: typing.Any) -> typing.Any: - return _deserialize(rf._type, value) if (rf and rf._is_model) else _serialize(value, rf._format if rf else None) + if not rf: + return _serialize(value, None) + if rf._is_multipart_file: + return value + if rf._is_model: + return _deserialize(rf._type, value) + return _serialize(value, rf._format) class Model(_MyMutableMapping): @@ -559,7 +565,14 @@ def as_dict(self, *, exclude_readonly: bool = False) -> typing.Dict[str, typing. for k, v in self.items(): if exclude_readonly and k in readonly_props: # pyright: ignore[reportUnboundVariable] continue - result[k] = Model._as_dict_value(v, exclude_readonly=exclude_readonly) + is_multipart_file = False + try: + is_multipart_file = next( + rf for rf in self._attr_to_rest_field.values() if rf._rest_name == k + )._is_multipart_file + except StopIteration: + pass + result[k] = v if is_multipart_file else Model._as_dict_value(v, exclude_readonly=exclude_readonly) return result @staticmethod @@ -567,7 +580,7 @@ def _as_dict_value(v: typing.Any, exclude_readonly: bool = False) -> typing.Any: if v is None or isinstance(v, _Null): return None if isinstance(v, (list, tuple, set)): - return [Model._as_dict_value(x, exclude_readonly=exclude_readonly) for x in v] + return type(v)(Model._as_dict_value(x, exclude_readonly=exclude_readonly) for x in v) if isinstance(v, dict): return {dk: Model._as_dict_value(dv, exclude_readonly=exclude_readonly) for dk, dv in v.items()} return v.as_dict(exclude_readonly=exclude_readonly) if hasattr(v, "as_dict") else v @@ -762,6 +775,7 @@ def __init__( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, + is_multipart_file: bool = False, ): self._type = type self._rest_name_input = name @@ -771,6 +785,7 @@ def __init__( self._is_model = False self._default = default self._format = format + self._is_multipart_file = is_multipart_file @property def _rest_name(self) -> str: @@ -816,8 +831,11 @@ def rest_field( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, + is_multipart_file: bool = False, ) -> typing.Any: - return _RestField(name=name, type=type, visibility=visibility, default=default, format=format) + return _RestField( + name=name, type=type, visibility=visibility, default=default, format=format, is_multipart_file=is_multipart_file + ) def rest_discriminator( diff --git a/packages/typespec-python/test/azure/generated/payload-media-type/payload/mediatype/_model_base.py b/packages/typespec-python/test/azure/generated/payload-media-type/payload/mediatype/_model_base.py index 585ccb0e0f9..01c401e6324 100644 --- a/packages/typespec-python/test/azure/generated/payload-media-type/payload/mediatype/_model_base.py +++ b/packages/typespec-python/test/azure/generated/payload-media-type/payload/mediatype/_model_base.py @@ -462,7 +462,13 @@ def _get_rest_field( def _create_value(rf: typing.Optional["_RestField"], value: typing.Any) -> typing.Any: - return _deserialize(rf._type, value) if (rf and rf._is_model) else _serialize(value, rf._format if rf else None) + if not rf: + return _serialize(value, None) + if rf._is_multipart_file: + return value + if rf._is_model: + return _deserialize(rf._type, value) + return _serialize(value, rf._format) class Model(_MyMutableMapping): @@ -559,7 +565,14 @@ def as_dict(self, *, exclude_readonly: bool = False) -> typing.Dict[str, typing. for k, v in self.items(): if exclude_readonly and k in readonly_props: # pyright: ignore[reportUnboundVariable] continue - result[k] = Model._as_dict_value(v, exclude_readonly=exclude_readonly) + is_multipart_file = False + try: + is_multipart_file = next( + rf for rf in self._attr_to_rest_field.values() if rf._rest_name == k + )._is_multipart_file + except StopIteration: + pass + result[k] = v if is_multipart_file else Model._as_dict_value(v, exclude_readonly=exclude_readonly) return result @staticmethod @@ -567,7 +580,7 @@ def _as_dict_value(v: typing.Any, exclude_readonly: bool = False) -> typing.Any: if v is None or isinstance(v, _Null): return None if isinstance(v, (list, tuple, set)): - return [Model._as_dict_value(x, exclude_readonly=exclude_readonly) for x in v] + return type(v)(Model._as_dict_value(x, exclude_readonly=exclude_readonly) for x in v) if isinstance(v, dict): return {dk: Model._as_dict_value(dv, exclude_readonly=exclude_readonly) for dk, dv in v.items()} return v.as_dict(exclude_readonly=exclude_readonly) if hasattr(v, "as_dict") else v @@ -762,6 +775,7 @@ def __init__( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, + is_multipart_file: bool = False, ): self._type = type self._rest_name_input = name @@ -771,6 +785,7 @@ def __init__( self._is_model = False self._default = default self._format = format + self._is_multipart_file = is_multipart_file @property def _rest_name(self) -> str: @@ -816,8 +831,11 @@ def rest_field( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, + is_multipart_file: bool = False, ) -> typing.Any: - return _RestField(name=name, type=type, visibility=visibility, default=default, format=format) + return _RestField( + name=name, type=type, visibility=visibility, default=default, format=format, is_multipart_file=is_multipart_file + ) def rest_discriminator( diff --git a/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/aio/operations/_operations.py b/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/aio/operations/_operations.py index a50dcfeb82d..a901550360c 100644 --- a/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/aio/operations/_operations.py +++ b/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/aio/operations/_operations.py @@ -6,6 +6,7 @@ # Code generated by Microsoft (R) Python Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- +import json import sys from typing import Any, Callable, Dict, Optional, TypeVar, Union, overload @@ -22,6 +23,7 @@ from azure.core.tracing.decorator_async import distributed_trace_async from ... import _model_base, models as _models +from ..._model_base import SdkJSONEncoder from ...operations._operations import ( build_form_data_basic_request, build_form_data_binary_array_parts_request, @@ -124,17 +126,21 @@ async def basic( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) - _body = body.as_dict() if isinstance(body, _model_base.Model) else body - _files = [] - _data = {} - if _body.get("id") is not None: - _data["id"] = _body["id"] - if _body.get("profileImage") is not None: - _files.append(("profileImage", _body["profileImage"])) + content_type = content_type or "multipart/form-data" + _content = None + if isinstance(body, _model_base.Model): + _body = body.as_dict() if isinstance(body, _model_base.Model) else body + _files = [] + _data = {} + if _body.get("id") is not None: + _data["id"] = _body["id"] + if _body.get("profileImage") is not None: + _files.append(("profileImage", _body["profileImage"])) + elif isinstance(body, MutableMapping): + _content = body _request = build_form_data_basic_request( - files=_files, - data=_data, + content=_content, headers=_headers, params=_params, ) @@ -245,23 +251,27 @@ async def complex( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) - _body = body.as_dict() if isinstance(body, _model_base.Model) else body - _files = [] - _data = {} - if _body.get("id") is not None: - _data["id"] = _body["id"] - if _body.get("address") is not None: - _files.append(("address", _body["address"])) - if _body.get("profileImage") is not None: - _files.append(("profileImage", _body["profileImage"])) - if _body.get("previousAddresses") is not None: - _files.extend([("previousAddresses", p) for p in _body["previousAddresses"]]) - if _body.get("pictures") is not None: - _files.extend([("pictures", p) for p in _body["pictures"]]) + content_type = content_type or "multipart/form-data" + _content = None + if isinstance(body, _model_base.Model): + _body = body.as_dict() if isinstance(body, _model_base.Model) else body + _files = [] + _data = {} + if _body.get("id") is not None: + _data["id"] = _body["id"] + if _body.get("address") is not None: + _data["address"] = _body["address"] + if _body.get("profileImage") is not None: + _files.append(("profileImage", _body["profileImage"])) + if _body.get("previousAddresses") is not None: + _data["previousAddresses"] = _body["previousAddresses"] + if _body.get("pictures") is not None: + _files.extend([("pictures", p) for p in _body["pictures"]]) + elif isinstance(body, MutableMapping): + _content = body _request = build_form_data_complex_request( - files=_files, - data=_data, + content=_content, headers=_headers, params=_params, ) @@ -354,17 +364,21 @@ async def json_part( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) - _body = body.as_dict() if isinstance(body, _model_base.Model) else body - _files = [] - _data = {} - if _body.get("address") is not None: - _files.append(("address", _body["address"])) - if _body.get("profileImage") is not None: - _files.append(("profileImage", _body["profileImage"])) + content_type = content_type or "multipart/form-data" + _content = None + if isinstance(body, _model_base.Model): + _body = body.as_dict() if isinstance(body, _model_base.Model) else body + _files = [] + _data = {} + if _body.get("address") is not None: + _data["address"] = _body["address"] + if _body.get("profileImage") is not None: + _files.append(("profileImage", _body["profileImage"])) + elif isinstance(body, MutableMapping): + _content = body _request = build_form_data_json_part_request( - files=_files, - data=_data, + content=_content, headers=_headers, params=_params, ) @@ -459,17 +473,21 @@ async def binary_array_parts( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) - _body = body.as_dict() if isinstance(body, _model_base.Model) else body - _files = [] - _data = {} - if _body.get("id") is not None: - _data["id"] = _body["id"] - if _body.get("pictures") is not None: - _files.extend([("pictures", p) for p in _body["pictures"]]) + content_type = content_type or "multipart/form-data" + _content = None + if isinstance(body, _model_base.Model): + _body = body.as_dict() if isinstance(body, _model_base.Model) else body + _files = [] + _data = {} + if _body.get("id") is not None: + _data["id"] = _body["id"] + if _body.get("pictures") is not None: + _files.extend([("pictures", p) for p in _body["pictures"]]) + elif isinstance(body, MutableMapping): + _content = body _request = build_form_data_binary_array_parts_request( - files=_files, - data=_data, + content=_content, headers=_headers, params=_params, ) @@ -568,17 +586,21 @@ async def json_array_parts( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) - _body = body.as_dict() if isinstance(body, _model_base.Model) else body - _files = [] - _data = {} - if _body.get("profileImage") is not None: - _files.append(("profileImage", _body["profileImage"])) - if _body.get("previousAddresses") is not None: - _files.extend([("previousAddresses", p) for p in _body["previousAddresses"]]) + content_type = content_type or "multipart/form-data" + _content = None + if isinstance(body, _model_base.Model): + _body = body.as_dict() if isinstance(body, _model_base.Model) else body + _files = [] + _data = {} + if _body.get("profileImage") is not None: + _files.append(("profileImage", _body["profileImage"])) + if _body.get("previousAddresses") is not None: + _data["previousAddresses"] = _body["previousAddresses"] + elif isinstance(body, MutableMapping): + _content = body _request = build_form_data_json_array_parts_request( - files=_files, - data=_data, + content=_content, headers=_headers, params=_params, ) @@ -669,17 +691,21 @@ async def multi_binary_parts( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) - _body = body.as_dict() if isinstance(body, _model_base.Model) else body - _files = [] - _data = {} - if _body.get("profileImage") is not None: - _files.append(("profileImage", _body["profileImage"])) - if _body.get("picture") is not None: - _files.append(("picture", _body["picture"])) + content_type = content_type or "multipart/form-data" + _content = None + if isinstance(body, _model_base.Model): + _body = body.as_dict() if isinstance(body, _model_base.Model) else body + _files = [] + _data = {} + if _body.get("profileImage") is not None: + _files.append(("profileImage", _body["profileImage"])) + if _body.get("picture") is not None: + _files.append(("picture", _body["picture"])) + elif isinstance(body, MutableMapping): + _content = body _request = build_form_data_multi_binary_parts_request( - files=_files, - data=_data, + content=_content, headers=_headers, params=_params, ) diff --git a/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/models/_models.py b/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/models/_models.py index 458d93df55f..012bda1e2d8 100644 --- a/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/models/_models.py +++ b/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/models/_models.py @@ -15,7 +15,7 @@ if TYPE_CHECKING: # pylint: disable=unused-import,ungrouped-imports - from .. import _model_base, models as _models + from .. import models as _models class Address(_model_base.Model): @@ -104,11 +104,11 @@ class ComplexPartsRequest(_model_base.Model): id: str = rest_field() """Required.""" - address: "_models.Address" = rest_field(is_multipart_file=True) + address: "_models.Address" = rest_field() """Required.""" profile_image: FileType = rest_field(name="profileImage", is_multipart_file=True) """Required.""" - previous_addresses: List["_models.Address"] = rest_field(name="previousAddresses", is_multipart_file=True) + previous_addresses: List["_models.Address"] = rest_field(name="previousAddresses") """Required.""" pictures: List[FileType] = rest_field(is_multipart_file=True) """Required.""" @@ -149,7 +149,7 @@ class JsonArrayPartsRequest(_model_base.Model): profile_image: FileType = rest_field(name="profileImage", is_multipart_file=True) """Required.""" - previous_addresses: List["_models.Address"] = rest_field(name="previousAddresses", is_multipart_file=True) + previous_addresses: List["_models.Address"] = rest_field(name="previousAddresses") """Required.""" @overload @@ -183,7 +183,7 @@ class JsonPartRequest(_model_base.Model): :vartype profile_image: filetype """ - address: "_models.Address" = rest_field(is_multipart_file=True) + address: "_models.Address" = rest_field() """Required.""" profile_image: FileType = rest_field(name="profileImage", is_multipart_file=True) """Required.""" diff --git a/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/operations/_operations.py b/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/operations/_operations.py index 5c4eb85ae9d..7e26b076e42 100644 --- a/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/operations/_operations.py +++ b/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/operations/_operations.py @@ -6,6 +6,7 @@ # Code generated by Microsoft (R) Python Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- +import json import sys from typing import Any, Callable, Dict, Optional, TypeVar, Union, overload @@ -23,6 +24,7 @@ from azure.core.utils import case_insensitive_dict from .. import _model_base, models as _models +from .._model_base import SdkJSONEncoder from .._serialization import Serializer if sys.version_info >= (3, 9): @@ -43,6 +45,10 @@ def build_form_data_basic_request(**kwargs: Any) -> HttpRequest: # Construct URL _url = "/multipart/form-data/mixed-parts" + # Construct headers + if content_type is not None: + _headers["content-type"] = _SERIALIZER.header("content_type", content_type, "str") + return HttpRequest(method="POST", url=_url, headers=_headers, **kwargs) @@ -52,6 +58,10 @@ def build_form_data_complex_request(**kwargs: Any) -> HttpRequest: # Construct URL _url = "/multipart/form-data/complex-parts" + # Construct headers + if content_type is not None: + _headers["content-type"] = _SERIALIZER.header("content_type", content_type, "str") + return HttpRequest(method="POST", url=_url, headers=_headers, **kwargs) @@ -61,6 +71,10 @@ def build_form_data_json_part_request(**kwargs: Any) -> HttpRequest: # Construct URL _url = "/multipart/form-data/json-part" + # Construct headers + if content_type is not None: + _headers["content-type"] = _SERIALIZER.header("content_type", content_type, "str") + return HttpRequest(method="POST", url=_url, headers=_headers, **kwargs) @@ -70,6 +84,10 @@ def build_form_data_binary_array_parts_request(**kwargs: Any) -> HttpRequest: # # Construct URL _url = "/multipart/form-data/binary-array-parts" + # Construct headers + if content_type is not None: + _headers["content-type"] = _SERIALIZER.header("content_type", content_type, "str") + return HttpRequest(method="POST", url=_url, headers=_headers, **kwargs) @@ -79,6 +97,10 @@ def build_form_data_json_array_parts_request(**kwargs: Any) -> HttpRequest: # Construct URL _url = "/multipart/form-data/json-array-parts" + # Construct headers + if content_type is not None: + _headers["content-type"] = _SERIALIZER.header("content_type", content_type, "str") + return HttpRequest(method="POST", url=_url, headers=_headers, **kwargs) @@ -88,6 +110,10 @@ def build_form_data_multi_binary_parts_request(**kwargs: Any) -> HttpRequest: # # Construct URL _url = "/multipart/form-data/multi-binary-parts" + # Construct headers + if content_type is not None: + _headers["content-type"] = _SERIALIZER.header("content_type", content_type, "str") + return HttpRequest(method="POST", url=_url, headers=_headers, **kwargs) @@ -175,17 +201,21 @@ def basic( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) - _body = body.as_dict() if isinstance(body, _model_base.Model) else body - _files = [] - _data = {} - if _body.get("id") is not None: - _data["id"] = _body["id"] - if _body.get("profileImage") is not None: - _files.append(("profileImage", _body["profileImage"])) + content_type = content_type or "multipart/form-data" + _content = None + if isinstance(body, _model_base.Model): + _body = body.as_dict() if isinstance(body, _model_base.Model) else body + _files = [] + _data = {} + if _body.get("id") is not None: + _data["id"] = _body["id"] + if _body.get("profileImage") is not None: + _files.append(("profileImage", _body["profileImage"])) + elif isinstance(body, MutableMapping): + _content = body _request = build_form_data_basic_request( - files=_files, - data=_data, + content=_content, headers=_headers, params=_params, ) @@ -296,23 +326,27 @@ def complex( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) - _body = body.as_dict() if isinstance(body, _model_base.Model) else body - _files = [] - _data = {} - if _body.get("id") is not None: - _data["id"] = _body["id"] - if _body.get("address") is not None: - _files.append(("address", _body["address"])) - if _body.get("profileImage") is not None: - _files.append(("profileImage", _body["profileImage"])) - if _body.get("previousAddresses") is not None: - _files.extend([("previousAddresses", p) for p in _body["previousAddresses"]]) - if _body.get("pictures") is not None: - _files.extend([("pictures", p) for p in _body["pictures"]]) + content_type = content_type or "multipart/form-data" + _content = None + if isinstance(body, _model_base.Model): + _body = body.as_dict() if isinstance(body, _model_base.Model) else body + _files = [] + _data = {} + if _body.get("id") is not None: + _data["id"] = _body["id"] + if _body.get("address") is not None: + _data["address"] = _body["address"] + if _body.get("profileImage") is not None: + _files.append(("profileImage", _body["profileImage"])) + if _body.get("previousAddresses") is not None: + _data["previousAddresses"] = _body["previousAddresses"] + if _body.get("pictures") is not None: + _files.extend([("pictures", p) for p in _body["pictures"]]) + elif isinstance(body, MutableMapping): + _content = body _request = build_form_data_complex_request( - files=_files, - data=_data, + content=_content, headers=_headers, params=_params, ) @@ -405,17 +439,21 @@ def json_part( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) - _body = body.as_dict() if isinstance(body, _model_base.Model) else body - _files = [] - _data = {} - if _body.get("address") is not None: - _files.append(("address", _body["address"])) - if _body.get("profileImage") is not None: - _files.append(("profileImage", _body["profileImage"])) + content_type = content_type or "multipart/form-data" + _content = None + if isinstance(body, _model_base.Model): + _body = body.as_dict() if isinstance(body, _model_base.Model) else body + _files = [] + _data = {} + if _body.get("address") is not None: + _data["address"] = _body["address"] + if _body.get("profileImage") is not None: + _files.append(("profileImage", _body["profileImage"])) + elif isinstance(body, MutableMapping): + _content = body _request = build_form_data_json_part_request( - files=_files, - data=_data, + content=_content, headers=_headers, params=_params, ) @@ -508,17 +546,21 @@ def binary_array_parts( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) - _body = body.as_dict() if isinstance(body, _model_base.Model) else body - _files = [] - _data = {} - if _body.get("id") is not None: - _data["id"] = _body["id"] - if _body.get("pictures") is not None: - _files.extend([("pictures", p) for p in _body["pictures"]]) + content_type = content_type or "multipart/form-data" + _content = None + if isinstance(body, _model_base.Model): + _body = body.as_dict() if isinstance(body, _model_base.Model) else body + _files = [] + _data = {} + if _body.get("id") is not None: + _data["id"] = _body["id"] + if _body.get("pictures") is not None: + _files.extend([("pictures", p) for p in _body["pictures"]]) + elif isinstance(body, MutableMapping): + _content = body _request = build_form_data_binary_array_parts_request( - files=_files, - data=_data, + content=_content, headers=_headers, params=_params, ) @@ -615,17 +657,21 @@ def json_array_parts( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) - _body = body.as_dict() if isinstance(body, _model_base.Model) else body - _files = [] - _data = {} - if _body.get("profileImage") is not None: - _files.append(("profileImage", _body["profileImage"])) - if _body.get("previousAddresses") is not None: - _files.extend([("previousAddresses", p) for p in _body["previousAddresses"]]) + content_type = content_type or "multipart/form-data" + _content = None + if isinstance(body, _model_base.Model): + _body = body.as_dict() if isinstance(body, _model_base.Model) else body + _files = [] + _data = {} + if _body.get("profileImage") is not None: + _files.append(("profileImage", _body["profileImage"])) + if _body.get("previousAddresses") is not None: + _data["previousAddresses"] = _body["previousAddresses"] + elif isinstance(body, MutableMapping): + _content = body _request = build_form_data_json_array_parts_request( - files=_files, - data=_data, + content=_content, headers=_headers, params=_params, ) @@ -714,17 +760,21 @@ def multi_binary_parts( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) - _body = body.as_dict() if isinstance(body, _model_base.Model) else body - _files = [] - _data = {} - if _body.get("profileImage") is not None: - _files.append(("profileImage", _body["profileImage"])) - if _body.get("picture") is not None: - _files.append(("picture", _body["picture"])) + content_type = content_type or "multipart/form-data" + _content = None + if isinstance(body, _model_base.Model): + _body = body.as_dict() if isinstance(body, _model_base.Model) else body + _files = [] + _data = {} + if _body.get("profileImage") is not None: + _files.append(("profileImage", _body["profileImage"])) + if _body.get("picture") is not None: + _files.append(("picture", _body["picture"])) + elif isinstance(body, MutableMapping): + _content = body _request = build_form_data_multi_binary_parts_request( - files=_files, - data=_data, + content=_content, headers=_headers, params=_params, ) diff --git a/packages/typespec-python/test/azure/generated/payload-pageable/payload/pageable/_model_base.py b/packages/typespec-python/test/azure/generated/payload-pageable/payload/pageable/_model_base.py index 585ccb0e0f9..01c401e6324 100644 --- a/packages/typespec-python/test/azure/generated/payload-pageable/payload/pageable/_model_base.py +++ b/packages/typespec-python/test/azure/generated/payload-pageable/payload/pageable/_model_base.py @@ -462,7 +462,13 @@ def _get_rest_field( def _create_value(rf: typing.Optional["_RestField"], value: typing.Any) -> typing.Any: - return _deserialize(rf._type, value) if (rf and rf._is_model) else _serialize(value, rf._format if rf else None) + if not rf: + return _serialize(value, None) + if rf._is_multipart_file: + return value + if rf._is_model: + return _deserialize(rf._type, value) + return _serialize(value, rf._format) class Model(_MyMutableMapping): @@ -559,7 +565,14 @@ def as_dict(self, *, exclude_readonly: bool = False) -> typing.Dict[str, typing. for k, v in self.items(): if exclude_readonly and k in readonly_props: # pyright: ignore[reportUnboundVariable] continue - result[k] = Model._as_dict_value(v, exclude_readonly=exclude_readonly) + is_multipart_file = False + try: + is_multipart_file = next( + rf for rf in self._attr_to_rest_field.values() if rf._rest_name == k + )._is_multipart_file + except StopIteration: + pass + result[k] = v if is_multipart_file else Model._as_dict_value(v, exclude_readonly=exclude_readonly) return result @staticmethod @@ -567,7 +580,7 @@ def _as_dict_value(v: typing.Any, exclude_readonly: bool = False) -> typing.Any: if v is None or isinstance(v, _Null): return None if isinstance(v, (list, tuple, set)): - return [Model._as_dict_value(x, exclude_readonly=exclude_readonly) for x in v] + return type(v)(Model._as_dict_value(x, exclude_readonly=exclude_readonly) for x in v) if isinstance(v, dict): return {dk: Model._as_dict_value(dv, exclude_readonly=exclude_readonly) for dk, dv in v.items()} return v.as_dict(exclude_readonly=exclude_readonly) if hasattr(v, "as_dict") else v @@ -762,6 +775,7 @@ def __init__( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, + is_multipart_file: bool = False, ): self._type = type self._rest_name_input = name @@ -771,6 +785,7 @@ def __init__( self._is_model = False self._default = default self._format = format + self._is_multipart_file = is_multipart_file @property def _rest_name(self) -> str: @@ -816,8 +831,11 @@ def rest_field( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, + is_multipart_file: bool = False, ) -> typing.Any: - return _RestField(name=name, type=type, visibility=visibility, default=default, format=format) + return _RestField( + name=name, type=type, visibility=visibility, default=default, format=format, is_multipart_file=is_multipart_file + ) def rest_discriminator( diff --git a/packages/typespec-python/test/azure/generated/projection-projected-name/projection/projectedname/_model_base.py b/packages/typespec-python/test/azure/generated/projection-projected-name/projection/projectedname/_model_base.py index 585ccb0e0f9..01c401e6324 100644 --- a/packages/typespec-python/test/azure/generated/projection-projected-name/projection/projectedname/_model_base.py +++ b/packages/typespec-python/test/azure/generated/projection-projected-name/projection/projectedname/_model_base.py @@ -462,7 +462,13 @@ def _get_rest_field( def _create_value(rf: typing.Optional["_RestField"], value: typing.Any) -> typing.Any: - return _deserialize(rf._type, value) if (rf and rf._is_model) else _serialize(value, rf._format if rf else None) + if not rf: + return _serialize(value, None) + if rf._is_multipart_file: + return value + if rf._is_model: + return _deserialize(rf._type, value) + return _serialize(value, rf._format) class Model(_MyMutableMapping): @@ -559,7 +565,14 @@ def as_dict(self, *, exclude_readonly: bool = False) -> typing.Dict[str, typing. for k, v in self.items(): if exclude_readonly and k in readonly_props: # pyright: ignore[reportUnboundVariable] continue - result[k] = Model._as_dict_value(v, exclude_readonly=exclude_readonly) + is_multipart_file = False + try: + is_multipart_file = next( + rf for rf in self._attr_to_rest_field.values() if rf._rest_name == k + )._is_multipart_file + except StopIteration: + pass + result[k] = v if is_multipart_file else Model._as_dict_value(v, exclude_readonly=exclude_readonly) return result @staticmethod @@ -567,7 +580,7 @@ def _as_dict_value(v: typing.Any, exclude_readonly: bool = False) -> typing.Any: if v is None or isinstance(v, _Null): return None if isinstance(v, (list, tuple, set)): - return [Model._as_dict_value(x, exclude_readonly=exclude_readonly) for x in v] + return type(v)(Model._as_dict_value(x, exclude_readonly=exclude_readonly) for x in v) if isinstance(v, dict): return {dk: Model._as_dict_value(dv, exclude_readonly=exclude_readonly) for dk, dv in v.items()} return v.as_dict(exclude_readonly=exclude_readonly) if hasattr(v, "as_dict") else v @@ -762,6 +775,7 @@ def __init__( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, + is_multipart_file: bool = False, ): self._type = type self._rest_name_input = name @@ -771,6 +785,7 @@ def __init__( self._is_model = False self._default = default self._format = format + self._is_multipart_file = is_multipart_file @property def _rest_name(self) -> str: @@ -816,8 +831,11 @@ def rest_field( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, + is_multipart_file: bool = False, ) -> typing.Any: - return _RestField(name=name, type=type, visibility=visibility, default=default, format=format) + return _RestField( + name=name, type=type, visibility=visibility, default=default, format=format, is_multipart_file=is_multipart_file + ) def rest_discriminator( diff --git a/packages/typespec-python/test/azure/generated/resiliency-srv-driven2/resiliency/srv/driven2/_model_base.py b/packages/typespec-python/test/azure/generated/resiliency-srv-driven2/resiliency/srv/driven2/_model_base.py index 585ccb0e0f9..01c401e6324 100644 --- a/packages/typespec-python/test/azure/generated/resiliency-srv-driven2/resiliency/srv/driven2/_model_base.py +++ b/packages/typespec-python/test/azure/generated/resiliency-srv-driven2/resiliency/srv/driven2/_model_base.py @@ -462,7 +462,13 @@ def _get_rest_field( def _create_value(rf: typing.Optional["_RestField"], value: typing.Any) -> typing.Any: - return _deserialize(rf._type, value) if (rf and rf._is_model) else _serialize(value, rf._format if rf else None) + if not rf: + return _serialize(value, None) + if rf._is_multipart_file: + return value + if rf._is_model: + return _deserialize(rf._type, value) + return _serialize(value, rf._format) class Model(_MyMutableMapping): @@ -559,7 +565,14 @@ def as_dict(self, *, exclude_readonly: bool = False) -> typing.Dict[str, typing. for k, v in self.items(): if exclude_readonly and k in readonly_props: # pyright: ignore[reportUnboundVariable] continue - result[k] = Model._as_dict_value(v, exclude_readonly=exclude_readonly) + is_multipart_file = False + try: + is_multipart_file = next( + rf for rf in self._attr_to_rest_field.values() if rf._rest_name == k + )._is_multipart_file + except StopIteration: + pass + result[k] = v if is_multipart_file else Model._as_dict_value(v, exclude_readonly=exclude_readonly) return result @staticmethod @@ -567,7 +580,7 @@ def _as_dict_value(v: typing.Any, exclude_readonly: bool = False) -> typing.Any: if v is None or isinstance(v, _Null): return None if isinstance(v, (list, tuple, set)): - return [Model._as_dict_value(x, exclude_readonly=exclude_readonly) for x in v] + return type(v)(Model._as_dict_value(x, exclude_readonly=exclude_readonly) for x in v) if isinstance(v, dict): return {dk: Model._as_dict_value(dv, exclude_readonly=exclude_readonly) for dk, dv in v.items()} return v.as_dict(exclude_readonly=exclude_readonly) if hasattr(v, "as_dict") else v @@ -762,6 +775,7 @@ def __init__( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, + is_multipart_file: bool = False, ): self._type = type self._rest_name_input = name @@ -771,6 +785,7 @@ def __init__( self._is_model = False self._default = default self._format = format + self._is_multipart_file = is_multipart_file @property def _rest_name(self) -> str: @@ -816,8 +831,11 @@ def rest_field( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, + is_multipart_file: bool = False, ) -> typing.Any: - return _RestField(name=name, type=type, visibility=visibility, default=default, format=format) + return _RestField( + name=name, type=type, visibility=visibility, default=default, format=format, is_multipart_file=is_multipart_file + ) def rest_discriminator( diff --git a/packages/typespec-python/test/azure/generated/server-path-multiple/server/path/multiple/_model_base.py b/packages/typespec-python/test/azure/generated/server-path-multiple/server/path/multiple/_model_base.py index 585ccb0e0f9..01c401e6324 100644 --- a/packages/typespec-python/test/azure/generated/server-path-multiple/server/path/multiple/_model_base.py +++ b/packages/typespec-python/test/azure/generated/server-path-multiple/server/path/multiple/_model_base.py @@ -462,7 +462,13 @@ def _get_rest_field( def _create_value(rf: typing.Optional["_RestField"], value: typing.Any) -> typing.Any: - return _deserialize(rf._type, value) if (rf and rf._is_model) else _serialize(value, rf._format if rf else None) + if not rf: + return _serialize(value, None) + if rf._is_multipart_file: + return value + if rf._is_model: + return _deserialize(rf._type, value) + return _serialize(value, rf._format) class Model(_MyMutableMapping): @@ -559,7 +565,14 @@ def as_dict(self, *, exclude_readonly: bool = False) -> typing.Dict[str, typing. for k, v in self.items(): if exclude_readonly and k in readonly_props: # pyright: ignore[reportUnboundVariable] continue - result[k] = Model._as_dict_value(v, exclude_readonly=exclude_readonly) + is_multipart_file = False + try: + is_multipart_file = next( + rf for rf in self._attr_to_rest_field.values() if rf._rest_name == k + )._is_multipart_file + except StopIteration: + pass + result[k] = v if is_multipart_file else Model._as_dict_value(v, exclude_readonly=exclude_readonly) return result @staticmethod @@ -567,7 +580,7 @@ def _as_dict_value(v: typing.Any, exclude_readonly: bool = False) -> typing.Any: if v is None or isinstance(v, _Null): return None if isinstance(v, (list, tuple, set)): - return [Model._as_dict_value(x, exclude_readonly=exclude_readonly) for x in v] + return type(v)(Model._as_dict_value(x, exclude_readonly=exclude_readonly) for x in v) if isinstance(v, dict): return {dk: Model._as_dict_value(dv, exclude_readonly=exclude_readonly) for dk, dv in v.items()} return v.as_dict(exclude_readonly=exclude_readonly) if hasattr(v, "as_dict") else v @@ -762,6 +775,7 @@ def __init__( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, + is_multipart_file: bool = False, ): self._type = type self._rest_name_input = name @@ -771,6 +785,7 @@ def __init__( self._is_model = False self._default = default self._format = format + self._is_multipart_file = is_multipart_file @property def _rest_name(self) -> str: @@ -816,8 +831,11 @@ def rest_field( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, + is_multipart_file: bool = False, ) -> typing.Any: - return _RestField(name=name, type=type, visibility=visibility, default=default, format=format) + return _RestField( + name=name, type=type, visibility=visibility, default=default, format=format, is_multipart_file=is_multipart_file + ) def rest_discriminator( diff --git a/packages/typespec-python/test/azure/generated/server-path-single/server/path/single/_model_base.py b/packages/typespec-python/test/azure/generated/server-path-single/server/path/single/_model_base.py index 585ccb0e0f9..01c401e6324 100644 --- a/packages/typespec-python/test/azure/generated/server-path-single/server/path/single/_model_base.py +++ b/packages/typespec-python/test/azure/generated/server-path-single/server/path/single/_model_base.py @@ -462,7 +462,13 @@ def _get_rest_field( def _create_value(rf: typing.Optional["_RestField"], value: typing.Any) -> typing.Any: - return _deserialize(rf._type, value) if (rf and rf._is_model) else _serialize(value, rf._format if rf else None) + if not rf: + return _serialize(value, None) + if rf._is_multipart_file: + return value + if rf._is_model: + return _deserialize(rf._type, value) + return _serialize(value, rf._format) class Model(_MyMutableMapping): @@ -559,7 +565,14 @@ def as_dict(self, *, exclude_readonly: bool = False) -> typing.Dict[str, typing. for k, v in self.items(): if exclude_readonly and k in readonly_props: # pyright: ignore[reportUnboundVariable] continue - result[k] = Model._as_dict_value(v, exclude_readonly=exclude_readonly) + is_multipart_file = False + try: + is_multipart_file = next( + rf for rf in self._attr_to_rest_field.values() if rf._rest_name == k + )._is_multipart_file + except StopIteration: + pass + result[k] = v if is_multipart_file else Model._as_dict_value(v, exclude_readonly=exclude_readonly) return result @staticmethod @@ -567,7 +580,7 @@ def _as_dict_value(v: typing.Any, exclude_readonly: bool = False) -> typing.Any: if v is None or isinstance(v, _Null): return None if isinstance(v, (list, tuple, set)): - return [Model._as_dict_value(x, exclude_readonly=exclude_readonly) for x in v] + return type(v)(Model._as_dict_value(x, exclude_readonly=exclude_readonly) for x in v) if isinstance(v, dict): return {dk: Model._as_dict_value(dv, exclude_readonly=exclude_readonly) for dk, dv in v.items()} return v.as_dict(exclude_readonly=exclude_readonly) if hasattr(v, "as_dict") else v @@ -762,6 +775,7 @@ def __init__( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, + is_multipart_file: bool = False, ): self._type = type self._rest_name_input = name @@ -771,6 +785,7 @@ def __init__( self._is_model = False self._default = default self._format = format + self._is_multipart_file = is_multipart_file @property def _rest_name(self) -> str: @@ -816,8 +831,11 @@ def rest_field( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, + is_multipart_file: bool = False, ) -> typing.Any: - return _RestField(name=name, type=type, visibility=visibility, default=default, format=format) + return _RestField( + name=name, type=type, visibility=visibility, default=default, format=format, is_multipart_file=is_multipart_file + ) def rest_discriminator( diff --git a/packages/typespec-python/test/azure/generated/server-versions-not-versioned/server/versions/notversioned/_model_base.py b/packages/typespec-python/test/azure/generated/server-versions-not-versioned/server/versions/notversioned/_model_base.py index 585ccb0e0f9..01c401e6324 100644 --- a/packages/typespec-python/test/azure/generated/server-versions-not-versioned/server/versions/notversioned/_model_base.py +++ b/packages/typespec-python/test/azure/generated/server-versions-not-versioned/server/versions/notversioned/_model_base.py @@ -462,7 +462,13 @@ def _get_rest_field( def _create_value(rf: typing.Optional["_RestField"], value: typing.Any) -> typing.Any: - return _deserialize(rf._type, value) if (rf and rf._is_model) else _serialize(value, rf._format if rf else None) + if not rf: + return _serialize(value, None) + if rf._is_multipart_file: + return value + if rf._is_model: + return _deserialize(rf._type, value) + return _serialize(value, rf._format) class Model(_MyMutableMapping): @@ -559,7 +565,14 @@ def as_dict(self, *, exclude_readonly: bool = False) -> typing.Dict[str, typing. for k, v in self.items(): if exclude_readonly and k in readonly_props: # pyright: ignore[reportUnboundVariable] continue - result[k] = Model._as_dict_value(v, exclude_readonly=exclude_readonly) + is_multipart_file = False + try: + is_multipart_file = next( + rf for rf in self._attr_to_rest_field.values() if rf._rest_name == k + )._is_multipart_file + except StopIteration: + pass + result[k] = v if is_multipart_file else Model._as_dict_value(v, exclude_readonly=exclude_readonly) return result @staticmethod @@ -567,7 +580,7 @@ def _as_dict_value(v: typing.Any, exclude_readonly: bool = False) -> typing.Any: if v is None or isinstance(v, _Null): return None if isinstance(v, (list, tuple, set)): - return [Model._as_dict_value(x, exclude_readonly=exclude_readonly) for x in v] + return type(v)(Model._as_dict_value(x, exclude_readonly=exclude_readonly) for x in v) if isinstance(v, dict): return {dk: Model._as_dict_value(dv, exclude_readonly=exclude_readonly) for dk, dv in v.items()} return v.as_dict(exclude_readonly=exclude_readonly) if hasattr(v, "as_dict") else v @@ -762,6 +775,7 @@ def __init__( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, + is_multipart_file: bool = False, ): self._type = type self._rest_name_input = name @@ -771,6 +785,7 @@ def __init__( self._is_model = False self._default = default self._format = format + self._is_multipart_file = is_multipart_file @property def _rest_name(self) -> str: @@ -816,8 +831,11 @@ def rest_field( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, + is_multipart_file: bool = False, ) -> typing.Any: - return _RestField(name=name, type=type, visibility=visibility, default=default, format=format) + return _RestField( + name=name, type=type, visibility=visibility, default=default, format=format, is_multipart_file=is_multipart_file + ) def rest_discriminator( diff --git a/packages/typespec-python/test/azure/generated/server-versions-versioned/server/versions/versioned/_model_base.py b/packages/typespec-python/test/azure/generated/server-versions-versioned/server/versions/versioned/_model_base.py index 585ccb0e0f9..01c401e6324 100644 --- a/packages/typespec-python/test/azure/generated/server-versions-versioned/server/versions/versioned/_model_base.py +++ b/packages/typespec-python/test/azure/generated/server-versions-versioned/server/versions/versioned/_model_base.py @@ -462,7 +462,13 @@ def _get_rest_field( def _create_value(rf: typing.Optional["_RestField"], value: typing.Any) -> typing.Any: - return _deserialize(rf._type, value) if (rf and rf._is_model) else _serialize(value, rf._format if rf else None) + if not rf: + return _serialize(value, None) + if rf._is_multipart_file: + return value + if rf._is_model: + return _deserialize(rf._type, value) + return _serialize(value, rf._format) class Model(_MyMutableMapping): @@ -559,7 +565,14 @@ def as_dict(self, *, exclude_readonly: bool = False) -> typing.Dict[str, typing. for k, v in self.items(): if exclude_readonly and k in readonly_props: # pyright: ignore[reportUnboundVariable] continue - result[k] = Model._as_dict_value(v, exclude_readonly=exclude_readonly) + is_multipart_file = False + try: + is_multipart_file = next( + rf for rf in self._attr_to_rest_field.values() if rf._rest_name == k + )._is_multipart_file + except StopIteration: + pass + result[k] = v if is_multipart_file else Model._as_dict_value(v, exclude_readonly=exclude_readonly) return result @staticmethod @@ -567,7 +580,7 @@ def _as_dict_value(v: typing.Any, exclude_readonly: bool = False) -> typing.Any: if v is None or isinstance(v, _Null): return None if isinstance(v, (list, tuple, set)): - return [Model._as_dict_value(x, exclude_readonly=exclude_readonly) for x in v] + return type(v)(Model._as_dict_value(x, exclude_readonly=exclude_readonly) for x in v) if isinstance(v, dict): return {dk: Model._as_dict_value(dv, exclude_readonly=exclude_readonly) for dk, dv in v.items()} return v.as_dict(exclude_readonly=exclude_readonly) if hasattr(v, "as_dict") else v @@ -762,6 +775,7 @@ def __init__( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, + is_multipart_file: bool = False, ): self._type = type self._rest_name_input = name @@ -771,6 +785,7 @@ def __init__( self._is_model = False self._default = default self._format = format + self._is_multipart_file = is_multipart_file @property def _rest_name(self) -> str: @@ -816,8 +831,11 @@ def rest_field( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, + is_multipart_file: bool = False, ) -> typing.Any: - return _RestField(name=name, type=type, visibility=visibility, default=default, format=format) + return _RestField( + name=name, type=type, visibility=visibility, default=default, format=format, is_multipart_file=is_multipart_file + ) def rest_discriminator( diff --git a/packages/typespec-python/test/azure/generated/special-headers-client-request-id/specialheaders/clientrequestid/_model_base.py b/packages/typespec-python/test/azure/generated/special-headers-client-request-id/specialheaders/clientrequestid/_model_base.py index 585ccb0e0f9..01c401e6324 100644 --- a/packages/typespec-python/test/azure/generated/special-headers-client-request-id/specialheaders/clientrequestid/_model_base.py +++ b/packages/typespec-python/test/azure/generated/special-headers-client-request-id/specialheaders/clientrequestid/_model_base.py @@ -462,7 +462,13 @@ def _get_rest_field( def _create_value(rf: typing.Optional["_RestField"], value: typing.Any) -> typing.Any: - return _deserialize(rf._type, value) if (rf and rf._is_model) else _serialize(value, rf._format if rf else None) + if not rf: + return _serialize(value, None) + if rf._is_multipart_file: + return value + if rf._is_model: + return _deserialize(rf._type, value) + return _serialize(value, rf._format) class Model(_MyMutableMapping): @@ -559,7 +565,14 @@ def as_dict(self, *, exclude_readonly: bool = False) -> typing.Dict[str, typing. for k, v in self.items(): if exclude_readonly and k in readonly_props: # pyright: ignore[reportUnboundVariable] continue - result[k] = Model._as_dict_value(v, exclude_readonly=exclude_readonly) + is_multipart_file = False + try: + is_multipart_file = next( + rf for rf in self._attr_to_rest_field.values() if rf._rest_name == k + )._is_multipart_file + except StopIteration: + pass + result[k] = v if is_multipart_file else Model._as_dict_value(v, exclude_readonly=exclude_readonly) return result @staticmethod @@ -567,7 +580,7 @@ def _as_dict_value(v: typing.Any, exclude_readonly: bool = False) -> typing.Any: if v is None or isinstance(v, _Null): return None if isinstance(v, (list, tuple, set)): - return [Model._as_dict_value(x, exclude_readonly=exclude_readonly) for x in v] + return type(v)(Model._as_dict_value(x, exclude_readonly=exclude_readonly) for x in v) if isinstance(v, dict): return {dk: Model._as_dict_value(dv, exclude_readonly=exclude_readonly) for dk, dv in v.items()} return v.as_dict(exclude_readonly=exclude_readonly) if hasattr(v, "as_dict") else v @@ -762,6 +775,7 @@ def __init__( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, + is_multipart_file: bool = False, ): self._type = type self._rest_name_input = name @@ -771,6 +785,7 @@ def __init__( self._is_model = False self._default = default self._format = format + self._is_multipart_file = is_multipart_file @property def _rest_name(self) -> str: @@ -816,8 +831,11 @@ def rest_field( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, + is_multipart_file: bool = False, ) -> typing.Any: - return _RestField(name=name, type=type, visibility=visibility, default=default, format=format) + return _RestField( + name=name, type=type, visibility=visibility, default=default, format=format, is_multipart_file=is_multipart_file + ) def rest_discriminator( diff --git a/packages/typespec-python/test/azure/generated/special-headers-conditional-request/specialheaders/conditionalrequest/_model_base.py b/packages/typespec-python/test/azure/generated/special-headers-conditional-request/specialheaders/conditionalrequest/_model_base.py index 585ccb0e0f9..01c401e6324 100644 --- a/packages/typespec-python/test/azure/generated/special-headers-conditional-request/specialheaders/conditionalrequest/_model_base.py +++ b/packages/typespec-python/test/azure/generated/special-headers-conditional-request/specialheaders/conditionalrequest/_model_base.py @@ -462,7 +462,13 @@ def _get_rest_field( def _create_value(rf: typing.Optional["_RestField"], value: typing.Any) -> typing.Any: - return _deserialize(rf._type, value) if (rf and rf._is_model) else _serialize(value, rf._format if rf else None) + if not rf: + return _serialize(value, None) + if rf._is_multipart_file: + return value + if rf._is_model: + return _deserialize(rf._type, value) + return _serialize(value, rf._format) class Model(_MyMutableMapping): @@ -559,7 +565,14 @@ def as_dict(self, *, exclude_readonly: bool = False) -> typing.Dict[str, typing. for k, v in self.items(): if exclude_readonly and k in readonly_props: # pyright: ignore[reportUnboundVariable] continue - result[k] = Model._as_dict_value(v, exclude_readonly=exclude_readonly) + is_multipart_file = False + try: + is_multipart_file = next( + rf for rf in self._attr_to_rest_field.values() if rf._rest_name == k + )._is_multipart_file + except StopIteration: + pass + result[k] = v if is_multipart_file else Model._as_dict_value(v, exclude_readonly=exclude_readonly) return result @staticmethod @@ -567,7 +580,7 @@ def _as_dict_value(v: typing.Any, exclude_readonly: bool = False) -> typing.Any: if v is None or isinstance(v, _Null): return None if isinstance(v, (list, tuple, set)): - return [Model._as_dict_value(x, exclude_readonly=exclude_readonly) for x in v] + return type(v)(Model._as_dict_value(x, exclude_readonly=exclude_readonly) for x in v) if isinstance(v, dict): return {dk: Model._as_dict_value(dv, exclude_readonly=exclude_readonly) for dk, dv in v.items()} return v.as_dict(exclude_readonly=exclude_readonly) if hasattr(v, "as_dict") else v @@ -762,6 +775,7 @@ def __init__( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, + is_multipart_file: bool = False, ): self._type = type self._rest_name_input = name @@ -771,6 +785,7 @@ def __init__( self._is_model = False self._default = default self._format = format + self._is_multipart_file = is_multipart_file @property def _rest_name(self) -> str: @@ -816,8 +831,11 @@ def rest_field( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, + is_multipart_file: bool = False, ) -> typing.Any: - return _RestField(name=name, type=type, visibility=visibility, default=default, format=format) + return _RestField( + name=name, type=type, visibility=visibility, default=default, format=format, is_multipart_file=is_multipart_file + ) def rest_discriminator( diff --git a/packages/typespec-python/test/azure/generated/special-headers-repeatability/specialheaders/repeatability/_model_base.py b/packages/typespec-python/test/azure/generated/special-headers-repeatability/specialheaders/repeatability/_model_base.py index 585ccb0e0f9..01c401e6324 100644 --- a/packages/typespec-python/test/azure/generated/special-headers-repeatability/specialheaders/repeatability/_model_base.py +++ b/packages/typespec-python/test/azure/generated/special-headers-repeatability/specialheaders/repeatability/_model_base.py @@ -462,7 +462,13 @@ def _get_rest_field( def _create_value(rf: typing.Optional["_RestField"], value: typing.Any) -> typing.Any: - return _deserialize(rf._type, value) if (rf and rf._is_model) else _serialize(value, rf._format if rf else None) + if not rf: + return _serialize(value, None) + if rf._is_multipart_file: + return value + if rf._is_model: + return _deserialize(rf._type, value) + return _serialize(value, rf._format) class Model(_MyMutableMapping): @@ -559,7 +565,14 @@ def as_dict(self, *, exclude_readonly: bool = False) -> typing.Dict[str, typing. for k, v in self.items(): if exclude_readonly and k in readonly_props: # pyright: ignore[reportUnboundVariable] continue - result[k] = Model._as_dict_value(v, exclude_readonly=exclude_readonly) + is_multipart_file = False + try: + is_multipart_file = next( + rf for rf in self._attr_to_rest_field.values() if rf._rest_name == k + )._is_multipart_file + except StopIteration: + pass + result[k] = v if is_multipart_file else Model._as_dict_value(v, exclude_readonly=exclude_readonly) return result @staticmethod @@ -567,7 +580,7 @@ def _as_dict_value(v: typing.Any, exclude_readonly: bool = False) -> typing.Any: if v is None or isinstance(v, _Null): return None if isinstance(v, (list, tuple, set)): - return [Model._as_dict_value(x, exclude_readonly=exclude_readonly) for x in v] + return type(v)(Model._as_dict_value(x, exclude_readonly=exclude_readonly) for x in v) if isinstance(v, dict): return {dk: Model._as_dict_value(dv, exclude_readonly=exclude_readonly) for dk, dv in v.items()} return v.as_dict(exclude_readonly=exclude_readonly) if hasattr(v, "as_dict") else v @@ -762,6 +775,7 @@ def __init__( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, + is_multipart_file: bool = False, ): self._type = type self._rest_name_input = name @@ -771,6 +785,7 @@ def __init__( self._is_model = False self._default = default self._format = format + self._is_multipart_file = is_multipart_file @property def _rest_name(self) -> str: @@ -816,8 +831,11 @@ def rest_field( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, + is_multipart_file: bool = False, ) -> typing.Any: - return _RestField(name=name, type=type, visibility=visibility, default=default, format=format) + return _RestField( + name=name, type=type, visibility=visibility, default=default, format=format, is_multipart_file=is_multipart_file + ) def rest_discriminator( diff --git a/packages/typespec-python/test/azure/generated/special-words/specialwords/_model_base.py b/packages/typespec-python/test/azure/generated/special-words/specialwords/_model_base.py index 585ccb0e0f9..01c401e6324 100644 --- a/packages/typespec-python/test/azure/generated/special-words/specialwords/_model_base.py +++ b/packages/typespec-python/test/azure/generated/special-words/specialwords/_model_base.py @@ -462,7 +462,13 @@ def _get_rest_field( def _create_value(rf: typing.Optional["_RestField"], value: typing.Any) -> typing.Any: - return _deserialize(rf._type, value) if (rf and rf._is_model) else _serialize(value, rf._format if rf else None) + if not rf: + return _serialize(value, None) + if rf._is_multipart_file: + return value + if rf._is_model: + return _deserialize(rf._type, value) + return _serialize(value, rf._format) class Model(_MyMutableMapping): @@ -559,7 +565,14 @@ def as_dict(self, *, exclude_readonly: bool = False) -> typing.Dict[str, typing. for k, v in self.items(): if exclude_readonly and k in readonly_props: # pyright: ignore[reportUnboundVariable] continue - result[k] = Model._as_dict_value(v, exclude_readonly=exclude_readonly) + is_multipart_file = False + try: + is_multipart_file = next( + rf for rf in self._attr_to_rest_field.values() if rf._rest_name == k + )._is_multipart_file + except StopIteration: + pass + result[k] = v if is_multipart_file else Model._as_dict_value(v, exclude_readonly=exclude_readonly) return result @staticmethod @@ -567,7 +580,7 @@ def _as_dict_value(v: typing.Any, exclude_readonly: bool = False) -> typing.Any: if v is None or isinstance(v, _Null): return None if isinstance(v, (list, tuple, set)): - return [Model._as_dict_value(x, exclude_readonly=exclude_readonly) for x in v] + return type(v)(Model._as_dict_value(x, exclude_readonly=exclude_readonly) for x in v) if isinstance(v, dict): return {dk: Model._as_dict_value(dv, exclude_readonly=exclude_readonly) for dk, dv in v.items()} return v.as_dict(exclude_readonly=exclude_readonly) if hasattr(v, "as_dict") else v @@ -762,6 +775,7 @@ def __init__( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, + is_multipart_file: bool = False, ): self._type = type self._rest_name_input = name @@ -771,6 +785,7 @@ def __init__( self._is_model = False self._default = default self._format = format + self._is_multipart_file = is_multipart_file @property def _rest_name(self) -> str: @@ -816,8 +831,11 @@ def rest_field( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, + is_multipart_file: bool = False, ) -> typing.Any: - return _RestField(name=name, type=type, visibility=visibility, default=default, format=format) + return _RestField( + name=name, type=type, visibility=visibility, default=default, format=format, is_multipart_file=is_multipart_file + ) def rest_discriminator( diff --git a/packages/typespec-python/test/azure/generated/typetest-array/typetest/array/_model_base.py b/packages/typespec-python/test/azure/generated/typetest-array/typetest/array/_model_base.py index 585ccb0e0f9..01c401e6324 100644 --- a/packages/typespec-python/test/azure/generated/typetest-array/typetest/array/_model_base.py +++ b/packages/typespec-python/test/azure/generated/typetest-array/typetest/array/_model_base.py @@ -462,7 +462,13 @@ def _get_rest_field( def _create_value(rf: typing.Optional["_RestField"], value: typing.Any) -> typing.Any: - return _deserialize(rf._type, value) if (rf and rf._is_model) else _serialize(value, rf._format if rf else None) + if not rf: + return _serialize(value, None) + if rf._is_multipart_file: + return value + if rf._is_model: + return _deserialize(rf._type, value) + return _serialize(value, rf._format) class Model(_MyMutableMapping): @@ -559,7 +565,14 @@ def as_dict(self, *, exclude_readonly: bool = False) -> typing.Dict[str, typing. for k, v in self.items(): if exclude_readonly and k in readonly_props: # pyright: ignore[reportUnboundVariable] continue - result[k] = Model._as_dict_value(v, exclude_readonly=exclude_readonly) + is_multipart_file = False + try: + is_multipart_file = next( + rf for rf in self._attr_to_rest_field.values() if rf._rest_name == k + )._is_multipart_file + except StopIteration: + pass + result[k] = v if is_multipart_file else Model._as_dict_value(v, exclude_readonly=exclude_readonly) return result @staticmethod @@ -567,7 +580,7 @@ def _as_dict_value(v: typing.Any, exclude_readonly: bool = False) -> typing.Any: if v is None or isinstance(v, _Null): return None if isinstance(v, (list, tuple, set)): - return [Model._as_dict_value(x, exclude_readonly=exclude_readonly) for x in v] + return type(v)(Model._as_dict_value(x, exclude_readonly=exclude_readonly) for x in v) if isinstance(v, dict): return {dk: Model._as_dict_value(dv, exclude_readonly=exclude_readonly) for dk, dv in v.items()} return v.as_dict(exclude_readonly=exclude_readonly) if hasattr(v, "as_dict") else v @@ -762,6 +775,7 @@ def __init__( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, + is_multipart_file: bool = False, ): self._type = type self._rest_name_input = name @@ -771,6 +785,7 @@ def __init__( self._is_model = False self._default = default self._format = format + self._is_multipart_file = is_multipart_file @property def _rest_name(self) -> str: @@ -816,8 +831,11 @@ def rest_field( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, + is_multipart_file: bool = False, ) -> typing.Any: - return _RestField(name=name, type=type, visibility=visibility, default=default, format=format) + return _RestField( + name=name, type=type, visibility=visibility, default=default, format=format, is_multipart_file=is_multipart_file + ) def rest_discriminator( diff --git a/packages/typespec-python/test/azure/generated/typetest-dictionary/typetest/dictionary/_model_base.py b/packages/typespec-python/test/azure/generated/typetest-dictionary/typetest/dictionary/_model_base.py index 585ccb0e0f9..01c401e6324 100644 --- a/packages/typespec-python/test/azure/generated/typetest-dictionary/typetest/dictionary/_model_base.py +++ b/packages/typespec-python/test/azure/generated/typetest-dictionary/typetest/dictionary/_model_base.py @@ -462,7 +462,13 @@ def _get_rest_field( def _create_value(rf: typing.Optional["_RestField"], value: typing.Any) -> typing.Any: - return _deserialize(rf._type, value) if (rf and rf._is_model) else _serialize(value, rf._format if rf else None) + if not rf: + return _serialize(value, None) + if rf._is_multipart_file: + return value + if rf._is_model: + return _deserialize(rf._type, value) + return _serialize(value, rf._format) class Model(_MyMutableMapping): @@ -559,7 +565,14 @@ def as_dict(self, *, exclude_readonly: bool = False) -> typing.Dict[str, typing. for k, v in self.items(): if exclude_readonly and k in readonly_props: # pyright: ignore[reportUnboundVariable] continue - result[k] = Model._as_dict_value(v, exclude_readonly=exclude_readonly) + is_multipart_file = False + try: + is_multipart_file = next( + rf for rf in self._attr_to_rest_field.values() if rf._rest_name == k + )._is_multipart_file + except StopIteration: + pass + result[k] = v if is_multipart_file else Model._as_dict_value(v, exclude_readonly=exclude_readonly) return result @staticmethod @@ -567,7 +580,7 @@ def _as_dict_value(v: typing.Any, exclude_readonly: bool = False) -> typing.Any: if v is None or isinstance(v, _Null): return None if isinstance(v, (list, tuple, set)): - return [Model._as_dict_value(x, exclude_readonly=exclude_readonly) for x in v] + return type(v)(Model._as_dict_value(x, exclude_readonly=exclude_readonly) for x in v) if isinstance(v, dict): return {dk: Model._as_dict_value(dv, exclude_readonly=exclude_readonly) for dk, dv in v.items()} return v.as_dict(exclude_readonly=exclude_readonly) if hasattr(v, "as_dict") else v @@ -762,6 +775,7 @@ def __init__( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, + is_multipart_file: bool = False, ): self._type = type self._rest_name_input = name @@ -771,6 +785,7 @@ def __init__( self._is_model = False self._default = default self._format = format + self._is_multipart_file = is_multipart_file @property def _rest_name(self) -> str: @@ -816,8 +831,11 @@ def rest_field( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, + is_multipart_file: bool = False, ) -> typing.Any: - return _RestField(name=name, type=type, visibility=visibility, default=default, format=format) + return _RestField( + name=name, type=type, visibility=visibility, default=default, format=format, is_multipart_file=is_multipart_file + ) def rest_discriminator( diff --git a/packages/typespec-python/test/azure/generated/typetest-enum-extensible/typetest/enum/extensible/_model_base.py b/packages/typespec-python/test/azure/generated/typetest-enum-extensible/typetest/enum/extensible/_model_base.py index 585ccb0e0f9..01c401e6324 100644 --- a/packages/typespec-python/test/azure/generated/typetest-enum-extensible/typetest/enum/extensible/_model_base.py +++ b/packages/typespec-python/test/azure/generated/typetest-enum-extensible/typetest/enum/extensible/_model_base.py @@ -462,7 +462,13 @@ def _get_rest_field( def _create_value(rf: typing.Optional["_RestField"], value: typing.Any) -> typing.Any: - return _deserialize(rf._type, value) if (rf and rf._is_model) else _serialize(value, rf._format if rf else None) + if not rf: + return _serialize(value, None) + if rf._is_multipart_file: + return value + if rf._is_model: + return _deserialize(rf._type, value) + return _serialize(value, rf._format) class Model(_MyMutableMapping): @@ -559,7 +565,14 @@ def as_dict(self, *, exclude_readonly: bool = False) -> typing.Dict[str, typing. for k, v in self.items(): if exclude_readonly and k in readonly_props: # pyright: ignore[reportUnboundVariable] continue - result[k] = Model._as_dict_value(v, exclude_readonly=exclude_readonly) + is_multipart_file = False + try: + is_multipart_file = next( + rf for rf in self._attr_to_rest_field.values() if rf._rest_name == k + )._is_multipart_file + except StopIteration: + pass + result[k] = v if is_multipart_file else Model._as_dict_value(v, exclude_readonly=exclude_readonly) return result @staticmethod @@ -567,7 +580,7 @@ def _as_dict_value(v: typing.Any, exclude_readonly: bool = False) -> typing.Any: if v is None or isinstance(v, _Null): return None if isinstance(v, (list, tuple, set)): - return [Model._as_dict_value(x, exclude_readonly=exclude_readonly) for x in v] + return type(v)(Model._as_dict_value(x, exclude_readonly=exclude_readonly) for x in v) if isinstance(v, dict): return {dk: Model._as_dict_value(dv, exclude_readonly=exclude_readonly) for dk, dv in v.items()} return v.as_dict(exclude_readonly=exclude_readonly) if hasattr(v, "as_dict") else v @@ -762,6 +775,7 @@ def __init__( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, + is_multipart_file: bool = False, ): self._type = type self._rest_name_input = name @@ -771,6 +785,7 @@ def __init__( self._is_model = False self._default = default self._format = format + self._is_multipart_file = is_multipart_file @property def _rest_name(self) -> str: @@ -816,8 +831,11 @@ def rest_field( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, + is_multipart_file: bool = False, ) -> typing.Any: - return _RestField(name=name, type=type, visibility=visibility, default=default, format=format) + return _RestField( + name=name, type=type, visibility=visibility, default=default, format=format, is_multipart_file=is_multipart_file + ) def rest_discriminator( diff --git a/packages/typespec-python/test/azure/generated/typetest-enum-fixed/typetest/enum/fixed/_model_base.py b/packages/typespec-python/test/azure/generated/typetest-enum-fixed/typetest/enum/fixed/_model_base.py index 585ccb0e0f9..01c401e6324 100644 --- a/packages/typespec-python/test/azure/generated/typetest-enum-fixed/typetest/enum/fixed/_model_base.py +++ b/packages/typespec-python/test/azure/generated/typetest-enum-fixed/typetest/enum/fixed/_model_base.py @@ -462,7 +462,13 @@ def _get_rest_field( def _create_value(rf: typing.Optional["_RestField"], value: typing.Any) -> typing.Any: - return _deserialize(rf._type, value) if (rf and rf._is_model) else _serialize(value, rf._format if rf else None) + if not rf: + return _serialize(value, None) + if rf._is_multipart_file: + return value + if rf._is_model: + return _deserialize(rf._type, value) + return _serialize(value, rf._format) class Model(_MyMutableMapping): @@ -559,7 +565,14 @@ def as_dict(self, *, exclude_readonly: bool = False) -> typing.Dict[str, typing. for k, v in self.items(): if exclude_readonly and k in readonly_props: # pyright: ignore[reportUnboundVariable] continue - result[k] = Model._as_dict_value(v, exclude_readonly=exclude_readonly) + is_multipart_file = False + try: + is_multipart_file = next( + rf for rf in self._attr_to_rest_field.values() if rf._rest_name == k + )._is_multipart_file + except StopIteration: + pass + result[k] = v if is_multipart_file else Model._as_dict_value(v, exclude_readonly=exclude_readonly) return result @staticmethod @@ -567,7 +580,7 @@ def _as_dict_value(v: typing.Any, exclude_readonly: bool = False) -> typing.Any: if v is None or isinstance(v, _Null): return None if isinstance(v, (list, tuple, set)): - return [Model._as_dict_value(x, exclude_readonly=exclude_readonly) for x in v] + return type(v)(Model._as_dict_value(x, exclude_readonly=exclude_readonly) for x in v) if isinstance(v, dict): return {dk: Model._as_dict_value(dv, exclude_readonly=exclude_readonly) for dk, dv in v.items()} return v.as_dict(exclude_readonly=exclude_readonly) if hasattr(v, "as_dict") else v @@ -762,6 +775,7 @@ def __init__( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, + is_multipart_file: bool = False, ): self._type = type self._rest_name_input = name @@ -771,6 +785,7 @@ def __init__( self._is_model = False self._default = default self._format = format + self._is_multipart_file = is_multipart_file @property def _rest_name(self) -> str: @@ -816,8 +831,11 @@ def rest_field( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, + is_multipart_file: bool = False, ) -> typing.Any: - return _RestField(name=name, type=type, visibility=visibility, default=default, format=format) + return _RestField( + name=name, type=type, visibility=visibility, default=default, format=format, is_multipart_file=is_multipart_file + ) def rest_discriminator( diff --git a/packages/typespec-python/test/azure/generated/typetest-model-empty/typetest/model/empty/_model_base.py b/packages/typespec-python/test/azure/generated/typetest-model-empty/typetest/model/empty/_model_base.py index 585ccb0e0f9..01c401e6324 100644 --- a/packages/typespec-python/test/azure/generated/typetest-model-empty/typetest/model/empty/_model_base.py +++ b/packages/typespec-python/test/azure/generated/typetest-model-empty/typetest/model/empty/_model_base.py @@ -462,7 +462,13 @@ def _get_rest_field( def _create_value(rf: typing.Optional["_RestField"], value: typing.Any) -> typing.Any: - return _deserialize(rf._type, value) if (rf and rf._is_model) else _serialize(value, rf._format if rf else None) + if not rf: + return _serialize(value, None) + if rf._is_multipart_file: + return value + if rf._is_model: + return _deserialize(rf._type, value) + return _serialize(value, rf._format) class Model(_MyMutableMapping): @@ -559,7 +565,14 @@ def as_dict(self, *, exclude_readonly: bool = False) -> typing.Dict[str, typing. for k, v in self.items(): if exclude_readonly and k in readonly_props: # pyright: ignore[reportUnboundVariable] continue - result[k] = Model._as_dict_value(v, exclude_readonly=exclude_readonly) + is_multipart_file = False + try: + is_multipart_file = next( + rf for rf in self._attr_to_rest_field.values() if rf._rest_name == k + )._is_multipart_file + except StopIteration: + pass + result[k] = v if is_multipart_file else Model._as_dict_value(v, exclude_readonly=exclude_readonly) return result @staticmethod @@ -567,7 +580,7 @@ def _as_dict_value(v: typing.Any, exclude_readonly: bool = False) -> typing.Any: if v is None or isinstance(v, _Null): return None if isinstance(v, (list, tuple, set)): - return [Model._as_dict_value(x, exclude_readonly=exclude_readonly) for x in v] + return type(v)(Model._as_dict_value(x, exclude_readonly=exclude_readonly) for x in v) if isinstance(v, dict): return {dk: Model._as_dict_value(dv, exclude_readonly=exclude_readonly) for dk, dv in v.items()} return v.as_dict(exclude_readonly=exclude_readonly) if hasattr(v, "as_dict") else v @@ -762,6 +775,7 @@ def __init__( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, + is_multipart_file: bool = False, ): self._type = type self._rest_name_input = name @@ -771,6 +785,7 @@ def __init__( self._is_model = False self._default = default self._format = format + self._is_multipart_file = is_multipart_file @property def _rest_name(self) -> str: @@ -816,8 +831,11 @@ def rest_field( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, + is_multipart_file: bool = False, ) -> typing.Any: - return _RestField(name=name, type=type, visibility=visibility, default=default, format=format) + return _RestField( + name=name, type=type, visibility=visibility, default=default, format=format, is_multipart_file=is_multipart_file + ) def rest_discriminator( diff --git a/packages/typespec-python/test/azure/generated/typetest-model-enumdiscriminator/typetest/model/enumdiscriminator/_model_base.py b/packages/typespec-python/test/azure/generated/typetest-model-enumdiscriminator/typetest/model/enumdiscriminator/_model_base.py index 585ccb0e0f9..01c401e6324 100644 --- a/packages/typespec-python/test/azure/generated/typetest-model-enumdiscriminator/typetest/model/enumdiscriminator/_model_base.py +++ b/packages/typespec-python/test/azure/generated/typetest-model-enumdiscriminator/typetest/model/enumdiscriminator/_model_base.py @@ -462,7 +462,13 @@ def _get_rest_field( def _create_value(rf: typing.Optional["_RestField"], value: typing.Any) -> typing.Any: - return _deserialize(rf._type, value) if (rf and rf._is_model) else _serialize(value, rf._format if rf else None) + if not rf: + return _serialize(value, None) + if rf._is_multipart_file: + return value + if rf._is_model: + return _deserialize(rf._type, value) + return _serialize(value, rf._format) class Model(_MyMutableMapping): @@ -559,7 +565,14 @@ def as_dict(self, *, exclude_readonly: bool = False) -> typing.Dict[str, typing. for k, v in self.items(): if exclude_readonly and k in readonly_props: # pyright: ignore[reportUnboundVariable] continue - result[k] = Model._as_dict_value(v, exclude_readonly=exclude_readonly) + is_multipart_file = False + try: + is_multipart_file = next( + rf for rf in self._attr_to_rest_field.values() if rf._rest_name == k + )._is_multipart_file + except StopIteration: + pass + result[k] = v if is_multipart_file else Model._as_dict_value(v, exclude_readonly=exclude_readonly) return result @staticmethod @@ -567,7 +580,7 @@ def _as_dict_value(v: typing.Any, exclude_readonly: bool = False) -> typing.Any: if v is None or isinstance(v, _Null): return None if isinstance(v, (list, tuple, set)): - return [Model._as_dict_value(x, exclude_readonly=exclude_readonly) for x in v] + return type(v)(Model._as_dict_value(x, exclude_readonly=exclude_readonly) for x in v) if isinstance(v, dict): return {dk: Model._as_dict_value(dv, exclude_readonly=exclude_readonly) for dk, dv in v.items()} return v.as_dict(exclude_readonly=exclude_readonly) if hasattr(v, "as_dict") else v @@ -762,6 +775,7 @@ def __init__( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, + is_multipart_file: bool = False, ): self._type = type self._rest_name_input = name @@ -771,6 +785,7 @@ def __init__( self._is_model = False self._default = default self._format = format + self._is_multipart_file = is_multipart_file @property def _rest_name(self) -> str: @@ -816,8 +831,11 @@ def rest_field( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, + is_multipart_file: bool = False, ) -> typing.Any: - return _RestField(name=name, type=type, visibility=visibility, default=default, format=format) + return _RestField( + name=name, type=type, visibility=visibility, default=default, format=format, is_multipart_file=is_multipart_file + ) def rest_discriminator( diff --git a/packages/typespec-python/test/azure/generated/typetest-model-nesteddiscriminator/typetest/model/nesteddiscriminator/_model_base.py b/packages/typespec-python/test/azure/generated/typetest-model-nesteddiscriminator/typetest/model/nesteddiscriminator/_model_base.py index 585ccb0e0f9..01c401e6324 100644 --- a/packages/typespec-python/test/azure/generated/typetest-model-nesteddiscriminator/typetest/model/nesteddiscriminator/_model_base.py +++ b/packages/typespec-python/test/azure/generated/typetest-model-nesteddiscriminator/typetest/model/nesteddiscriminator/_model_base.py @@ -462,7 +462,13 @@ def _get_rest_field( def _create_value(rf: typing.Optional["_RestField"], value: typing.Any) -> typing.Any: - return _deserialize(rf._type, value) if (rf and rf._is_model) else _serialize(value, rf._format if rf else None) + if not rf: + return _serialize(value, None) + if rf._is_multipart_file: + return value + if rf._is_model: + return _deserialize(rf._type, value) + return _serialize(value, rf._format) class Model(_MyMutableMapping): @@ -559,7 +565,14 @@ def as_dict(self, *, exclude_readonly: bool = False) -> typing.Dict[str, typing. for k, v in self.items(): if exclude_readonly and k in readonly_props: # pyright: ignore[reportUnboundVariable] continue - result[k] = Model._as_dict_value(v, exclude_readonly=exclude_readonly) + is_multipart_file = False + try: + is_multipart_file = next( + rf for rf in self._attr_to_rest_field.values() if rf._rest_name == k + )._is_multipart_file + except StopIteration: + pass + result[k] = v if is_multipart_file else Model._as_dict_value(v, exclude_readonly=exclude_readonly) return result @staticmethod @@ -567,7 +580,7 @@ def _as_dict_value(v: typing.Any, exclude_readonly: bool = False) -> typing.Any: if v is None or isinstance(v, _Null): return None if isinstance(v, (list, tuple, set)): - return [Model._as_dict_value(x, exclude_readonly=exclude_readonly) for x in v] + return type(v)(Model._as_dict_value(x, exclude_readonly=exclude_readonly) for x in v) if isinstance(v, dict): return {dk: Model._as_dict_value(dv, exclude_readonly=exclude_readonly) for dk, dv in v.items()} return v.as_dict(exclude_readonly=exclude_readonly) if hasattr(v, "as_dict") else v @@ -762,6 +775,7 @@ def __init__( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, + is_multipart_file: bool = False, ): self._type = type self._rest_name_input = name @@ -771,6 +785,7 @@ def __init__( self._is_model = False self._default = default self._format = format + self._is_multipart_file = is_multipart_file @property def _rest_name(self) -> str: @@ -816,8 +831,11 @@ def rest_field( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, + is_multipart_file: bool = False, ) -> typing.Any: - return _RestField(name=name, type=type, visibility=visibility, default=default, format=format) + return _RestField( + name=name, type=type, visibility=visibility, default=default, format=format, is_multipart_file=is_multipart_file + ) def rest_discriminator( diff --git a/packages/typespec-python/test/azure/generated/typetest-model-notdiscriminated/typetest/model/notdiscriminated/_model_base.py b/packages/typespec-python/test/azure/generated/typetest-model-notdiscriminated/typetest/model/notdiscriminated/_model_base.py index 585ccb0e0f9..01c401e6324 100644 --- a/packages/typespec-python/test/azure/generated/typetest-model-notdiscriminated/typetest/model/notdiscriminated/_model_base.py +++ b/packages/typespec-python/test/azure/generated/typetest-model-notdiscriminated/typetest/model/notdiscriminated/_model_base.py @@ -462,7 +462,13 @@ def _get_rest_field( def _create_value(rf: typing.Optional["_RestField"], value: typing.Any) -> typing.Any: - return _deserialize(rf._type, value) if (rf and rf._is_model) else _serialize(value, rf._format if rf else None) + if not rf: + return _serialize(value, None) + if rf._is_multipart_file: + return value + if rf._is_model: + return _deserialize(rf._type, value) + return _serialize(value, rf._format) class Model(_MyMutableMapping): @@ -559,7 +565,14 @@ def as_dict(self, *, exclude_readonly: bool = False) -> typing.Dict[str, typing. for k, v in self.items(): if exclude_readonly and k in readonly_props: # pyright: ignore[reportUnboundVariable] continue - result[k] = Model._as_dict_value(v, exclude_readonly=exclude_readonly) + is_multipart_file = False + try: + is_multipart_file = next( + rf for rf in self._attr_to_rest_field.values() if rf._rest_name == k + )._is_multipart_file + except StopIteration: + pass + result[k] = v if is_multipart_file else Model._as_dict_value(v, exclude_readonly=exclude_readonly) return result @staticmethod @@ -567,7 +580,7 @@ def _as_dict_value(v: typing.Any, exclude_readonly: bool = False) -> typing.Any: if v is None or isinstance(v, _Null): return None if isinstance(v, (list, tuple, set)): - return [Model._as_dict_value(x, exclude_readonly=exclude_readonly) for x in v] + return type(v)(Model._as_dict_value(x, exclude_readonly=exclude_readonly) for x in v) if isinstance(v, dict): return {dk: Model._as_dict_value(dv, exclude_readonly=exclude_readonly) for dk, dv in v.items()} return v.as_dict(exclude_readonly=exclude_readonly) if hasattr(v, "as_dict") else v @@ -762,6 +775,7 @@ def __init__( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, + is_multipart_file: bool = False, ): self._type = type self._rest_name_input = name @@ -771,6 +785,7 @@ def __init__( self._is_model = False self._default = default self._format = format + self._is_multipart_file = is_multipart_file @property def _rest_name(self) -> str: @@ -816,8 +831,11 @@ def rest_field( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, + is_multipart_file: bool = False, ) -> typing.Any: - return _RestField(name=name, type=type, visibility=visibility, default=default, format=format) + return _RestField( + name=name, type=type, visibility=visibility, default=default, format=format, is_multipart_file=is_multipart_file + ) def rest_discriminator( diff --git a/packages/typespec-python/test/azure/generated/typetest-model-recursive/typetest/model/recursive/_model_base.py b/packages/typespec-python/test/azure/generated/typetest-model-recursive/typetest/model/recursive/_model_base.py index 585ccb0e0f9..01c401e6324 100644 --- a/packages/typespec-python/test/azure/generated/typetest-model-recursive/typetest/model/recursive/_model_base.py +++ b/packages/typespec-python/test/azure/generated/typetest-model-recursive/typetest/model/recursive/_model_base.py @@ -462,7 +462,13 @@ def _get_rest_field( def _create_value(rf: typing.Optional["_RestField"], value: typing.Any) -> typing.Any: - return _deserialize(rf._type, value) if (rf and rf._is_model) else _serialize(value, rf._format if rf else None) + if not rf: + return _serialize(value, None) + if rf._is_multipart_file: + return value + if rf._is_model: + return _deserialize(rf._type, value) + return _serialize(value, rf._format) class Model(_MyMutableMapping): @@ -559,7 +565,14 @@ def as_dict(self, *, exclude_readonly: bool = False) -> typing.Dict[str, typing. for k, v in self.items(): if exclude_readonly and k in readonly_props: # pyright: ignore[reportUnboundVariable] continue - result[k] = Model._as_dict_value(v, exclude_readonly=exclude_readonly) + is_multipart_file = False + try: + is_multipart_file = next( + rf for rf in self._attr_to_rest_field.values() if rf._rest_name == k + )._is_multipart_file + except StopIteration: + pass + result[k] = v if is_multipart_file else Model._as_dict_value(v, exclude_readonly=exclude_readonly) return result @staticmethod @@ -567,7 +580,7 @@ def _as_dict_value(v: typing.Any, exclude_readonly: bool = False) -> typing.Any: if v is None or isinstance(v, _Null): return None if isinstance(v, (list, tuple, set)): - return [Model._as_dict_value(x, exclude_readonly=exclude_readonly) for x in v] + return type(v)(Model._as_dict_value(x, exclude_readonly=exclude_readonly) for x in v) if isinstance(v, dict): return {dk: Model._as_dict_value(dv, exclude_readonly=exclude_readonly) for dk, dv in v.items()} return v.as_dict(exclude_readonly=exclude_readonly) if hasattr(v, "as_dict") else v @@ -762,6 +775,7 @@ def __init__( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, + is_multipart_file: bool = False, ): self._type = type self._rest_name_input = name @@ -771,6 +785,7 @@ def __init__( self._is_model = False self._default = default self._format = format + self._is_multipart_file = is_multipart_file @property def _rest_name(self) -> str: @@ -816,8 +831,11 @@ def rest_field( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, + is_multipart_file: bool = False, ) -> typing.Any: - return _RestField(name=name, type=type, visibility=visibility, default=default, format=format) + return _RestField( + name=name, type=type, visibility=visibility, default=default, format=format, is_multipart_file=is_multipart_file + ) def rest_discriminator( diff --git a/packages/typespec-python/test/azure/generated/typetest-model-singlediscriminator/typetest/model/singlediscriminator/_model_base.py b/packages/typespec-python/test/azure/generated/typetest-model-singlediscriminator/typetest/model/singlediscriminator/_model_base.py index 585ccb0e0f9..01c401e6324 100644 --- a/packages/typespec-python/test/azure/generated/typetest-model-singlediscriminator/typetest/model/singlediscriminator/_model_base.py +++ b/packages/typespec-python/test/azure/generated/typetest-model-singlediscriminator/typetest/model/singlediscriminator/_model_base.py @@ -462,7 +462,13 @@ def _get_rest_field( def _create_value(rf: typing.Optional["_RestField"], value: typing.Any) -> typing.Any: - return _deserialize(rf._type, value) if (rf and rf._is_model) else _serialize(value, rf._format if rf else None) + if not rf: + return _serialize(value, None) + if rf._is_multipart_file: + return value + if rf._is_model: + return _deserialize(rf._type, value) + return _serialize(value, rf._format) class Model(_MyMutableMapping): @@ -559,7 +565,14 @@ def as_dict(self, *, exclude_readonly: bool = False) -> typing.Dict[str, typing. for k, v in self.items(): if exclude_readonly and k in readonly_props: # pyright: ignore[reportUnboundVariable] continue - result[k] = Model._as_dict_value(v, exclude_readonly=exclude_readonly) + is_multipart_file = False + try: + is_multipart_file = next( + rf for rf in self._attr_to_rest_field.values() if rf._rest_name == k + )._is_multipart_file + except StopIteration: + pass + result[k] = v if is_multipart_file else Model._as_dict_value(v, exclude_readonly=exclude_readonly) return result @staticmethod @@ -567,7 +580,7 @@ def _as_dict_value(v: typing.Any, exclude_readonly: bool = False) -> typing.Any: if v is None or isinstance(v, _Null): return None if isinstance(v, (list, tuple, set)): - return [Model._as_dict_value(x, exclude_readonly=exclude_readonly) for x in v] + return type(v)(Model._as_dict_value(x, exclude_readonly=exclude_readonly) for x in v) if isinstance(v, dict): return {dk: Model._as_dict_value(dv, exclude_readonly=exclude_readonly) for dk, dv in v.items()} return v.as_dict(exclude_readonly=exclude_readonly) if hasattr(v, "as_dict") else v @@ -762,6 +775,7 @@ def __init__( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, + is_multipart_file: bool = False, ): self._type = type self._rest_name_input = name @@ -771,6 +785,7 @@ def __init__( self._is_model = False self._default = default self._format = format + self._is_multipart_file = is_multipart_file @property def _rest_name(self) -> str: @@ -816,8 +831,11 @@ def rest_field( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, + is_multipart_file: bool = False, ) -> typing.Any: - return _RestField(name=name, type=type, visibility=visibility, default=default, format=format) + return _RestField( + name=name, type=type, visibility=visibility, default=default, format=format, is_multipart_file=is_multipart_file + ) def rest_discriminator( diff --git a/packages/typespec-python/test/azure/generated/typetest-model-usage/typetest/model/usage/_model_base.py b/packages/typespec-python/test/azure/generated/typetest-model-usage/typetest/model/usage/_model_base.py index 585ccb0e0f9..01c401e6324 100644 --- a/packages/typespec-python/test/azure/generated/typetest-model-usage/typetest/model/usage/_model_base.py +++ b/packages/typespec-python/test/azure/generated/typetest-model-usage/typetest/model/usage/_model_base.py @@ -462,7 +462,13 @@ def _get_rest_field( def _create_value(rf: typing.Optional["_RestField"], value: typing.Any) -> typing.Any: - return _deserialize(rf._type, value) if (rf and rf._is_model) else _serialize(value, rf._format if rf else None) + if not rf: + return _serialize(value, None) + if rf._is_multipart_file: + return value + if rf._is_model: + return _deserialize(rf._type, value) + return _serialize(value, rf._format) class Model(_MyMutableMapping): @@ -559,7 +565,14 @@ def as_dict(self, *, exclude_readonly: bool = False) -> typing.Dict[str, typing. for k, v in self.items(): if exclude_readonly and k in readonly_props: # pyright: ignore[reportUnboundVariable] continue - result[k] = Model._as_dict_value(v, exclude_readonly=exclude_readonly) + is_multipart_file = False + try: + is_multipart_file = next( + rf for rf in self._attr_to_rest_field.values() if rf._rest_name == k + )._is_multipart_file + except StopIteration: + pass + result[k] = v if is_multipart_file else Model._as_dict_value(v, exclude_readonly=exclude_readonly) return result @staticmethod @@ -567,7 +580,7 @@ def _as_dict_value(v: typing.Any, exclude_readonly: bool = False) -> typing.Any: if v is None or isinstance(v, _Null): return None if isinstance(v, (list, tuple, set)): - return [Model._as_dict_value(x, exclude_readonly=exclude_readonly) for x in v] + return type(v)(Model._as_dict_value(x, exclude_readonly=exclude_readonly) for x in v) if isinstance(v, dict): return {dk: Model._as_dict_value(dv, exclude_readonly=exclude_readonly) for dk, dv in v.items()} return v.as_dict(exclude_readonly=exclude_readonly) if hasattr(v, "as_dict") else v @@ -762,6 +775,7 @@ def __init__( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, + is_multipart_file: bool = False, ): self._type = type self._rest_name_input = name @@ -771,6 +785,7 @@ def __init__( self._is_model = False self._default = default self._format = format + self._is_multipart_file = is_multipart_file @property def _rest_name(self) -> str: @@ -816,8 +831,11 @@ def rest_field( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, + is_multipart_file: bool = False, ) -> typing.Any: - return _RestField(name=name, type=type, visibility=visibility, default=default, format=format) + return _RestField( + name=name, type=type, visibility=visibility, default=default, format=format, is_multipart_file=is_multipart_file + ) def rest_discriminator( diff --git a/packages/typespec-python/test/azure/generated/typetest-model-visibility/typetest/model/visibility/_model_base.py b/packages/typespec-python/test/azure/generated/typetest-model-visibility/typetest/model/visibility/_model_base.py index 585ccb0e0f9..01c401e6324 100644 --- a/packages/typespec-python/test/azure/generated/typetest-model-visibility/typetest/model/visibility/_model_base.py +++ b/packages/typespec-python/test/azure/generated/typetest-model-visibility/typetest/model/visibility/_model_base.py @@ -462,7 +462,13 @@ def _get_rest_field( def _create_value(rf: typing.Optional["_RestField"], value: typing.Any) -> typing.Any: - return _deserialize(rf._type, value) if (rf and rf._is_model) else _serialize(value, rf._format if rf else None) + if not rf: + return _serialize(value, None) + if rf._is_multipart_file: + return value + if rf._is_model: + return _deserialize(rf._type, value) + return _serialize(value, rf._format) class Model(_MyMutableMapping): @@ -559,7 +565,14 @@ def as_dict(self, *, exclude_readonly: bool = False) -> typing.Dict[str, typing. for k, v in self.items(): if exclude_readonly and k in readonly_props: # pyright: ignore[reportUnboundVariable] continue - result[k] = Model._as_dict_value(v, exclude_readonly=exclude_readonly) + is_multipart_file = False + try: + is_multipart_file = next( + rf for rf in self._attr_to_rest_field.values() if rf._rest_name == k + )._is_multipart_file + except StopIteration: + pass + result[k] = v if is_multipart_file else Model._as_dict_value(v, exclude_readonly=exclude_readonly) return result @staticmethod @@ -567,7 +580,7 @@ def _as_dict_value(v: typing.Any, exclude_readonly: bool = False) -> typing.Any: if v is None or isinstance(v, _Null): return None if isinstance(v, (list, tuple, set)): - return [Model._as_dict_value(x, exclude_readonly=exclude_readonly) for x in v] + return type(v)(Model._as_dict_value(x, exclude_readonly=exclude_readonly) for x in v) if isinstance(v, dict): return {dk: Model._as_dict_value(dv, exclude_readonly=exclude_readonly) for dk, dv in v.items()} return v.as_dict(exclude_readonly=exclude_readonly) if hasattr(v, "as_dict") else v @@ -762,6 +775,7 @@ def __init__( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, + is_multipart_file: bool = False, ): self._type = type self._rest_name_input = name @@ -771,6 +785,7 @@ def __init__( self._is_model = False self._default = default self._format = format + self._is_multipart_file = is_multipart_file @property def _rest_name(self) -> str: @@ -816,8 +831,11 @@ def rest_field( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, + is_multipart_file: bool = False, ) -> typing.Any: - return _RestField(name=name, type=type, visibility=visibility, default=default, format=format) + return _RestField( + name=name, type=type, visibility=visibility, default=default, format=format, is_multipart_file=is_multipart_file + ) def rest_discriminator( diff --git a/packages/typespec-python/test/azure/generated/typetest-property-additionalproperties/typetest/property/additionalproperties/_model_base.py b/packages/typespec-python/test/azure/generated/typetest-property-additionalproperties/typetest/property/additionalproperties/_model_base.py index 585ccb0e0f9..01c401e6324 100644 --- a/packages/typespec-python/test/azure/generated/typetest-property-additionalproperties/typetest/property/additionalproperties/_model_base.py +++ b/packages/typespec-python/test/azure/generated/typetest-property-additionalproperties/typetest/property/additionalproperties/_model_base.py @@ -462,7 +462,13 @@ def _get_rest_field( def _create_value(rf: typing.Optional["_RestField"], value: typing.Any) -> typing.Any: - return _deserialize(rf._type, value) if (rf and rf._is_model) else _serialize(value, rf._format if rf else None) + if not rf: + return _serialize(value, None) + if rf._is_multipart_file: + return value + if rf._is_model: + return _deserialize(rf._type, value) + return _serialize(value, rf._format) class Model(_MyMutableMapping): @@ -559,7 +565,14 @@ def as_dict(self, *, exclude_readonly: bool = False) -> typing.Dict[str, typing. for k, v in self.items(): if exclude_readonly and k in readonly_props: # pyright: ignore[reportUnboundVariable] continue - result[k] = Model._as_dict_value(v, exclude_readonly=exclude_readonly) + is_multipart_file = False + try: + is_multipart_file = next( + rf for rf in self._attr_to_rest_field.values() if rf._rest_name == k + )._is_multipart_file + except StopIteration: + pass + result[k] = v if is_multipart_file else Model._as_dict_value(v, exclude_readonly=exclude_readonly) return result @staticmethod @@ -567,7 +580,7 @@ def _as_dict_value(v: typing.Any, exclude_readonly: bool = False) -> typing.Any: if v is None or isinstance(v, _Null): return None if isinstance(v, (list, tuple, set)): - return [Model._as_dict_value(x, exclude_readonly=exclude_readonly) for x in v] + return type(v)(Model._as_dict_value(x, exclude_readonly=exclude_readonly) for x in v) if isinstance(v, dict): return {dk: Model._as_dict_value(dv, exclude_readonly=exclude_readonly) for dk, dv in v.items()} return v.as_dict(exclude_readonly=exclude_readonly) if hasattr(v, "as_dict") else v @@ -762,6 +775,7 @@ def __init__( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, + is_multipart_file: bool = False, ): self._type = type self._rest_name_input = name @@ -771,6 +785,7 @@ def __init__( self._is_model = False self._default = default self._format = format + self._is_multipart_file = is_multipart_file @property def _rest_name(self) -> str: @@ -816,8 +831,11 @@ def rest_field( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, + is_multipart_file: bool = False, ) -> typing.Any: - return _RestField(name=name, type=type, visibility=visibility, default=default, format=format) + return _RestField( + name=name, type=type, visibility=visibility, default=default, format=format, is_multipart_file=is_multipart_file + ) def rest_discriminator( diff --git a/packages/typespec-python/test/azure/generated/typetest-property-nullable/typetest/property/nullable/_model_base.py b/packages/typespec-python/test/azure/generated/typetest-property-nullable/typetest/property/nullable/_model_base.py index 585ccb0e0f9..01c401e6324 100644 --- a/packages/typespec-python/test/azure/generated/typetest-property-nullable/typetest/property/nullable/_model_base.py +++ b/packages/typespec-python/test/azure/generated/typetest-property-nullable/typetest/property/nullable/_model_base.py @@ -462,7 +462,13 @@ def _get_rest_field( def _create_value(rf: typing.Optional["_RestField"], value: typing.Any) -> typing.Any: - return _deserialize(rf._type, value) if (rf and rf._is_model) else _serialize(value, rf._format if rf else None) + if not rf: + return _serialize(value, None) + if rf._is_multipart_file: + return value + if rf._is_model: + return _deserialize(rf._type, value) + return _serialize(value, rf._format) class Model(_MyMutableMapping): @@ -559,7 +565,14 @@ def as_dict(self, *, exclude_readonly: bool = False) -> typing.Dict[str, typing. for k, v in self.items(): if exclude_readonly and k in readonly_props: # pyright: ignore[reportUnboundVariable] continue - result[k] = Model._as_dict_value(v, exclude_readonly=exclude_readonly) + is_multipart_file = False + try: + is_multipart_file = next( + rf for rf in self._attr_to_rest_field.values() if rf._rest_name == k + )._is_multipart_file + except StopIteration: + pass + result[k] = v if is_multipart_file else Model._as_dict_value(v, exclude_readonly=exclude_readonly) return result @staticmethod @@ -567,7 +580,7 @@ def _as_dict_value(v: typing.Any, exclude_readonly: bool = False) -> typing.Any: if v is None or isinstance(v, _Null): return None if isinstance(v, (list, tuple, set)): - return [Model._as_dict_value(x, exclude_readonly=exclude_readonly) for x in v] + return type(v)(Model._as_dict_value(x, exclude_readonly=exclude_readonly) for x in v) if isinstance(v, dict): return {dk: Model._as_dict_value(dv, exclude_readonly=exclude_readonly) for dk, dv in v.items()} return v.as_dict(exclude_readonly=exclude_readonly) if hasattr(v, "as_dict") else v @@ -762,6 +775,7 @@ def __init__( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, + is_multipart_file: bool = False, ): self._type = type self._rest_name_input = name @@ -771,6 +785,7 @@ def __init__( self._is_model = False self._default = default self._format = format + self._is_multipart_file = is_multipart_file @property def _rest_name(self) -> str: @@ -816,8 +831,11 @@ def rest_field( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, + is_multipart_file: bool = False, ) -> typing.Any: - return _RestField(name=name, type=type, visibility=visibility, default=default, format=format) + return _RestField( + name=name, type=type, visibility=visibility, default=default, format=format, is_multipart_file=is_multipart_file + ) def rest_discriminator( diff --git a/packages/typespec-python/test/azure/generated/typetest-property-optional/typetest/property/optional/_model_base.py b/packages/typespec-python/test/azure/generated/typetest-property-optional/typetest/property/optional/_model_base.py index 585ccb0e0f9..01c401e6324 100644 --- a/packages/typespec-python/test/azure/generated/typetest-property-optional/typetest/property/optional/_model_base.py +++ b/packages/typespec-python/test/azure/generated/typetest-property-optional/typetest/property/optional/_model_base.py @@ -462,7 +462,13 @@ def _get_rest_field( def _create_value(rf: typing.Optional["_RestField"], value: typing.Any) -> typing.Any: - return _deserialize(rf._type, value) if (rf and rf._is_model) else _serialize(value, rf._format if rf else None) + if not rf: + return _serialize(value, None) + if rf._is_multipart_file: + return value + if rf._is_model: + return _deserialize(rf._type, value) + return _serialize(value, rf._format) class Model(_MyMutableMapping): @@ -559,7 +565,14 @@ def as_dict(self, *, exclude_readonly: bool = False) -> typing.Dict[str, typing. for k, v in self.items(): if exclude_readonly and k in readonly_props: # pyright: ignore[reportUnboundVariable] continue - result[k] = Model._as_dict_value(v, exclude_readonly=exclude_readonly) + is_multipart_file = False + try: + is_multipart_file = next( + rf for rf in self._attr_to_rest_field.values() if rf._rest_name == k + )._is_multipart_file + except StopIteration: + pass + result[k] = v if is_multipart_file else Model._as_dict_value(v, exclude_readonly=exclude_readonly) return result @staticmethod @@ -567,7 +580,7 @@ def _as_dict_value(v: typing.Any, exclude_readonly: bool = False) -> typing.Any: if v is None or isinstance(v, _Null): return None if isinstance(v, (list, tuple, set)): - return [Model._as_dict_value(x, exclude_readonly=exclude_readonly) for x in v] + return type(v)(Model._as_dict_value(x, exclude_readonly=exclude_readonly) for x in v) if isinstance(v, dict): return {dk: Model._as_dict_value(dv, exclude_readonly=exclude_readonly) for dk, dv in v.items()} return v.as_dict(exclude_readonly=exclude_readonly) if hasattr(v, "as_dict") else v @@ -762,6 +775,7 @@ def __init__( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, + is_multipart_file: bool = False, ): self._type = type self._rest_name_input = name @@ -771,6 +785,7 @@ def __init__( self._is_model = False self._default = default self._format = format + self._is_multipart_file = is_multipart_file @property def _rest_name(self) -> str: @@ -816,8 +831,11 @@ def rest_field( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, + is_multipart_file: bool = False, ) -> typing.Any: - return _RestField(name=name, type=type, visibility=visibility, default=default, format=format) + return _RestField( + name=name, type=type, visibility=visibility, default=default, format=format, is_multipart_file=is_multipart_file + ) def rest_discriminator( diff --git a/packages/typespec-python/test/azure/generated/typetest-property-valuetypes/typetest/property/valuetypes/_model_base.py b/packages/typespec-python/test/azure/generated/typetest-property-valuetypes/typetest/property/valuetypes/_model_base.py index 585ccb0e0f9..01c401e6324 100644 --- a/packages/typespec-python/test/azure/generated/typetest-property-valuetypes/typetest/property/valuetypes/_model_base.py +++ b/packages/typespec-python/test/azure/generated/typetest-property-valuetypes/typetest/property/valuetypes/_model_base.py @@ -462,7 +462,13 @@ def _get_rest_field( def _create_value(rf: typing.Optional["_RestField"], value: typing.Any) -> typing.Any: - return _deserialize(rf._type, value) if (rf and rf._is_model) else _serialize(value, rf._format if rf else None) + if not rf: + return _serialize(value, None) + if rf._is_multipart_file: + return value + if rf._is_model: + return _deserialize(rf._type, value) + return _serialize(value, rf._format) class Model(_MyMutableMapping): @@ -559,7 +565,14 @@ def as_dict(self, *, exclude_readonly: bool = False) -> typing.Dict[str, typing. for k, v in self.items(): if exclude_readonly and k in readonly_props: # pyright: ignore[reportUnboundVariable] continue - result[k] = Model._as_dict_value(v, exclude_readonly=exclude_readonly) + is_multipart_file = False + try: + is_multipart_file = next( + rf for rf in self._attr_to_rest_field.values() if rf._rest_name == k + )._is_multipart_file + except StopIteration: + pass + result[k] = v if is_multipart_file else Model._as_dict_value(v, exclude_readonly=exclude_readonly) return result @staticmethod @@ -567,7 +580,7 @@ def _as_dict_value(v: typing.Any, exclude_readonly: bool = False) -> typing.Any: if v is None or isinstance(v, _Null): return None if isinstance(v, (list, tuple, set)): - return [Model._as_dict_value(x, exclude_readonly=exclude_readonly) for x in v] + return type(v)(Model._as_dict_value(x, exclude_readonly=exclude_readonly) for x in v) if isinstance(v, dict): return {dk: Model._as_dict_value(dv, exclude_readonly=exclude_readonly) for dk, dv in v.items()} return v.as_dict(exclude_readonly=exclude_readonly) if hasattr(v, "as_dict") else v @@ -762,6 +775,7 @@ def __init__( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, + is_multipart_file: bool = False, ): self._type = type self._rest_name_input = name @@ -771,6 +785,7 @@ def __init__( self._is_model = False self._default = default self._format = format + self._is_multipart_file = is_multipart_file @property def _rest_name(self) -> str: @@ -816,8 +831,11 @@ def rest_field( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, + is_multipart_file: bool = False, ) -> typing.Any: - return _RestField(name=name, type=type, visibility=visibility, default=default, format=format) + return _RestField( + name=name, type=type, visibility=visibility, default=default, format=format, is_multipart_file=is_multipart_file + ) def rest_discriminator( diff --git a/packages/typespec-python/test/azure/generated/typetest-scalar/typetest/scalar/_model_base.py b/packages/typespec-python/test/azure/generated/typetest-scalar/typetest/scalar/_model_base.py index 585ccb0e0f9..01c401e6324 100644 --- a/packages/typespec-python/test/azure/generated/typetest-scalar/typetest/scalar/_model_base.py +++ b/packages/typespec-python/test/azure/generated/typetest-scalar/typetest/scalar/_model_base.py @@ -462,7 +462,13 @@ def _get_rest_field( def _create_value(rf: typing.Optional["_RestField"], value: typing.Any) -> typing.Any: - return _deserialize(rf._type, value) if (rf and rf._is_model) else _serialize(value, rf._format if rf else None) + if not rf: + return _serialize(value, None) + if rf._is_multipart_file: + return value + if rf._is_model: + return _deserialize(rf._type, value) + return _serialize(value, rf._format) class Model(_MyMutableMapping): @@ -559,7 +565,14 @@ def as_dict(self, *, exclude_readonly: bool = False) -> typing.Dict[str, typing. for k, v in self.items(): if exclude_readonly and k in readonly_props: # pyright: ignore[reportUnboundVariable] continue - result[k] = Model._as_dict_value(v, exclude_readonly=exclude_readonly) + is_multipart_file = False + try: + is_multipart_file = next( + rf for rf in self._attr_to_rest_field.values() if rf._rest_name == k + )._is_multipart_file + except StopIteration: + pass + result[k] = v if is_multipart_file else Model._as_dict_value(v, exclude_readonly=exclude_readonly) return result @staticmethod @@ -567,7 +580,7 @@ def _as_dict_value(v: typing.Any, exclude_readonly: bool = False) -> typing.Any: if v is None or isinstance(v, _Null): return None if isinstance(v, (list, tuple, set)): - return [Model._as_dict_value(x, exclude_readonly=exclude_readonly) for x in v] + return type(v)(Model._as_dict_value(x, exclude_readonly=exclude_readonly) for x in v) if isinstance(v, dict): return {dk: Model._as_dict_value(dv, exclude_readonly=exclude_readonly) for dk, dv in v.items()} return v.as_dict(exclude_readonly=exclude_readonly) if hasattr(v, "as_dict") else v @@ -762,6 +775,7 @@ def __init__( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, + is_multipart_file: bool = False, ): self._type = type self._rest_name_input = name @@ -771,6 +785,7 @@ def __init__( self._is_model = False self._default = default self._format = format + self._is_multipart_file = is_multipart_file @property def _rest_name(self) -> str: @@ -816,8 +831,11 @@ def rest_field( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, + is_multipart_file: bool = False, ) -> typing.Any: - return _RestField(name=name, type=type, visibility=visibility, default=default, format=format) + return _RestField( + name=name, type=type, visibility=visibility, default=default, format=format, is_multipart_file=is_multipart_file + ) def rest_discriminator( diff --git a/packages/typespec-python/test/azure/generated/typetest-union/typetest/union/_model_base.py b/packages/typespec-python/test/azure/generated/typetest-union/typetest/union/_model_base.py index 585ccb0e0f9..01c401e6324 100644 --- a/packages/typespec-python/test/azure/generated/typetest-union/typetest/union/_model_base.py +++ b/packages/typespec-python/test/azure/generated/typetest-union/typetest/union/_model_base.py @@ -462,7 +462,13 @@ def _get_rest_field( def _create_value(rf: typing.Optional["_RestField"], value: typing.Any) -> typing.Any: - return _deserialize(rf._type, value) if (rf and rf._is_model) else _serialize(value, rf._format if rf else None) + if not rf: + return _serialize(value, None) + if rf._is_multipart_file: + return value + if rf._is_model: + return _deserialize(rf._type, value) + return _serialize(value, rf._format) class Model(_MyMutableMapping): @@ -559,7 +565,14 @@ def as_dict(self, *, exclude_readonly: bool = False) -> typing.Dict[str, typing. for k, v in self.items(): if exclude_readonly and k in readonly_props: # pyright: ignore[reportUnboundVariable] continue - result[k] = Model._as_dict_value(v, exclude_readonly=exclude_readonly) + is_multipart_file = False + try: + is_multipart_file = next( + rf for rf in self._attr_to_rest_field.values() if rf._rest_name == k + )._is_multipart_file + except StopIteration: + pass + result[k] = v if is_multipart_file else Model._as_dict_value(v, exclude_readonly=exclude_readonly) return result @staticmethod @@ -567,7 +580,7 @@ def _as_dict_value(v: typing.Any, exclude_readonly: bool = False) -> typing.Any: if v is None or isinstance(v, _Null): return None if isinstance(v, (list, tuple, set)): - return [Model._as_dict_value(x, exclude_readonly=exclude_readonly) for x in v] + return type(v)(Model._as_dict_value(x, exclude_readonly=exclude_readonly) for x in v) if isinstance(v, dict): return {dk: Model._as_dict_value(dv, exclude_readonly=exclude_readonly) for dk, dv in v.items()} return v.as_dict(exclude_readonly=exclude_readonly) if hasattr(v, "as_dict") else v @@ -762,6 +775,7 @@ def __init__( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, + is_multipart_file: bool = False, ): self._type = type self._rest_name_input = name @@ -771,6 +785,7 @@ def __init__( self._is_model = False self._default = default self._format = format + self._is_multipart_file = is_multipart_file @property def _rest_name(self) -> str: @@ -816,8 +831,11 @@ def rest_field( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, + is_multipart_file: bool = False, ) -> typing.Any: - return _RestField(name=name, type=type, visibility=visibility, default=default, format=format) + return _RestField( + name=name, type=type, visibility=visibility, default=default, format=format, is_multipart_file=is_multipart_file + ) def rest_discriminator( diff --git a/packages/typespec-python/test/azure/generated/typetest-union/typetest/union/aio/operations/_operations.py b/packages/typespec-python/test/azure/generated/typetest-union/typetest/union/aio/operations/_operations.py index db7086a6538..63044cbf846 100644 --- a/packages/typespec-python/test/azure/generated/typetest-union/typetest/union/aio/operations/_operations.py +++ b/packages/typespec-python/test/azure/generated/typetest-union/typetest/union/aio/operations/_operations.py @@ -9,7 +9,7 @@ from io import IOBase import json import sys -from typing import Any, Callable, Dict, IO, Literal, Optional, TYPE_CHECKING, TypeVar, Union, overload +from typing import Any, Callable, Dict, IO, Literal, Optional, TypeVar, Union, overload from azure.core.exceptions import ( ClientAuthenticationError, @@ -53,10 +53,6 @@ from collections.abc import MutableMapping else: from typing import MutableMapping # type: ignore # pylint: disable=ungrouped-imports - -if TYPE_CHECKING: - # pylint: disable=unused-import,ungrouped-imports - from ... import _types JSON = MutableMapping[str, Any] # pylint: disable=unsubscriptable-object _Unset: Any = object() T = TypeVar("T") @@ -524,8 +520,7 @@ async def get(self, **kwargs: Any) -> _models.GetResponse7: # response body for status code(s): 200 response == { - "prop": "str" # Required. Is one of the following types: str, Literal["b"], - Literal["c"] + "prop": "str" # Required. Known values are: "b" and "c". } """ error_map = { @@ -590,19 +585,22 @@ async def send( # pylint: disable=inconsistent-return-statements # JSON input template you can fill out and use as your body input. body = { - "prop": "str" # Required. Is one of the following types: str, Literal["b"], - Literal["c"] + "prop": "str" # Required. Known values are: "b" and "c". } """ @overload async def send( # pylint: disable=inconsistent-return-statements - self, *, prop: "_types.StringExtensibleNamedUnion", content_type: str = "application/json", **kwargs: Any + self, + *, + prop: Union[str, _models.StringExtensibleNamedUnion], + content_type: str = "application/json", + **kwargs: Any ) -> None: """send. - :keyword prop: Is one of the following types: str, Literal["b"], Literal["c"] Required. - :paramtype prop: str or str or str + :keyword prop: Known values are: "b" and "c". Required. + :paramtype prop: str or ~typetest.union.models.StringExtensibleNamedUnion :keyword content_type: Body Parameter content-type. Content type parameter for JSON body. Default value is "application/json". :paramtype content_type: str @@ -632,15 +630,15 @@ async def send( # pylint: disable=inconsistent-return-statements self, body: Union[JSON, IO[bytes]] = _Unset, *, - prop: "_types.StringExtensibleNamedUnion" = _Unset, + prop: Union[str, _models.StringExtensibleNamedUnion] = _Unset, **kwargs: Any ) -> None: """send. :param body: Is either a JSON type or a IO[bytes] type. Required. :type body: JSON or IO[bytes] - :keyword prop: Is one of the following types: str, Literal["b"], Literal["c"] Required. - :paramtype prop: str or str or str + :keyword prop: Known values are: "b" and "c". Required. + :paramtype prop: str or ~typetest.union.models.StringExtensibleNamedUnion :return: None :rtype: None :raises ~azure.core.exceptions.HttpResponseError: @@ -650,8 +648,7 @@ async def send( # pylint: disable=inconsistent-return-statements # JSON input template you can fill out and use as your body input. body = { - "prop": "str" # Required. Is one of the following types: str, Literal["b"], - Literal["c"] + "prop": "str" # Required. Known values are: "b" and "c". } """ error_map = { diff --git a/packages/typespec-python/test/azure/generated/typetest-union/typetest/union/models/__init__.py b/packages/typespec-python/test/azure/generated/typetest-union/typetest/union/models/__init__.py index 0b3e7e5c96c..698551c96ac 100644 --- a/packages/typespec-python/test/azure/generated/typetest-union/typetest/union/models/__init__.py +++ b/packages/typespec-python/test/azure/generated/typetest-union/typetest/union/models/__init__.py @@ -24,6 +24,7 @@ from ._models import StringAndArrayCases from ._enums import LR +from ._enums import StringExtensibleNamedUnion from ._enums import UD from ._patch import __all__ as _patch_all from ._patch import * # pylint: disable=unused-wildcard-import @@ -47,6 +48,7 @@ "MixedTypesCases", "StringAndArrayCases", "LR", + "StringExtensibleNamedUnion", "UD", ] __all__.extend([p for p in _patch_all if p not in __all__]) diff --git a/packages/typespec-python/test/azure/generated/typetest-union/typetest/union/models/_enums.py b/packages/typespec-python/test/azure/generated/typetest-union/typetest/union/models/_enums.py index 88239c12a92..29548823c2a 100644 --- a/packages/typespec-python/test/azure/generated/typetest-union/typetest/union/models/_enums.py +++ b/packages/typespec-python/test/azure/generated/typetest-union/typetest/union/models/_enums.py @@ -17,6 +17,13 @@ class LR(str, Enum, metaclass=CaseInsensitiveEnumMeta): RIGHT = "right" +class StringExtensibleNamedUnion(str, Enum, metaclass=CaseInsensitiveEnumMeta): + """Type of StringExtensibleNamedUnion.""" + + OPTION_B = "b" + C = "c" + + class UD(str, Enum, metaclass=CaseInsensitiveEnumMeta): """Type of UD.""" diff --git a/packages/typespec-python/test/azure/generated/typetest-union/typetest/union/models/_models.py b/packages/typespec-python/test/azure/generated/typetest-union/typetest/union/models/_models.py index e2a3539c463..33153bd7832 100644 --- a/packages/typespec-python/test/azure/generated/typetest-union/typetest/union/models/_models.py +++ b/packages/typespec-python/test/azure/generated/typetest-union/typetest/union/models/_models.py @@ -20,7 +20,7 @@ if TYPE_CHECKING: # pylint: disable=unused-import,ungrouped-imports - from .. import _types, models as _models + from .. import models as _models JSON = MutableMapping[str, Any] # pylint: disable=unsubscriptable-object @@ -348,18 +348,18 @@ class GetResponse7(_model_base.Model): All required parameters must be populated in order to send to server. - :ivar prop: Required. Is one of the following types: str, Literal["b"], Literal["c"] - :vartype prop: str or str or str + :ivar prop: Required. Known values are: "b" and "c". + :vartype prop: str or ~typetest.union.models.StringExtensibleNamedUnion """ - prop: "_types.StringExtensibleNamedUnion" = rest_field() - """Required. Is one of the following types: str, Literal[\"b\"], Literal[\"c\"]""" + prop: Union[str, "_models.StringExtensibleNamedUnion"] = rest_field() + """Required. Known values are: \"b\" and \"c\".""" @overload def __init__( self, *, - prop: "_types.StringExtensibleNamedUnion", + prop: Union[str, "_models.StringExtensibleNamedUnion"], ): ... diff --git a/packages/typespec-python/test/azure/generated/typetest-union/typetest/union/operations/_operations.py b/packages/typespec-python/test/azure/generated/typetest-union/typetest/union/operations/_operations.py index 02f7bf856e5..bb30719b104 100644 --- a/packages/typespec-python/test/azure/generated/typetest-union/typetest/union/operations/_operations.py +++ b/packages/typespec-python/test/azure/generated/typetest-union/typetest/union/operations/_operations.py @@ -9,7 +9,7 @@ from io import IOBase import json import sys -from typing import Any, Callable, Dict, IO, Literal, Optional, TYPE_CHECKING, TypeVar, Union, overload +from typing import Any, Callable, Dict, IO, Literal, Optional, TypeVar, Union, overload from azure.core.exceptions import ( ClientAuthenticationError, @@ -32,10 +32,6 @@ from collections.abc import MutableMapping else: from typing import MutableMapping # type: ignore # pylint: disable=ungrouped-imports - -if TYPE_CHECKING: - # pylint: disable=unused-import,ungrouped-imports - from .. import _types JSON = MutableMapping[str, Any] # pylint: disable=unsubscriptable-object _Unset: Any = object() T = TypeVar("T") @@ -786,8 +782,7 @@ def get(self, **kwargs: Any) -> _models.GetResponse7: # response body for status code(s): 200 response == { - "prop": "str" # Required. Is one of the following types: str, Literal["b"], - Literal["c"] + "prop": "str" # Required. Known values are: "b" and "c". } """ error_map = { @@ -852,19 +847,22 @@ def send( # pylint: disable=inconsistent-return-statements # JSON input template you can fill out and use as your body input. body = { - "prop": "str" # Required. Is one of the following types: str, Literal["b"], - Literal["c"] + "prop": "str" # Required. Known values are: "b" and "c". } """ @overload def send( # pylint: disable=inconsistent-return-statements - self, *, prop: "_types.StringExtensibleNamedUnion", content_type: str = "application/json", **kwargs: Any + self, + *, + prop: Union[str, _models.StringExtensibleNamedUnion], + content_type: str = "application/json", + **kwargs: Any ) -> None: """send. - :keyword prop: Is one of the following types: str, Literal["b"], Literal["c"] Required. - :paramtype prop: str or str or str + :keyword prop: Known values are: "b" and "c". Required. + :paramtype prop: str or ~typetest.union.models.StringExtensibleNamedUnion :keyword content_type: Body Parameter content-type. Content type parameter for JSON body. Default value is "application/json". :paramtype content_type: str @@ -894,15 +892,15 @@ def send( # pylint: disable=inconsistent-return-statements self, body: Union[JSON, IO[bytes]] = _Unset, *, - prop: "_types.StringExtensibleNamedUnion" = _Unset, + prop: Union[str, _models.StringExtensibleNamedUnion] = _Unset, **kwargs: Any ) -> None: """send. :param body: Is either a JSON type or a IO[bytes] type. Required. :type body: JSON or IO[bytes] - :keyword prop: Is one of the following types: str, Literal["b"], Literal["c"] Required. - :paramtype prop: str or str or str + :keyword prop: Known values are: "b" and "c". Required. + :paramtype prop: str or ~typetest.union.models.StringExtensibleNamedUnion :return: None :rtype: None :raises ~azure.core.exceptions.HttpResponseError: @@ -912,8 +910,7 @@ def send( # pylint: disable=inconsistent-return-statements # JSON input template you can fill out and use as your body input. body = { - "prop": "str" # Required. Is one of the following types: str, Literal["b"], - Literal["c"] + "prop": "str" # Required. Known values are: "b" and "c". } """ error_map = { diff --git a/packages/typespec-python/test/unbranded/generated/authentication-api-key/authentication/apikey/_model_base.py b/packages/typespec-python/test/unbranded/generated/authentication-api-key/authentication/apikey/_model_base.py index d322088ee78..18fc4d77a91 100644 --- a/packages/typespec-python/test/unbranded/generated/authentication-api-key/authentication/apikey/_model_base.py +++ b/packages/typespec-python/test/unbranded/generated/authentication-api-key/authentication/apikey/_model_base.py @@ -462,7 +462,13 @@ def _get_rest_field( def _create_value(rf: typing.Optional["_RestField"], value: typing.Any) -> typing.Any: - return _deserialize(rf._type, value) if (rf and rf._is_model) else _serialize(value, rf._format if rf else None) + if not rf: + return _serialize(value, None) + if rf._is_multipart_file: + return value + if rf._is_model: + return _deserialize(rf._type, value) + return _serialize(value, rf._format) class Model(_MyMutableMapping): @@ -559,7 +565,14 @@ def as_dict(self, *, exclude_readonly: bool = False) -> typing.Dict[str, typing. for k, v in self.items(): if exclude_readonly and k in readonly_props: # pyright: ignore[reportUnboundVariable] continue - result[k] = Model._as_dict_value(v, exclude_readonly=exclude_readonly) + is_multipart_file = False + try: + is_multipart_file = next( + rf for rf in self._attr_to_rest_field.values() if rf._rest_name == k + )._is_multipart_file + except StopIteration: + pass + result[k] = v if is_multipart_file else Model._as_dict_value(v, exclude_readonly=exclude_readonly) return result @staticmethod @@ -567,7 +580,7 @@ def _as_dict_value(v: typing.Any, exclude_readonly: bool = False) -> typing.Any: if v is None or isinstance(v, _Null): return None if isinstance(v, (list, tuple, set)): - return [Model._as_dict_value(x, exclude_readonly=exclude_readonly) for x in v] + return type(v)(Model._as_dict_value(x, exclude_readonly=exclude_readonly) for x in v) if isinstance(v, dict): return {dk: Model._as_dict_value(dv, exclude_readonly=exclude_readonly) for dk, dv in v.items()} return v.as_dict(exclude_readonly=exclude_readonly) if hasattr(v, "as_dict") else v @@ -762,6 +775,7 @@ def __init__( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, + is_multipart_file: bool = False, ): self._type = type self._rest_name_input = name @@ -771,6 +785,7 @@ def __init__( self._is_model = False self._default = default self._format = format + self._is_multipart_file = is_multipart_file @property def _rest_name(self) -> str: @@ -816,8 +831,11 @@ def rest_field( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, + is_multipart_file: bool = False, ) -> typing.Any: - return _RestField(name=name, type=type, visibility=visibility, default=default, format=format) + return _RestField( + name=name, type=type, visibility=visibility, default=default, format=format, is_multipart_file=is_multipart_file + ) def rest_discriminator( diff --git a/packages/typespec-python/test/unbranded/generated/authentication-http-custom/authentication/http/custom/_model_base.py b/packages/typespec-python/test/unbranded/generated/authentication-http-custom/authentication/http/custom/_model_base.py index d322088ee78..18fc4d77a91 100644 --- a/packages/typespec-python/test/unbranded/generated/authentication-http-custom/authentication/http/custom/_model_base.py +++ b/packages/typespec-python/test/unbranded/generated/authentication-http-custom/authentication/http/custom/_model_base.py @@ -462,7 +462,13 @@ def _get_rest_field( def _create_value(rf: typing.Optional["_RestField"], value: typing.Any) -> typing.Any: - return _deserialize(rf._type, value) if (rf and rf._is_model) else _serialize(value, rf._format if rf else None) + if not rf: + return _serialize(value, None) + if rf._is_multipart_file: + return value + if rf._is_model: + return _deserialize(rf._type, value) + return _serialize(value, rf._format) class Model(_MyMutableMapping): @@ -559,7 +565,14 @@ def as_dict(self, *, exclude_readonly: bool = False) -> typing.Dict[str, typing. for k, v in self.items(): if exclude_readonly and k in readonly_props: # pyright: ignore[reportUnboundVariable] continue - result[k] = Model._as_dict_value(v, exclude_readonly=exclude_readonly) + is_multipart_file = False + try: + is_multipart_file = next( + rf for rf in self._attr_to_rest_field.values() if rf._rest_name == k + )._is_multipart_file + except StopIteration: + pass + result[k] = v if is_multipart_file else Model._as_dict_value(v, exclude_readonly=exclude_readonly) return result @staticmethod @@ -567,7 +580,7 @@ def _as_dict_value(v: typing.Any, exclude_readonly: bool = False) -> typing.Any: if v is None or isinstance(v, _Null): return None if isinstance(v, (list, tuple, set)): - return [Model._as_dict_value(x, exclude_readonly=exclude_readonly) for x in v] + return type(v)(Model._as_dict_value(x, exclude_readonly=exclude_readonly) for x in v) if isinstance(v, dict): return {dk: Model._as_dict_value(dv, exclude_readonly=exclude_readonly) for dk, dv in v.items()} return v.as_dict(exclude_readonly=exclude_readonly) if hasattr(v, "as_dict") else v @@ -762,6 +775,7 @@ def __init__( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, + is_multipart_file: bool = False, ): self._type = type self._rest_name_input = name @@ -771,6 +785,7 @@ def __init__( self._is_model = False self._default = default self._format = format + self._is_multipart_file = is_multipart_file @property def _rest_name(self) -> str: @@ -816,8 +831,11 @@ def rest_field( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, + is_multipart_file: bool = False, ) -> typing.Any: - return _RestField(name=name, type=type, visibility=visibility, default=default, format=format) + return _RestField( + name=name, type=type, visibility=visibility, default=default, format=format, is_multipart_file=is_multipart_file + ) def rest_discriminator( diff --git a/packages/typespec-python/test/unbranded/generated/authentication-oauth2/authentication/oauth2/_model_base.py b/packages/typespec-python/test/unbranded/generated/authentication-oauth2/authentication/oauth2/_model_base.py index d322088ee78..18fc4d77a91 100644 --- a/packages/typespec-python/test/unbranded/generated/authentication-oauth2/authentication/oauth2/_model_base.py +++ b/packages/typespec-python/test/unbranded/generated/authentication-oauth2/authentication/oauth2/_model_base.py @@ -462,7 +462,13 @@ def _get_rest_field( def _create_value(rf: typing.Optional["_RestField"], value: typing.Any) -> typing.Any: - return _deserialize(rf._type, value) if (rf and rf._is_model) else _serialize(value, rf._format if rf else None) + if not rf: + return _serialize(value, None) + if rf._is_multipart_file: + return value + if rf._is_model: + return _deserialize(rf._type, value) + return _serialize(value, rf._format) class Model(_MyMutableMapping): @@ -559,7 +565,14 @@ def as_dict(self, *, exclude_readonly: bool = False) -> typing.Dict[str, typing. for k, v in self.items(): if exclude_readonly and k in readonly_props: # pyright: ignore[reportUnboundVariable] continue - result[k] = Model._as_dict_value(v, exclude_readonly=exclude_readonly) + is_multipart_file = False + try: + is_multipart_file = next( + rf for rf in self._attr_to_rest_field.values() if rf._rest_name == k + )._is_multipart_file + except StopIteration: + pass + result[k] = v if is_multipart_file else Model._as_dict_value(v, exclude_readonly=exclude_readonly) return result @staticmethod @@ -567,7 +580,7 @@ def _as_dict_value(v: typing.Any, exclude_readonly: bool = False) -> typing.Any: if v is None or isinstance(v, _Null): return None if isinstance(v, (list, tuple, set)): - return [Model._as_dict_value(x, exclude_readonly=exclude_readonly) for x in v] + return type(v)(Model._as_dict_value(x, exclude_readonly=exclude_readonly) for x in v) if isinstance(v, dict): return {dk: Model._as_dict_value(dv, exclude_readonly=exclude_readonly) for dk, dv in v.items()} return v.as_dict(exclude_readonly=exclude_readonly) if hasattr(v, "as_dict") else v @@ -762,6 +775,7 @@ def __init__( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, + is_multipart_file: bool = False, ): self._type = type self._rest_name_input = name @@ -771,6 +785,7 @@ def __init__( self._is_model = False self._default = default self._format = format + self._is_multipart_file = is_multipart_file @property def _rest_name(self) -> str: @@ -816,8 +831,11 @@ def rest_field( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, + is_multipart_file: bool = False, ) -> typing.Any: - return _RestField(name=name, type=type, visibility=visibility, default=default, format=format) + return _RestField( + name=name, type=type, visibility=visibility, default=default, format=format, is_multipart_file=is_multipart_file + ) def rest_discriminator( diff --git a/packages/typespec-python/test/unbranded/generated/authentication-union/authentication/union/_model_base.py b/packages/typespec-python/test/unbranded/generated/authentication-union/authentication/union/_model_base.py index d322088ee78..18fc4d77a91 100644 --- a/packages/typespec-python/test/unbranded/generated/authentication-union/authentication/union/_model_base.py +++ b/packages/typespec-python/test/unbranded/generated/authentication-union/authentication/union/_model_base.py @@ -462,7 +462,13 @@ def _get_rest_field( def _create_value(rf: typing.Optional["_RestField"], value: typing.Any) -> typing.Any: - return _deserialize(rf._type, value) if (rf and rf._is_model) else _serialize(value, rf._format if rf else None) + if not rf: + return _serialize(value, None) + if rf._is_multipart_file: + return value + if rf._is_model: + return _deserialize(rf._type, value) + return _serialize(value, rf._format) class Model(_MyMutableMapping): @@ -559,7 +565,14 @@ def as_dict(self, *, exclude_readonly: bool = False) -> typing.Dict[str, typing. for k, v in self.items(): if exclude_readonly and k in readonly_props: # pyright: ignore[reportUnboundVariable] continue - result[k] = Model._as_dict_value(v, exclude_readonly=exclude_readonly) + is_multipart_file = False + try: + is_multipart_file = next( + rf for rf in self._attr_to_rest_field.values() if rf._rest_name == k + )._is_multipart_file + except StopIteration: + pass + result[k] = v if is_multipart_file else Model._as_dict_value(v, exclude_readonly=exclude_readonly) return result @staticmethod @@ -567,7 +580,7 @@ def _as_dict_value(v: typing.Any, exclude_readonly: bool = False) -> typing.Any: if v is None or isinstance(v, _Null): return None if isinstance(v, (list, tuple, set)): - return [Model._as_dict_value(x, exclude_readonly=exclude_readonly) for x in v] + return type(v)(Model._as_dict_value(x, exclude_readonly=exclude_readonly) for x in v) if isinstance(v, dict): return {dk: Model._as_dict_value(dv, exclude_readonly=exclude_readonly) for dk, dv in v.items()} return v.as_dict(exclude_readonly=exclude_readonly) if hasattr(v, "as_dict") else v @@ -762,6 +775,7 @@ def __init__( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, + is_multipart_file: bool = False, ): self._type = type self._rest_name_input = name @@ -771,6 +785,7 @@ def __init__( self._is_model = False self._default = default self._format = format + self._is_multipart_file = is_multipart_file @property def _rest_name(self) -> str: @@ -816,8 +831,11 @@ def rest_field( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, + is_multipart_file: bool = False, ) -> typing.Any: - return _RestField(name=name, type=type, visibility=visibility, default=default, format=format) + return _RestField( + name=name, type=type, visibility=visibility, default=default, format=format, is_multipart_file=is_multipart_file + ) def rest_discriminator( diff --git a/packages/typespec-python/test/unbranded/generated/client-structure-default/client/structure/service/_model_base.py b/packages/typespec-python/test/unbranded/generated/client-structure-default/client/structure/service/_model_base.py index d322088ee78..18fc4d77a91 100644 --- a/packages/typespec-python/test/unbranded/generated/client-structure-default/client/structure/service/_model_base.py +++ b/packages/typespec-python/test/unbranded/generated/client-structure-default/client/structure/service/_model_base.py @@ -462,7 +462,13 @@ def _get_rest_field( def _create_value(rf: typing.Optional["_RestField"], value: typing.Any) -> typing.Any: - return _deserialize(rf._type, value) if (rf and rf._is_model) else _serialize(value, rf._format if rf else None) + if not rf: + return _serialize(value, None) + if rf._is_multipart_file: + return value + if rf._is_model: + return _deserialize(rf._type, value) + return _serialize(value, rf._format) class Model(_MyMutableMapping): @@ -559,7 +565,14 @@ def as_dict(self, *, exclude_readonly: bool = False) -> typing.Dict[str, typing. for k, v in self.items(): if exclude_readonly and k in readonly_props: # pyright: ignore[reportUnboundVariable] continue - result[k] = Model._as_dict_value(v, exclude_readonly=exclude_readonly) + is_multipart_file = False + try: + is_multipart_file = next( + rf for rf in self._attr_to_rest_field.values() if rf._rest_name == k + )._is_multipart_file + except StopIteration: + pass + result[k] = v if is_multipart_file else Model._as_dict_value(v, exclude_readonly=exclude_readonly) return result @staticmethod @@ -567,7 +580,7 @@ def _as_dict_value(v: typing.Any, exclude_readonly: bool = False) -> typing.Any: if v is None or isinstance(v, _Null): return None if isinstance(v, (list, tuple, set)): - return [Model._as_dict_value(x, exclude_readonly=exclude_readonly) for x in v] + return type(v)(Model._as_dict_value(x, exclude_readonly=exclude_readonly) for x in v) if isinstance(v, dict): return {dk: Model._as_dict_value(dv, exclude_readonly=exclude_readonly) for dk, dv in v.items()} return v.as_dict(exclude_readonly=exclude_readonly) if hasattr(v, "as_dict") else v @@ -762,6 +775,7 @@ def __init__( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, + is_multipart_file: bool = False, ): self._type = type self._rest_name_input = name @@ -771,6 +785,7 @@ def __init__( self._is_model = False self._default = default self._format = format + self._is_multipart_file = is_multipart_file @property def _rest_name(self) -> str: @@ -816,8 +831,11 @@ def rest_field( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, + is_multipart_file: bool = False, ) -> typing.Any: - return _RestField(name=name, type=type, visibility=visibility, default=default, format=format) + return _RestField( + name=name, type=type, visibility=visibility, default=default, format=format, is_multipart_file=is_multipart_file + ) def rest_discriminator( diff --git a/packages/typespec-python/test/unbranded/generated/client-structure-multiclient/client/structure/multiclient/_model_base.py b/packages/typespec-python/test/unbranded/generated/client-structure-multiclient/client/structure/multiclient/_model_base.py index d322088ee78..18fc4d77a91 100644 --- a/packages/typespec-python/test/unbranded/generated/client-structure-multiclient/client/structure/multiclient/_model_base.py +++ b/packages/typespec-python/test/unbranded/generated/client-structure-multiclient/client/structure/multiclient/_model_base.py @@ -462,7 +462,13 @@ def _get_rest_field( def _create_value(rf: typing.Optional["_RestField"], value: typing.Any) -> typing.Any: - return _deserialize(rf._type, value) if (rf and rf._is_model) else _serialize(value, rf._format if rf else None) + if not rf: + return _serialize(value, None) + if rf._is_multipart_file: + return value + if rf._is_model: + return _deserialize(rf._type, value) + return _serialize(value, rf._format) class Model(_MyMutableMapping): @@ -559,7 +565,14 @@ def as_dict(self, *, exclude_readonly: bool = False) -> typing.Dict[str, typing. for k, v in self.items(): if exclude_readonly and k in readonly_props: # pyright: ignore[reportUnboundVariable] continue - result[k] = Model._as_dict_value(v, exclude_readonly=exclude_readonly) + is_multipart_file = False + try: + is_multipart_file = next( + rf for rf in self._attr_to_rest_field.values() if rf._rest_name == k + )._is_multipart_file + except StopIteration: + pass + result[k] = v if is_multipart_file else Model._as_dict_value(v, exclude_readonly=exclude_readonly) return result @staticmethod @@ -567,7 +580,7 @@ def _as_dict_value(v: typing.Any, exclude_readonly: bool = False) -> typing.Any: if v is None or isinstance(v, _Null): return None if isinstance(v, (list, tuple, set)): - return [Model._as_dict_value(x, exclude_readonly=exclude_readonly) for x in v] + return type(v)(Model._as_dict_value(x, exclude_readonly=exclude_readonly) for x in v) if isinstance(v, dict): return {dk: Model._as_dict_value(dv, exclude_readonly=exclude_readonly) for dk, dv in v.items()} return v.as_dict(exclude_readonly=exclude_readonly) if hasattr(v, "as_dict") else v @@ -762,6 +775,7 @@ def __init__( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, + is_multipart_file: bool = False, ): self._type = type self._rest_name_input = name @@ -771,6 +785,7 @@ def __init__( self._is_model = False self._default = default self._format = format + self._is_multipart_file = is_multipart_file @property def _rest_name(self) -> str: @@ -816,8 +831,11 @@ def rest_field( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, + is_multipart_file: bool = False, ) -> typing.Any: - return _RestField(name=name, type=type, visibility=visibility, default=default, format=format) + return _RestField( + name=name, type=type, visibility=visibility, default=default, format=format, is_multipart_file=is_multipart_file + ) def rest_discriminator( diff --git a/packages/typespec-python/test/unbranded/generated/client-structure-renamedoperation/client/structure/renamedoperation/_model_base.py b/packages/typespec-python/test/unbranded/generated/client-structure-renamedoperation/client/structure/renamedoperation/_model_base.py index d322088ee78..18fc4d77a91 100644 --- a/packages/typespec-python/test/unbranded/generated/client-structure-renamedoperation/client/structure/renamedoperation/_model_base.py +++ b/packages/typespec-python/test/unbranded/generated/client-structure-renamedoperation/client/structure/renamedoperation/_model_base.py @@ -462,7 +462,13 @@ def _get_rest_field( def _create_value(rf: typing.Optional["_RestField"], value: typing.Any) -> typing.Any: - return _deserialize(rf._type, value) if (rf and rf._is_model) else _serialize(value, rf._format if rf else None) + if not rf: + return _serialize(value, None) + if rf._is_multipart_file: + return value + if rf._is_model: + return _deserialize(rf._type, value) + return _serialize(value, rf._format) class Model(_MyMutableMapping): @@ -559,7 +565,14 @@ def as_dict(self, *, exclude_readonly: bool = False) -> typing.Dict[str, typing. for k, v in self.items(): if exclude_readonly and k in readonly_props: # pyright: ignore[reportUnboundVariable] continue - result[k] = Model._as_dict_value(v, exclude_readonly=exclude_readonly) + is_multipart_file = False + try: + is_multipart_file = next( + rf for rf in self._attr_to_rest_field.values() if rf._rest_name == k + )._is_multipart_file + except StopIteration: + pass + result[k] = v if is_multipart_file else Model._as_dict_value(v, exclude_readonly=exclude_readonly) return result @staticmethod @@ -567,7 +580,7 @@ def _as_dict_value(v: typing.Any, exclude_readonly: bool = False) -> typing.Any: if v is None or isinstance(v, _Null): return None if isinstance(v, (list, tuple, set)): - return [Model._as_dict_value(x, exclude_readonly=exclude_readonly) for x in v] + return type(v)(Model._as_dict_value(x, exclude_readonly=exclude_readonly) for x in v) if isinstance(v, dict): return {dk: Model._as_dict_value(dv, exclude_readonly=exclude_readonly) for dk, dv in v.items()} return v.as_dict(exclude_readonly=exclude_readonly) if hasattr(v, "as_dict") else v @@ -762,6 +775,7 @@ def __init__( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, + is_multipart_file: bool = False, ): self._type = type self._rest_name_input = name @@ -771,6 +785,7 @@ def __init__( self._is_model = False self._default = default self._format = format + self._is_multipart_file = is_multipart_file @property def _rest_name(self) -> str: @@ -816,8 +831,11 @@ def rest_field( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, + is_multipart_file: bool = False, ) -> typing.Any: - return _RestField(name=name, type=type, visibility=visibility, default=default, format=format) + return _RestField( + name=name, type=type, visibility=visibility, default=default, format=format, is_multipart_file=is_multipart_file + ) def rest_discriminator( diff --git a/packages/typespec-python/test/unbranded/generated/client-structure-twooperationgroup/client/structure/twooperationgroup/_model_base.py b/packages/typespec-python/test/unbranded/generated/client-structure-twooperationgroup/client/structure/twooperationgroup/_model_base.py index d322088ee78..18fc4d77a91 100644 --- a/packages/typespec-python/test/unbranded/generated/client-structure-twooperationgroup/client/structure/twooperationgroup/_model_base.py +++ b/packages/typespec-python/test/unbranded/generated/client-structure-twooperationgroup/client/structure/twooperationgroup/_model_base.py @@ -462,7 +462,13 @@ def _get_rest_field( def _create_value(rf: typing.Optional["_RestField"], value: typing.Any) -> typing.Any: - return _deserialize(rf._type, value) if (rf and rf._is_model) else _serialize(value, rf._format if rf else None) + if not rf: + return _serialize(value, None) + if rf._is_multipart_file: + return value + if rf._is_model: + return _deserialize(rf._type, value) + return _serialize(value, rf._format) class Model(_MyMutableMapping): @@ -559,7 +565,14 @@ def as_dict(self, *, exclude_readonly: bool = False) -> typing.Dict[str, typing. for k, v in self.items(): if exclude_readonly and k in readonly_props: # pyright: ignore[reportUnboundVariable] continue - result[k] = Model._as_dict_value(v, exclude_readonly=exclude_readonly) + is_multipart_file = False + try: + is_multipart_file = next( + rf for rf in self._attr_to_rest_field.values() if rf._rest_name == k + )._is_multipart_file + except StopIteration: + pass + result[k] = v if is_multipart_file else Model._as_dict_value(v, exclude_readonly=exclude_readonly) return result @staticmethod @@ -567,7 +580,7 @@ def _as_dict_value(v: typing.Any, exclude_readonly: bool = False) -> typing.Any: if v is None or isinstance(v, _Null): return None if isinstance(v, (list, tuple, set)): - return [Model._as_dict_value(x, exclude_readonly=exclude_readonly) for x in v] + return type(v)(Model._as_dict_value(x, exclude_readonly=exclude_readonly) for x in v) if isinstance(v, dict): return {dk: Model._as_dict_value(dv, exclude_readonly=exclude_readonly) for dk, dv in v.items()} return v.as_dict(exclude_readonly=exclude_readonly) if hasattr(v, "as_dict") else v @@ -762,6 +775,7 @@ def __init__( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, + is_multipart_file: bool = False, ): self._type = type self._rest_name_input = name @@ -771,6 +785,7 @@ def __init__( self._is_model = False self._default = default self._format = format + self._is_multipart_file = is_multipart_file @property def _rest_name(self) -> str: @@ -816,8 +831,11 @@ def rest_field( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, + is_multipart_file: bool = False, ) -> typing.Any: - return _RestField(name=name, type=type, visibility=visibility, default=default, format=format) + return _RestField( + name=name, type=type, visibility=visibility, default=default, format=format, is_multipart_file=is_multipart_file + ) def rest_discriminator( diff --git a/packages/typespec-python/test/unbranded/generated/encode-bytes/encode/bytes/_model_base.py b/packages/typespec-python/test/unbranded/generated/encode-bytes/encode/bytes/_model_base.py index d322088ee78..18fc4d77a91 100644 --- a/packages/typespec-python/test/unbranded/generated/encode-bytes/encode/bytes/_model_base.py +++ b/packages/typespec-python/test/unbranded/generated/encode-bytes/encode/bytes/_model_base.py @@ -462,7 +462,13 @@ def _get_rest_field( def _create_value(rf: typing.Optional["_RestField"], value: typing.Any) -> typing.Any: - return _deserialize(rf._type, value) if (rf and rf._is_model) else _serialize(value, rf._format if rf else None) + if not rf: + return _serialize(value, None) + if rf._is_multipart_file: + return value + if rf._is_model: + return _deserialize(rf._type, value) + return _serialize(value, rf._format) class Model(_MyMutableMapping): @@ -559,7 +565,14 @@ def as_dict(self, *, exclude_readonly: bool = False) -> typing.Dict[str, typing. for k, v in self.items(): if exclude_readonly and k in readonly_props: # pyright: ignore[reportUnboundVariable] continue - result[k] = Model._as_dict_value(v, exclude_readonly=exclude_readonly) + is_multipart_file = False + try: + is_multipart_file = next( + rf for rf in self._attr_to_rest_field.values() if rf._rest_name == k + )._is_multipart_file + except StopIteration: + pass + result[k] = v if is_multipart_file else Model._as_dict_value(v, exclude_readonly=exclude_readonly) return result @staticmethod @@ -567,7 +580,7 @@ def _as_dict_value(v: typing.Any, exclude_readonly: bool = False) -> typing.Any: if v is None or isinstance(v, _Null): return None if isinstance(v, (list, tuple, set)): - return [Model._as_dict_value(x, exclude_readonly=exclude_readonly) for x in v] + return type(v)(Model._as_dict_value(x, exclude_readonly=exclude_readonly) for x in v) if isinstance(v, dict): return {dk: Model._as_dict_value(dv, exclude_readonly=exclude_readonly) for dk, dv in v.items()} return v.as_dict(exclude_readonly=exclude_readonly) if hasattr(v, "as_dict") else v @@ -762,6 +775,7 @@ def __init__( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, + is_multipart_file: bool = False, ): self._type = type self._rest_name_input = name @@ -771,6 +785,7 @@ def __init__( self._is_model = False self._default = default self._format = format + self._is_multipart_file = is_multipart_file @property def _rest_name(self) -> str: @@ -816,8 +831,11 @@ def rest_field( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, + is_multipart_file: bool = False, ) -> typing.Any: - return _RestField(name=name, type=type, visibility=visibility, default=default, format=format) + return _RestField( + name=name, type=type, visibility=visibility, default=default, format=format, is_multipart_file=is_multipart_file + ) def rest_discriminator( diff --git a/packages/typespec-python/test/unbranded/generated/encode-datetime/encode/datetime/_model_base.py b/packages/typespec-python/test/unbranded/generated/encode-datetime/encode/datetime/_model_base.py index d322088ee78..18fc4d77a91 100644 --- a/packages/typespec-python/test/unbranded/generated/encode-datetime/encode/datetime/_model_base.py +++ b/packages/typespec-python/test/unbranded/generated/encode-datetime/encode/datetime/_model_base.py @@ -462,7 +462,13 @@ def _get_rest_field( def _create_value(rf: typing.Optional["_RestField"], value: typing.Any) -> typing.Any: - return _deserialize(rf._type, value) if (rf and rf._is_model) else _serialize(value, rf._format if rf else None) + if not rf: + return _serialize(value, None) + if rf._is_multipart_file: + return value + if rf._is_model: + return _deserialize(rf._type, value) + return _serialize(value, rf._format) class Model(_MyMutableMapping): @@ -559,7 +565,14 @@ def as_dict(self, *, exclude_readonly: bool = False) -> typing.Dict[str, typing. for k, v in self.items(): if exclude_readonly and k in readonly_props: # pyright: ignore[reportUnboundVariable] continue - result[k] = Model._as_dict_value(v, exclude_readonly=exclude_readonly) + is_multipart_file = False + try: + is_multipart_file = next( + rf for rf in self._attr_to_rest_field.values() if rf._rest_name == k + )._is_multipart_file + except StopIteration: + pass + result[k] = v if is_multipart_file else Model._as_dict_value(v, exclude_readonly=exclude_readonly) return result @staticmethod @@ -567,7 +580,7 @@ def _as_dict_value(v: typing.Any, exclude_readonly: bool = False) -> typing.Any: if v is None or isinstance(v, _Null): return None if isinstance(v, (list, tuple, set)): - return [Model._as_dict_value(x, exclude_readonly=exclude_readonly) for x in v] + return type(v)(Model._as_dict_value(x, exclude_readonly=exclude_readonly) for x in v) if isinstance(v, dict): return {dk: Model._as_dict_value(dv, exclude_readonly=exclude_readonly) for dk, dv in v.items()} return v.as_dict(exclude_readonly=exclude_readonly) if hasattr(v, "as_dict") else v @@ -762,6 +775,7 @@ def __init__( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, + is_multipart_file: bool = False, ): self._type = type self._rest_name_input = name @@ -771,6 +785,7 @@ def __init__( self._is_model = False self._default = default self._format = format + self._is_multipart_file = is_multipart_file @property def _rest_name(self) -> str: @@ -816,8 +831,11 @@ def rest_field( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, + is_multipart_file: bool = False, ) -> typing.Any: - return _RestField(name=name, type=type, visibility=visibility, default=default, format=format) + return _RestField( + name=name, type=type, visibility=visibility, default=default, format=format, is_multipart_file=is_multipart_file + ) def rest_discriminator( diff --git a/packages/typespec-python/test/unbranded/generated/encode-duration/encode/duration/_model_base.py b/packages/typespec-python/test/unbranded/generated/encode-duration/encode/duration/_model_base.py index d322088ee78..18fc4d77a91 100644 --- a/packages/typespec-python/test/unbranded/generated/encode-duration/encode/duration/_model_base.py +++ b/packages/typespec-python/test/unbranded/generated/encode-duration/encode/duration/_model_base.py @@ -462,7 +462,13 @@ def _get_rest_field( def _create_value(rf: typing.Optional["_RestField"], value: typing.Any) -> typing.Any: - return _deserialize(rf._type, value) if (rf and rf._is_model) else _serialize(value, rf._format if rf else None) + if not rf: + return _serialize(value, None) + if rf._is_multipart_file: + return value + if rf._is_model: + return _deserialize(rf._type, value) + return _serialize(value, rf._format) class Model(_MyMutableMapping): @@ -559,7 +565,14 @@ def as_dict(self, *, exclude_readonly: bool = False) -> typing.Dict[str, typing. for k, v in self.items(): if exclude_readonly and k in readonly_props: # pyright: ignore[reportUnboundVariable] continue - result[k] = Model._as_dict_value(v, exclude_readonly=exclude_readonly) + is_multipart_file = False + try: + is_multipart_file = next( + rf for rf in self._attr_to_rest_field.values() if rf._rest_name == k + )._is_multipart_file + except StopIteration: + pass + result[k] = v if is_multipart_file else Model._as_dict_value(v, exclude_readonly=exclude_readonly) return result @staticmethod @@ -567,7 +580,7 @@ def _as_dict_value(v: typing.Any, exclude_readonly: bool = False) -> typing.Any: if v is None or isinstance(v, _Null): return None if isinstance(v, (list, tuple, set)): - return [Model._as_dict_value(x, exclude_readonly=exclude_readonly) for x in v] + return type(v)(Model._as_dict_value(x, exclude_readonly=exclude_readonly) for x in v) if isinstance(v, dict): return {dk: Model._as_dict_value(dv, exclude_readonly=exclude_readonly) for dk, dv in v.items()} return v.as_dict(exclude_readonly=exclude_readonly) if hasattr(v, "as_dict") else v @@ -762,6 +775,7 @@ def __init__( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, + is_multipart_file: bool = False, ): self._type = type self._rest_name_input = name @@ -771,6 +785,7 @@ def __init__( self._is_model = False self._default = default self._format = format + self._is_multipart_file = is_multipart_file @property def _rest_name(self) -> str: @@ -816,8 +831,11 @@ def rest_field( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, + is_multipart_file: bool = False, ) -> typing.Any: - return _RestField(name=name, type=type, visibility=visibility, default=default, format=format) + return _RestField( + name=name, type=type, visibility=visibility, default=default, format=format, is_multipart_file=is_multipart_file + ) def rest_discriminator( diff --git a/packages/typespec-python/test/unbranded/generated/headasbooleanfalse/headasbooleanfalse/_model_base.py b/packages/typespec-python/test/unbranded/generated/headasbooleanfalse/headasbooleanfalse/_model_base.py index d322088ee78..18fc4d77a91 100644 --- a/packages/typespec-python/test/unbranded/generated/headasbooleanfalse/headasbooleanfalse/_model_base.py +++ b/packages/typespec-python/test/unbranded/generated/headasbooleanfalse/headasbooleanfalse/_model_base.py @@ -462,7 +462,13 @@ def _get_rest_field( def _create_value(rf: typing.Optional["_RestField"], value: typing.Any) -> typing.Any: - return _deserialize(rf._type, value) if (rf and rf._is_model) else _serialize(value, rf._format if rf else None) + if not rf: + return _serialize(value, None) + if rf._is_multipart_file: + return value + if rf._is_model: + return _deserialize(rf._type, value) + return _serialize(value, rf._format) class Model(_MyMutableMapping): @@ -559,7 +565,14 @@ def as_dict(self, *, exclude_readonly: bool = False) -> typing.Dict[str, typing. for k, v in self.items(): if exclude_readonly and k in readonly_props: # pyright: ignore[reportUnboundVariable] continue - result[k] = Model._as_dict_value(v, exclude_readonly=exclude_readonly) + is_multipart_file = False + try: + is_multipart_file = next( + rf for rf in self._attr_to_rest_field.values() if rf._rest_name == k + )._is_multipart_file + except StopIteration: + pass + result[k] = v if is_multipart_file else Model._as_dict_value(v, exclude_readonly=exclude_readonly) return result @staticmethod @@ -567,7 +580,7 @@ def _as_dict_value(v: typing.Any, exclude_readonly: bool = False) -> typing.Any: if v is None or isinstance(v, _Null): return None if isinstance(v, (list, tuple, set)): - return [Model._as_dict_value(x, exclude_readonly=exclude_readonly) for x in v] + return type(v)(Model._as_dict_value(x, exclude_readonly=exclude_readonly) for x in v) if isinstance(v, dict): return {dk: Model._as_dict_value(dv, exclude_readonly=exclude_readonly) for dk, dv in v.items()} return v.as_dict(exclude_readonly=exclude_readonly) if hasattr(v, "as_dict") else v @@ -762,6 +775,7 @@ def __init__( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, + is_multipart_file: bool = False, ): self._type = type self._rest_name_input = name @@ -771,6 +785,7 @@ def __init__( self._is_model = False self._default = default self._format = format + self._is_multipart_file = is_multipart_file @property def _rest_name(self) -> str: @@ -816,8 +831,11 @@ def rest_field( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, + is_multipart_file: bool = False, ) -> typing.Any: - return _RestField(name=name, type=type, visibility=visibility, default=default, format=format) + return _RestField( + name=name, type=type, visibility=visibility, default=default, format=format, is_multipart_file=is_multipart_file + ) def rest_discriminator( diff --git a/packages/typespec-python/test/unbranded/generated/headasbooleantrue/headasbooleantrue/_model_base.py b/packages/typespec-python/test/unbranded/generated/headasbooleantrue/headasbooleantrue/_model_base.py index d322088ee78..18fc4d77a91 100644 --- a/packages/typespec-python/test/unbranded/generated/headasbooleantrue/headasbooleantrue/_model_base.py +++ b/packages/typespec-python/test/unbranded/generated/headasbooleantrue/headasbooleantrue/_model_base.py @@ -462,7 +462,13 @@ def _get_rest_field( def _create_value(rf: typing.Optional["_RestField"], value: typing.Any) -> typing.Any: - return _deserialize(rf._type, value) if (rf and rf._is_model) else _serialize(value, rf._format if rf else None) + if not rf: + return _serialize(value, None) + if rf._is_multipart_file: + return value + if rf._is_model: + return _deserialize(rf._type, value) + return _serialize(value, rf._format) class Model(_MyMutableMapping): @@ -559,7 +565,14 @@ def as_dict(self, *, exclude_readonly: bool = False) -> typing.Dict[str, typing. for k, v in self.items(): if exclude_readonly and k in readonly_props: # pyright: ignore[reportUnboundVariable] continue - result[k] = Model._as_dict_value(v, exclude_readonly=exclude_readonly) + is_multipart_file = False + try: + is_multipart_file = next( + rf for rf in self._attr_to_rest_field.values() if rf._rest_name == k + )._is_multipart_file + except StopIteration: + pass + result[k] = v if is_multipart_file else Model._as_dict_value(v, exclude_readonly=exclude_readonly) return result @staticmethod @@ -567,7 +580,7 @@ def _as_dict_value(v: typing.Any, exclude_readonly: bool = False) -> typing.Any: if v is None or isinstance(v, _Null): return None if isinstance(v, (list, tuple, set)): - return [Model._as_dict_value(x, exclude_readonly=exclude_readonly) for x in v] + return type(v)(Model._as_dict_value(x, exclude_readonly=exclude_readonly) for x in v) if isinstance(v, dict): return {dk: Model._as_dict_value(dv, exclude_readonly=exclude_readonly) for dk, dv in v.items()} return v.as_dict(exclude_readonly=exclude_readonly) if hasattr(v, "as_dict") else v @@ -762,6 +775,7 @@ def __init__( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, + is_multipart_file: bool = False, ): self._type = type self._rest_name_input = name @@ -771,6 +785,7 @@ def __init__( self._is_model = False self._default = default self._format = format + self._is_multipart_file = is_multipart_file @property def _rest_name(self) -> str: @@ -816,8 +831,11 @@ def rest_field( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, + is_multipart_file: bool = False, ) -> typing.Any: - return _RestField(name=name, type=type, visibility=visibility, default=default, format=format) + return _RestField( + name=name, type=type, visibility=visibility, default=default, format=format, is_multipart_file=is_multipart_file + ) def rest_discriminator( diff --git a/packages/typespec-python/test/unbranded/generated/parameters-body-optionality/parameters/bodyoptionality/_model_base.py b/packages/typespec-python/test/unbranded/generated/parameters-body-optionality/parameters/bodyoptionality/_model_base.py index d322088ee78..18fc4d77a91 100644 --- a/packages/typespec-python/test/unbranded/generated/parameters-body-optionality/parameters/bodyoptionality/_model_base.py +++ b/packages/typespec-python/test/unbranded/generated/parameters-body-optionality/parameters/bodyoptionality/_model_base.py @@ -462,7 +462,13 @@ def _get_rest_field( def _create_value(rf: typing.Optional["_RestField"], value: typing.Any) -> typing.Any: - return _deserialize(rf._type, value) if (rf and rf._is_model) else _serialize(value, rf._format if rf else None) + if not rf: + return _serialize(value, None) + if rf._is_multipart_file: + return value + if rf._is_model: + return _deserialize(rf._type, value) + return _serialize(value, rf._format) class Model(_MyMutableMapping): @@ -559,7 +565,14 @@ def as_dict(self, *, exclude_readonly: bool = False) -> typing.Dict[str, typing. for k, v in self.items(): if exclude_readonly and k in readonly_props: # pyright: ignore[reportUnboundVariable] continue - result[k] = Model._as_dict_value(v, exclude_readonly=exclude_readonly) + is_multipart_file = False + try: + is_multipart_file = next( + rf for rf in self._attr_to_rest_field.values() if rf._rest_name == k + )._is_multipart_file + except StopIteration: + pass + result[k] = v if is_multipart_file else Model._as_dict_value(v, exclude_readonly=exclude_readonly) return result @staticmethod @@ -567,7 +580,7 @@ def _as_dict_value(v: typing.Any, exclude_readonly: bool = False) -> typing.Any: if v is None or isinstance(v, _Null): return None if isinstance(v, (list, tuple, set)): - return [Model._as_dict_value(x, exclude_readonly=exclude_readonly) for x in v] + return type(v)(Model._as_dict_value(x, exclude_readonly=exclude_readonly) for x in v) if isinstance(v, dict): return {dk: Model._as_dict_value(dv, exclude_readonly=exclude_readonly) for dk, dv in v.items()} return v.as_dict(exclude_readonly=exclude_readonly) if hasattr(v, "as_dict") else v @@ -762,6 +775,7 @@ def __init__( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, + is_multipart_file: bool = False, ): self._type = type self._rest_name_input = name @@ -771,6 +785,7 @@ def __init__( self._is_model = False self._default = default self._format = format + self._is_multipart_file = is_multipart_file @property def _rest_name(self) -> str: @@ -816,8 +831,11 @@ def rest_field( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, + is_multipart_file: bool = False, ) -> typing.Any: - return _RestField(name=name, type=type, visibility=visibility, default=default, format=format) + return _RestField( + name=name, type=type, visibility=visibility, default=default, format=format, is_multipart_file=is_multipart_file + ) def rest_discriminator( diff --git a/packages/typespec-python/test/unbranded/generated/parameters-collection-format/parameters/collectionformat/_model_base.py b/packages/typespec-python/test/unbranded/generated/parameters-collection-format/parameters/collectionformat/_model_base.py index d322088ee78..18fc4d77a91 100644 --- a/packages/typespec-python/test/unbranded/generated/parameters-collection-format/parameters/collectionformat/_model_base.py +++ b/packages/typespec-python/test/unbranded/generated/parameters-collection-format/parameters/collectionformat/_model_base.py @@ -462,7 +462,13 @@ def _get_rest_field( def _create_value(rf: typing.Optional["_RestField"], value: typing.Any) -> typing.Any: - return _deserialize(rf._type, value) if (rf and rf._is_model) else _serialize(value, rf._format if rf else None) + if not rf: + return _serialize(value, None) + if rf._is_multipart_file: + return value + if rf._is_model: + return _deserialize(rf._type, value) + return _serialize(value, rf._format) class Model(_MyMutableMapping): @@ -559,7 +565,14 @@ def as_dict(self, *, exclude_readonly: bool = False) -> typing.Dict[str, typing. for k, v in self.items(): if exclude_readonly and k in readonly_props: # pyright: ignore[reportUnboundVariable] continue - result[k] = Model._as_dict_value(v, exclude_readonly=exclude_readonly) + is_multipart_file = False + try: + is_multipart_file = next( + rf for rf in self._attr_to_rest_field.values() if rf._rest_name == k + )._is_multipart_file + except StopIteration: + pass + result[k] = v if is_multipart_file else Model._as_dict_value(v, exclude_readonly=exclude_readonly) return result @staticmethod @@ -567,7 +580,7 @@ def _as_dict_value(v: typing.Any, exclude_readonly: bool = False) -> typing.Any: if v is None or isinstance(v, _Null): return None if isinstance(v, (list, tuple, set)): - return [Model._as_dict_value(x, exclude_readonly=exclude_readonly) for x in v] + return type(v)(Model._as_dict_value(x, exclude_readonly=exclude_readonly) for x in v) if isinstance(v, dict): return {dk: Model._as_dict_value(dv, exclude_readonly=exclude_readonly) for dk, dv in v.items()} return v.as_dict(exclude_readonly=exclude_readonly) if hasattr(v, "as_dict") else v @@ -762,6 +775,7 @@ def __init__( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, + is_multipart_file: bool = False, ): self._type = type self._rest_name_input = name @@ -771,6 +785,7 @@ def __init__( self._is_model = False self._default = default self._format = format + self._is_multipart_file = is_multipart_file @property def _rest_name(self) -> str: @@ -816,8 +831,11 @@ def rest_field( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, + is_multipart_file: bool = False, ) -> typing.Any: - return _RestField(name=name, type=type, visibility=visibility, default=default, format=format) + return _RestField( + name=name, type=type, visibility=visibility, default=default, format=format, is_multipart_file=is_multipart_file + ) def rest_discriminator( diff --git a/packages/typespec-python/test/unbranded/generated/parameters-spread/parameters/spread/_model_base.py b/packages/typespec-python/test/unbranded/generated/parameters-spread/parameters/spread/_model_base.py index d322088ee78..18fc4d77a91 100644 --- a/packages/typespec-python/test/unbranded/generated/parameters-spread/parameters/spread/_model_base.py +++ b/packages/typespec-python/test/unbranded/generated/parameters-spread/parameters/spread/_model_base.py @@ -462,7 +462,13 @@ def _get_rest_field( def _create_value(rf: typing.Optional["_RestField"], value: typing.Any) -> typing.Any: - return _deserialize(rf._type, value) if (rf and rf._is_model) else _serialize(value, rf._format if rf else None) + if not rf: + return _serialize(value, None) + if rf._is_multipart_file: + return value + if rf._is_model: + return _deserialize(rf._type, value) + return _serialize(value, rf._format) class Model(_MyMutableMapping): @@ -559,7 +565,14 @@ def as_dict(self, *, exclude_readonly: bool = False) -> typing.Dict[str, typing. for k, v in self.items(): if exclude_readonly and k in readonly_props: # pyright: ignore[reportUnboundVariable] continue - result[k] = Model._as_dict_value(v, exclude_readonly=exclude_readonly) + is_multipart_file = False + try: + is_multipart_file = next( + rf for rf in self._attr_to_rest_field.values() if rf._rest_name == k + )._is_multipart_file + except StopIteration: + pass + result[k] = v if is_multipart_file else Model._as_dict_value(v, exclude_readonly=exclude_readonly) return result @staticmethod @@ -567,7 +580,7 @@ def _as_dict_value(v: typing.Any, exclude_readonly: bool = False) -> typing.Any: if v is None or isinstance(v, _Null): return None if isinstance(v, (list, tuple, set)): - return [Model._as_dict_value(x, exclude_readonly=exclude_readonly) for x in v] + return type(v)(Model._as_dict_value(x, exclude_readonly=exclude_readonly) for x in v) if isinstance(v, dict): return {dk: Model._as_dict_value(dv, exclude_readonly=exclude_readonly) for dk, dv in v.items()} return v.as_dict(exclude_readonly=exclude_readonly) if hasattr(v, "as_dict") else v @@ -762,6 +775,7 @@ def __init__( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, + is_multipart_file: bool = False, ): self._type = type self._rest_name_input = name @@ -771,6 +785,7 @@ def __init__( self._is_model = False self._default = default self._format = format + self._is_multipart_file = is_multipart_file @property def _rest_name(self) -> str: @@ -816,8 +831,11 @@ def rest_field( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, + is_multipart_file: bool = False, ) -> typing.Any: - return _RestField(name=name, type=type, visibility=visibility, default=default, format=format) + return _RestField( + name=name, type=type, visibility=visibility, default=default, format=format, is_multipart_file=is_multipart_file + ) def rest_discriminator( diff --git a/packages/typespec-python/test/unbranded/generated/payload-content-negotiation/payload/contentnegotiation/_model_base.py b/packages/typespec-python/test/unbranded/generated/payload-content-negotiation/payload/contentnegotiation/_model_base.py index d322088ee78..18fc4d77a91 100644 --- a/packages/typespec-python/test/unbranded/generated/payload-content-negotiation/payload/contentnegotiation/_model_base.py +++ b/packages/typespec-python/test/unbranded/generated/payload-content-negotiation/payload/contentnegotiation/_model_base.py @@ -462,7 +462,13 @@ def _get_rest_field( def _create_value(rf: typing.Optional["_RestField"], value: typing.Any) -> typing.Any: - return _deserialize(rf._type, value) if (rf and rf._is_model) else _serialize(value, rf._format if rf else None) + if not rf: + return _serialize(value, None) + if rf._is_multipart_file: + return value + if rf._is_model: + return _deserialize(rf._type, value) + return _serialize(value, rf._format) class Model(_MyMutableMapping): @@ -559,7 +565,14 @@ def as_dict(self, *, exclude_readonly: bool = False) -> typing.Dict[str, typing. for k, v in self.items(): if exclude_readonly and k in readonly_props: # pyright: ignore[reportUnboundVariable] continue - result[k] = Model._as_dict_value(v, exclude_readonly=exclude_readonly) + is_multipart_file = False + try: + is_multipart_file = next( + rf for rf in self._attr_to_rest_field.values() if rf._rest_name == k + )._is_multipart_file + except StopIteration: + pass + result[k] = v if is_multipart_file else Model._as_dict_value(v, exclude_readonly=exclude_readonly) return result @staticmethod @@ -567,7 +580,7 @@ def _as_dict_value(v: typing.Any, exclude_readonly: bool = False) -> typing.Any: if v is None or isinstance(v, _Null): return None if isinstance(v, (list, tuple, set)): - return [Model._as_dict_value(x, exclude_readonly=exclude_readonly) for x in v] + return type(v)(Model._as_dict_value(x, exclude_readonly=exclude_readonly) for x in v) if isinstance(v, dict): return {dk: Model._as_dict_value(dv, exclude_readonly=exclude_readonly) for dk, dv in v.items()} return v.as_dict(exclude_readonly=exclude_readonly) if hasattr(v, "as_dict") else v @@ -762,6 +775,7 @@ def __init__( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, + is_multipart_file: bool = False, ): self._type = type self._rest_name_input = name @@ -771,6 +785,7 @@ def __init__( self._is_model = False self._default = default self._format = format + self._is_multipart_file = is_multipart_file @property def _rest_name(self) -> str: @@ -816,8 +831,11 @@ def rest_field( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, + is_multipart_file: bool = False, ) -> typing.Any: - return _RestField(name=name, type=type, visibility=visibility, default=default, format=format) + return _RestField( + name=name, type=type, visibility=visibility, default=default, format=format, is_multipart_file=is_multipart_file + ) def rest_discriminator( diff --git a/packages/typespec-python/test/unbranded/generated/payload-media-type/payload/mediatype/_model_base.py b/packages/typespec-python/test/unbranded/generated/payload-media-type/payload/mediatype/_model_base.py index d322088ee78..18fc4d77a91 100644 --- a/packages/typespec-python/test/unbranded/generated/payload-media-type/payload/mediatype/_model_base.py +++ b/packages/typespec-python/test/unbranded/generated/payload-media-type/payload/mediatype/_model_base.py @@ -462,7 +462,13 @@ def _get_rest_field( def _create_value(rf: typing.Optional["_RestField"], value: typing.Any) -> typing.Any: - return _deserialize(rf._type, value) if (rf and rf._is_model) else _serialize(value, rf._format if rf else None) + if not rf: + return _serialize(value, None) + if rf._is_multipart_file: + return value + if rf._is_model: + return _deserialize(rf._type, value) + return _serialize(value, rf._format) class Model(_MyMutableMapping): @@ -559,7 +565,14 @@ def as_dict(self, *, exclude_readonly: bool = False) -> typing.Dict[str, typing. for k, v in self.items(): if exclude_readonly and k in readonly_props: # pyright: ignore[reportUnboundVariable] continue - result[k] = Model._as_dict_value(v, exclude_readonly=exclude_readonly) + is_multipart_file = False + try: + is_multipart_file = next( + rf for rf in self._attr_to_rest_field.values() if rf._rest_name == k + )._is_multipart_file + except StopIteration: + pass + result[k] = v if is_multipart_file else Model._as_dict_value(v, exclude_readonly=exclude_readonly) return result @staticmethod @@ -567,7 +580,7 @@ def _as_dict_value(v: typing.Any, exclude_readonly: bool = False) -> typing.Any: if v is None or isinstance(v, _Null): return None if isinstance(v, (list, tuple, set)): - return [Model._as_dict_value(x, exclude_readonly=exclude_readonly) for x in v] + return type(v)(Model._as_dict_value(x, exclude_readonly=exclude_readonly) for x in v) if isinstance(v, dict): return {dk: Model._as_dict_value(dv, exclude_readonly=exclude_readonly) for dk, dv in v.items()} return v.as_dict(exclude_readonly=exclude_readonly) if hasattr(v, "as_dict") else v @@ -762,6 +775,7 @@ def __init__( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, + is_multipart_file: bool = False, ): self._type = type self._rest_name_input = name @@ -771,6 +785,7 @@ def __init__( self._is_model = False self._default = default self._format = format + self._is_multipart_file = is_multipart_file @property def _rest_name(self) -> str: @@ -816,8 +831,11 @@ def rest_field( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, + is_multipart_file: bool = False, ) -> typing.Any: - return _RestField(name=name, type=type, visibility=visibility, default=default, format=format) + return _RestField( + name=name, type=type, visibility=visibility, default=default, format=format, is_multipart_file=is_multipart_file + ) def rest_discriminator( diff --git a/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/_model_base.py b/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/_model_base.py index d322088ee78..18fc4d77a91 100644 --- a/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/_model_base.py +++ b/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/_model_base.py @@ -462,7 +462,13 @@ def _get_rest_field( def _create_value(rf: typing.Optional["_RestField"], value: typing.Any) -> typing.Any: - return _deserialize(rf._type, value) if (rf and rf._is_model) else _serialize(value, rf._format if rf else None) + if not rf: + return _serialize(value, None) + if rf._is_multipart_file: + return value + if rf._is_model: + return _deserialize(rf._type, value) + return _serialize(value, rf._format) class Model(_MyMutableMapping): @@ -559,7 +565,14 @@ def as_dict(self, *, exclude_readonly: bool = False) -> typing.Dict[str, typing. for k, v in self.items(): if exclude_readonly and k in readonly_props: # pyright: ignore[reportUnboundVariable] continue - result[k] = Model._as_dict_value(v, exclude_readonly=exclude_readonly) + is_multipart_file = False + try: + is_multipart_file = next( + rf for rf in self._attr_to_rest_field.values() if rf._rest_name == k + )._is_multipart_file + except StopIteration: + pass + result[k] = v if is_multipart_file else Model._as_dict_value(v, exclude_readonly=exclude_readonly) return result @staticmethod @@ -567,7 +580,7 @@ def _as_dict_value(v: typing.Any, exclude_readonly: bool = False) -> typing.Any: if v is None or isinstance(v, _Null): return None if isinstance(v, (list, tuple, set)): - return [Model._as_dict_value(x, exclude_readonly=exclude_readonly) for x in v] + return type(v)(Model._as_dict_value(x, exclude_readonly=exclude_readonly) for x in v) if isinstance(v, dict): return {dk: Model._as_dict_value(dv, exclude_readonly=exclude_readonly) for dk, dv in v.items()} return v.as_dict(exclude_readonly=exclude_readonly) if hasattr(v, "as_dict") else v @@ -762,6 +775,7 @@ def __init__( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, + is_multipart_file: bool = False, ): self._type = type self._rest_name_input = name @@ -771,6 +785,7 @@ def __init__( self._is_model = False self._default = default self._format = format + self._is_multipart_file = is_multipart_file @property def _rest_name(self) -> str: @@ -816,8 +831,11 @@ def rest_field( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, + is_multipart_file: bool = False, ) -> typing.Any: - return _RestField(name=name, type=type, visibility=visibility, default=default, format=format) + return _RestField( + name=name, type=type, visibility=visibility, default=default, format=format, is_multipart_file=is_multipart_file + ) def rest_discriminator( diff --git a/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/aio/operations/_operations.py b/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/aio/operations/_operations.py index e44ff14414f..28242500d74 100644 --- a/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/aio/operations/_operations.py +++ b/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/aio/operations/_operations.py @@ -6,6 +6,7 @@ # Code generated by Unbranded (R) Python Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- +import json import sys from typing import Any, Callable, Dict, Optional, TypeVar, Union, overload @@ -21,6 +22,7 @@ from corehttp.runtime.pipeline import PipelineResponse from ... import _model_base, models as _models +from ..._model_base import SdkJSONEncoder from ...operations._operations import ( build_form_data_basic_request, build_form_data_binary_array_parts_request, @@ -122,13 +124,21 @@ async def basic( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) - _body = body.as_dict() if isinstance(body, _model_base.Model) else body - _files = [] - if _body.get("profileImage") is not None: - _files.append(_body["profileImage"]) + content_type = content_type or "multipart/form-data" + _content = None + if isinstance(body, _model_base.Model): + _body = body.as_dict() if isinstance(body, _model_base.Model) else body + _files = [] + _data = {} + if _body.get("id") is not None: + _data["id"] = _body["id"] + if _body.get("profileImage") is not None: + _files.append(("profileImage", _body["profileImage"])) + elif isinstance(body, MutableMapping): + _content = body _request = build_form_data_basic_request( - files=_files, + content=_content, headers=_headers, params=_params, ) @@ -238,19 +248,27 @@ async def complex( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) - _body = body.as_dict() if isinstance(body, _model_base.Model) else body - _files = [] - if _body.get("address") is not None: - _files.append(_body["address"]) - if _body.get("profileImage") is not None: - _files.append(_body["profileImage"]) - if _body.get("previousAddresses") is not None: - _files.extend(_body["previousAddresses"]) - if _body.get("pictures") is not None: - _files.extend(_body["pictures"]) + content_type = content_type or "multipart/form-data" + _content = None + if isinstance(body, _model_base.Model): + _body = body.as_dict() if isinstance(body, _model_base.Model) else body + _files = [] + _data = {} + if _body.get("id") is not None: + _data["id"] = _body["id"] + if _body.get("address") is not None: + _data["address"] = _body["address"] + if _body.get("profileImage") is not None: + _files.append(("profileImage", _body["profileImage"])) + if _body.get("previousAddresses") is not None: + _data["previousAddresses"] = _body["previousAddresses"] + if _body.get("pictures") is not None: + _files.extend([("pictures", p) for p in _body["pictures"]]) + elif isinstance(body, MutableMapping): + _content = body _request = build_form_data_complex_request( - files=_files, + content=_content, headers=_headers, params=_params, ) @@ -342,15 +360,21 @@ async def json_part( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) - _body = body.as_dict() if isinstance(body, _model_base.Model) else body - _files = [] - if _body.get("address") is not None: - _files.append(_body["address"]) - if _body.get("profileImage") is not None: - _files.append(_body["profileImage"]) + content_type = content_type or "multipart/form-data" + _content = None + if isinstance(body, _model_base.Model): + _body = body.as_dict() if isinstance(body, _model_base.Model) else body + _files = [] + _data = {} + if _body.get("address") is not None: + _data["address"] = _body["address"] + if _body.get("profileImage") is not None: + _files.append(("profileImage", _body["profileImage"])) + elif isinstance(body, MutableMapping): + _content = body _request = build_form_data_json_part_request( - files=_files, + content=_content, headers=_headers, params=_params, ) @@ -444,13 +468,21 @@ async def binary_array_parts( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) - _body = body.as_dict() if isinstance(body, _model_base.Model) else body - _files = [] - if _body.get("pictures") is not None: - _files.extend(_body["pictures"]) + content_type = content_type or "multipart/form-data" + _content = None + if isinstance(body, _model_base.Model): + _body = body.as_dict() if isinstance(body, _model_base.Model) else body + _files = [] + _data = {} + if _body.get("id") is not None: + _data["id"] = _body["id"] + if _body.get("pictures") is not None: + _files.extend([("pictures", p) for p in _body["pictures"]]) + elif isinstance(body, MutableMapping): + _content = body _request = build_form_data_binary_array_parts_request( - files=_files, + content=_content, headers=_headers, params=_params, ) @@ -548,15 +580,21 @@ async def json_array_parts( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) - _body = body.as_dict() if isinstance(body, _model_base.Model) else body - _files = [] - if _body.get("profileImage") is not None: - _files.append(_body["profileImage"]) - if _body.get("previousAddresses") is not None: - _files.extend(_body["previousAddresses"]) + content_type = content_type or "multipart/form-data" + _content = None + if isinstance(body, _model_base.Model): + _body = body.as_dict() if isinstance(body, _model_base.Model) else body + _files = [] + _data = {} + if _body.get("profileImage") is not None: + _files.append(("profileImage", _body["profileImage"])) + if _body.get("previousAddresses") is not None: + _data["previousAddresses"] = _body["previousAddresses"] + elif isinstance(body, MutableMapping): + _content = body _request = build_form_data_json_array_parts_request( - files=_files, + content=_content, headers=_headers, params=_params, ) @@ -646,15 +684,21 @@ async def multi_binary_parts( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) - _body = body.as_dict() if isinstance(body, _model_base.Model) else body - _files = [] - if _body.get("profileImage") is not None: - _files.append(_body["profileImage"]) - if _body.get("picture") is not None: - _files.append(_body["picture"]) + content_type = content_type or "multipart/form-data" + _content = None + if isinstance(body, _model_base.Model): + _body = body.as_dict() if isinstance(body, _model_base.Model) else body + _files = [] + _data = {} + if _body.get("profileImage") is not None: + _files.append(("profileImage", _body["profileImage"])) + if _body.get("picture") is not None: + _files.append(("picture", _body["picture"])) + elif isinstance(body, MutableMapping): + _content = body _request = build_form_data_multi_binary_parts_request( - files=_files, + content=_content, headers=_headers, params=_params, ) diff --git a/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/models/_models.py b/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/models/_models.py index 901955107d2..f85e80aa665 100644 --- a/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/models/_models.py +++ b/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/models/_models.py @@ -15,7 +15,7 @@ if TYPE_CHECKING: # pylint: disable=unused-import,ungrouped-imports - from .. import _model_base, models as _models + from .. import models as _models class Address(_model_base.Model): @@ -62,7 +62,7 @@ class BinaryArrayPartsRequest(_model_base.Model): id: str = rest_field() """Required.""" - pictures: List[FileType] = rest_field() + pictures: List[FileType] = rest_field(is_multipart_file=True) """Required.""" @overload @@ -106,11 +106,11 @@ class ComplexPartsRequest(_model_base.Model): """Required.""" address: "_models.Address" = rest_field() """Required.""" - profile_image: FileType = rest_field(name="profileImage") + profile_image: FileType = rest_field(name="profileImage", is_multipart_file=True) """Required.""" previous_addresses: List["_models.Address"] = rest_field(name="previousAddresses") """Required.""" - pictures: List[FileType] = rest_field() + pictures: List[FileType] = rest_field(is_multipart_file=True) """Required.""" @overload @@ -147,7 +147,7 @@ class JsonArrayPartsRequest(_model_base.Model): :vartype previous_addresses: list[~payload.multipart.models.Address] """ - profile_image: FileType = rest_field(name="profileImage") + profile_image: FileType = rest_field(name="profileImage", is_multipart_file=True) """Required.""" previous_addresses: List["_models.Address"] = rest_field(name="previousAddresses") """Required.""" @@ -185,7 +185,7 @@ class JsonPartRequest(_model_base.Model): address: "_models.Address" = rest_field() """Required.""" - profile_image: FileType = rest_field(name="profileImage") + profile_image: FileType = rest_field(name="profileImage", is_multipart_file=True) """Required.""" @overload @@ -219,9 +219,9 @@ class MultiBinaryPartsRequest(_model_base.Model): :vartype picture: filetype """ - profile_image: FileType = rest_field(name="profileImage") + profile_image: FileType = rest_field(name="profileImage", is_multipart_file=True) """Required.""" - picture: Optional[FileType] = rest_field() + picture: Optional[FileType] = rest_field(is_multipart_file=True) @overload def __init__( @@ -256,7 +256,7 @@ class MultiPartRequest(_model_base.Model): id: str = rest_field() """Required.""" - profile_image: FileType = rest_field(name="profileImage") + profile_image: FileType = rest_field(name="profileImage", is_multipart_file=True) """Required.""" @overload diff --git a/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/operations/_operations.py b/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/operations/_operations.py index b21ea00266d..4b034dd35bb 100644 --- a/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/operations/_operations.py +++ b/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/operations/_operations.py @@ -6,6 +6,7 @@ # Code generated by Unbranded (R) Python Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- +import json import sys from typing import Any, Callable, Dict, Optional, TypeVar, Union, overload @@ -22,6 +23,7 @@ from corehttp.utils import case_insensitive_dict from .. import _model_base, models as _models +from .._model_base import SdkJSONEncoder from .._serialization import Serializer if sys.version_info >= (3, 9): @@ -42,6 +44,10 @@ def build_form_data_basic_request(**kwargs: Any) -> HttpRequest: # Construct URL _url = "/multipart/form-data/mixed-parts" + # Construct headers + if content_type is not None: + _headers["content-type"] = _SERIALIZER.header("content_type", content_type, "str") + return HttpRequest(method="POST", url=_url, headers=_headers, **kwargs) @@ -51,6 +57,10 @@ def build_form_data_complex_request(**kwargs: Any) -> HttpRequest: # Construct URL _url = "/multipart/form-data/complex-parts" + # Construct headers + if content_type is not None: + _headers["content-type"] = _SERIALIZER.header("content_type", content_type, "str") + return HttpRequest(method="POST", url=_url, headers=_headers, **kwargs) @@ -60,6 +70,10 @@ def build_form_data_json_part_request(**kwargs: Any) -> HttpRequest: # Construct URL _url = "/multipart/form-data/json-part" + # Construct headers + if content_type is not None: + _headers["content-type"] = _SERIALIZER.header("content_type", content_type, "str") + return HttpRequest(method="POST", url=_url, headers=_headers, **kwargs) @@ -69,6 +83,10 @@ def build_form_data_binary_array_parts_request(**kwargs: Any) -> HttpRequest: # # Construct URL _url = "/multipart/form-data/binary-array-parts" + # Construct headers + if content_type is not None: + _headers["content-type"] = _SERIALIZER.header("content_type", content_type, "str") + return HttpRequest(method="POST", url=_url, headers=_headers, **kwargs) @@ -78,6 +96,10 @@ def build_form_data_json_array_parts_request(**kwargs: Any) -> HttpRequest: # Construct URL _url = "/multipart/form-data/json-array-parts" + # Construct headers + if content_type is not None: + _headers["content-type"] = _SERIALIZER.header("content_type", content_type, "str") + return HttpRequest(method="POST", url=_url, headers=_headers, **kwargs) @@ -87,6 +109,10 @@ def build_form_data_multi_binary_parts_request(**kwargs: Any) -> HttpRequest: # # Construct URL _url = "/multipart/form-data/multi-binary-parts" + # Construct headers + if content_type is not None: + _headers["content-type"] = _SERIALIZER.header("content_type", content_type, "str") + return HttpRequest(method="POST", url=_url, headers=_headers, **kwargs) @@ -173,13 +199,21 @@ def basic( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) - _body = body.as_dict() if isinstance(body, _model_base.Model) else body - _files = [] - if _body.get("profileImage") is not None: - _files.append(_body["profileImage"]) + content_type = content_type or "multipart/form-data" + _content = None + if isinstance(body, _model_base.Model): + _body = body.as_dict() if isinstance(body, _model_base.Model) else body + _files = [] + _data = {} + if _body.get("id") is not None: + _data["id"] = _body["id"] + if _body.get("profileImage") is not None: + _files.append(("profileImage", _body["profileImage"])) + elif isinstance(body, MutableMapping): + _content = body _request = build_form_data_basic_request( - files=_files, + content=_content, headers=_headers, params=_params, ) @@ -289,19 +323,27 @@ def complex( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) - _body = body.as_dict() if isinstance(body, _model_base.Model) else body - _files = [] - if _body.get("address") is not None: - _files.append(_body["address"]) - if _body.get("profileImage") is not None: - _files.append(_body["profileImage"]) - if _body.get("previousAddresses") is not None: - _files.extend(_body["previousAddresses"]) - if _body.get("pictures") is not None: - _files.extend(_body["pictures"]) + content_type = content_type or "multipart/form-data" + _content = None + if isinstance(body, _model_base.Model): + _body = body.as_dict() if isinstance(body, _model_base.Model) else body + _files = [] + _data = {} + if _body.get("id") is not None: + _data["id"] = _body["id"] + if _body.get("address") is not None: + _data["address"] = _body["address"] + if _body.get("profileImage") is not None: + _files.append(("profileImage", _body["profileImage"])) + if _body.get("previousAddresses") is not None: + _data["previousAddresses"] = _body["previousAddresses"] + if _body.get("pictures") is not None: + _files.extend([("pictures", p) for p in _body["pictures"]]) + elif isinstance(body, MutableMapping): + _content = body _request = build_form_data_complex_request( - files=_files, + content=_content, headers=_headers, params=_params, ) @@ -393,15 +435,21 @@ def json_part( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) - _body = body.as_dict() if isinstance(body, _model_base.Model) else body - _files = [] - if _body.get("address") is not None: - _files.append(_body["address"]) - if _body.get("profileImage") is not None: - _files.append(_body["profileImage"]) + content_type = content_type or "multipart/form-data" + _content = None + if isinstance(body, _model_base.Model): + _body = body.as_dict() if isinstance(body, _model_base.Model) else body + _files = [] + _data = {} + if _body.get("address") is not None: + _data["address"] = _body["address"] + if _body.get("profileImage") is not None: + _files.append(("profileImage", _body["profileImage"])) + elif isinstance(body, MutableMapping): + _content = body _request = build_form_data_json_part_request( - files=_files, + content=_content, headers=_headers, params=_params, ) @@ -493,13 +541,21 @@ def binary_array_parts( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) - _body = body.as_dict() if isinstance(body, _model_base.Model) else body - _files = [] - if _body.get("pictures") is not None: - _files.extend(_body["pictures"]) + content_type = content_type or "multipart/form-data" + _content = None + if isinstance(body, _model_base.Model): + _body = body.as_dict() if isinstance(body, _model_base.Model) else body + _files = [] + _data = {} + if _body.get("id") is not None: + _data["id"] = _body["id"] + if _body.get("pictures") is not None: + _files.extend([("pictures", p) for p in _body["pictures"]]) + elif isinstance(body, MutableMapping): + _content = body _request = build_form_data_binary_array_parts_request( - files=_files, + content=_content, headers=_headers, params=_params, ) @@ -595,15 +651,21 @@ def json_array_parts( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) - _body = body.as_dict() if isinstance(body, _model_base.Model) else body - _files = [] - if _body.get("profileImage") is not None: - _files.append(_body["profileImage"]) - if _body.get("previousAddresses") is not None: - _files.extend(_body["previousAddresses"]) + content_type = content_type or "multipart/form-data" + _content = None + if isinstance(body, _model_base.Model): + _body = body.as_dict() if isinstance(body, _model_base.Model) else body + _files = [] + _data = {} + if _body.get("profileImage") is not None: + _files.append(("profileImage", _body["profileImage"])) + if _body.get("previousAddresses") is not None: + _data["previousAddresses"] = _body["previousAddresses"] + elif isinstance(body, MutableMapping): + _content = body _request = build_form_data_json_array_parts_request( - files=_files, + content=_content, headers=_headers, params=_params, ) @@ -691,15 +753,21 @@ def multi_binary_parts( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) - _body = body.as_dict() if isinstance(body, _model_base.Model) else body - _files = [] - if _body.get("profileImage") is not None: - _files.append(_body["profileImage"]) - if _body.get("picture") is not None: - _files.append(_body["picture"]) + content_type = content_type or "multipart/form-data" + _content = None + if isinstance(body, _model_base.Model): + _body = body.as_dict() if isinstance(body, _model_base.Model) else body + _files = [] + _data = {} + if _body.get("profileImage") is not None: + _files.append(("profileImage", _body["profileImage"])) + if _body.get("picture") is not None: + _files.append(("picture", _body["picture"])) + elif isinstance(body, MutableMapping): + _content = body _request = build_form_data_multi_binary_parts_request( - files=_files, + content=_content, headers=_headers, params=_params, ) diff --git a/packages/typespec-python/test/unbranded/generated/payload-pageable/payload/pageable/_model_base.py b/packages/typespec-python/test/unbranded/generated/payload-pageable/payload/pageable/_model_base.py index d322088ee78..18fc4d77a91 100644 --- a/packages/typespec-python/test/unbranded/generated/payload-pageable/payload/pageable/_model_base.py +++ b/packages/typespec-python/test/unbranded/generated/payload-pageable/payload/pageable/_model_base.py @@ -462,7 +462,13 @@ def _get_rest_field( def _create_value(rf: typing.Optional["_RestField"], value: typing.Any) -> typing.Any: - return _deserialize(rf._type, value) if (rf and rf._is_model) else _serialize(value, rf._format if rf else None) + if not rf: + return _serialize(value, None) + if rf._is_multipart_file: + return value + if rf._is_model: + return _deserialize(rf._type, value) + return _serialize(value, rf._format) class Model(_MyMutableMapping): @@ -559,7 +565,14 @@ def as_dict(self, *, exclude_readonly: bool = False) -> typing.Dict[str, typing. for k, v in self.items(): if exclude_readonly and k in readonly_props: # pyright: ignore[reportUnboundVariable] continue - result[k] = Model._as_dict_value(v, exclude_readonly=exclude_readonly) + is_multipart_file = False + try: + is_multipart_file = next( + rf for rf in self._attr_to_rest_field.values() if rf._rest_name == k + )._is_multipart_file + except StopIteration: + pass + result[k] = v if is_multipart_file else Model._as_dict_value(v, exclude_readonly=exclude_readonly) return result @staticmethod @@ -567,7 +580,7 @@ def _as_dict_value(v: typing.Any, exclude_readonly: bool = False) -> typing.Any: if v is None or isinstance(v, _Null): return None if isinstance(v, (list, tuple, set)): - return [Model._as_dict_value(x, exclude_readonly=exclude_readonly) for x in v] + return type(v)(Model._as_dict_value(x, exclude_readonly=exclude_readonly) for x in v) if isinstance(v, dict): return {dk: Model._as_dict_value(dv, exclude_readonly=exclude_readonly) for dk, dv in v.items()} return v.as_dict(exclude_readonly=exclude_readonly) if hasattr(v, "as_dict") else v @@ -762,6 +775,7 @@ def __init__( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, + is_multipart_file: bool = False, ): self._type = type self._rest_name_input = name @@ -771,6 +785,7 @@ def __init__( self._is_model = False self._default = default self._format = format + self._is_multipart_file = is_multipart_file @property def _rest_name(self) -> str: @@ -816,8 +831,11 @@ def rest_field( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, + is_multipart_file: bool = False, ) -> typing.Any: - return _RestField(name=name, type=type, visibility=visibility, default=default, format=format) + return _RestField( + name=name, type=type, visibility=visibility, default=default, format=format, is_multipart_file=is_multipart_file + ) def rest_discriminator( diff --git a/packages/typespec-python/test/unbranded/generated/projection-projected-name/projection/projectedname/_model_base.py b/packages/typespec-python/test/unbranded/generated/projection-projected-name/projection/projectedname/_model_base.py index d322088ee78..18fc4d77a91 100644 --- a/packages/typespec-python/test/unbranded/generated/projection-projected-name/projection/projectedname/_model_base.py +++ b/packages/typespec-python/test/unbranded/generated/projection-projected-name/projection/projectedname/_model_base.py @@ -462,7 +462,13 @@ def _get_rest_field( def _create_value(rf: typing.Optional["_RestField"], value: typing.Any) -> typing.Any: - return _deserialize(rf._type, value) if (rf and rf._is_model) else _serialize(value, rf._format if rf else None) + if not rf: + return _serialize(value, None) + if rf._is_multipart_file: + return value + if rf._is_model: + return _deserialize(rf._type, value) + return _serialize(value, rf._format) class Model(_MyMutableMapping): @@ -559,7 +565,14 @@ def as_dict(self, *, exclude_readonly: bool = False) -> typing.Dict[str, typing. for k, v in self.items(): if exclude_readonly and k in readonly_props: # pyright: ignore[reportUnboundVariable] continue - result[k] = Model._as_dict_value(v, exclude_readonly=exclude_readonly) + is_multipart_file = False + try: + is_multipart_file = next( + rf for rf in self._attr_to_rest_field.values() if rf._rest_name == k + )._is_multipart_file + except StopIteration: + pass + result[k] = v if is_multipart_file else Model._as_dict_value(v, exclude_readonly=exclude_readonly) return result @staticmethod @@ -567,7 +580,7 @@ def _as_dict_value(v: typing.Any, exclude_readonly: bool = False) -> typing.Any: if v is None or isinstance(v, _Null): return None if isinstance(v, (list, tuple, set)): - return [Model._as_dict_value(x, exclude_readonly=exclude_readonly) for x in v] + return type(v)(Model._as_dict_value(x, exclude_readonly=exclude_readonly) for x in v) if isinstance(v, dict): return {dk: Model._as_dict_value(dv, exclude_readonly=exclude_readonly) for dk, dv in v.items()} return v.as_dict(exclude_readonly=exclude_readonly) if hasattr(v, "as_dict") else v @@ -762,6 +775,7 @@ def __init__( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, + is_multipart_file: bool = False, ): self._type = type self._rest_name_input = name @@ -771,6 +785,7 @@ def __init__( self._is_model = False self._default = default self._format = format + self._is_multipart_file = is_multipart_file @property def _rest_name(self) -> str: @@ -816,8 +831,11 @@ def rest_field( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, + is_multipart_file: bool = False, ) -> typing.Any: - return _RestField(name=name, type=type, visibility=visibility, default=default, format=format) + return _RestField( + name=name, type=type, visibility=visibility, default=default, format=format, is_multipart_file=is_multipart_file + ) def rest_discriminator( diff --git a/packages/typespec-python/test/unbranded/generated/resiliency-srv-driven1/resiliency/srv/driven1/_model_base.py b/packages/typespec-python/test/unbranded/generated/resiliency-srv-driven1/resiliency/srv/driven1/_model_base.py index d322088ee78..18fc4d77a91 100644 --- a/packages/typespec-python/test/unbranded/generated/resiliency-srv-driven1/resiliency/srv/driven1/_model_base.py +++ b/packages/typespec-python/test/unbranded/generated/resiliency-srv-driven1/resiliency/srv/driven1/_model_base.py @@ -462,7 +462,13 @@ def _get_rest_field( def _create_value(rf: typing.Optional["_RestField"], value: typing.Any) -> typing.Any: - return _deserialize(rf._type, value) if (rf and rf._is_model) else _serialize(value, rf._format if rf else None) + if not rf: + return _serialize(value, None) + if rf._is_multipart_file: + return value + if rf._is_model: + return _deserialize(rf._type, value) + return _serialize(value, rf._format) class Model(_MyMutableMapping): @@ -559,7 +565,14 @@ def as_dict(self, *, exclude_readonly: bool = False) -> typing.Dict[str, typing. for k, v in self.items(): if exclude_readonly and k in readonly_props: # pyright: ignore[reportUnboundVariable] continue - result[k] = Model._as_dict_value(v, exclude_readonly=exclude_readonly) + is_multipart_file = False + try: + is_multipart_file = next( + rf for rf in self._attr_to_rest_field.values() if rf._rest_name == k + )._is_multipart_file + except StopIteration: + pass + result[k] = v if is_multipart_file else Model._as_dict_value(v, exclude_readonly=exclude_readonly) return result @staticmethod @@ -567,7 +580,7 @@ def _as_dict_value(v: typing.Any, exclude_readonly: bool = False) -> typing.Any: if v is None or isinstance(v, _Null): return None if isinstance(v, (list, tuple, set)): - return [Model._as_dict_value(x, exclude_readonly=exclude_readonly) for x in v] + return type(v)(Model._as_dict_value(x, exclude_readonly=exclude_readonly) for x in v) if isinstance(v, dict): return {dk: Model._as_dict_value(dv, exclude_readonly=exclude_readonly) for dk, dv in v.items()} return v.as_dict(exclude_readonly=exclude_readonly) if hasattr(v, "as_dict") else v @@ -762,6 +775,7 @@ def __init__( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, + is_multipart_file: bool = False, ): self._type = type self._rest_name_input = name @@ -771,6 +785,7 @@ def __init__( self._is_model = False self._default = default self._format = format + self._is_multipart_file = is_multipart_file @property def _rest_name(self) -> str: @@ -816,8 +831,11 @@ def rest_field( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, + is_multipart_file: bool = False, ) -> typing.Any: - return _RestField(name=name, type=type, visibility=visibility, default=default, format=format) + return _RestField( + name=name, type=type, visibility=visibility, default=default, format=format, is_multipart_file=is_multipart_file + ) def rest_discriminator( diff --git a/packages/typespec-python/test/unbranded/generated/resiliency-srv-driven2/resiliency/srv/driven2/_model_base.py b/packages/typespec-python/test/unbranded/generated/resiliency-srv-driven2/resiliency/srv/driven2/_model_base.py index d322088ee78..18fc4d77a91 100644 --- a/packages/typespec-python/test/unbranded/generated/resiliency-srv-driven2/resiliency/srv/driven2/_model_base.py +++ b/packages/typespec-python/test/unbranded/generated/resiliency-srv-driven2/resiliency/srv/driven2/_model_base.py @@ -462,7 +462,13 @@ def _get_rest_field( def _create_value(rf: typing.Optional["_RestField"], value: typing.Any) -> typing.Any: - return _deserialize(rf._type, value) if (rf and rf._is_model) else _serialize(value, rf._format if rf else None) + if not rf: + return _serialize(value, None) + if rf._is_multipart_file: + return value + if rf._is_model: + return _deserialize(rf._type, value) + return _serialize(value, rf._format) class Model(_MyMutableMapping): @@ -559,7 +565,14 @@ def as_dict(self, *, exclude_readonly: bool = False) -> typing.Dict[str, typing. for k, v in self.items(): if exclude_readonly and k in readonly_props: # pyright: ignore[reportUnboundVariable] continue - result[k] = Model._as_dict_value(v, exclude_readonly=exclude_readonly) + is_multipart_file = False + try: + is_multipart_file = next( + rf for rf in self._attr_to_rest_field.values() if rf._rest_name == k + )._is_multipart_file + except StopIteration: + pass + result[k] = v if is_multipart_file else Model._as_dict_value(v, exclude_readonly=exclude_readonly) return result @staticmethod @@ -567,7 +580,7 @@ def _as_dict_value(v: typing.Any, exclude_readonly: bool = False) -> typing.Any: if v is None or isinstance(v, _Null): return None if isinstance(v, (list, tuple, set)): - return [Model._as_dict_value(x, exclude_readonly=exclude_readonly) for x in v] + return type(v)(Model._as_dict_value(x, exclude_readonly=exclude_readonly) for x in v) if isinstance(v, dict): return {dk: Model._as_dict_value(dv, exclude_readonly=exclude_readonly) for dk, dv in v.items()} return v.as_dict(exclude_readonly=exclude_readonly) if hasattr(v, "as_dict") else v @@ -762,6 +775,7 @@ def __init__( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, + is_multipart_file: bool = False, ): self._type = type self._rest_name_input = name @@ -771,6 +785,7 @@ def __init__( self._is_model = False self._default = default self._format = format + self._is_multipart_file = is_multipart_file @property def _rest_name(self) -> str: @@ -816,8 +831,11 @@ def rest_field( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, + is_multipart_file: bool = False, ) -> typing.Any: - return _RestField(name=name, type=type, visibility=visibility, default=default, format=format) + return _RestField( + name=name, type=type, visibility=visibility, default=default, format=format, is_multipart_file=is_multipart_file + ) def rest_discriminator( diff --git a/packages/typespec-python/test/unbranded/generated/server-path-multiple/server/path/multiple/_model_base.py b/packages/typespec-python/test/unbranded/generated/server-path-multiple/server/path/multiple/_model_base.py index d322088ee78..18fc4d77a91 100644 --- a/packages/typespec-python/test/unbranded/generated/server-path-multiple/server/path/multiple/_model_base.py +++ b/packages/typespec-python/test/unbranded/generated/server-path-multiple/server/path/multiple/_model_base.py @@ -462,7 +462,13 @@ def _get_rest_field( def _create_value(rf: typing.Optional["_RestField"], value: typing.Any) -> typing.Any: - return _deserialize(rf._type, value) if (rf and rf._is_model) else _serialize(value, rf._format if rf else None) + if not rf: + return _serialize(value, None) + if rf._is_multipart_file: + return value + if rf._is_model: + return _deserialize(rf._type, value) + return _serialize(value, rf._format) class Model(_MyMutableMapping): @@ -559,7 +565,14 @@ def as_dict(self, *, exclude_readonly: bool = False) -> typing.Dict[str, typing. for k, v in self.items(): if exclude_readonly and k in readonly_props: # pyright: ignore[reportUnboundVariable] continue - result[k] = Model._as_dict_value(v, exclude_readonly=exclude_readonly) + is_multipart_file = False + try: + is_multipart_file = next( + rf for rf in self._attr_to_rest_field.values() if rf._rest_name == k + )._is_multipart_file + except StopIteration: + pass + result[k] = v if is_multipart_file else Model._as_dict_value(v, exclude_readonly=exclude_readonly) return result @staticmethod @@ -567,7 +580,7 @@ def _as_dict_value(v: typing.Any, exclude_readonly: bool = False) -> typing.Any: if v is None or isinstance(v, _Null): return None if isinstance(v, (list, tuple, set)): - return [Model._as_dict_value(x, exclude_readonly=exclude_readonly) for x in v] + return type(v)(Model._as_dict_value(x, exclude_readonly=exclude_readonly) for x in v) if isinstance(v, dict): return {dk: Model._as_dict_value(dv, exclude_readonly=exclude_readonly) for dk, dv in v.items()} return v.as_dict(exclude_readonly=exclude_readonly) if hasattr(v, "as_dict") else v @@ -762,6 +775,7 @@ def __init__( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, + is_multipart_file: bool = False, ): self._type = type self._rest_name_input = name @@ -771,6 +785,7 @@ def __init__( self._is_model = False self._default = default self._format = format + self._is_multipart_file = is_multipart_file @property def _rest_name(self) -> str: @@ -816,8 +831,11 @@ def rest_field( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, + is_multipart_file: bool = False, ) -> typing.Any: - return _RestField(name=name, type=type, visibility=visibility, default=default, format=format) + return _RestField( + name=name, type=type, visibility=visibility, default=default, format=format, is_multipart_file=is_multipart_file + ) def rest_discriminator( diff --git a/packages/typespec-python/test/unbranded/generated/server-path-single/server/path/single/_model_base.py b/packages/typespec-python/test/unbranded/generated/server-path-single/server/path/single/_model_base.py index d322088ee78..18fc4d77a91 100644 --- a/packages/typespec-python/test/unbranded/generated/server-path-single/server/path/single/_model_base.py +++ b/packages/typespec-python/test/unbranded/generated/server-path-single/server/path/single/_model_base.py @@ -462,7 +462,13 @@ def _get_rest_field( def _create_value(rf: typing.Optional["_RestField"], value: typing.Any) -> typing.Any: - return _deserialize(rf._type, value) if (rf and rf._is_model) else _serialize(value, rf._format if rf else None) + if not rf: + return _serialize(value, None) + if rf._is_multipart_file: + return value + if rf._is_model: + return _deserialize(rf._type, value) + return _serialize(value, rf._format) class Model(_MyMutableMapping): @@ -559,7 +565,14 @@ def as_dict(self, *, exclude_readonly: bool = False) -> typing.Dict[str, typing. for k, v in self.items(): if exclude_readonly and k in readonly_props: # pyright: ignore[reportUnboundVariable] continue - result[k] = Model._as_dict_value(v, exclude_readonly=exclude_readonly) + is_multipart_file = False + try: + is_multipart_file = next( + rf for rf in self._attr_to_rest_field.values() if rf._rest_name == k + )._is_multipart_file + except StopIteration: + pass + result[k] = v if is_multipart_file else Model._as_dict_value(v, exclude_readonly=exclude_readonly) return result @staticmethod @@ -567,7 +580,7 @@ def _as_dict_value(v: typing.Any, exclude_readonly: bool = False) -> typing.Any: if v is None or isinstance(v, _Null): return None if isinstance(v, (list, tuple, set)): - return [Model._as_dict_value(x, exclude_readonly=exclude_readonly) for x in v] + return type(v)(Model._as_dict_value(x, exclude_readonly=exclude_readonly) for x in v) if isinstance(v, dict): return {dk: Model._as_dict_value(dv, exclude_readonly=exclude_readonly) for dk, dv in v.items()} return v.as_dict(exclude_readonly=exclude_readonly) if hasattr(v, "as_dict") else v @@ -762,6 +775,7 @@ def __init__( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, + is_multipart_file: bool = False, ): self._type = type self._rest_name_input = name @@ -771,6 +785,7 @@ def __init__( self._is_model = False self._default = default self._format = format + self._is_multipart_file = is_multipart_file @property def _rest_name(self) -> str: @@ -816,8 +831,11 @@ def rest_field( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, + is_multipart_file: bool = False, ) -> typing.Any: - return _RestField(name=name, type=type, visibility=visibility, default=default, format=format) + return _RestField( + name=name, type=type, visibility=visibility, default=default, format=format, is_multipart_file=is_multipart_file + ) def rest_discriminator( diff --git a/packages/typespec-python/test/unbranded/generated/server-versions-not-versioned/server/versions/notversioned/_model_base.py b/packages/typespec-python/test/unbranded/generated/server-versions-not-versioned/server/versions/notversioned/_model_base.py index d322088ee78..18fc4d77a91 100644 --- a/packages/typespec-python/test/unbranded/generated/server-versions-not-versioned/server/versions/notversioned/_model_base.py +++ b/packages/typespec-python/test/unbranded/generated/server-versions-not-versioned/server/versions/notversioned/_model_base.py @@ -462,7 +462,13 @@ def _get_rest_field( def _create_value(rf: typing.Optional["_RestField"], value: typing.Any) -> typing.Any: - return _deserialize(rf._type, value) if (rf and rf._is_model) else _serialize(value, rf._format if rf else None) + if not rf: + return _serialize(value, None) + if rf._is_multipart_file: + return value + if rf._is_model: + return _deserialize(rf._type, value) + return _serialize(value, rf._format) class Model(_MyMutableMapping): @@ -559,7 +565,14 @@ def as_dict(self, *, exclude_readonly: bool = False) -> typing.Dict[str, typing. for k, v in self.items(): if exclude_readonly and k in readonly_props: # pyright: ignore[reportUnboundVariable] continue - result[k] = Model._as_dict_value(v, exclude_readonly=exclude_readonly) + is_multipart_file = False + try: + is_multipart_file = next( + rf for rf in self._attr_to_rest_field.values() if rf._rest_name == k + )._is_multipart_file + except StopIteration: + pass + result[k] = v if is_multipart_file else Model._as_dict_value(v, exclude_readonly=exclude_readonly) return result @staticmethod @@ -567,7 +580,7 @@ def _as_dict_value(v: typing.Any, exclude_readonly: bool = False) -> typing.Any: if v is None or isinstance(v, _Null): return None if isinstance(v, (list, tuple, set)): - return [Model._as_dict_value(x, exclude_readonly=exclude_readonly) for x in v] + return type(v)(Model._as_dict_value(x, exclude_readonly=exclude_readonly) for x in v) if isinstance(v, dict): return {dk: Model._as_dict_value(dv, exclude_readonly=exclude_readonly) for dk, dv in v.items()} return v.as_dict(exclude_readonly=exclude_readonly) if hasattr(v, "as_dict") else v @@ -762,6 +775,7 @@ def __init__( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, + is_multipart_file: bool = False, ): self._type = type self._rest_name_input = name @@ -771,6 +785,7 @@ def __init__( self._is_model = False self._default = default self._format = format + self._is_multipart_file = is_multipart_file @property def _rest_name(self) -> str: @@ -816,8 +831,11 @@ def rest_field( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, + is_multipart_file: bool = False, ) -> typing.Any: - return _RestField(name=name, type=type, visibility=visibility, default=default, format=format) + return _RestField( + name=name, type=type, visibility=visibility, default=default, format=format, is_multipart_file=is_multipart_file + ) def rest_discriminator( diff --git a/packages/typespec-python/test/unbranded/generated/server-versions-versioned/server/versions/versioned/_model_base.py b/packages/typespec-python/test/unbranded/generated/server-versions-versioned/server/versions/versioned/_model_base.py index d322088ee78..18fc4d77a91 100644 --- a/packages/typespec-python/test/unbranded/generated/server-versions-versioned/server/versions/versioned/_model_base.py +++ b/packages/typespec-python/test/unbranded/generated/server-versions-versioned/server/versions/versioned/_model_base.py @@ -462,7 +462,13 @@ def _get_rest_field( def _create_value(rf: typing.Optional["_RestField"], value: typing.Any) -> typing.Any: - return _deserialize(rf._type, value) if (rf and rf._is_model) else _serialize(value, rf._format if rf else None) + if not rf: + return _serialize(value, None) + if rf._is_multipart_file: + return value + if rf._is_model: + return _deserialize(rf._type, value) + return _serialize(value, rf._format) class Model(_MyMutableMapping): @@ -559,7 +565,14 @@ def as_dict(self, *, exclude_readonly: bool = False) -> typing.Dict[str, typing. for k, v in self.items(): if exclude_readonly and k in readonly_props: # pyright: ignore[reportUnboundVariable] continue - result[k] = Model._as_dict_value(v, exclude_readonly=exclude_readonly) + is_multipart_file = False + try: + is_multipart_file = next( + rf for rf in self._attr_to_rest_field.values() if rf._rest_name == k + )._is_multipart_file + except StopIteration: + pass + result[k] = v if is_multipart_file else Model._as_dict_value(v, exclude_readonly=exclude_readonly) return result @staticmethod @@ -567,7 +580,7 @@ def _as_dict_value(v: typing.Any, exclude_readonly: bool = False) -> typing.Any: if v is None or isinstance(v, _Null): return None if isinstance(v, (list, tuple, set)): - return [Model._as_dict_value(x, exclude_readonly=exclude_readonly) for x in v] + return type(v)(Model._as_dict_value(x, exclude_readonly=exclude_readonly) for x in v) if isinstance(v, dict): return {dk: Model._as_dict_value(dv, exclude_readonly=exclude_readonly) for dk, dv in v.items()} return v.as_dict(exclude_readonly=exclude_readonly) if hasattr(v, "as_dict") else v @@ -762,6 +775,7 @@ def __init__( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, + is_multipart_file: bool = False, ): self._type = type self._rest_name_input = name @@ -771,6 +785,7 @@ def __init__( self._is_model = False self._default = default self._format = format + self._is_multipart_file = is_multipart_file @property def _rest_name(self) -> str: @@ -816,8 +831,11 @@ def rest_field( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, + is_multipart_file: bool = False, ) -> typing.Any: - return _RestField(name=name, type=type, visibility=visibility, default=default, format=format) + return _RestField( + name=name, type=type, visibility=visibility, default=default, format=format, is_multipart_file=is_multipart_file + ) def rest_discriminator( diff --git a/packages/typespec-python/test/unbranded/generated/special-headers-conditional-request/specialheaders/conditionalrequest/_model_base.py b/packages/typespec-python/test/unbranded/generated/special-headers-conditional-request/specialheaders/conditionalrequest/_model_base.py index d322088ee78..18fc4d77a91 100644 --- a/packages/typespec-python/test/unbranded/generated/special-headers-conditional-request/specialheaders/conditionalrequest/_model_base.py +++ b/packages/typespec-python/test/unbranded/generated/special-headers-conditional-request/specialheaders/conditionalrequest/_model_base.py @@ -462,7 +462,13 @@ def _get_rest_field( def _create_value(rf: typing.Optional["_RestField"], value: typing.Any) -> typing.Any: - return _deserialize(rf._type, value) if (rf and rf._is_model) else _serialize(value, rf._format if rf else None) + if not rf: + return _serialize(value, None) + if rf._is_multipart_file: + return value + if rf._is_model: + return _deserialize(rf._type, value) + return _serialize(value, rf._format) class Model(_MyMutableMapping): @@ -559,7 +565,14 @@ def as_dict(self, *, exclude_readonly: bool = False) -> typing.Dict[str, typing. for k, v in self.items(): if exclude_readonly and k in readonly_props: # pyright: ignore[reportUnboundVariable] continue - result[k] = Model._as_dict_value(v, exclude_readonly=exclude_readonly) + is_multipart_file = False + try: + is_multipart_file = next( + rf for rf in self._attr_to_rest_field.values() if rf._rest_name == k + )._is_multipart_file + except StopIteration: + pass + result[k] = v if is_multipart_file else Model._as_dict_value(v, exclude_readonly=exclude_readonly) return result @staticmethod @@ -567,7 +580,7 @@ def _as_dict_value(v: typing.Any, exclude_readonly: bool = False) -> typing.Any: if v is None or isinstance(v, _Null): return None if isinstance(v, (list, tuple, set)): - return [Model._as_dict_value(x, exclude_readonly=exclude_readonly) for x in v] + return type(v)(Model._as_dict_value(x, exclude_readonly=exclude_readonly) for x in v) if isinstance(v, dict): return {dk: Model._as_dict_value(dv, exclude_readonly=exclude_readonly) for dk, dv in v.items()} return v.as_dict(exclude_readonly=exclude_readonly) if hasattr(v, "as_dict") else v @@ -762,6 +775,7 @@ def __init__( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, + is_multipart_file: bool = False, ): self._type = type self._rest_name_input = name @@ -771,6 +785,7 @@ def __init__( self._is_model = False self._default = default self._format = format + self._is_multipart_file = is_multipart_file @property def _rest_name(self) -> str: @@ -816,8 +831,11 @@ def rest_field( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, + is_multipart_file: bool = False, ) -> typing.Any: - return _RestField(name=name, type=type, visibility=visibility, default=default, format=format) + return _RestField( + name=name, type=type, visibility=visibility, default=default, format=format, is_multipart_file=is_multipart_file + ) def rest_discriminator( diff --git a/packages/typespec-python/test/unbranded/generated/special-headers-repeatability/specialheaders/repeatability/_model_base.py b/packages/typespec-python/test/unbranded/generated/special-headers-repeatability/specialheaders/repeatability/_model_base.py index d322088ee78..18fc4d77a91 100644 --- a/packages/typespec-python/test/unbranded/generated/special-headers-repeatability/specialheaders/repeatability/_model_base.py +++ b/packages/typespec-python/test/unbranded/generated/special-headers-repeatability/specialheaders/repeatability/_model_base.py @@ -462,7 +462,13 @@ def _get_rest_field( def _create_value(rf: typing.Optional["_RestField"], value: typing.Any) -> typing.Any: - return _deserialize(rf._type, value) if (rf and rf._is_model) else _serialize(value, rf._format if rf else None) + if not rf: + return _serialize(value, None) + if rf._is_multipart_file: + return value + if rf._is_model: + return _deserialize(rf._type, value) + return _serialize(value, rf._format) class Model(_MyMutableMapping): @@ -559,7 +565,14 @@ def as_dict(self, *, exclude_readonly: bool = False) -> typing.Dict[str, typing. for k, v in self.items(): if exclude_readonly and k in readonly_props: # pyright: ignore[reportUnboundVariable] continue - result[k] = Model._as_dict_value(v, exclude_readonly=exclude_readonly) + is_multipart_file = False + try: + is_multipart_file = next( + rf for rf in self._attr_to_rest_field.values() if rf._rest_name == k + )._is_multipart_file + except StopIteration: + pass + result[k] = v if is_multipart_file else Model._as_dict_value(v, exclude_readonly=exclude_readonly) return result @staticmethod @@ -567,7 +580,7 @@ def _as_dict_value(v: typing.Any, exclude_readonly: bool = False) -> typing.Any: if v is None or isinstance(v, _Null): return None if isinstance(v, (list, tuple, set)): - return [Model._as_dict_value(x, exclude_readonly=exclude_readonly) for x in v] + return type(v)(Model._as_dict_value(x, exclude_readonly=exclude_readonly) for x in v) if isinstance(v, dict): return {dk: Model._as_dict_value(dv, exclude_readonly=exclude_readonly) for dk, dv in v.items()} return v.as_dict(exclude_readonly=exclude_readonly) if hasattr(v, "as_dict") else v @@ -762,6 +775,7 @@ def __init__( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, + is_multipart_file: bool = False, ): self._type = type self._rest_name_input = name @@ -771,6 +785,7 @@ def __init__( self._is_model = False self._default = default self._format = format + self._is_multipart_file = is_multipart_file @property def _rest_name(self) -> str: @@ -816,8 +831,11 @@ def rest_field( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, + is_multipart_file: bool = False, ) -> typing.Any: - return _RestField(name=name, type=type, visibility=visibility, default=default, format=format) + return _RestField( + name=name, type=type, visibility=visibility, default=default, format=format, is_multipart_file=is_multipart_file + ) def rest_discriminator( diff --git a/packages/typespec-python/test/unbranded/generated/special-words/specialwords/_model_base.py b/packages/typespec-python/test/unbranded/generated/special-words/specialwords/_model_base.py index d322088ee78..18fc4d77a91 100644 --- a/packages/typespec-python/test/unbranded/generated/special-words/specialwords/_model_base.py +++ b/packages/typespec-python/test/unbranded/generated/special-words/specialwords/_model_base.py @@ -462,7 +462,13 @@ def _get_rest_field( def _create_value(rf: typing.Optional["_RestField"], value: typing.Any) -> typing.Any: - return _deserialize(rf._type, value) if (rf and rf._is_model) else _serialize(value, rf._format if rf else None) + if not rf: + return _serialize(value, None) + if rf._is_multipart_file: + return value + if rf._is_model: + return _deserialize(rf._type, value) + return _serialize(value, rf._format) class Model(_MyMutableMapping): @@ -559,7 +565,14 @@ def as_dict(self, *, exclude_readonly: bool = False) -> typing.Dict[str, typing. for k, v in self.items(): if exclude_readonly and k in readonly_props: # pyright: ignore[reportUnboundVariable] continue - result[k] = Model._as_dict_value(v, exclude_readonly=exclude_readonly) + is_multipart_file = False + try: + is_multipart_file = next( + rf for rf in self._attr_to_rest_field.values() if rf._rest_name == k + )._is_multipart_file + except StopIteration: + pass + result[k] = v if is_multipart_file else Model._as_dict_value(v, exclude_readonly=exclude_readonly) return result @staticmethod @@ -567,7 +580,7 @@ def _as_dict_value(v: typing.Any, exclude_readonly: bool = False) -> typing.Any: if v is None or isinstance(v, _Null): return None if isinstance(v, (list, tuple, set)): - return [Model._as_dict_value(x, exclude_readonly=exclude_readonly) for x in v] + return type(v)(Model._as_dict_value(x, exclude_readonly=exclude_readonly) for x in v) if isinstance(v, dict): return {dk: Model._as_dict_value(dv, exclude_readonly=exclude_readonly) for dk, dv in v.items()} return v.as_dict(exclude_readonly=exclude_readonly) if hasattr(v, "as_dict") else v @@ -762,6 +775,7 @@ def __init__( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, + is_multipart_file: bool = False, ): self._type = type self._rest_name_input = name @@ -771,6 +785,7 @@ def __init__( self._is_model = False self._default = default self._format = format + self._is_multipart_file = is_multipart_file @property def _rest_name(self) -> str: @@ -816,8 +831,11 @@ def rest_field( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, + is_multipart_file: bool = False, ) -> typing.Any: - return _RestField(name=name, type=type, visibility=visibility, default=default, format=format) + return _RestField( + name=name, type=type, visibility=visibility, default=default, format=format, is_multipart_file=is_multipart_file + ) def rest_discriminator( diff --git a/packages/typespec-python/test/unbranded/generated/typetest-array/typetest/array/_model_base.py b/packages/typespec-python/test/unbranded/generated/typetest-array/typetest/array/_model_base.py index d322088ee78..18fc4d77a91 100644 --- a/packages/typespec-python/test/unbranded/generated/typetest-array/typetest/array/_model_base.py +++ b/packages/typespec-python/test/unbranded/generated/typetest-array/typetest/array/_model_base.py @@ -462,7 +462,13 @@ def _get_rest_field( def _create_value(rf: typing.Optional["_RestField"], value: typing.Any) -> typing.Any: - return _deserialize(rf._type, value) if (rf and rf._is_model) else _serialize(value, rf._format if rf else None) + if not rf: + return _serialize(value, None) + if rf._is_multipart_file: + return value + if rf._is_model: + return _deserialize(rf._type, value) + return _serialize(value, rf._format) class Model(_MyMutableMapping): @@ -559,7 +565,14 @@ def as_dict(self, *, exclude_readonly: bool = False) -> typing.Dict[str, typing. for k, v in self.items(): if exclude_readonly and k in readonly_props: # pyright: ignore[reportUnboundVariable] continue - result[k] = Model._as_dict_value(v, exclude_readonly=exclude_readonly) + is_multipart_file = False + try: + is_multipart_file = next( + rf for rf in self._attr_to_rest_field.values() if rf._rest_name == k + )._is_multipart_file + except StopIteration: + pass + result[k] = v if is_multipart_file else Model._as_dict_value(v, exclude_readonly=exclude_readonly) return result @staticmethod @@ -567,7 +580,7 @@ def _as_dict_value(v: typing.Any, exclude_readonly: bool = False) -> typing.Any: if v is None or isinstance(v, _Null): return None if isinstance(v, (list, tuple, set)): - return [Model._as_dict_value(x, exclude_readonly=exclude_readonly) for x in v] + return type(v)(Model._as_dict_value(x, exclude_readonly=exclude_readonly) for x in v) if isinstance(v, dict): return {dk: Model._as_dict_value(dv, exclude_readonly=exclude_readonly) for dk, dv in v.items()} return v.as_dict(exclude_readonly=exclude_readonly) if hasattr(v, "as_dict") else v @@ -762,6 +775,7 @@ def __init__( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, + is_multipart_file: bool = False, ): self._type = type self._rest_name_input = name @@ -771,6 +785,7 @@ def __init__( self._is_model = False self._default = default self._format = format + self._is_multipart_file = is_multipart_file @property def _rest_name(self) -> str: @@ -816,8 +831,11 @@ def rest_field( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, + is_multipart_file: bool = False, ) -> typing.Any: - return _RestField(name=name, type=type, visibility=visibility, default=default, format=format) + return _RestField( + name=name, type=type, visibility=visibility, default=default, format=format, is_multipart_file=is_multipart_file + ) def rest_discriminator( diff --git a/packages/typespec-python/test/unbranded/generated/typetest-dictionary/typetest/dictionary/_model_base.py b/packages/typespec-python/test/unbranded/generated/typetest-dictionary/typetest/dictionary/_model_base.py index d322088ee78..18fc4d77a91 100644 --- a/packages/typespec-python/test/unbranded/generated/typetest-dictionary/typetest/dictionary/_model_base.py +++ b/packages/typespec-python/test/unbranded/generated/typetest-dictionary/typetest/dictionary/_model_base.py @@ -462,7 +462,13 @@ def _get_rest_field( def _create_value(rf: typing.Optional["_RestField"], value: typing.Any) -> typing.Any: - return _deserialize(rf._type, value) if (rf and rf._is_model) else _serialize(value, rf._format if rf else None) + if not rf: + return _serialize(value, None) + if rf._is_multipart_file: + return value + if rf._is_model: + return _deserialize(rf._type, value) + return _serialize(value, rf._format) class Model(_MyMutableMapping): @@ -559,7 +565,14 @@ def as_dict(self, *, exclude_readonly: bool = False) -> typing.Dict[str, typing. for k, v in self.items(): if exclude_readonly and k in readonly_props: # pyright: ignore[reportUnboundVariable] continue - result[k] = Model._as_dict_value(v, exclude_readonly=exclude_readonly) + is_multipart_file = False + try: + is_multipart_file = next( + rf for rf in self._attr_to_rest_field.values() if rf._rest_name == k + )._is_multipart_file + except StopIteration: + pass + result[k] = v if is_multipart_file else Model._as_dict_value(v, exclude_readonly=exclude_readonly) return result @staticmethod @@ -567,7 +580,7 @@ def _as_dict_value(v: typing.Any, exclude_readonly: bool = False) -> typing.Any: if v is None or isinstance(v, _Null): return None if isinstance(v, (list, tuple, set)): - return [Model._as_dict_value(x, exclude_readonly=exclude_readonly) for x in v] + return type(v)(Model._as_dict_value(x, exclude_readonly=exclude_readonly) for x in v) if isinstance(v, dict): return {dk: Model._as_dict_value(dv, exclude_readonly=exclude_readonly) for dk, dv in v.items()} return v.as_dict(exclude_readonly=exclude_readonly) if hasattr(v, "as_dict") else v @@ -762,6 +775,7 @@ def __init__( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, + is_multipart_file: bool = False, ): self._type = type self._rest_name_input = name @@ -771,6 +785,7 @@ def __init__( self._is_model = False self._default = default self._format = format + self._is_multipart_file = is_multipart_file @property def _rest_name(self) -> str: @@ -816,8 +831,11 @@ def rest_field( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, + is_multipart_file: bool = False, ) -> typing.Any: - return _RestField(name=name, type=type, visibility=visibility, default=default, format=format) + return _RestField( + name=name, type=type, visibility=visibility, default=default, format=format, is_multipart_file=is_multipart_file + ) def rest_discriminator( diff --git a/packages/typespec-python/test/unbranded/generated/typetest-enum-extensible/typetest/enum/extensible/_model_base.py b/packages/typespec-python/test/unbranded/generated/typetest-enum-extensible/typetest/enum/extensible/_model_base.py index d322088ee78..18fc4d77a91 100644 --- a/packages/typespec-python/test/unbranded/generated/typetest-enum-extensible/typetest/enum/extensible/_model_base.py +++ b/packages/typespec-python/test/unbranded/generated/typetest-enum-extensible/typetest/enum/extensible/_model_base.py @@ -462,7 +462,13 @@ def _get_rest_field( def _create_value(rf: typing.Optional["_RestField"], value: typing.Any) -> typing.Any: - return _deserialize(rf._type, value) if (rf and rf._is_model) else _serialize(value, rf._format if rf else None) + if not rf: + return _serialize(value, None) + if rf._is_multipart_file: + return value + if rf._is_model: + return _deserialize(rf._type, value) + return _serialize(value, rf._format) class Model(_MyMutableMapping): @@ -559,7 +565,14 @@ def as_dict(self, *, exclude_readonly: bool = False) -> typing.Dict[str, typing. for k, v in self.items(): if exclude_readonly and k in readonly_props: # pyright: ignore[reportUnboundVariable] continue - result[k] = Model._as_dict_value(v, exclude_readonly=exclude_readonly) + is_multipart_file = False + try: + is_multipart_file = next( + rf for rf in self._attr_to_rest_field.values() if rf._rest_name == k + )._is_multipart_file + except StopIteration: + pass + result[k] = v if is_multipart_file else Model._as_dict_value(v, exclude_readonly=exclude_readonly) return result @staticmethod @@ -567,7 +580,7 @@ def _as_dict_value(v: typing.Any, exclude_readonly: bool = False) -> typing.Any: if v is None or isinstance(v, _Null): return None if isinstance(v, (list, tuple, set)): - return [Model._as_dict_value(x, exclude_readonly=exclude_readonly) for x in v] + return type(v)(Model._as_dict_value(x, exclude_readonly=exclude_readonly) for x in v) if isinstance(v, dict): return {dk: Model._as_dict_value(dv, exclude_readonly=exclude_readonly) for dk, dv in v.items()} return v.as_dict(exclude_readonly=exclude_readonly) if hasattr(v, "as_dict") else v @@ -762,6 +775,7 @@ def __init__( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, + is_multipart_file: bool = False, ): self._type = type self._rest_name_input = name @@ -771,6 +785,7 @@ def __init__( self._is_model = False self._default = default self._format = format + self._is_multipart_file = is_multipart_file @property def _rest_name(self) -> str: @@ -816,8 +831,11 @@ def rest_field( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, + is_multipart_file: bool = False, ) -> typing.Any: - return _RestField(name=name, type=type, visibility=visibility, default=default, format=format) + return _RestField( + name=name, type=type, visibility=visibility, default=default, format=format, is_multipart_file=is_multipart_file + ) def rest_discriminator( diff --git a/packages/typespec-python/test/unbranded/generated/typetest-enum-fixed/typetest/enum/fixed/_model_base.py b/packages/typespec-python/test/unbranded/generated/typetest-enum-fixed/typetest/enum/fixed/_model_base.py index d322088ee78..18fc4d77a91 100644 --- a/packages/typespec-python/test/unbranded/generated/typetest-enum-fixed/typetest/enum/fixed/_model_base.py +++ b/packages/typespec-python/test/unbranded/generated/typetest-enum-fixed/typetest/enum/fixed/_model_base.py @@ -462,7 +462,13 @@ def _get_rest_field( def _create_value(rf: typing.Optional["_RestField"], value: typing.Any) -> typing.Any: - return _deserialize(rf._type, value) if (rf and rf._is_model) else _serialize(value, rf._format if rf else None) + if not rf: + return _serialize(value, None) + if rf._is_multipart_file: + return value + if rf._is_model: + return _deserialize(rf._type, value) + return _serialize(value, rf._format) class Model(_MyMutableMapping): @@ -559,7 +565,14 @@ def as_dict(self, *, exclude_readonly: bool = False) -> typing.Dict[str, typing. for k, v in self.items(): if exclude_readonly and k in readonly_props: # pyright: ignore[reportUnboundVariable] continue - result[k] = Model._as_dict_value(v, exclude_readonly=exclude_readonly) + is_multipart_file = False + try: + is_multipart_file = next( + rf for rf in self._attr_to_rest_field.values() if rf._rest_name == k + )._is_multipart_file + except StopIteration: + pass + result[k] = v if is_multipart_file else Model._as_dict_value(v, exclude_readonly=exclude_readonly) return result @staticmethod @@ -567,7 +580,7 @@ def _as_dict_value(v: typing.Any, exclude_readonly: bool = False) -> typing.Any: if v is None or isinstance(v, _Null): return None if isinstance(v, (list, tuple, set)): - return [Model._as_dict_value(x, exclude_readonly=exclude_readonly) for x in v] + return type(v)(Model._as_dict_value(x, exclude_readonly=exclude_readonly) for x in v) if isinstance(v, dict): return {dk: Model._as_dict_value(dv, exclude_readonly=exclude_readonly) for dk, dv in v.items()} return v.as_dict(exclude_readonly=exclude_readonly) if hasattr(v, "as_dict") else v @@ -762,6 +775,7 @@ def __init__( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, + is_multipart_file: bool = False, ): self._type = type self._rest_name_input = name @@ -771,6 +785,7 @@ def __init__( self._is_model = False self._default = default self._format = format + self._is_multipart_file = is_multipart_file @property def _rest_name(self) -> str: @@ -816,8 +831,11 @@ def rest_field( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, + is_multipart_file: bool = False, ) -> typing.Any: - return _RestField(name=name, type=type, visibility=visibility, default=default, format=format) + return _RestField( + name=name, type=type, visibility=visibility, default=default, format=format, is_multipart_file=is_multipart_file + ) def rest_discriminator( diff --git a/packages/typespec-python/test/unbranded/generated/typetest-model-empty/typetest/model/empty/_model_base.py b/packages/typespec-python/test/unbranded/generated/typetest-model-empty/typetest/model/empty/_model_base.py index d322088ee78..18fc4d77a91 100644 --- a/packages/typespec-python/test/unbranded/generated/typetest-model-empty/typetest/model/empty/_model_base.py +++ b/packages/typespec-python/test/unbranded/generated/typetest-model-empty/typetest/model/empty/_model_base.py @@ -462,7 +462,13 @@ def _get_rest_field( def _create_value(rf: typing.Optional["_RestField"], value: typing.Any) -> typing.Any: - return _deserialize(rf._type, value) if (rf and rf._is_model) else _serialize(value, rf._format if rf else None) + if not rf: + return _serialize(value, None) + if rf._is_multipart_file: + return value + if rf._is_model: + return _deserialize(rf._type, value) + return _serialize(value, rf._format) class Model(_MyMutableMapping): @@ -559,7 +565,14 @@ def as_dict(self, *, exclude_readonly: bool = False) -> typing.Dict[str, typing. for k, v in self.items(): if exclude_readonly and k in readonly_props: # pyright: ignore[reportUnboundVariable] continue - result[k] = Model._as_dict_value(v, exclude_readonly=exclude_readonly) + is_multipart_file = False + try: + is_multipart_file = next( + rf for rf in self._attr_to_rest_field.values() if rf._rest_name == k + )._is_multipart_file + except StopIteration: + pass + result[k] = v if is_multipart_file else Model._as_dict_value(v, exclude_readonly=exclude_readonly) return result @staticmethod @@ -567,7 +580,7 @@ def _as_dict_value(v: typing.Any, exclude_readonly: bool = False) -> typing.Any: if v is None or isinstance(v, _Null): return None if isinstance(v, (list, tuple, set)): - return [Model._as_dict_value(x, exclude_readonly=exclude_readonly) for x in v] + return type(v)(Model._as_dict_value(x, exclude_readonly=exclude_readonly) for x in v) if isinstance(v, dict): return {dk: Model._as_dict_value(dv, exclude_readonly=exclude_readonly) for dk, dv in v.items()} return v.as_dict(exclude_readonly=exclude_readonly) if hasattr(v, "as_dict") else v @@ -762,6 +775,7 @@ def __init__( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, + is_multipart_file: bool = False, ): self._type = type self._rest_name_input = name @@ -771,6 +785,7 @@ def __init__( self._is_model = False self._default = default self._format = format + self._is_multipart_file = is_multipart_file @property def _rest_name(self) -> str: @@ -816,8 +831,11 @@ def rest_field( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, + is_multipart_file: bool = False, ) -> typing.Any: - return _RestField(name=name, type=type, visibility=visibility, default=default, format=format) + return _RestField( + name=name, type=type, visibility=visibility, default=default, format=format, is_multipart_file=is_multipart_file + ) def rest_discriminator( diff --git a/packages/typespec-python/test/unbranded/generated/typetest-model-enumdiscriminator/typetest/model/enumdiscriminator/_model_base.py b/packages/typespec-python/test/unbranded/generated/typetest-model-enumdiscriminator/typetest/model/enumdiscriminator/_model_base.py index d322088ee78..18fc4d77a91 100644 --- a/packages/typespec-python/test/unbranded/generated/typetest-model-enumdiscriminator/typetest/model/enumdiscriminator/_model_base.py +++ b/packages/typespec-python/test/unbranded/generated/typetest-model-enumdiscriminator/typetest/model/enumdiscriminator/_model_base.py @@ -462,7 +462,13 @@ def _get_rest_field( def _create_value(rf: typing.Optional["_RestField"], value: typing.Any) -> typing.Any: - return _deserialize(rf._type, value) if (rf and rf._is_model) else _serialize(value, rf._format if rf else None) + if not rf: + return _serialize(value, None) + if rf._is_multipart_file: + return value + if rf._is_model: + return _deserialize(rf._type, value) + return _serialize(value, rf._format) class Model(_MyMutableMapping): @@ -559,7 +565,14 @@ def as_dict(self, *, exclude_readonly: bool = False) -> typing.Dict[str, typing. for k, v in self.items(): if exclude_readonly and k in readonly_props: # pyright: ignore[reportUnboundVariable] continue - result[k] = Model._as_dict_value(v, exclude_readonly=exclude_readonly) + is_multipart_file = False + try: + is_multipart_file = next( + rf for rf in self._attr_to_rest_field.values() if rf._rest_name == k + )._is_multipart_file + except StopIteration: + pass + result[k] = v if is_multipart_file else Model._as_dict_value(v, exclude_readonly=exclude_readonly) return result @staticmethod @@ -567,7 +580,7 @@ def _as_dict_value(v: typing.Any, exclude_readonly: bool = False) -> typing.Any: if v is None or isinstance(v, _Null): return None if isinstance(v, (list, tuple, set)): - return [Model._as_dict_value(x, exclude_readonly=exclude_readonly) for x in v] + return type(v)(Model._as_dict_value(x, exclude_readonly=exclude_readonly) for x in v) if isinstance(v, dict): return {dk: Model._as_dict_value(dv, exclude_readonly=exclude_readonly) for dk, dv in v.items()} return v.as_dict(exclude_readonly=exclude_readonly) if hasattr(v, "as_dict") else v @@ -762,6 +775,7 @@ def __init__( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, + is_multipart_file: bool = False, ): self._type = type self._rest_name_input = name @@ -771,6 +785,7 @@ def __init__( self._is_model = False self._default = default self._format = format + self._is_multipart_file = is_multipart_file @property def _rest_name(self) -> str: @@ -816,8 +831,11 @@ def rest_field( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, + is_multipart_file: bool = False, ) -> typing.Any: - return _RestField(name=name, type=type, visibility=visibility, default=default, format=format) + return _RestField( + name=name, type=type, visibility=visibility, default=default, format=format, is_multipart_file=is_multipart_file + ) def rest_discriminator( diff --git a/packages/typespec-python/test/unbranded/generated/typetest-model-nesteddiscriminator/typetest/model/nesteddiscriminator/_model_base.py b/packages/typespec-python/test/unbranded/generated/typetest-model-nesteddiscriminator/typetest/model/nesteddiscriminator/_model_base.py index d322088ee78..18fc4d77a91 100644 --- a/packages/typespec-python/test/unbranded/generated/typetest-model-nesteddiscriminator/typetest/model/nesteddiscriminator/_model_base.py +++ b/packages/typespec-python/test/unbranded/generated/typetest-model-nesteddiscriminator/typetest/model/nesteddiscriminator/_model_base.py @@ -462,7 +462,13 @@ def _get_rest_field( def _create_value(rf: typing.Optional["_RestField"], value: typing.Any) -> typing.Any: - return _deserialize(rf._type, value) if (rf and rf._is_model) else _serialize(value, rf._format if rf else None) + if not rf: + return _serialize(value, None) + if rf._is_multipart_file: + return value + if rf._is_model: + return _deserialize(rf._type, value) + return _serialize(value, rf._format) class Model(_MyMutableMapping): @@ -559,7 +565,14 @@ def as_dict(self, *, exclude_readonly: bool = False) -> typing.Dict[str, typing. for k, v in self.items(): if exclude_readonly and k in readonly_props: # pyright: ignore[reportUnboundVariable] continue - result[k] = Model._as_dict_value(v, exclude_readonly=exclude_readonly) + is_multipart_file = False + try: + is_multipart_file = next( + rf for rf in self._attr_to_rest_field.values() if rf._rest_name == k + )._is_multipart_file + except StopIteration: + pass + result[k] = v if is_multipart_file else Model._as_dict_value(v, exclude_readonly=exclude_readonly) return result @staticmethod @@ -567,7 +580,7 @@ def _as_dict_value(v: typing.Any, exclude_readonly: bool = False) -> typing.Any: if v is None or isinstance(v, _Null): return None if isinstance(v, (list, tuple, set)): - return [Model._as_dict_value(x, exclude_readonly=exclude_readonly) for x in v] + return type(v)(Model._as_dict_value(x, exclude_readonly=exclude_readonly) for x in v) if isinstance(v, dict): return {dk: Model._as_dict_value(dv, exclude_readonly=exclude_readonly) for dk, dv in v.items()} return v.as_dict(exclude_readonly=exclude_readonly) if hasattr(v, "as_dict") else v @@ -762,6 +775,7 @@ def __init__( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, + is_multipart_file: bool = False, ): self._type = type self._rest_name_input = name @@ -771,6 +785,7 @@ def __init__( self._is_model = False self._default = default self._format = format + self._is_multipart_file = is_multipart_file @property def _rest_name(self) -> str: @@ -816,8 +831,11 @@ def rest_field( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, + is_multipart_file: bool = False, ) -> typing.Any: - return _RestField(name=name, type=type, visibility=visibility, default=default, format=format) + return _RestField( + name=name, type=type, visibility=visibility, default=default, format=format, is_multipart_file=is_multipart_file + ) def rest_discriminator( diff --git a/packages/typespec-python/test/unbranded/generated/typetest-model-notdiscriminated/typetest/model/notdiscriminated/_model_base.py b/packages/typespec-python/test/unbranded/generated/typetest-model-notdiscriminated/typetest/model/notdiscriminated/_model_base.py index d322088ee78..18fc4d77a91 100644 --- a/packages/typespec-python/test/unbranded/generated/typetest-model-notdiscriminated/typetest/model/notdiscriminated/_model_base.py +++ b/packages/typespec-python/test/unbranded/generated/typetest-model-notdiscriminated/typetest/model/notdiscriminated/_model_base.py @@ -462,7 +462,13 @@ def _get_rest_field( def _create_value(rf: typing.Optional["_RestField"], value: typing.Any) -> typing.Any: - return _deserialize(rf._type, value) if (rf and rf._is_model) else _serialize(value, rf._format if rf else None) + if not rf: + return _serialize(value, None) + if rf._is_multipart_file: + return value + if rf._is_model: + return _deserialize(rf._type, value) + return _serialize(value, rf._format) class Model(_MyMutableMapping): @@ -559,7 +565,14 @@ def as_dict(self, *, exclude_readonly: bool = False) -> typing.Dict[str, typing. for k, v in self.items(): if exclude_readonly and k in readonly_props: # pyright: ignore[reportUnboundVariable] continue - result[k] = Model._as_dict_value(v, exclude_readonly=exclude_readonly) + is_multipart_file = False + try: + is_multipart_file = next( + rf for rf in self._attr_to_rest_field.values() if rf._rest_name == k + )._is_multipart_file + except StopIteration: + pass + result[k] = v if is_multipart_file else Model._as_dict_value(v, exclude_readonly=exclude_readonly) return result @staticmethod @@ -567,7 +580,7 @@ def _as_dict_value(v: typing.Any, exclude_readonly: bool = False) -> typing.Any: if v is None or isinstance(v, _Null): return None if isinstance(v, (list, tuple, set)): - return [Model._as_dict_value(x, exclude_readonly=exclude_readonly) for x in v] + return type(v)(Model._as_dict_value(x, exclude_readonly=exclude_readonly) for x in v) if isinstance(v, dict): return {dk: Model._as_dict_value(dv, exclude_readonly=exclude_readonly) for dk, dv in v.items()} return v.as_dict(exclude_readonly=exclude_readonly) if hasattr(v, "as_dict") else v @@ -762,6 +775,7 @@ def __init__( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, + is_multipart_file: bool = False, ): self._type = type self._rest_name_input = name @@ -771,6 +785,7 @@ def __init__( self._is_model = False self._default = default self._format = format + self._is_multipart_file = is_multipart_file @property def _rest_name(self) -> str: @@ -816,8 +831,11 @@ def rest_field( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, + is_multipart_file: bool = False, ) -> typing.Any: - return _RestField(name=name, type=type, visibility=visibility, default=default, format=format) + return _RestField( + name=name, type=type, visibility=visibility, default=default, format=format, is_multipart_file=is_multipart_file + ) def rest_discriminator( diff --git a/packages/typespec-python/test/unbranded/generated/typetest-model-recursive/typetest/model/recursive/_model_base.py b/packages/typespec-python/test/unbranded/generated/typetest-model-recursive/typetest/model/recursive/_model_base.py index d322088ee78..18fc4d77a91 100644 --- a/packages/typespec-python/test/unbranded/generated/typetest-model-recursive/typetest/model/recursive/_model_base.py +++ b/packages/typespec-python/test/unbranded/generated/typetest-model-recursive/typetest/model/recursive/_model_base.py @@ -462,7 +462,13 @@ def _get_rest_field( def _create_value(rf: typing.Optional["_RestField"], value: typing.Any) -> typing.Any: - return _deserialize(rf._type, value) if (rf and rf._is_model) else _serialize(value, rf._format if rf else None) + if not rf: + return _serialize(value, None) + if rf._is_multipart_file: + return value + if rf._is_model: + return _deserialize(rf._type, value) + return _serialize(value, rf._format) class Model(_MyMutableMapping): @@ -559,7 +565,14 @@ def as_dict(self, *, exclude_readonly: bool = False) -> typing.Dict[str, typing. for k, v in self.items(): if exclude_readonly and k in readonly_props: # pyright: ignore[reportUnboundVariable] continue - result[k] = Model._as_dict_value(v, exclude_readonly=exclude_readonly) + is_multipart_file = False + try: + is_multipart_file = next( + rf for rf in self._attr_to_rest_field.values() if rf._rest_name == k + )._is_multipart_file + except StopIteration: + pass + result[k] = v if is_multipart_file else Model._as_dict_value(v, exclude_readonly=exclude_readonly) return result @staticmethod @@ -567,7 +580,7 @@ def _as_dict_value(v: typing.Any, exclude_readonly: bool = False) -> typing.Any: if v is None or isinstance(v, _Null): return None if isinstance(v, (list, tuple, set)): - return [Model._as_dict_value(x, exclude_readonly=exclude_readonly) for x in v] + return type(v)(Model._as_dict_value(x, exclude_readonly=exclude_readonly) for x in v) if isinstance(v, dict): return {dk: Model._as_dict_value(dv, exclude_readonly=exclude_readonly) for dk, dv in v.items()} return v.as_dict(exclude_readonly=exclude_readonly) if hasattr(v, "as_dict") else v @@ -762,6 +775,7 @@ def __init__( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, + is_multipart_file: bool = False, ): self._type = type self._rest_name_input = name @@ -771,6 +785,7 @@ def __init__( self._is_model = False self._default = default self._format = format + self._is_multipart_file = is_multipart_file @property def _rest_name(self) -> str: @@ -816,8 +831,11 @@ def rest_field( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, + is_multipart_file: bool = False, ) -> typing.Any: - return _RestField(name=name, type=type, visibility=visibility, default=default, format=format) + return _RestField( + name=name, type=type, visibility=visibility, default=default, format=format, is_multipart_file=is_multipart_file + ) def rest_discriminator( diff --git a/packages/typespec-python/test/unbranded/generated/typetest-model-singlediscriminator/typetest/model/singlediscriminator/_model_base.py b/packages/typespec-python/test/unbranded/generated/typetest-model-singlediscriminator/typetest/model/singlediscriminator/_model_base.py index d322088ee78..18fc4d77a91 100644 --- a/packages/typespec-python/test/unbranded/generated/typetest-model-singlediscriminator/typetest/model/singlediscriminator/_model_base.py +++ b/packages/typespec-python/test/unbranded/generated/typetest-model-singlediscriminator/typetest/model/singlediscriminator/_model_base.py @@ -462,7 +462,13 @@ def _get_rest_field( def _create_value(rf: typing.Optional["_RestField"], value: typing.Any) -> typing.Any: - return _deserialize(rf._type, value) if (rf and rf._is_model) else _serialize(value, rf._format if rf else None) + if not rf: + return _serialize(value, None) + if rf._is_multipart_file: + return value + if rf._is_model: + return _deserialize(rf._type, value) + return _serialize(value, rf._format) class Model(_MyMutableMapping): @@ -559,7 +565,14 @@ def as_dict(self, *, exclude_readonly: bool = False) -> typing.Dict[str, typing. for k, v in self.items(): if exclude_readonly and k in readonly_props: # pyright: ignore[reportUnboundVariable] continue - result[k] = Model._as_dict_value(v, exclude_readonly=exclude_readonly) + is_multipart_file = False + try: + is_multipart_file = next( + rf for rf in self._attr_to_rest_field.values() if rf._rest_name == k + )._is_multipart_file + except StopIteration: + pass + result[k] = v if is_multipart_file else Model._as_dict_value(v, exclude_readonly=exclude_readonly) return result @staticmethod @@ -567,7 +580,7 @@ def _as_dict_value(v: typing.Any, exclude_readonly: bool = False) -> typing.Any: if v is None or isinstance(v, _Null): return None if isinstance(v, (list, tuple, set)): - return [Model._as_dict_value(x, exclude_readonly=exclude_readonly) for x in v] + return type(v)(Model._as_dict_value(x, exclude_readonly=exclude_readonly) for x in v) if isinstance(v, dict): return {dk: Model._as_dict_value(dv, exclude_readonly=exclude_readonly) for dk, dv in v.items()} return v.as_dict(exclude_readonly=exclude_readonly) if hasattr(v, "as_dict") else v @@ -762,6 +775,7 @@ def __init__( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, + is_multipart_file: bool = False, ): self._type = type self._rest_name_input = name @@ -771,6 +785,7 @@ def __init__( self._is_model = False self._default = default self._format = format + self._is_multipart_file = is_multipart_file @property def _rest_name(self) -> str: @@ -816,8 +831,11 @@ def rest_field( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, + is_multipart_file: bool = False, ) -> typing.Any: - return _RestField(name=name, type=type, visibility=visibility, default=default, format=format) + return _RestField( + name=name, type=type, visibility=visibility, default=default, format=format, is_multipart_file=is_multipart_file + ) def rest_discriminator( diff --git a/packages/typespec-python/test/unbranded/generated/typetest-model-usage/typetest/model/usage/_model_base.py b/packages/typespec-python/test/unbranded/generated/typetest-model-usage/typetest/model/usage/_model_base.py index d322088ee78..18fc4d77a91 100644 --- a/packages/typespec-python/test/unbranded/generated/typetest-model-usage/typetest/model/usage/_model_base.py +++ b/packages/typespec-python/test/unbranded/generated/typetest-model-usage/typetest/model/usage/_model_base.py @@ -462,7 +462,13 @@ def _get_rest_field( def _create_value(rf: typing.Optional["_RestField"], value: typing.Any) -> typing.Any: - return _deserialize(rf._type, value) if (rf and rf._is_model) else _serialize(value, rf._format if rf else None) + if not rf: + return _serialize(value, None) + if rf._is_multipart_file: + return value + if rf._is_model: + return _deserialize(rf._type, value) + return _serialize(value, rf._format) class Model(_MyMutableMapping): @@ -559,7 +565,14 @@ def as_dict(self, *, exclude_readonly: bool = False) -> typing.Dict[str, typing. for k, v in self.items(): if exclude_readonly and k in readonly_props: # pyright: ignore[reportUnboundVariable] continue - result[k] = Model._as_dict_value(v, exclude_readonly=exclude_readonly) + is_multipart_file = False + try: + is_multipart_file = next( + rf for rf in self._attr_to_rest_field.values() if rf._rest_name == k + )._is_multipart_file + except StopIteration: + pass + result[k] = v if is_multipart_file else Model._as_dict_value(v, exclude_readonly=exclude_readonly) return result @staticmethod @@ -567,7 +580,7 @@ def _as_dict_value(v: typing.Any, exclude_readonly: bool = False) -> typing.Any: if v is None or isinstance(v, _Null): return None if isinstance(v, (list, tuple, set)): - return [Model._as_dict_value(x, exclude_readonly=exclude_readonly) for x in v] + return type(v)(Model._as_dict_value(x, exclude_readonly=exclude_readonly) for x in v) if isinstance(v, dict): return {dk: Model._as_dict_value(dv, exclude_readonly=exclude_readonly) for dk, dv in v.items()} return v.as_dict(exclude_readonly=exclude_readonly) if hasattr(v, "as_dict") else v @@ -762,6 +775,7 @@ def __init__( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, + is_multipart_file: bool = False, ): self._type = type self._rest_name_input = name @@ -771,6 +785,7 @@ def __init__( self._is_model = False self._default = default self._format = format + self._is_multipart_file = is_multipart_file @property def _rest_name(self) -> str: @@ -816,8 +831,11 @@ def rest_field( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, + is_multipart_file: bool = False, ) -> typing.Any: - return _RestField(name=name, type=type, visibility=visibility, default=default, format=format) + return _RestField( + name=name, type=type, visibility=visibility, default=default, format=format, is_multipart_file=is_multipart_file + ) def rest_discriminator( diff --git a/packages/typespec-python/test/unbranded/generated/typetest-model-visibility/typetest/model/visibility/_model_base.py b/packages/typespec-python/test/unbranded/generated/typetest-model-visibility/typetest/model/visibility/_model_base.py index d322088ee78..18fc4d77a91 100644 --- a/packages/typespec-python/test/unbranded/generated/typetest-model-visibility/typetest/model/visibility/_model_base.py +++ b/packages/typespec-python/test/unbranded/generated/typetest-model-visibility/typetest/model/visibility/_model_base.py @@ -462,7 +462,13 @@ def _get_rest_field( def _create_value(rf: typing.Optional["_RestField"], value: typing.Any) -> typing.Any: - return _deserialize(rf._type, value) if (rf and rf._is_model) else _serialize(value, rf._format if rf else None) + if not rf: + return _serialize(value, None) + if rf._is_multipart_file: + return value + if rf._is_model: + return _deserialize(rf._type, value) + return _serialize(value, rf._format) class Model(_MyMutableMapping): @@ -559,7 +565,14 @@ def as_dict(self, *, exclude_readonly: bool = False) -> typing.Dict[str, typing. for k, v in self.items(): if exclude_readonly and k in readonly_props: # pyright: ignore[reportUnboundVariable] continue - result[k] = Model._as_dict_value(v, exclude_readonly=exclude_readonly) + is_multipart_file = False + try: + is_multipart_file = next( + rf for rf in self._attr_to_rest_field.values() if rf._rest_name == k + )._is_multipart_file + except StopIteration: + pass + result[k] = v if is_multipart_file else Model._as_dict_value(v, exclude_readonly=exclude_readonly) return result @staticmethod @@ -567,7 +580,7 @@ def _as_dict_value(v: typing.Any, exclude_readonly: bool = False) -> typing.Any: if v is None or isinstance(v, _Null): return None if isinstance(v, (list, tuple, set)): - return [Model._as_dict_value(x, exclude_readonly=exclude_readonly) for x in v] + return type(v)(Model._as_dict_value(x, exclude_readonly=exclude_readonly) for x in v) if isinstance(v, dict): return {dk: Model._as_dict_value(dv, exclude_readonly=exclude_readonly) for dk, dv in v.items()} return v.as_dict(exclude_readonly=exclude_readonly) if hasattr(v, "as_dict") else v @@ -762,6 +775,7 @@ def __init__( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, + is_multipart_file: bool = False, ): self._type = type self._rest_name_input = name @@ -771,6 +785,7 @@ def __init__( self._is_model = False self._default = default self._format = format + self._is_multipart_file = is_multipart_file @property def _rest_name(self) -> str: @@ -816,8 +831,11 @@ def rest_field( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, + is_multipart_file: bool = False, ) -> typing.Any: - return _RestField(name=name, type=type, visibility=visibility, default=default, format=format) + return _RestField( + name=name, type=type, visibility=visibility, default=default, format=format, is_multipart_file=is_multipart_file + ) def rest_discriminator( diff --git a/packages/typespec-python/test/unbranded/generated/typetest-property-additionalproperties/typetest/property/additionalproperties/_model_base.py b/packages/typespec-python/test/unbranded/generated/typetest-property-additionalproperties/typetest/property/additionalproperties/_model_base.py index d322088ee78..18fc4d77a91 100644 --- a/packages/typespec-python/test/unbranded/generated/typetest-property-additionalproperties/typetest/property/additionalproperties/_model_base.py +++ b/packages/typespec-python/test/unbranded/generated/typetest-property-additionalproperties/typetest/property/additionalproperties/_model_base.py @@ -462,7 +462,13 @@ def _get_rest_field( def _create_value(rf: typing.Optional["_RestField"], value: typing.Any) -> typing.Any: - return _deserialize(rf._type, value) if (rf and rf._is_model) else _serialize(value, rf._format if rf else None) + if not rf: + return _serialize(value, None) + if rf._is_multipart_file: + return value + if rf._is_model: + return _deserialize(rf._type, value) + return _serialize(value, rf._format) class Model(_MyMutableMapping): @@ -559,7 +565,14 @@ def as_dict(self, *, exclude_readonly: bool = False) -> typing.Dict[str, typing. for k, v in self.items(): if exclude_readonly and k in readonly_props: # pyright: ignore[reportUnboundVariable] continue - result[k] = Model._as_dict_value(v, exclude_readonly=exclude_readonly) + is_multipart_file = False + try: + is_multipart_file = next( + rf for rf in self._attr_to_rest_field.values() if rf._rest_name == k + )._is_multipart_file + except StopIteration: + pass + result[k] = v if is_multipart_file else Model._as_dict_value(v, exclude_readonly=exclude_readonly) return result @staticmethod @@ -567,7 +580,7 @@ def _as_dict_value(v: typing.Any, exclude_readonly: bool = False) -> typing.Any: if v is None or isinstance(v, _Null): return None if isinstance(v, (list, tuple, set)): - return [Model._as_dict_value(x, exclude_readonly=exclude_readonly) for x in v] + return type(v)(Model._as_dict_value(x, exclude_readonly=exclude_readonly) for x in v) if isinstance(v, dict): return {dk: Model._as_dict_value(dv, exclude_readonly=exclude_readonly) for dk, dv in v.items()} return v.as_dict(exclude_readonly=exclude_readonly) if hasattr(v, "as_dict") else v @@ -762,6 +775,7 @@ def __init__( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, + is_multipart_file: bool = False, ): self._type = type self._rest_name_input = name @@ -771,6 +785,7 @@ def __init__( self._is_model = False self._default = default self._format = format + self._is_multipart_file = is_multipart_file @property def _rest_name(self) -> str: @@ -816,8 +831,11 @@ def rest_field( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, + is_multipart_file: bool = False, ) -> typing.Any: - return _RestField(name=name, type=type, visibility=visibility, default=default, format=format) + return _RestField( + name=name, type=type, visibility=visibility, default=default, format=format, is_multipart_file=is_multipart_file + ) def rest_discriminator( diff --git a/packages/typespec-python/test/unbranded/generated/typetest-property-nullable/typetest/property/nullable/_model_base.py b/packages/typespec-python/test/unbranded/generated/typetest-property-nullable/typetest/property/nullable/_model_base.py index d322088ee78..18fc4d77a91 100644 --- a/packages/typespec-python/test/unbranded/generated/typetest-property-nullable/typetest/property/nullable/_model_base.py +++ b/packages/typespec-python/test/unbranded/generated/typetest-property-nullable/typetest/property/nullable/_model_base.py @@ -462,7 +462,13 @@ def _get_rest_field( def _create_value(rf: typing.Optional["_RestField"], value: typing.Any) -> typing.Any: - return _deserialize(rf._type, value) if (rf and rf._is_model) else _serialize(value, rf._format if rf else None) + if not rf: + return _serialize(value, None) + if rf._is_multipart_file: + return value + if rf._is_model: + return _deserialize(rf._type, value) + return _serialize(value, rf._format) class Model(_MyMutableMapping): @@ -559,7 +565,14 @@ def as_dict(self, *, exclude_readonly: bool = False) -> typing.Dict[str, typing. for k, v in self.items(): if exclude_readonly and k in readonly_props: # pyright: ignore[reportUnboundVariable] continue - result[k] = Model._as_dict_value(v, exclude_readonly=exclude_readonly) + is_multipart_file = False + try: + is_multipart_file = next( + rf for rf in self._attr_to_rest_field.values() if rf._rest_name == k + )._is_multipart_file + except StopIteration: + pass + result[k] = v if is_multipart_file else Model._as_dict_value(v, exclude_readonly=exclude_readonly) return result @staticmethod @@ -567,7 +580,7 @@ def _as_dict_value(v: typing.Any, exclude_readonly: bool = False) -> typing.Any: if v is None or isinstance(v, _Null): return None if isinstance(v, (list, tuple, set)): - return [Model._as_dict_value(x, exclude_readonly=exclude_readonly) for x in v] + return type(v)(Model._as_dict_value(x, exclude_readonly=exclude_readonly) for x in v) if isinstance(v, dict): return {dk: Model._as_dict_value(dv, exclude_readonly=exclude_readonly) for dk, dv in v.items()} return v.as_dict(exclude_readonly=exclude_readonly) if hasattr(v, "as_dict") else v @@ -762,6 +775,7 @@ def __init__( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, + is_multipart_file: bool = False, ): self._type = type self._rest_name_input = name @@ -771,6 +785,7 @@ def __init__( self._is_model = False self._default = default self._format = format + self._is_multipart_file = is_multipart_file @property def _rest_name(self) -> str: @@ -816,8 +831,11 @@ def rest_field( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, + is_multipart_file: bool = False, ) -> typing.Any: - return _RestField(name=name, type=type, visibility=visibility, default=default, format=format) + return _RestField( + name=name, type=type, visibility=visibility, default=default, format=format, is_multipart_file=is_multipart_file + ) def rest_discriminator( diff --git a/packages/typespec-python/test/unbranded/generated/typetest-property-optional/typetest/property/optional/_model_base.py b/packages/typespec-python/test/unbranded/generated/typetest-property-optional/typetest/property/optional/_model_base.py index d322088ee78..18fc4d77a91 100644 --- a/packages/typespec-python/test/unbranded/generated/typetest-property-optional/typetest/property/optional/_model_base.py +++ b/packages/typespec-python/test/unbranded/generated/typetest-property-optional/typetest/property/optional/_model_base.py @@ -462,7 +462,13 @@ def _get_rest_field( def _create_value(rf: typing.Optional["_RestField"], value: typing.Any) -> typing.Any: - return _deserialize(rf._type, value) if (rf and rf._is_model) else _serialize(value, rf._format if rf else None) + if not rf: + return _serialize(value, None) + if rf._is_multipart_file: + return value + if rf._is_model: + return _deserialize(rf._type, value) + return _serialize(value, rf._format) class Model(_MyMutableMapping): @@ -559,7 +565,14 @@ def as_dict(self, *, exclude_readonly: bool = False) -> typing.Dict[str, typing. for k, v in self.items(): if exclude_readonly and k in readonly_props: # pyright: ignore[reportUnboundVariable] continue - result[k] = Model._as_dict_value(v, exclude_readonly=exclude_readonly) + is_multipart_file = False + try: + is_multipart_file = next( + rf for rf in self._attr_to_rest_field.values() if rf._rest_name == k + )._is_multipart_file + except StopIteration: + pass + result[k] = v if is_multipart_file else Model._as_dict_value(v, exclude_readonly=exclude_readonly) return result @staticmethod @@ -567,7 +580,7 @@ def _as_dict_value(v: typing.Any, exclude_readonly: bool = False) -> typing.Any: if v is None or isinstance(v, _Null): return None if isinstance(v, (list, tuple, set)): - return [Model._as_dict_value(x, exclude_readonly=exclude_readonly) for x in v] + return type(v)(Model._as_dict_value(x, exclude_readonly=exclude_readonly) for x in v) if isinstance(v, dict): return {dk: Model._as_dict_value(dv, exclude_readonly=exclude_readonly) for dk, dv in v.items()} return v.as_dict(exclude_readonly=exclude_readonly) if hasattr(v, "as_dict") else v @@ -762,6 +775,7 @@ def __init__( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, + is_multipart_file: bool = False, ): self._type = type self._rest_name_input = name @@ -771,6 +785,7 @@ def __init__( self._is_model = False self._default = default self._format = format + self._is_multipart_file = is_multipart_file @property def _rest_name(self) -> str: @@ -816,8 +831,11 @@ def rest_field( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, + is_multipart_file: bool = False, ) -> typing.Any: - return _RestField(name=name, type=type, visibility=visibility, default=default, format=format) + return _RestField( + name=name, type=type, visibility=visibility, default=default, format=format, is_multipart_file=is_multipart_file + ) def rest_discriminator( diff --git a/packages/typespec-python/test/unbranded/generated/typetest-property-valuetypes/typetest/property/valuetypes/_model_base.py b/packages/typespec-python/test/unbranded/generated/typetest-property-valuetypes/typetest/property/valuetypes/_model_base.py index d322088ee78..18fc4d77a91 100644 --- a/packages/typespec-python/test/unbranded/generated/typetest-property-valuetypes/typetest/property/valuetypes/_model_base.py +++ b/packages/typespec-python/test/unbranded/generated/typetest-property-valuetypes/typetest/property/valuetypes/_model_base.py @@ -462,7 +462,13 @@ def _get_rest_field( def _create_value(rf: typing.Optional["_RestField"], value: typing.Any) -> typing.Any: - return _deserialize(rf._type, value) if (rf and rf._is_model) else _serialize(value, rf._format if rf else None) + if not rf: + return _serialize(value, None) + if rf._is_multipart_file: + return value + if rf._is_model: + return _deserialize(rf._type, value) + return _serialize(value, rf._format) class Model(_MyMutableMapping): @@ -559,7 +565,14 @@ def as_dict(self, *, exclude_readonly: bool = False) -> typing.Dict[str, typing. for k, v in self.items(): if exclude_readonly and k in readonly_props: # pyright: ignore[reportUnboundVariable] continue - result[k] = Model._as_dict_value(v, exclude_readonly=exclude_readonly) + is_multipart_file = False + try: + is_multipart_file = next( + rf for rf in self._attr_to_rest_field.values() if rf._rest_name == k + )._is_multipart_file + except StopIteration: + pass + result[k] = v if is_multipart_file else Model._as_dict_value(v, exclude_readonly=exclude_readonly) return result @staticmethod @@ -567,7 +580,7 @@ def _as_dict_value(v: typing.Any, exclude_readonly: bool = False) -> typing.Any: if v is None or isinstance(v, _Null): return None if isinstance(v, (list, tuple, set)): - return [Model._as_dict_value(x, exclude_readonly=exclude_readonly) for x in v] + return type(v)(Model._as_dict_value(x, exclude_readonly=exclude_readonly) for x in v) if isinstance(v, dict): return {dk: Model._as_dict_value(dv, exclude_readonly=exclude_readonly) for dk, dv in v.items()} return v.as_dict(exclude_readonly=exclude_readonly) if hasattr(v, "as_dict") else v @@ -762,6 +775,7 @@ def __init__( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, + is_multipart_file: bool = False, ): self._type = type self._rest_name_input = name @@ -771,6 +785,7 @@ def __init__( self._is_model = False self._default = default self._format = format + self._is_multipart_file = is_multipart_file @property def _rest_name(self) -> str: @@ -816,8 +831,11 @@ def rest_field( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, + is_multipart_file: bool = False, ) -> typing.Any: - return _RestField(name=name, type=type, visibility=visibility, default=default, format=format) + return _RestField( + name=name, type=type, visibility=visibility, default=default, format=format, is_multipart_file=is_multipart_file + ) def rest_discriminator( diff --git a/packages/typespec-python/test/unbranded/generated/typetest-scalar/typetest/scalar/_model_base.py b/packages/typespec-python/test/unbranded/generated/typetest-scalar/typetest/scalar/_model_base.py index d322088ee78..18fc4d77a91 100644 --- a/packages/typespec-python/test/unbranded/generated/typetest-scalar/typetest/scalar/_model_base.py +++ b/packages/typespec-python/test/unbranded/generated/typetest-scalar/typetest/scalar/_model_base.py @@ -462,7 +462,13 @@ def _get_rest_field( def _create_value(rf: typing.Optional["_RestField"], value: typing.Any) -> typing.Any: - return _deserialize(rf._type, value) if (rf and rf._is_model) else _serialize(value, rf._format if rf else None) + if not rf: + return _serialize(value, None) + if rf._is_multipart_file: + return value + if rf._is_model: + return _deserialize(rf._type, value) + return _serialize(value, rf._format) class Model(_MyMutableMapping): @@ -559,7 +565,14 @@ def as_dict(self, *, exclude_readonly: bool = False) -> typing.Dict[str, typing. for k, v in self.items(): if exclude_readonly and k in readonly_props: # pyright: ignore[reportUnboundVariable] continue - result[k] = Model._as_dict_value(v, exclude_readonly=exclude_readonly) + is_multipart_file = False + try: + is_multipart_file = next( + rf for rf in self._attr_to_rest_field.values() if rf._rest_name == k + )._is_multipart_file + except StopIteration: + pass + result[k] = v if is_multipart_file else Model._as_dict_value(v, exclude_readonly=exclude_readonly) return result @staticmethod @@ -567,7 +580,7 @@ def _as_dict_value(v: typing.Any, exclude_readonly: bool = False) -> typing.Any: if v is None or isinstance(v, _Null): return None if isinstance(v, (list, tuple, set)): - return [Model._as_dict_value(x, exclude_readonly=exclude_readonly) for x in v] + return type(v)(Model._as_dict_value(x, exclude_readonly=exclude_readonly) for x in v) if isinstance(v, dict): return {dk: Model._as_dict_value(dv, exclude_readonly=exclude_readonly) for dk, dv in v.items()} return v.as_dict(exclude_readonly=exclude_readonly) if hasattr(v, "as_dict") else v @@ -762,6 +775,7 @@ def __init__( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, + is_multipart_file: bool = False, ): self._type = type self._rest_name_input = name @@ -771,6 +785,7 @@ def __init__( self._is_model = False self._default = default self._format = format + self._is_multipart_file = is_multipart_file @property def _rest_name(self) -> str: @@ -816,8 +831,11 @@ def rest_field( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, + is_multipart_file: bool = False, ) -> typing.Any: - return _RestField(name=name, type=type, visibility=visibility, default=default, format=format) + return _RestField( + name=name, type=type, visibility=visibility, default=default, format=format, is_multipart_file=is_multipart_file + ) def rest_discriminator( diff --git a/packages/typespec-python/test/unbranded/generated/typetest-union/typetest/union/_model_base.py b/packages/typespec-python/test/unbranded/generated/typetest-union/typetest/union/_model_base.py index d322088ee78..18fc4d77a91 100644 --- a/packages/typespec-python/test/unbranded/generated/typetest-union/typetest/union/_model_base.py +++ b/packages/typespec-python/test/unbranded/generated/typetest-union/typetest/union/_model_base.py @@ -462,7 +462,13 @@ def _get_rest_field( def _create_value(rf: typing.Optional["_RestField"], value: typing.Any) -> typing.Any: - return _deserialize(rf._type, value) if (rf and rf._is_model) else _serialize(value, rf._format if rf else None) + if not rf: + return _serialize(value, None) + if rf._is_multipart_file: + return value + if rf._is_model: + return _deserialize(rf._type, value) + return _serialize(value, rf._format) class Model(_MyMutableMapping): @@ -559,7 +565,14 @@ def as_dict(self, *, exclude_readonly: bool = False) -> typing.Dict[str, typing. for k, v in self.items(): if exclude_readonly and k in readonly_props: # pyright: ignore[reportUnboundVariable] continue - result[k] = Model._as_dict_value(v, exclude_readonly=exclude_readonly) + is_multipart_file = False + try: + is_multipart_file = next( + rf for rf in self._attr_to_rest_field.values() if rf._rest_name == k + )._is_multipart_file + except StopIteration: + pass + result[k] = v if is_multipart_file else Model._as_dict_value(v, exclude_readonly=exclude_readonly) return result @staticmethod @@ -567,7 +580,7 @@ def _as_dict_value(v: typing.Any, exclude_readonly: bool = False) -> typing.Any: if v is None or isinstance(v, _Null): return None if isinstance(v, (list, tuple, set)): - return [Model._as_dict_value(x, exclude_readonly=exclude_readonly) for x in v] + return type(v)(Model._as_dict_value(x, exclude_readonly=exclude_readonly) for x in v) if isinstance(v, dict): return {dk: Model._as_dict_value(dv, exclude_readonly=exclude_readonly) for dk, dv in v.items()} return v.as_dict(exclude_readonly=exclude_readonly) if hasattr(v, "as_dict") else v @@ -762,6 +775,7 @@ def __init__( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, + is_multipart_file: bool = False, ): self._type = type self._rest_name_input = name @@ -771,6 +785,7 @@ def __init__( self._is_model = False self._default = default self._format = format + self._is_multipart_file = is_multipart_file @property def _rest_name(self) -> str: @@ -816,8 +831,11 @@ def rest_field( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, + is_multipart_file: bool = False, ) -> typing.Any: - return _RestField(name=name, type=type, visibility=visibility, default=default, format=format) + return _RestField( + name=name, type=type, visibility=visibility, default=default, format=format, is_multipart_file=is_multipart_file + ) def rest_discriminator( diff --git a/packages/typespec-python/test/unbranded/generated/typetest-union/typetest/union/aio/operations/_operations.py b/packages/typespec-python/test/unbranded/generated/typetest-union/typetest/union/aio/operations/_operations.py index b60e4219d02..c2781ab8276 100644 --- a/packages/typespec-python/test/unbranded/generated/typetest-union/typetest/union/aio/operations/_operations.py +++ b/packages/typespec-python/test/unbranded/generated/typetest-union/typetest/union/aio/operations/_operations.py @@ -9,7 +9,7 @@ from io import IOBase import json import sys -from typing import Any, Callable, Dict, IO, Literal, Optional, TYPE_CHECKING, TypeVar, Union, overload +from typing import Any, Callable, Dict, IO, Literal, Optional, TypeVar, Union, overload from corehttp.exceptions import ( ClientAuthenticationError, @@ -52,10 +52,6 @@ from collections.abc import MutableMapping else: from typing import MutableMapping # type: ignore # pylint: disable=ungrouped-imports - -if TYPE_CHECKING: - # pylint: disable=unused-import,ungrouped-imports - from ... import _types JSON = MutableMapping[str, Any] # pylint: disable=unsubscriptable-object _Unset: Any = object() T = TypeVar("T") @@ -518,8 +514,7 @@ async def get(self, **kwargs: Any) -> _models.GetResponse7: # response body for status code(s): 200 response == { - "prop": "str" # Required. Is one of the following types: str, Literal["b"], - Literal["c"] + "prop": "str" # Required. Known values are: "b" and "c". } """ error_map = { @@ -584,19 +579,22 @@ async def send( # pylint: disable=inconsistent-return-statements # JSON input template you can fill out and use as your body input. body = { - "prop": "str" # Required. Is one of the following types: str, Literal["b"], - Literal["c"] + "prop": "str" # Required. Known values are: "b" and "c". } """ @overload async def send( # pylint: disable=inconsistent-return-statements - self, *, prop: "_types.StringExtensibleNamedUnion", content_type: str = "application/json", **kwargs: Any + self, + *, + prop: Union[str, _models.StringExtensibleNamedUnion], + content_type: str = "application/json", + **kwargs: Any ) -> None: """send. - :keyword prop: Is one of the following types: str, Literal["b"], Literal["c"] Required. - :paramtype prop: str or str or str + :keyword prop: Known values are: "b" and "c". Required. + :paramtype prop: str or ~typetest.union.models.StringExtensibleNamedUnion :keyword content_type: Body Parameter content-type. Content type parameter for JSON body. Default value is "application/json". :paramtype content_type: str @@ -625,15 +623,15 @@ async def send( # pylint: disable=inconsistent-return-statements self, body: Union[JSON, IO[bytes]] = _Unset, *, - prop: "_types.StringExtensibleNamedUnion" = _Unset, + prop: Union[str, _models.StringExtensibleNamedUnion] = _Unset, **kwargs: Any ) -> None: """send. :param body: Is either a JSON type or a IO[bytes] type. Required. :type body: JSON or IO[bytes] - :keyword prop: Is one of the following types: str, Literal["b"], Literal["c"] Required. - :paramtype prop: str or str or str + :keyword prop: Known values are: "b" and "c". Required. + :paramtype prop: str or ~typetest.union.models.StringExtensibleNamedUnion :return: None :rtype: None :raises ~corehttp.exceptions.HttpResponseError: @@ -643,8 +641,7 @@ async def send( # pylint: disable=inconsistent-return-statements # JSON input template you can fill out and use as your body input. body = { - "prop": "str" # Required. Is one of the following types: str, Literal["b"], - Literal["c"] + "prop": "str" # Required. Known values are: "b" and "c". } """ error_map = { diff --git a/packages/typespec-python/test/unbranded/generated/typetest-union/typetest/union/models/__init__.py b/packages/typespec-python/test/unbranded/generated/typetest-union/typetest/union/models/__init__.py index 41878b14bf3..1f0f02f44ca 100644 --- a/packages/typespec-python/test/unbranded/generated/typetest-union/typetest/union/models/__init__.py +++ b/packages/typespec-python/test/unbranded/generated/typetest-union/typetest/union/models/__init__.py @@ -24,6 +24,7 @@ from ._models import StringAndArrayCases from ._enums import LR +from ._enums import StringExtensibleNamedUnion from ._enums import UD from ._patch import __all__ as _patch_all from ._patch import * # pylint: disable=unused-wildcard-import @@ -47,6 +48,7 @@ "MixedTypesCases", "StringAndArrayCases", "LR", + "StringExtensibleNamedUnion", "UD", ] __all__.extend([p for p in _patch_all if p not in __all__]) diff --git a/packages/typespec-python/test/unbranded/generated/typetest-union/typetest/union/models/_enums.py b/packages/typespec-python/test/unbranded/generated/typetest-union/typetest/union/models/_enums.py index c3a26e0a1c0..fcffe67a5ec 100644 --- a/packages/typespec-python/test/unbranded/generated/typetest-union/typetest/union/models/_enums.py +++ b/packages/typespec-python/test/unbranded/generated/typetest-union/typetest/union/models/_enums.py @@ -17,6 +17,13 @@ class LR(str, Enum, metaclass=CaseInsensitiveEnumMeta): RIGHT = "right" +class StringExtensibleNamedUnion(str, Enum, metaclass=CaseInsensitiveEnumMeta): + """Type of StringExtensibleNamedUnion.""" + + OPTION_B = "b" + C = "c" + + class UD(str, Enum, metaclass=CaseInsensitiveEnumMeta): """Type of UD.""" diff --git a/packages/typespec-python/test/unbranded/generated/typetest-union/typetest/union/models/_models.py b/packages/typespec-python/test/unbranded/generated/typetest-union/typetest/union/models/_models.py index b46fe32696a..862d2057096 100644 --- a/packages/typespec-python/test/unbranded/generated/typetest-union/typetest/union/models/_models.py +++ b/packages/typespec-python/test/unbranded/generated/typetest-union/typetest/union/models/_models.py @@ -20,7 +20,7 @@ if TYPE_CHECKING: # pylint: disable=unused-import,ungrouped-imports - from .. import _types, models as _models + from .. import models as _models JSON = MutableMapping[str, Any] # pylint: disable=unsubscriptable-object @@ -348,18 +348,18 @@ class GetResponse7(_model_base.Model): All required parameters must be populated in order to send to server. - :ivar prop: Required. Is one of the following types: str, Literal["b"], Literal["c"] - :vartype prop: str or str or str + :ivar prop: Required. Known values are: "b" and "c". + :vartype prop: str or ~typetest.union.models.StringExtensibleNamedUnion """ - prop: "_types.StringExtensibleNamedUnion" = rest_field() - """Required. Is one of the following types: str, Literal[\"b\"], Literal[\"c\"]""" + prop: Union[str, "_models.StringExtensibleNamedUnion"] = rest_field() + """Required. Known values are: \"b\" and \"c\".""" @overload def __init__( self, *, - prop: "_types.StringExtensibleNamedUnion", + prop: Union[str, "_models.StringExtensibleNamedUnion"], ): ... diff --git a/packages/typespec-python/test/unbranded/generated/typetest-union/typetest/union/operations/_operations.py b/packages/typespec-python/test/unbranded/generated/typetest-union/typetest/union/operations/_operations.py index c51a286461f..faccfc1f13a 100644 --- a/packages/typespec-python/test/unbranded/generated/typetest-union/typetest/union/operations/_operations.py +++ b/packages/typespec-python/test/unbranded/generated/typetest-union/typetest/union/operations/_operations.py @@ -9,7 +9,7 @@ from io import IOBase import json import sys -from typing import Any, Callable, Dict, IO, Literal, Optional, TYPE_CHECKING, TypeVar, Union, overload +from typing import Any, Callable, Dict, IO, Literal, Optional, TypeVar, Union, overload from corehttp.exceptions import ( ClientAuthenticationError, @@ -31,10 +31,6 @@ from collections.abc import MutableMapping else: from typing import MutableMapping # type: ignore # pylint: disable=ungrouped-imports - -if TYPE_CHECKING: - # pylint: disable=unused-import,ungrouped-imports - from .. import _types JSON = MutableMapping[str, Any] # pylint: disable=unsubscriptable-object _Unset: Any = object() T = TypeVar("T") @@ -780,8 +776,7 @@ def get(self, **kwargs: Any) -> _models.GetResponse7: # response body for status code(s): 200 response == { - "prop": "str" # Required. Is one of the following types: str, Literal["b"], - Literal["c"] + "prop": "str" # Required. Known values are: "b" and "c". } """ error_map = { @@ -846,19 +841,22 @@ def send( # pylint: disable=inconsistent-return-statements # JSON input template you can fill out and use as your body input. body = { - "prop": "str" # Required. Is one of the following types: str, Literal["b"], - Literal["c"] + "prop": "str" # Required. Known values are: "b" and "c". } """ @overload def send( # pylint: disable=inconsistent-return-statements - self, *, prop: "_types.StringExtensibleNamedUnion", content_type: str = "application/json", **kwargs: Any + self, + *, + prop: Union[str, _models.StringExtensibleNamedUnion], + content_type: str = "application/json", + **kwargs: Any ) -> None: """send. - :keyword prop: Is one of the following types: str, Literal["b"], Literal["c"] Required. - :paramtype prop: str or str or str + :keyword prop: Known values are: "b" and "c". Required. + :paramtype prop: str or ~typetest.union.models.StringExtensibleNamedUnion :keyword content_type: Body Parameter content-type. Content type parameter for JSON body. Default value is "application/json". :paramtype content_type: str @@ -887,15 +885,15 @@ def send( # pylint: disable=inconsistent-return-statements self, body: Union[JSON, IO[bytes]] = _Unset, *, - prop: "_types.StringExtensibleNamedUnion" = _Unset, + prop: Union[str, _models.StringExtensibleNamedUnion] = _Unset, **kwargs: Any ) -> None: """send. :param body: Is either a JSON type or a IO[bytes] type. Required. :type body: JSON or IO[bytes] - :keyword prop: Is one of the following types: str, Literal["b"], Literal["c"] Required. - :paramtype prop: str or str or str + :keyword prop: Known values are: "b" and "c". Required. + :paramtype prop: str or ~typetest.union.models.StringExtensibleNamedUnion :return: None :rtype: None :raises ~corehttp.exceptions.HttpResponseError: @@ -905,8 +903,7 @@ def send( # pylint: disable=inconsistent-return-statements # JSON input template you can fill out and use as your body input. body = { - "prop": "str" # Required. Is one of the following types: str, Literal["b"], - Literal["c"] + "prop": "str" # Required. Known values are: "b" and "c". } """ error_map = { diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index e997128d1df..a2917766faf 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -74,8 +74,8 @@ importers: specifier: '>=0.38.0 <1.0.0' version: 0.38.0(@azure-tools/typespec-autorest@0.38.0)(@azure-tools/typespec-azure-core@0.38.0)(@typespec/compiler@0.52.0)(@typespec/http@0.52.0)(@typespec/openapi@0.52.0)(@typespec/rest@0.52.0)(@typespec/versioning@0.52.0) '@azure-tools/typespec-client-generator-core': - specifier: 0.39.0-dev.2 - version: 0.39.0-dev.2(@typespec/compiler@0.52.0)(@typespec/http@0.52.0)(@typespec/rest@0.52.0)(@typespec/versioning@0.52.0) + specifier: 0.39.0-dev.3 + version: 0.39.0-dev.3(@typespec/compiler@0.52.0)(@typespec/http@0.52.0)(@typespec/rest@0.52.0)(@typespec/versioning@0.52.0) '@types/js-yaml': specifier: ~4.0.5 version: 4.0.5 @@ -364,8 +364,8 @@ packages: '@typespec/versioning': 0.52.0(@typespec/compiler@0.52.0) dev: true - /@azure-tools/typespec-client-generator-core@0.39.0-dev.2(@typespec/compiler@0.52.0)(@typespec/http@0.52.0)(@typespec/rest@0.52.0)(@typespec/versioning@0.52.0): - resolution: {integrity: sha512-lYjtAKYa82O6VlsSqxbbJ3IPHwe/alWnI57Dbx7KYJjqeEnmk+6aZG9amRTAYGm6EiqVAQnxG6DDW947kZlsIQ==} + /@azure-tools/typespec-client-generator-core@0.39.0-dev.3(@typespec/compiler@0.52.0)(@typespec/http@0.52.0)(@typespec/rest@0.52.0)(@typespec/versioning@0.52.0): + resolution: {integrity: sha512-D61bQ08hZTa7ddznGAbrKj3Npztdx8vWYRMeta1RefBp/eQeRVOI/2H54gN5OMOMKNwe29jM1mHlWBXM+jF+zg==} engines: {node: '>=18.0.0'} peerDependencies: '@typespec/compiler': ~0.52.0 || >=0.53.0-dev <0.53.0 From 9c4db12106364cb6683375494a57c7cec8aadaa8 Mon Sep 17 00:00:00 2001 From: iscai-msft Date: Wed, 31 Jan 2024 20:12:42 -0500 Subject: [PATCH 15/45] update to dev 4 version --- .../autorest.python/autorest/m4reformatter/__init__.py | 7 +++++-- packages/typespec-python/package.json | 4 ++-- packages/typespec-python/src/types.ts | 7 +++++-- pnpm-lock.yaml | 8 ++++---- 4 files changed, 16 insertions(+), 10 deletions(-) diff --git a/packages/autorest.python/autorest/m4reformatter/__init__.py b/packages/autorest.python/autorest/m4reformatter/__init__.py index 5636fd85457..a37d152cfbc 100644 --- a/packages/autorest.python/autorest/m4reformatter/__init__.py +++ b/packages/autorest.python/autorest/m4reformatter/__init__.py @@ -524,8 +524,11 @@ def _update_operation_helper( body_parameter["type"]["type"] == "combined" if body_parameter else False ) abstract = False - if body_parameter and len(body_parameter["type"].get("types", [])) > 2: - # this means there are more than 2 types of body + if body_parameter and ( + body_parameter.get("entries") + or len(body_parameter["type"].get("types", [])) > 2 + ): + # this means it's formdata or urlencoded, or there are more than 2 types of body abstract = True return { "name": yaml_data["language"]["default"]["name"], diff --git a/packages/typespec-python/package.json b/packages/typespec-python/package.json index ad872751183..65e3aff1351 100644 --- a/packages/typespec-python/package.json +++ b/packages/typespec-python/package.json @@ -43,7 +43,7 @@ ], "peerDependencies": { "@azure-tools/typespec-azure-core": ">=0.38.0 <1.0.0", - "@azure-tools/typespec-client-generator-core": "0.39.0-dev.3", + "@azure-tools/typespec-client-generator-core": "0.39.0-dev.4", "@typespec/compiler": ">=0.52.0 <1.0.0", "@typespec/http": ">=0.52.0 <1.0.0", "@typespec/rest": ">=0.52.0 <1.0.0", @@ -74,7 +74,7 @@ "rimraf": "~5.0.0", "typescript": "~5.1.3", "@azure-tools/typespec-azure-core": "~0.38.0", - "@azure-tools/typespec-client-generator-core": "0.39.0-dev.3", + "@azure-tools/typespec-client-generator-core": "0.39.0-dev.4", "@typespec/compiler": "~0.52.0", "@typespec/http": "~0.52.0", "@typespec/rest": "~0.52.0", diff --git a/packages/typespec-python/src/types.ts b/packages/typespec-python/src/types.ts index a939b176786..e9fb23adc36 100644 --- a/packages/typespec-python/src/types.ts +++ b/packages/typespec-python/src/types.ts @@ -86,7 +86,6 @@ export function getType( case "enumvalue": return emitEnumMember(type, emitEnum(type.enumType)); case "bytes": - case "multipartFile": case "boolean": case "date": case "time": @@ -196,10 +195,14 @@ function visibilityMapping(visibility?: Visibility[]): string[] | undefined { } function emitProperty(context: SdkContext, type: SdkBodyModelPropertyType): Record { + const propertyType = getType(context, type.type); + if (type.isMultipartFileInput) { + propertyType.type = "multipartFile"; + } return { clientName: camelToSnakeCase(type.nameInClient), wireName: type.serializedName, - type: getType(context, type.type), + type: propertyType, optional: type.optional, description: type.description, addedOn: type.apiVersions[0], diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index a2917766faf..c15ca6df168 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -74,8 +74,8 @@ importers: specifier: '>=0.38.0 <1.0.0' version: 0.38.0(@azure-tools/typespec-autorest@0.38.0)(@azure-tools/typespec-azure-core@0.38.0)(@typespec/compiler@0.52.0)(@typespec/http@0.52.0)(@typespec/openapi@0.52.0)(@typespec/rest@0.52.0)(@typespec/versioning@0.52.0) '@azure-tools/typespec-client-generator-core': - specifier: 0.39.0-dev.3 - version: 0.39.0-dev.3(@typespec/compiler@0.52.0)(@typespec/http@0.52.0)(@typespec/rest@0.52.0)(@typespec/versioning@0.52.0) + specifier: 0.39.0-dev.4 + version: 0.39.0-dev.4(@typespec/compiler@0.52.0)(@typespec/http@0.52.0)(@typespec/rest@0.52.0)(@typespec/versioning@0.52.0) '@types/js-yaml': specifier: ~4.0.5 version: 4.0.5 @@ -364,8 +364,8 @@ packages: '@typespec/versioning': 0.52.0(@typespec/compiler@0.52.0) dev: true - /@azure-tools/typespec-client-generator-core@0.39.0-dev.3(@typespec/compiler@0.52.0)(@typespec/http@0.52.0)(@typespec/rest@0.52.0)(@typespec/versioning@0.52.0): - resolution: {integrity: sha512-D61bQ08hZTa7ddznGAbrKj3Npztdx8vWYRMeta1RefBp/eQeRVOI/2H54gN5OMOMKNwe29jM1mHlWBXM+jF+zg==} + /@azure-tools/typespec-client-generator-core@0.39.0-dev.4(@typespec/compiler@0.52.0)(@typespec/http@0.52.0)(@typespec/rest@0.52.0)(@typespec/versioning@0.52.0): + resolution: {integrity: sha512-SonleUQ8vd68bW0D9PFmdKOcB0divOz6Q3vtngZm3pBIyfa3Rm8Qxs9jKavgnVQGby08lfJC2zf1ekBx3zSMVA==} engines: {node: '>=18.0.0'} peerDependencies: '@typespec/compiler': ~0.52.0 || >=0.53.0-dev <0.53.0 From 445d4a3ca723f1322d030a08ec120af04564459e Mon Sep 17 00:00:00 2001 From: iscai-msft Date: Wed, 31 Jan 2024 21:26:24 -0500 Subject: [PATCH 16/45] use dev.5 --- .../autorest/codegen/models/__init__.py | 2 - .../autorest/codegen/models/base.py | 2 +- .../autorest/codegen/models/combined_type.py | 2 +- .../autorest/codegen/models/constant_type.py | 4 -- .../autorest/codegen/models/list_type.py | 4 -- .../autorest/codegen/models/model_type.py | 2 +- .../autorest/codegen/models/parameter.py | 2 +- .../codegen/models/primitive_types.py | 33 --------------- .../autorest/codegen/models/property.py | 19 +++++---- .../codegen/serializers/builder_serializer.py | 3 +- .../codegen/serializers/model_serializer.py | 7 ++-- .../codegen/templates/model_base.py.jinja2 | 14 +++---- packages/typespec-python/package.json | 4 +- packages/typespec-python/src/types.ts | 7 +--- pnpm-lock.yaml | 41 ++++++++++--------- 15 files changed, 52 insertions(+), 94 deletions(-) diff --git a/packages/autorest.python/autorest/codegen/models/__init__.py b/packages/autorest.python/autorest/codegen/models/__init__.py index a7e4af664a6..0e1d228e02c 100644 --- a/packages/autorest.python/autorest/codegen/models/__init__.py +++ b/packages/autorest.python/autorest/codegen/models/__init__.py @@ -20,7 +20,6 @@ DurationType, IntegerType, FloatType, - MultipartFileType, StringType, TimeType, AnyType, @@ -149,7 +148,6 @@ "unixtime": UnixTimeType, "credential": StringType, "sdkcore": SdkCoreType, - "multipartFile": MultipartFileType } _LOGGER = logging.getLogger(__name__) diff --git a/packages/autorest.python/autorest/codegen/models/base.py b/packages/autorest.python/autorest/codegen/models/base.py index 1fefc0f1cac..01b4fa2b264 100644 --- a/packages/autorest.python/autorest/codegen/models/base.py +++ b/packages/autorest.python/autorest/codegen/models/base.py @@ -188,5 +188,5 @@ def type_description(self) -> str: return self.type_annotation() @property - def is_multipart_file(self) -> bool: + def is_form_data(self) -> bool: return False diff --git a/packages/autorest.python/autorest/codegen/models/combined_type.py b/packages/autorest.python/autorest/codegen/models/combined_type.py index f50766e598a..9bb239fb17b 100644 --- a/packages/autorest.python/autorest/codegen/models/combined_type.py +++ b/packages/autorest.python/autorest/codegen/models/combined_type.py @@ -81,7 +81,7 @@ def type_definition(self, **kwargs: Any) -> str: @property def is_form_data(self) -> bool: - return any(t.type == "model" and t.is_form_data for t in self.types) + return any(t.is_form_data for t in self.types) def get_json_template_representation( self, diff --git a/packages/autorest.python/autorest/codegen/models/constant_type.py b/packages/autorest.python/autorest/codegen/models/constant_type.py index eef567fcc60..afcb304e6db 100644 --- a/packages/autorest.python/autorest/codegen/models/constant_type.py +++ b/packages/autorest.python/autorest/codegen/models/constant_type.py @@ -37,10 +37,6 @@ def __init__( self.value_type = value_type self.value = value - @property - def is_multipart_file(self) -> bool: - return self.value_type.is_multipart_file - def get_declaration(self, value=None): if value and value != self.value: _LOGGER.warning( diff --git a/packages/autorest.python/autorest/codegen/models/list_type.py b/packages/autorest.python/autorest/codegen/models/list_type.py index 9395e3d617f..ad477f10e4a 100644 --- a/packages/autorest.python/autorest/codegen/models/list_type.py +++ b/packages/autorest.python/autorest/codegen/models/list_type.py @@ -25,10 +25,6 @@ def __init__( self.min_items: Optional[int] = yaml_data.get("minItems") self.unique_items: bool = yaml_data.get("uniqueItems", False) - @property - def is_multipart_file(self) -> bool: - return self.element_type.is_multipart_file - @property def encode(self) -> Optional[str]: return self.element_type.encode if hasattr(self.element_type, "encode") else None # type: ignore diff --git a/packages/autorest.python/autorest/codegen/models/model_type.py b/packages/autorest.python/autorest/codegen/models/model_type.py index ba298cdd1a6..506063a3ad4 100644 --- a/packages/autorest.python/autorest/codegen/models/model_type.py +++ b/packages/autorest.python/autorest/codegen/models/model_type.py @@ -78,7 +78,7 @@ def __init__( @property def is_form_data(self) -> bool: - return any(p.is_multipart_file for p in self.properties) + return any(p.is_multipart_file_input for p in self.properties) @property def is_xml(self) -> bool: diff --git a/packages/autorest.python/autorest/codegen/models/parameter.py b/packages/autorest.python/autorest/codegen/models/parameter.py index 054008334de..22bec5078ac 100644 --- a/packages/autorest.python/autorest/codegen/models/parameter.py +++ b/packages/autorest.python/autorest/codegen/models/parameter.py @@ -247,7 +247,7 @@ class BodyParameter(_ParameterBase): @property def is_form_data(self) -> bool: - return self.type.type == "model" and self.type.is_form_data + return self.type.is_form_data @property def is_partial_body(self) -> bool: diff --git a/packages/autorest.python/autorest/codegen/models/primitive_types.py b/packages/autorest.python/autorest/codegen/models/primitive_types.py index b0f0eaf915b..3b265e634d3 100644 --- a/packages/autorest.python/autorest/codegen/models/primitive_types.py +++ b/packages/autorest.python/autorest/codegen/models/primitive_types.py @@ -81,39 +81,6 @@ def docstring_type(self, **kwargs: Any) -> str: def instance_check_template(self) -> str: return "isinstance({}, bool)" -class MultipartFileType(PrimitiveType): - def __init__(self, yaml_data: Dict[str, Any], code_model: "CodeModel") -> None: - super().__init__(yaml_data=yaml_data, code_model=code_model) - self.type = "FileType" - - def imports(self, **kwargs: Any) -> FileImport: - file_import = FileImport(self.code_model) - file_import.add_submodule_import(".._vendor", "FileType", ImportType.STDLIB) - return file_import - - @property - def is_multipart_file(self) -> bool: - return True - - @property - def instance_check_template(self) -> str: - return "isinstance({}, FileType)" - - @property - def serialization_type(self) -> str: - return "filetype" - - def docstring_type(self, **kwargs: Any) -> str: - return "filetype" - - def type_annotation(self, **kwargs: Any) -> str: - return "FileType" - - @property - def default_template_representation_declaration(self) -> str: - return self.get_declaration("FileInputType") - - class BinaryType(PrimitiveType): def __init__(self, yaml_data: Dict[str, Any], code_model: "CodeModel") -> None: super().__init__(yaml_data=yaml_data, code_model=code_model) diff --git a/packages/autorest.python/autorest/codegen/models/property.py b/packages/autorest.python/autorest/codegen/models/property.py index ed35f5a796a..3de87054560 100644 --- a/packages/autorest.python/autorest/codegen/models/property.py +++ b/packages/autorest.python/autorest/codegen/models/property.py @@ -37,6 +37,7 @@ def __init__( if self.client_default_value is None: self.client_default_value = self.type.client_default_value self.flattened_names: List[str] = yaml_data.get("flattenedNames", []) + self.is_multipart_file_input: bool = yaml_data.get("isMultipartFileInput", False) @property def pylint_disable(self) -> str: @@ -94,6 +95,11 @@ def is_enum_discriminator(self) -> bool: return self.is_discriminator and self.type.type == "enum" def type_annotation(self, *, is_operation_file: bool = False) -> str: + if self.is_multipart_file_input: + # we only support FileType or list of FileType + if self.type.type == "list": + return "List[FileType]" + return "FileType" if self.is_enum_discriminator: # here we are the enum discriminator property on the base model return "Literal[None]" @@ -114,6 +120,8 @@ def get_json_template_representation( client_default_value_declaration: Optional[str] = None, description: Optional[str] = None, ) -> Any: + if self.is_multipart_file_input: + return "[filetype]" if self.type.type == "list" else "filetype" if self.client_default_value: client_default_value_declaration = self.get_declaration( self.client_default_value @@ -161,16 +169,9 @@ def imports(self, **kwargs) -> FileImport: "rest_discriminator" if self.is_discriminator else "rest_field", ImportType.LOCAL, ) + if self.is_multipart_file_input: + file_import.add_submodule_import(".._vendor", "FileType", ImportType.LOCAL) return file_import - - @property - def is_multipart_file(self) -> bool: - """ - We need to check if the type is a model because this could cause infinite recursion. - The only file values that we consider is either a single mutlipart file type, or a list - of them, so there's no need to check for models - """ - return self.type != "model" and self.type.is_multipart_file # this prevents infinite recursion f @classmethod def from_yaml( diff --git a/packages/autorest.python/autorest/codegen/serializers/builder_serializer.py b/packages/autorest.python/autorest/codegen/serializers/builder_serializer.py index 5b78b6f7982..8a6c2c4567b 100644 --- a/packages/autorest.python/autorest/codegen/serializers/builder_serializer.py +++ b/packages/autorest.python/autorest/codegen/serializers/builder_serializer.py @@ -33,7 +33,6 @@ DPGModelType, ParameterListType, ByteArraySchema, - MultipartFileType, ) from .parameter_serializer import ParameterSerializer, PopKwargType from ..models.parameter_list import ParameterType @@ -750,7 +749,7 @@ def _serialize_body_parameter(self, builder: OperationType) -> List[str]: for prop in model_type.properties: prop_access = f'_body["{prop.wire_name}"]' retval.append(f'if _body.get("{prop.wire_name}") is not None:') - if prop.is_multipart_file: + if prop.is_multipart_file_input: if isinstance(prop.type, ListType): retval.append(f' _files.extend([("{prop.wire_name}", {prop.wire_name[0]}) for {prop.wire_name[0]} in {prop_access}])') else: diff --git a/packages/autorest.python/autorest/codegen/serializers/model_serializer.py b/packages/autorest.python/autorest/codegen/serializers/model_serializer.py index 5b68366ea91..d143ff16793 100644 --- a/packages/autorest.python/autorest/codegen/serializers/model_serializer.py +++ b/packages/autorest.python/autorest/codegen/serializers/model_serializer.py @@ -257,10 +257,11 @@ def declare_property(prop: Property) -> str: args.append(f"visibility=[{v_list}]") if prop.client_default_value is not None: args.append(f"default={prop.client_default_value_declaration}") - if hasattr(prop.type, "encode") and prop.type.encode: # type: ignore + + if prop.is_multipart_file_input: + args.append("is_multipart_file_input=True") + elif hasattr(prop.type, "encode") and prop.type.encode: # type: ignore args.append(f'format="{prop.type.encode}"') # type: ignore - if prop.is_multipart_file: - args.append("is_multipart_file=True") field = "rest_discriminator" if prop.is_discriminator else "rest_field" type_ignore = ( diff --git a/packages/autorest.python/autorest/codegen/templates/model_base.py.jinja2 b/packages/autorest.python/autorest/codegen/templates/model_base.py.jinja2 index 84a9be73a0c..ab618a4e050 100644 --- a/packages/autorest.python/autorest/codegen/templates/model_base.py.jinja2 +++ b/packages/autorest.python/autorest/codegen/templates/model_base.py.jinja2 @@ -573,12 +573,12 @@ class Model(_MyMutableMapping): for k, v in self.items(): if exclude_readonly and k in readonly_props: # pyright: ignore[reportUnboundVariable] continue - is_multipart_file = False + is_multipart_file_input = False try: - is_multipart_file = next(rf for rf in self._attr_to_rest_field.values() if rf._rest_name == k)._is_multipart_file + is_multipart_file_input = next(rf for rf in self._attr_to_rest_field.values() if rf._rest_name == k)._is_multipart_file except StopIteration: pass - result[k] = v if is_multipart_file else Model._as_dict_value(v, exclude_readonly=exclude_readonly) + result[k] = v if is_multipart_file_input else Model._as_dict_value(v, exclude_readonly=exclude_readonly) return result @staticmethod @@ -790,7 +790,7 @@ class _RestField: visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, - is_multipart_file: bool = False, + is_multipart_file_input: bool = False, ): self._type = type self._rest_name_input = name @@ -800,7 +800,7 @@ class _RestField: self._is_model = False self._default = default self._format = format - self._is_multipart_file = is_multipart_file + self._is_multipart_file_input = is_multipart_file_input @property def _rest_name(self) -> str: @@ -846,9 +846,9 @@ def rest_field( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, - is_multipart_file: bool = False, + is_multipart_file_input: bool = False, ) -> typing.Any: - return _RestField(name=name, type=type, visibility=visibility, default=default, format=format, is_multipart_file=is_multipart_file) + return _RestField(name=name, type=type, visibility=visibility, default=default, format=format, is_multipart_file_input=is_multipart_file_input) def rest_discriminator( diff --git a/packages/typespec-python/package.json b/packages/typespec-python/package.json index 65e3aff1351..fcd31a5ab9e 100644 --- a/packages/typespec-python/package.json +++ b/packages/typespec-python/package.json @@ -43,7 +43,7 @@ ], "peerDependencies": { "@azure-tools/typespec-azure-core": ">=0.38.0 <1.0.0", - "@azure-tools/typespec-client-generator-core": "0.39.0-dev.4", + "@azure-tools/typespec-client-generator-core": "https://artprodcus3.artifacts.visualstudio.com/A0fb41ef4-5012-48a9-bf39-4ee3de03ee35/29ec6040-b234-4e31-b139-33dc4287b756/_apis/artifact/cGlwZWxpbmVhcnRpZmFjdDovL2F6dXJlLXNkay9wcm9qZWN0SWQvMjllYzYwNDAtYjIzNC00ZTMxLWIxMzktMzNkYzQyODdiNzU2L2J1aWxkSWQvMzQ1Nzc5OC9hcnRpZmFjdE5hbWUvcGFja2FnZXM1/content?format=file&subPath=%2Fazure-tools-typespec-client-generator-core-0.39.0-pr-200.20240131.17.tgz", "@typespec/compiler": ">=0.52.0 <1.0.0", "@typespec/http": ">=0.52.0 <1.0.0", "@typespec/rest": ">=0.52.0 <1.0.0", @@ -74,7 +74,7 @@ "rimraf": "~5.0.0", "typescript": "~5.1.3", "@azure-tools/typespec-azure-core": "~0.38.0", - "@azure-tools/typespec-client-generator-core": "0.39.0-dev.4", + "@azure-tools/typespec-client-generator-core": "https://artprodcus3.artifacts.visualstudio.com/A0fb41ef4-5012-48a9-bf39-4ee3de03ee35/29ec6040-b234-4e31-b139-33dc4287b756/_apis/artifact/cGlwZWxpbmVhcnRpZmFjdDovL2F6dXJlLXNkay9wcm9qZWN0SWQvMjllYzYwNDAtYjIzNC00ZTMxLWIxMzktMzNkYzQyODdiNzU2L2J1aWxkSWQvMzQ1Nzc5OC9hcnRpZmFjdE5hbWUvcGFja2FnZXM1/content?format=file&subPath=%2Fazure-tools-typespec-client-generator-core-0.39.0-pr-200.20240131.17.tgz", "@typespec/compiler": "~0.52.0", "@typespec/http": "~0.52.0", "@typespec/rest": "~0.52.0", diff --git a/packages/typespec-python/src/types.ts b/packages/typespec-python/src/types.ts index e9fb23adc36..69b6cc979e0 100644 --- a/packages/typespec-python/src/types.ts +++ b/packages/typespec-python/src/types.ts @@ -195,19 +195,16 @@ function visibilityMapping(visibility?: Visibility[]): string[] | undefined { } function emitProperty(context: SdkContext, type: SdkBodyModelPropertyType): Record { - const propertyType = getType(context, type.type); - if (type.isMultipartFileInput) { - propertyType.type = "multipartFile"; - } return { clientName: camelToSnakeCase(type.nameInClient), wireName: type.serializedName, - type: propertyType, + type: getType(context, type.type), optional: type.optional, description: type.description, addedOn: type.apiVersions[0], visibility: visibilityMapping(type.visibility), isDiscriminator: type.discriminator, + isMultipartFileInput: type.isMultipartFileInput, }; } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index c15ca6df168..cbab598430c 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -74,8 +74,8 @@ importers: specifier: '>=0.38.0 <1.0.0' version: 0.38.0(@azure-tools/typespec-autorest@0.38.0)(@azure-tools/typespec-azure-core@0.38.0)(@typespec/compiler@0.52.0)(@typespec/http@0.52.0)(@typespec/openapi@0.52.0)(@typespec/rest@0.52.0)(@typespec/versioning@0.52.0) '@azure-tools/typespec-client-generator-core': - specifier: 0.39.0-dev.4 - version: 0.39.0-dev.4(@typespec/compiler@0.52.0)(@typespec/http@0.52.0)(@typespec/rest@0.52.0)(@typespec/versioning@0.52.0) + specifier: https://artprodcus3.artifacts.visualstudio.com/A0fb41ef4-5012-48a9-bf39-4ee3de03ee35/29ec6040-b234-4e31-b139-33dc4287b756/_apis/artifact/cGlwZWxpbmVhcnRpZmFjdDovL2F6dXJlLXNkay9wcm9qZWN0SWQvMjllYzYwNDAtYjIzNC00ZTMxLWIxMzktMzNkYzQyODdiNzU2L2J1aWxkSWQvMzQ1Nzc5OC9hcnRpZmFjdE5hbWUvcGFja2FnZXM1/content?format=file&subPath=%2Fazure-tools-typespec-client-generator-core-0.39.0-pr-200.20240131.17.tgz + version: '@artprodcus3.artifacts.visualstudio.com/A0fb41ef4-5012-48a9-bf39-4ee3de03ee35/29ec6040-b234-4e31-b139-33dc4287b756/_apis/artifact/cGlwZWxpbmVhcnRpZmFjdDovL2F6dXJlLXNkay9wcm9qZWN0SWQvMjllYzYwNDAtYjIzNC00ZTMxLWIxMzktMzNkYzQyODdiNzU2L2J1aWxkSWQvMzQ1Nzc5OC9hcnRpZmFjdE5hbWUvcGFja2FnZXM1/content?format=file&subPath=%252Fazure-tools-typespec-client-generator-core-0.39.0-pr-200.20240131.17.tgz(@typespec/compiler@0.52.0)(@typespec/http@0.52.0)(@typespec/rest@0.52.0)(@typespec/versioning@0.52.0)' '@types/js-yaml': specifier: ~4.0.5 version: 4.0.5 @@ -364,23 +364,6 @@ packages: '@typespec/versioning': 0.52.0(@typespec/compiler@0.52.0) dev: true - /@azure-tools/typespec-client-generator-core@0.39.0-dev.4(@typespec/compiler@0.52.0)(@typespec/http@0.52.0)(@typespec/rest@0.52.0)(@typespec/versioning@0.52.0): - resolution: {integrity: sha512-SonleUQ8vd68bW0D9PFmdKOcB0divOz6Q3vtngZm3pBIyfa3Rm8Qxs9jKavgnVQGby08lfJC2zf1ekBx3zSMVA==} - engines: {node: '>=18.0.0'} - peerDependencies: - '@typespec/compiler': ~0.52.0 || >=0.53.0-dev <0.53.0 - '@typespec/http': ~0.52.0 || >=0.53.0-dev <0.53.0 - '@typespec/rest': ~0.52.0 || >=0.53.0-dev <0.53.0 - '@typespec/versioning': ~0.52.0 || >=0.53.0-dev <0.53.0 - dependencies: - '@typespec/compiler': 0.52.0 - '@typespec/http': 0.52.0(@typespec/compiler@0.52.0) - '@typespec/rest': 0.52.0(@typespec/compiler@0.52.0)(@typespec/http@0.52.0) - '@typespec/versioning': 0.52.0(@typespec/compiler@0.52.0) - change-case: 5.3.0 - pluralize: 8.0.0 - dev: true - /@azure/abort-controller@1.1.0: resolution: {integrity: sha512-TrRLIoSQVzfAJX9H1JeFjzAoDGcoK1IYX1UImfceTZpsyYfWr09Ss1aHW1y5TrrR3iq6RZLBwJ3E24uwPhwahw==} engines: {node: '>=12.0.0'} @@ -5437,3 +5420,23 @@ packages: /zod@3.21.4: resolution: {integrity: sha512-m46AKbrzKVzOzs/DZgVnG5H55N1sv1M8qZU3A8RIKbs3mrACDNeIOeilDymVb2HdmP8uwshOCF4uJ8uM9rCqJw==} dev: true + + '@artprodcus3.artifacts.visualstudio.com/A0fb41ef4-5012-48a9-bf39-4ee3de03ee35/29ec6040-b234-4e31-b139-33dc4287b756/_apis/artifact/cGlwZWxpbmVhcnRpZmFjdDovL2F6dXJlLXNkay9wcm9qZWN0SWQvMjllYzYwNDAtYjIzNC00ZTMxLWIxMzktMzNkYzQyODdiNzU2L2J1aWxkSWQvMzQ1Nzc5OC9hcnRpZmFjdE5hbWUvcGFja2FnZXM1/content?format=file&subPath=%252Fazure-tools-typespec-client-generator-core-0.39.0-pr-200.20240131.17.tgz(@typespec/compiler@0.52.0)(@typespec/http@0.52.0)(@typespec/rest@0.52.0)(@typespec/versioning@0.52.0)': + resolution: {tarball: https://artprodcus3.artifacts.visualstudio.com/A0fb41ef4-5012-48a9-bf39-4ee3de03ee35/29ec6040-b234-4e31-b139-33dc4287b756/_apis/artifact/cGlwZWxpbmVhcnRpZmFjdDovL2F6dXJlLXNkay9wcm9qZWN0SWQvMjllYzYwNDAtYjIzNC00ZTMxLWIxMzktMzNkYzQyODdiNzU2L2J1aWxkSWQvMzQ1Nzc5OC9hcnRpZmFjdE5hbWUvcGFja2FnZXM1/content?format=file&subPath=%2Fazure-tools-typespec-client-generator-core-0.39.0-pr-200.20240131.17.tgz} + id: '@artprodcus3.artifacts.visualstudio.com/A0fb41ef4-5012-48a9-bf39-4ee3de03ee35/29ec6040-b234-4e31-b139-33dc4287b756/_apis/artifact/cGlwZWxpbmVhcnRpZmFjdDovL2F6dXJlLXNkay9wcm9qZWN0SWQvMjllYzYwNDAtYjIzNC00ZTMxLWIxMzktMzNkYzQyODdiNzU2L2J1aWxkSWQvMzQ1Nzc5OC9hcnRpZmFjdE5hbWUvcGFja2FnZXM1/content?format=file&subPath=%252Fazure-tools-typespec-client-generator-core-0.39.0-pr-200.20240131.17.tgz' + name: '@azure-tools/typespec-client-generator-core' + version: 0.39.0-pr-200.20240131.17 + engines: {node: '>=18.0.0'} + peerDependencies: + '@typespec/compiler': ~0.52.0 + '@typespec/http': ~0.52.0 + '@typespec/rest': ~0.52.0 + '@typespec/versioning': ~0.52.0 + dependencies: + '@typespec/compiler': 0.52.0 + '@typespec/http': 0.52.0(@typespec/compiler@0.52.0) + '@typespec/rest': 0.52.0(@typespec/compiler@0.52.0)(@typespec/http@0.52.0) + '@typespec/versioning': 0.52.0(@typespec/compiler@0.52.0) + change-case: 5.3.0 + pluralize: 8.0.0 + dev: true From 3e57197e3a9e65bb19665fdd91817d756f5e1dbf Mon Sep 17 00:00:00 2001 From: iscai-msft Date: Wed, 31 Jan 2024 21:55:27 -0500 Subject: [PATCH 17/45] passes multipart test --- .../autorest/codegen/models/model_type.py | 7 + .../codegen/serializers/builder_serializer.py | 3 +- .../codegen/templates/model_base.py.jinja2 | 4 +- .../authentication/apikey/_model_base.py | 23 +- .../authentication/http/custom/_model_base.py | 23 +- .../authentication/oauth2/_model_base.py | 23 +- .../authentication/union/_model_base.py | 23 +- .../core/access/_model_base.py | 23 +- .../clientgenerator/core/usage/_model_base.py | 23 +- .../specs/azure/core/basic/_model_base.py | 23 +- .../azure/core/lro/standard/_model_base.py | 23 +- .../specs/azure/core/traits/_model_base.py | 23 +- .../azure/mgmt/spheredpg/_model_base.py | 23 +- .../azurecore/lro/rpc/_model_base.py | 23 +- .../azurecore/lro/rpclegacy/_model_base.py | 23 +- .../client/structure/service/_model_base.py | 23 +- .../structure/multiclient/_model_base.py | 23 +- .../structure/renamedoperation/_model_base.py | 23 +- .../twooperationgroup/_model_base.py | 23 +- .../encode-bytes/encode/bytes/_model_base.py | 23 +- .../encode/datetime/_model_base.py | 23 +- .../encode/duration/_model_base.py | 23 +- .../headasbooleanfalse/_model_base.py | 23 +- .../headasbooleantrue/_model_base.py | 23 +- .../parameters/bodyoptionality/_model_base.py | 23 +- .../collectionformat/_model_base.py | 23 +- .../parameters/spread/_model_base.py | 23 +- .../payload/contentnegotiation/_model_base.py | 23 +- .../payload/mediatype/_model_base.py | 23 +- .../payload/multipart/_model_base.py | 23 +- .../multipart/aio/operations/_operations.py | 188 +++++++--------- .../payload/multipart/models/_models.py | 36 +-- .../multipart/operations/_operations.py | 212 +++++++----------- .../payload/pageable/_model_base.py | 23 +- .../projection/projectedname/_model_base.py | 23 +- .../resiliency/srv/driven1/_model_base.py | 31 ++- .../resiliency/srv/driven2/_model_base.py | 23 +- .../server/path/multiple/_model_base.py | 23 +- .../server/path/single/_model_base.py | 23 +- .../versions/notversioned/_model_base.py | 23 +- .../server/versions/versioned/_model_base.py | 23 +- .../clientrequestid/_model_base.py | 23 +- .../conditionalrequest/_model_base.py | 23 +- .../repeatability/_model_base.py | 23 +- .../special-words/specialwords/_model_base.py | 23 +- .../typetest/array/_model_base.py | 23 +- .../typetest/dictionary/_model_base.py | 23 +- .../typetest/enum/extensible/_model_base.py | 23 +- .../typetest/enum/fixed/_model_base.py | 23 +- .../typetest/model/empty/_model_base.py | 23 +- .../model/enumdiscriminator/_model_base.py | 23 +- .../model/nesteddiscriminator/_model_base.py | 23 +- .../model/notdiscriminated/_model_base.py | 23 +- .../typetest/model/recursive/_model_base.py | 23 +- .../model/singlediscriminator/_model_base.py | 23 +- .../typetest/model/usage/_model_base.py | 23 +- .../typetest/model/visibility/_model_base.py | 23 +- .../additionalproperties/_model_base.py | 23 +- .../typetest/property/nullable/_model_base.py | 23 +- .../typetest/property/optional/_model_base.py | 23 +- .../property/valuetypes/_model_base.py | 23 +- .../typetest/scalar/_model_base.py | 23 +- .../typetest/union/_model_base.py | 23 +- .../authentication/apikey/_model_base.py | 23 +- .../authentication/http/custom/_model_base.py | 23 +- .../authentication/oauth2/_model_base.py | 23 +- .../authentication/union/_model_base.py | 23 +- .../client/structure/service/_model_base.py | 23 +- .../structure/multiclient/_model_base.py | 23 +- .../structure/renamedoperation/_model_base.py | 23 +- .../twooperationgroup/_model_base.py | 23 +- .../encode-bytes/encode/bytes/_model_base.py | 23 +- .../encode/datetime/_model_base.py | 23 +- .../encode/duration/_model_base.py | 23 +- .../headasbooleanfalse/_model_base.py | 23 +- .../headasbooleantrue/_model_base.py | 23 +- .../parameters/bodyoptionality/_model_base.py | 23 +- .../collectionformat/_model_base.py | 23 +- .../parameters/spread/_model_base.py | 23 +- .../payload/contentnegotiation/_model_base.py | 23 +- .../payload/mediatype/_model_base.py | 23 +- .../payload/multipart/_model_base.py | 23 +- .../multipart/aio/operations/_operations.py | 188 +++++++--------- .../payload/multipart/models/_models.py | 36 +-- .../multipart/operations/_operations.py | 212 +++++++----------- .../payload/pageable/_model_base.py | 23 +- .../projection/projectedname/_model_base.py | 23 +- .../resiliency/srv/driven1/_model_base.py | 23 +- .../resiliency/srv/driven2/_model_base.py | 23 +- .../server/path/multiple/_model_base.py | 23 +- .../server/path/single/_model_base.py | 23 +- .../versions/notversioned/_model_base.py | 23 +- .../server/versions/versioned/_model_base.py | 23 +- .../conditionalrequest/_model_base.py | 23 +- .../repeatability/_model_base.py | 23 +- .../special-words/specialwords/_model_base.py | 23 +- .../typetest/array/_model_base.py | 23 +- .../typetest/dictionary/_model_base.py | 23 +- .../typetest/enum/extensible/_model_base.py | 23 +- .../typetest/enum/fixed/_model_base.py | 23 +- .../typetest/model/empty/_model_base.py | 23 +- .../model/enumdiscriminator/_model_base.py | 23 +- .../model/nesteddiscriminator/_model_base.py | 23 +- .../model/notdiscriminated/_model_base.py | 23 +- .../typetest/model/recursive/_model_base.py | 23 +- .../model/singlediscriminator/_model_base.py | 23 +- .../typetest/model/usage/_model_base.py | 23 +- .../typetest/model/visibility/_model_base.py | 23 +- .../additionalproperties/_model_base.py | 23 +- .../typetest/property/nullable/_model_base.py | 23 +- .../typetest/property/optional/_model_base.py | 23 +- .../property/valuetypes/_model_base.py | 23 +- .../typetest/scalar/_model_base.py | 23 +- .../typetest/union/_model_base.py | 23 +- 114 files changed, 1850 insertions(+), 1459 deletions(-) diff --git a/packages/autorest.python/autorest/codegen/models/model_type.py b/packages/autorest.python/autorest/codegen/models/model_type.py index 506063a3ad4..ecc8e9f2f95 100644 --- a/packages/autorest.python/autorest/codegen/models/model_type.py +++ b/packages/autorest.python/autorest/codegen/models/model_type.py @@ -327,6 +327,13 @@ def imports(self, **kwargs: Any) -> FileImport: if kwargs.get("model_typing") else TypingSection.REGULAR, ) + if any(not p.is_multipart_file_input for p in self.properties): + file_import.add_submodule_import( + f"{relative_path}_model_base", + "SdkJSONEncoder", + ImportType.LOCAL, + ) + file_import.add_import("json", ImportType.STDLIB) return file_import diff --git a/packages/autorest.python/autorest/codegen/serializers/builder_serializer.py b/packages/autorest.python/autorest/codegen/serializers/builder_serializer.py index 8a6c2c4567b..c550f56be88 100644 --- a/packages/autorest.python/autorest/codegen/serializers/builder_serializer.py +++ b/packages/autorest.python/autorest/codegen/serializers/builder_serializer.py @@ -756,7 +756,8 @@ def _serialize_body_parameter(self, builder: OperationType) -> List[str]: # we assume that it's just a single multipart file input retval.append(f' _files.append(("{prop.wire_name}", {prop_access}))') else: - retval.append(f' _data["{prop.wire_name}"] = {prop_access}') + serialization = f"json.dumps({prop_access}, cls=SdkJSONEncoder, exclude_readonly=True)" if prop.type.type in ["list", "tuple", "dict", "model"] else prop_access + retval.append(f' _data["{prop.wire_name}"] = {serialization}') return retval retval: List[str] = [] body_kwarg_name = builder.request_builder.parameters.body_parameter.client_name diff --git a/packages/autorest.python/autorest/codegen/templates/model_base.py.jinja2 b/packages/autorest.python/autorest/codegen/templates/model_base.py.jinja2 index ab618a4e050..28d6b5741ae 100644 --- a/packages/autorest.python/autorest/codegen/templates/model_base.py.jinja2 +++ b/packages/autorest.python/autorest/codegen/templates/model_base.py.jinja2 @@ -472,7 +472,7 @@ def _get_rest_field( def _create_value(rf: typing.Optional["_RestField"], value: typing.Any) -> typing.Any: if not rf: return _serialize(value, None) - if rf._is_multipart_file: + if rf._is_multipart_file_input: return value if rf._is_model: return _deserialize(rf._type, value) @@ -575,7 +575,7 @@ class Model(_MyMutableMapping): continue is_multipart_file_input = False try: - is_multipart_file_input = next(rf for rf in self._attr_to_rest_field.values() if rf._rest_name == k)._is_multipart_file + is_multipart_file_input = next(rf for rf in self._attr_to_rest_field.values() if rf._rest_name == k)._is_multipart_file_input except StopIteration: pass result[k] = v if is_multipart_file_input else Model._as_dict_value(v, exclude_readonly=exclude_readonly) diff --git a/packages/typespec-python/test/azure/generated/authentication-api-key/authentication/apikey/_model_base.py b/packages/typespec-python/test/azure/generated/authentication-api-key/authentication/apikey/_model_base.py index 01c401e6324..247049f44d9 100644 --- a/packages/typespec-python/test/azure/generated/authentication-api-key/authentication/apikey/_model_base.py +++ b/packages/typespec-python/test/azure/generated/authentication-api-key/authentication/apikey/_model_base.py @@ -464,7 +464,7 @@ def _get_rest_field( def _create_value(rf: typing.Optional["_RestField"], value: typing.Any) -> typing.Any: if not rf: return _serialize(value, None) - if rf._is_multipart_file: + if rf._is_multipart_file_input: return value if rf._is_model: return _deserialize(rf._type, value) @@ -565,14 +565,14 @@ def as_dict(self, *, exclude_readonly: bool = False) -> typing.Dict[str, typing. for k, v in self.items(): if exclude_readonly and k in readonly_props: # pyright: ignore[reportUnboundVariable] continue - is_multipart_file = False + is_multipart_file_input = False try: - is_multipart_file = next( + is_multipart_file_input = next( rf for rf in self._attr_to_rest_field.values() if rf._rest_name == k - )._is_multipart_file + )._is_multipart_file_input except StopIteration: pass - result[k] = v if is_multipart_file else Model._as_dict_value(v, exclude_readonly=exclude_readonly) + result[k] = v if is_multipart_file_input else Model._as_dict_value(v, exclude_readonly=exclude_readonly) return result @staticmethod @@ -775,7 +775,7 @@ def __init__( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, - is_multipart_file: bool = False, + is_multipart_file_input: bool = False, ): self._type = type self._rest_name_input = name @@ -785,7 +785,7 @@ def __init__( self._is_model = False self._default = default self._format = format - self._is_multipart_file = is_multipart_file + self._is_multipart_file_input = is_multipart_file_input @property def _rest_name(self) -> str: @@ -831,10 +831,15 @@ def rest_field( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, - is_multipart_file: bool = False, + is_multipart_file_input: bool = False, ) -> typing.Any: return _RestField( - name=name, type=type, visibility=visibility, default=default, format=format, is_multipart_file=is_multipart_file + name=name, + type=type, + visibility=visibility, + default=default, + format=format, + is_multipart_file_input=is_multipart_file_input, ) diff --git a/packages/typespec-python/test/azure/generated/authentication-http-custom/authentication/http/custom/_model_base.py b/packages/typespec-python/test/azure/generated/authentication-http-custom/authentication/http/custom/_model_base.py index 01c401e6324..247049f44d9 100644 --- a/packages/typespec-python/test/azure/generated/authentication-http-custom/authentication/http/custom/_model_base.py +++ b/packages/typespec-python/test/azure/generated/authentication-http-custom/authentication/http/custom/_model_base.py @@ -464,7 +464,7 @@ def _get_rest_field( def _create_value(rf: typing.Optional["_RestField"], value: typing.Any) -> typing.Any: if not rf: return _serialize(value, None) - if rf._is_multipart_file: + if rf._is_multipart_file_input: return value if rf._is_model: return _deserialize(rf._type, value) @@ -565,14 +565,14 @@ def as_dict(self, *, exclude_readonly: bool = False) -> typing.Dict[str, typing. for k, v in self.items(): if exclude_readonly and k in readonly_props: # pyright: ignore[reportUnboundVariable] continue - is_multipart_file = False + is_multipart_file_input = False try: - is_multipart_file = next( + is_multipart_file_input = next( rf for rf in self._attr_to_rest_field.values() if rf._rest_name == k - )._is_multipart_file + )._is_multipart_file_input except StopIteration: pass - result[k] = v if is_multipart_file else Model._as_dict_value(v, exclude_readonly=exclude_readonly) + result[k] = v if is_multipart_file_input else Model._as_dict_value(v, exclude_readonly=exclude_readonly) return result @staticmethod @@ -775,7 +775,7 @@ def __init__( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, - is_multipart_file: bool = False, + is_multipart_file_input: bool = False, ): self._type = type self._rest_name_input = name @@ -785,7 +785,7 @@ def __init__( self._is_model = False self._default = default self._format = format - self._is_multipart_file = is_multipart_file + self._is_multipart_file_input = is_multipart_file_input @property def _rest_name(self) -> str: @@ -831,10 +831,15 @@ def rest_field( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, - is_multipart_file: bool = False, + is_multipart_file_input: bool = False, ) -> typing.Any: return _RestField( - name=name, type=type, visibility=visibility, default=default, format=format, is_multipart_file=is_multipart_file + name=name, + type=type, + visibility=visibility, + default=default, + format=format, + is_multipart_file_input=is_multipart_file_input, ) diff --git a/packages/typespec-python/test/azure/generated/authentication-oauth2/authentication/oauth2/_model_base.py b/packages/typespec-python/test/azure/generated/authentication-oauth2/authentication/oauth2/_model_base.py index 01c401e6324..247049f44d9 100644 --- a/packages/typespec-python/test/azure/generated/authentication-oauth2/authentication/oauth2/_model_base.py +++ b/packages/typespec-python/test/azure/generated/authentication-oauth2/authentication/oauth2/_model_base.py @@ -464,7 +464,7 @@ def _get_rest_field( def _create_value(rf: typing.Optional["_RestField"], value: typing.Any) -> typing.Any: if not rf: return _serialize(value, None) - if rf._is_multipart_file: + if rf._is_multipart_file_input: return value if rf._is_model: return _deserialize(rf._type, value) @@ -565,14 +565,14 @@ def as_dict(self, *, exclude_readonly: bool = False) -> typing.Dict[str, typing. for k, v in self.items(): if exclude_readonly and k in readonly_props: # pyright: ignore[reportUnboundVariable] continue - is_multipart_file = False + is_multipart_file_input = False try: - is_multipart_file = next( + is_multipart_file_input = next( rf for rf in self._attr_to_rest_field.values() if rf._rest_name == k - )._is_multipart_file + )._is_multipart_file_input except StopIteration: pass - result[k] = v if is_multipart_file else Model._as_dict_value(v, exclude_readonly=exclude_readonly) + result[k] = v if is_multipart_file_input else Model._as_dict_value(v, exclude_readonly=exclude_readonly) return result @staticmethod @@ -775,7 +775,7 @@ def __init__( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, - is_multipart_file: bool = False, + is_multipart_file_input: bool = False, ): self._type = type self._rest_name_input = name @@ -785,7 +785,7 @@ def __init__( self._is_model = False self._default = default self._format = format - self._is_multipart_file = is_multipart_file + self._is_multipart_file_input = is_multipart_file_input @property def _rest_name(self) -> str: @@ -831,10 +831,15 @@ def rest_field( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, - is_multipart_file: bool = False, + is_multipart_file_input: bool = False, ) -> typing.Any: return _RestField( - name=name, type=type, visibility=visibility, default=default, format=format, is_multipart_file=is_multipart_file + name=name, + type=type, + visibility=visibility, + default=default, + format=format, + is_multipart_file_input=is_multipart_file_input, ) diff --git a/packages/typespec-python/test/azure/generated/authentication-union/authentication/union/_model_base.py b/packages/typespec-python/test/azure/generated/authentication-union/authentication/union/_model_base.py index 01c401e6324..247049f44d9 100644 --- a/packages/typespec-python/test/azure/generated/authentication-union/authentication/union/_model_base.py +++ b/packages/typespec-python/test/azure/generated/authentication-union/authentication/union/_model_base.py @@ -464,7 +464,7 @@ def _get_rest_field( def _create_value(rf: typing.Optional["_RestField"], value: typing.Any) -> typing.Any: if not rf: return _serialize(value, None) - if rf._is_multipart_file: + if rf._is_multipart_file_input: return value if rf._is_model: return _deserialize(rf._type, value) @@ -565,14 +565,14 @@ def as_dict(self, *, exclude_readonly: bool = False) -> typing.Dict[str, typing. for k, v in self.items(): if exclude_readonly and k in readonly_props: # pyright: ignore[reportUnboundVariable] continue - is_multipart_file = False + is_multipart_file_input = False try: - is_multipart_file = next( + is_multipart_file_input = next( rf for rf in self._attr_to_rest_field.values() if rf._rest_name == k - )._is_multipart_file + )._is_multipart_file_input except StopIteration: pass - result[k] = v if is_multipart_file else Model._as_dict_value(v, exclude_readonly=exclude_readonly) + result[k] = v if is_multipart_file_input else Model._as_dict_value(v, exclude_readonly=exclude_readonly) return result @staticmethod @@ -775,7 +775,7 @@ def __init__( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, - is_multipart_file: bool = False, + is_multipart_file_input: bool = False, ): self._type = type self._rest_name_input = name @@ -785,7 +785,7 @@ def __init__( self._is_model = False self._default = default self._format = format - self._is_multipart_file = is_multipart_file + self._is_multipart_file_input = is_multipart_file_input @property def _rest_name(self) -> str: @@ -831,10 +831,15 @@ def rest_field( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, - is_multipart_file: bool = False, + is_multipart_file_input: bool = False, ) -> typing.Any: return _RestField( - name=name, type=type, visibility=visibility, default=default, format=format, is_multipart_file=is_multipart_file + name=name, + type=type, + visibility=visibility, + default=default, + format=format, + 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/_model_base.py b/packages/typespec-python/test/azure/generated/azure-client-generator-core-access/specs/azure/clientgenerator/core/access/_model_base.py index 01c401e6324..247049f44d9 100644 --- a/packages/typespec-python/test/azure/generated/azure-client-generator-core-access/specs/azure/clientgenerator/core/access/_model_base.py +++ b/packages/typespec-python/test/azure/generated/azure-client-generator-core-access/specs/azure/clientgenerator/core/access/_model_base.py @@ -464,7 +464,7 @@ def _get_rest_field( def _create_value(rf: typing.Optional["_RestField"], value: typing.Any) -> typing.Any: if not rf: return _serialize(value, None) - if rf._is_multipart_file: + if rf._is_multipart_file_input: return value if rf._is_model: return _deserialize(rf._type, value) @@ -565,14 +565,14 @@ def as_dict(self, *, exclude_readonly: bool = False) -> typing.Dict[str, typing. for k, v in self.items(): if exclude_readonly and k in readonly_props: # pyright: ignore[reportUnboundVariable] continue - is_multipart_file = False + is_multipart_file_input = False try: - is_multipart_file = next( + is_multipart_file_input = next( rf for rf in self._attr_to_rest_field.values() if rf._rest_name == k - )._is_multipart_file + )._is_multipart_file_input except StopIteration: pass - result[k] = v if is_multipart_file else Model._as_dict_value(v, exclude_readonly=exclude_readonly) + result[k] = v if is_multipart_file_input else Model._as_dict_value(v, exclude_readonly=exclude_readonly) return result @staticmethod @@ -775,7 +775,7 @@ def __init__( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, - is_multipart_file: bool = False, + is_multipart_file_input: bool = False, ): self._type = type self._rest_name_input = name @@ -785,7 +785,7 @@ def __init__( self._is_model = False self._default = default self._format = format - self._is_multipart_file = is_multipart_file + self._is_multipart_file_input = is_multipart_file_input @property def _rest_name(self) -> str: @@ -831,10 +831,15 @@ def rest_field( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, - is_multipart_file: bool = False, + is_multipart_file_input: bool = False, ) -> typing.Any: return _RestField( - name=name, type=type, visibility=visibility, default=default, format=format, is_multipart_file=is_multipart_file + name=name, + type=type, + visibility=visibility, + default=default, + format=format, + 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/_model_base.py b/packages/typespec-python/test/azure/generated/azure-client-generator-core-usage/specs/azure/clientgenerator/core/usage/_model_base.py index 01c401e6324..247049f44d9 100644 --- a/packages/typespec-python/test/azure/generated/azure-client-generator-core-usage/specs/azure/clientgenerator/core/usage/_model_base.py +++ b/packages/typespec-python/test/azure/generated/azure-client-generator-core-usage/specs/azure/clientgenerator/core/usage/_model_base.py @@ -464,7 +464,7 @@ def _get_rest_field( def _create_value(rf: typing.Optional["_RestField"], value: typing.Any) -> typing.Any: if not rf: return _serialize(value, None) - if rf._is_multipart_file: + if rf._is_multipart_file_input: return value if rf._is_model: return _deserialize(rf._type, value) @@ -565,14 +565,14 @@ def as_dict(self, *, exclude_readonly: bool = False) -> typing.Dict[str, typing. for k, v in self.items(): if exclude_readonly and k in readonly_props: # pyright: ignore[reportUnboundVariable] continue - is_multipart_file = False + is_multipart_file_input = False try: - is_multipart_file = next( + is_multipart_file_input = next( rf for rf in self._attr_to_rest_field.values() if rf._rest_name == k - )._is_multipart_file + )._is_multipart_file_input except StopIteration: pass - result[k] = v if is_multipart_file else Model._as_dict_value(v, exclude_readonly=exclude_readonly) + result[k] = v if is_multipart_file_input else Model._as_dict_value(v, exclude_readonly=exclude_readonly) return result @staticmethod @@ -775,7 +775,7 @@ def __init__( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, - is_multipart_file: bool = False, + is_multipart_file_input: bool = False, ): self._type = type self._rest_name_input = name @@ -785,7 +785,7 @@ def __init__( self._is_model = False self._default = default self._format = format - self._is_multipart_file = is_multipart_file + self._is_multipart_file_input = is_multipart_file_input @property def _rest_name(self) -> str: @@ -831,10 +831,15 @@ def rest_field( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, - is_multipart_file: bool = False, + is_multipart_file_input: bool = False, ) -> typing.Any: return _RestField( - name=name, type=type, visibility=visibility, default=default, format=format, is_multipart_file=is_multipart_file + name=name, + type=type, + visibility=visibility, + default=default, + format=format, + is_multipart_file_input=is_multipart_file_input, ) diff --git a/packages/typespec-python/test/azure/generated/azure-core-basic/specs/azure/core/basic/_model_base.py b/packages/typespec-python/test/azure/generated/azure-core-basic/specs/azure/core/basic/_model_base.py index 01c401e6324..247049f44d9 100644 --- a/packages/typespec-python/test/azure/generated/azure-core-basic/specs/azure/core/basic/_model_base.py +++ b/packages/typespec-python/test/azure/generated/azure-core-basic/specs/azure/core/basic/_model_base.py @@ -464,7 +464,7 @@ def _get_rest_field( def _create_value(rf: typing.Optional["_RestField"], value: typing.Any) -> typing.Any: if not rf: return _serialize(value, None) - if rf._is_multipart_file: + if rf._is_multipart_file_input: return value if rf._is_model: return _deserialize(rf._type, value) @@ -565,14 +565,14 @@ def as_dict(self, *, exclude_readonly: bool = False) -> typing.Dict[str, typing. for k, v in self.items(): if exclude_readonly and k in readonly_props: # pyright: ignore[reportUnboundVariable] continue - is_multipart_file = False + is_multipart_file_input = False try: - is_multipart_file = next( + is_multipart_file_input = next( rf for rf in self._attr_to_rest_field.values() if rf._rest_name == k - )._is_multipart_file + )._is_multipart_file_input except StopIteration: pass - result[k] = v if is_multipart_file else Model._as_dict_value(v, exclude_readonly=exclude_readonly) + result[k] = v if is_multipart_file_input else Model._as_dict_value(v, exclude_readonly=exclude_readonly) return result @staticmethod @@ -775,7 +775,7 @@ def __init__( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, - is_multipart_file: bool = False, + is_multipart_file_input: bool = False, ): self._type = type self._rest_name_input = name @@ -785,7 +785,7 @@ def __init__( self._is_model = False self._default = default self._format = format - self._is_multipart_file = is_multipart_file + self._is_multipart_file_input = is_multipart_file_input @property def _rest_name(self) -> str: @@ -831,10 +831,15 @@ def rest_field( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, - is_multipart_file: bool = False, + is_multipart_file_input: bool = False, ) -> typing.Any: return _RestField( - name=name, type=type, visibility=visibility, default=default, format=format, is_multipart_file=is_multipart_file + name=name, + type=type, + visibility=visibility, + default=default, + format=format, + 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/_model_base.py b/packages/typespec-python/test/azure/generated/azure-core-lro-standard/specs/azure/core/lro/standard/_model_base.py index 01c401e6324..247049f44d9 100644 --- a/packages/typespec-python/test/azure/generated/azure-core-lro-standard/specs/azure/core/lro/standard/_model_base.py +++ b/packages/typespec-python/test/azure/generated/azure-core-lro-standard/specs/azure/core/lro/standard/_model_base.py @@ -464,7 +464,7 @@ def _get_rest_field( def _create_value(rf: typing.Optional["_RestField"], value: typing.Any) -> typing.Any: if not rf: return _serialize(value, None) - if rf._is_multipart_file: + if rf._is_multipart_file_input: return value if rf._is_model: return _deserialize(rf._type, value) @@ -565,14 +565,14 @@ def as_dict(self, *, exclude_readonly: bool = False) -> typing.Dict[str, typing. for k, v in self.items(): if exclude_readonly and k in readonly_props: # pyright: ignore[reportUnboundVariable] continue - is_multipart_file = False + is_multipart_file_input = False try: - is_multipart_file = next( + is_multipart_file_input = next( rf for rf in self._attr_to_rest_field.values() if rf._rest_name == k - )._is_multipart_file + )._is_multipart_file_input except StopIteration: pass - result[k] = v if is_multipart_file else Model._as_dict_value(v, exclude_readonly=exclude_readonly) + result[k] = v if is_multipart_file_input else Model._as_dict_value(v, exclude_readonly=exclude_readonly) return result @staticmethod @@ -775,7 +775,7 @@ def __init__( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, - is_multipart_file: bool = False, + is_multipart_file_input: bool = False, ): self._type = type self._rest_name_input = name @@ -785,7 +785,7 @@ def __init__( self._is_model = False self._default = default self._format = format - self._is_multipart_file = is_multipart_file + self._is_multipart_file_input = is_multipart_file_input @property def _rest_name(self) -> str: @@ -831,10 +831,15 @@ def rest_field( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, - is_multipart_file: bool = False, + is_multipart_file_input: bool = False, ) -> typing.Any: return _RestField( - name=name, type=type, visibility=visibility, default=default, format=format, is_multipart_file=is_multipart_file + name=name, + type=type, + visibility=visibility, + default=default, + format=format, + is_multipart_file_input=is_multipart_file_input, ) diff --git a/packages/typespec-python/test/azure/generated/azure-core-traits/specs/azure/core/traits/_model_base.py b/packages/typespec-python/test/azure/generated/azure-core-traits/specs/azure/core/traits/_model_base.py index 01c401e6324..247049f44d9 100644 --- a/packages/typespec-python/test/azure/generated/azure-core-traits/specs/azure/core/traits/_model_base.py +++ b/packages/typespec-python/test/azure/generated/azure-core-traits/specs/azure/core/traits/_model_base.py @@ -464,7 +464,7 @@ def _get_rest_field( def _create_value(rf: typing.Optional["_RestField"], value: typing.Any) -> typing.Any: if not rf: return _serialize(value, None) - if rf._is_multipart_file: + if rf._is_multipart_file_input: return value if rf._is_model: return _deserialize(rf._type, value) @@ -565,14 +565,14 @@ def as_dict(self, *, exclude_readonly: bool = False) -> typing.Dict[str, typing. for k, v in self.items(): if exclude_readonly and k in readonly_props: # pyright: ignore[reportUnboundVariable] continue - is_multipart_file = False + is_multipart_file_input = False try: - is_multipart_file = next( + is_multipart_file_input = next( rf for rf in self._attr_to_rest_field.values() if rf._rest_name == k - )._is_multipart_file + )._is_multipart_file_input except StopIteration: pass - result[k] = v if is_multipart_file else Model._as_dict_value(v, exclude_readonly=exclude_readonly) + result[k] = v if is_multipart_file_input else Model._as_dict_value(v, exclude_readonly=exclude_readonly) return result @staticmethod @@ -775,7 +775,7 @@ def __init__( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, - is_multipart_file: bool = False, + is_multipart_file_input: bool = False, ): self._type = type self._rest_name_input = name @@ -785,7 +785,7 @@ def __init__( self._is_model = False self._default = default self._format = format - self._is_multipart_file = is_multipart_file + self._is_multipart_file_input = is_multipart_file_input @property def _rest_name(self) -> str: @@ -831,10 +831,15 @@ def rest_field( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, - is_multipart_file: bool = False, + is_multipart_file_input: bool = False, ) -> typing.Any: return _RestField( - name=name, type=type, visibility=visibility, default=default, format=format, is_multipart_file=is_multipart_file + name=name, + type=type, + visibility=visibility, + default=default, + format=format, + is_multipart_file_input=is_multipart_file_input, ) diff --git a/packages/typespec-python/test/azure/generated/azure-mgmt-spheredpg/azure/mgmt/spheredpg/_model_base.py b/packages/typespec-python/test/azure/generated/azure-mgmt-spheredpg/azure/mgmt/spheredpg/_model_base.py index 01c401e6324..247049f44d9 100644 --- a/packages/typespec-python/test/azure/generated/azure-mgmt-spheredpg/azure/mgmt/spheredpg/_model_base.py +++ b/packages/typespec-python/test/azure/generated/azure-mgmt-spheredpg/azure/mgmt/spheredpg/_model_base.py @@ -464,7 +464,7 @@ def _get_rest_field( def _create_value(rf: typing.Optional["_RestField"], value: typing.Any) -> typing.Any: if not rf: return _serialize(value, None) - if rf._is_multipart_file: + if rf._is_multipart_file_input: return value if rf._is_model: return _deserialize(rf._type, value) @@ -565,14 +565,14 @@ def as_dict(self, *, exclude_readonly: bool = False) -> typing.Dict[str, typing. for k, v in self.items(): if exclude_readonly and k in readonly_props: # pyright: ignore[reportUnboundVariable] continue - is_multipart_file = False + is_multipart_file_input = False try: - is_multipart_file = next( + is_multipart_file_input = next( rf for rf in self._attr_to_rest_field.values() if rf._rest_name == k - )._is_multipart_file + )._is_multipart_file_input except StopIteration: pass - result[k] = v if is_multipart_file else Model._as_dict_value(v, exclude_readonly=exclude_readonly) + result[k] = v if is_multipart_file_input else Model._as_dict_value(v, exclude_readonly=exclude_readonly) return result @staticmethod @@ -775,7 +775,7 @@ def __init__( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, - is_multipart_file: bool = False, + is_multipart_file_input: bool = False, ): self._type = type self._rest_name_input = name @@ -785,7 +785,7 @@ def __init__( self._is_model = False self._default = default self._format = format - self._is_multipart_file = is_multipart_file + self._is_multipart_file_input = is_multipart_file_input @property def _rest_name(self) -> str: @@ -831,10 +831,15 @@ def rest_field( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, - is_multipart_file: bool = False, + is_multipart_file_input: bool = False, ) -> typing.Any: return _RestField( - name=name, type=type, visibility=visibility, default=default, format=format, is_multipart_file=is_multipart_file + name=name, + type=type, + visibility=visibility, + default=default, + format=format, + is_multipart_file_input=is_multipart_file_input, ) diff --git a/packages/typespec-python/test/azure/generated/azurecore-lro-rpc/azurecore/lro/rpc/_model_base.py b/packages/typespec-python/test/azure/generated/azurecore-lro-rpc/azurecore/lro/rpc/_model_base.py index 01c401e6324..247049f44d9 100644 --- a/packages/typespec-python/test/azure/generated/azurecore-lro-rpc/azurecore/lro/rpc/_model_base.py +++ b/packages/typespec-python/test/azure/generated/azurecore-lro-rpc/azurecore/lro/rpc/_model_base.py @@ -464,7 +464,7 @@ def _get_rest_field( def _create_value(rf: typing.Optional["_RestField"], value: typing.Any) -> typing.Any: if not rf: return _serialize(value, None) - if rf._is_multipart_file: + if rf._is_multipart_file_input: return value if rf._is_model: return _deserialize(rf._type, value) @@ -565,14 +565,14 @@ def as_dict(self, *, exclude_readonly: bool = False) -> typing.Dict[str, typing. for k, v in self.items(): if exclude_readonly and k in readonly_props: # pyright: ignore[reportUnboundVariable] continue - is_multipart_file = False + is_multipart_file_input = False try: - is_multipart_file = next( + is_multipart_file_input = next( rf for rf in self._attr_to_rest_field.values() if rf._rest_name == k - )._is_multipart_file + )._is_multipart_file_input except StopIteration: pass - result[k] = v if is_multipart_file else Model._as_dict_value(v, exclude_readonly=exclude_readonly) + result[k] = v if is_multipart_file_input else Model._as_dict_value(v, exclude_readonly=exclude_readonly) return result @staticmethod @@ -775,7 +775,7 @@ def __init__( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, - is_multipart_file: bool = False, + is_multipart_file_input: bool = False, ): self._type = type self._rest_name_input = name @@ -785,7 +785,7 @@ def __init__( self._is_model = False self._default = default self._format = format - self._is_multipart_file = is_multipart_file + self._is_multipart_file_input = is_multipart_file_input @property def _rest_name(self) -> str: @@ -831,10 +831,15 @@ def rest_field( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, - is_multipart_file: bool = False, + is_multipart_file_input: bool = False, ) -> typing.Any: return _RestField( - name=name, type=type, visibility=visibility, default=default, format=format, is_multipart_file=is_multipart_file + name=name, + type=type, + visibility=visibility, + default=default, + format=format, + is_multipart_file_input=is_multipart_file_input, ) diff --git a/packages/typespec-python/test/azure/generated/azurecore-lro-rpclegacy/azurecore/lro/rpclegacy/_model_base.py b/packages/typespec-python/test/azure/generated/azurecore-lro-rpclegacy/azurecore/lro/rpclegacy/_model_base.py index 01c401e6324..247049f44d9 100644 --- a/packages/typespec-python/test/azure/generated/azurecore-lro-rpclegacy/azurecore/lro/rpclegacy/_model_base.py +++ b/packages/typespec-python/test/azure/generated/azurecore-lro-rpclegacy/azurecore/lro/rpclegacy/_model_base.py @@ -464,7 +464,7 @@ def _get_rest_field( def _create_value(rf: typing.Optional["_RestField"], value: typing.Any) -> typing.Any: if not rf: return _serialize(value, None) - if rf._is_multipart_file: + if rf._is_multipart_file_input: return value if rf._is_model: return _deserialize(rf._type, value) @@ -565,14 +565,14 @@ def as_dict(self, *, exclude_readonly: bool = False) -> typing.Dict[str, typing. for k, v in self.items(): if exclude_readonly and k in readonly_props: # pyright: ignore[reportUnboundVariable] continue - is_multipart_file = False + is_multipart_file_input = False try: - is_multipart_file = next( + is_multipart_file_input = next( rf for rf in self._attr_to_rest_field.values() if rf._rest_name == k - )._is_multipart_file + )._is_multipart_file_input except StopIteration: pass - result[k] = v if is_multipart_file else Model._as_dict_value(v, exclude_readonly=exclude_readonly) + result[k] = v if is_multipart_file_input else Model._as_dict_value(v, exclude_readonly=exclude_readonly) return result @staticmethod @@ -775,7 +775,7 @@ def __init__( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, - is_multipart_file: bool = False, + is_multipart_file_input: bool = False, ): self._type = type self._rest_name_input = name @@ -785,7 +785,7 @@ def __init__( self._is_model = False self._default = default self._format = format - self._is_multipart_file = is_multipart_file + self._is_multipart_file_input = is_multipart_file_input @property def _rest_name(self) -> str: @@ -831,10 +831,15 @@ def rest_field( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, - is_multipart_file: bool = False, + is_multipart_file_input: bool = False, ) -> typing.Any: return _RestField( - name=name, type=type, visibility=visibility, default=default, format=format, is_multipart_file=is_multipart_file + name=name, + type=type, + visibility=visibility, + default=default, + format=format, + is_multipart_file_input=is_multipart_file_input, ) diff --git a/packages/typespec-python/test/azure/generated/client-structure-default/client/structure/service/_model_base.py b/packages/typespec-python/test/azure/generated/client-structure-default/client/structure/service/_model_base.py index 01c401e6324..247049f44d9 100644 --- a/packages/typespec-python/test/azure/generated/client-structure-default/client/structure/service/_model_base.py +++ b/packages/typespec-python/test/azure/generated/client-structure-default/client/structure/service/_model_base.py @@ -464,7 +464,7 @@ def _get_rest_field( def _create_value(rf: typing.Optional["_RestField"], value: typing.Any) -> typing.Any: if not rf: return _serialize(value, None) - if rf._is_multipart_file: + if rf._is_multipart_file_input: return value if rf._is_model: return _deserialize(rf._type, value) @@ -565,14 +565,14 @@ def as_dict(self, *, exclude_readonly: bool = False) -> typing.Dict[str, typing. for k, v in self.items(): if exclude_readonly and k in readonly_props: # pyright: ignore[reportUnboundVariable] continue - is_multipart_file = False + is_multipart_file_input = False try: - is_multipart_file = next( + is_multipart_file_input = next( rf for rf in self._attr_to_rest_field.values() if rf._rest_name == k - )._is_multipart_file + )._is_multipart_file_input except StopIteration: pass - result[k] = v if is_multipart_file else Model._as_dict_value(v, exclude_readonly=exclude_readonly) + result[k] = v if is_multipart_file_input else Model._as_dict_value(v, exclude_readonly=exclude_readonly) return result @staticmethod @@ -775,7 +775,7 @@ def __init__( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, - is_multipart_file: bool = False, + is_multipart_file_input: bool = False, ): self._type = type self._rest_name_input = name @@ -785,7 +785,7 @@ def __init__( self._is_model = False self._default = default self._format = format - self._is_multipart_file = is_multipart_file + self._is_multipart_file_input = is_multipart_file_input @property def _rest_name(self) -> str: @@ -831,10 +831,15 @@ def rest_field( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, - is_multipart_file: bool = False, + is_multipart_file_input: bool = False, ) -> typing.Any: return _RestField( - name=name, type=type, visibility=visibility, default=default, format=format, is_multipart_file=is_multipart_file + name=name, + type=type, + visibility=visibility, + default=default, + format=format, + is_multipart_file_input=is_multipart_file_input, ) diff --git a/packages/typespec-python/test/azure/generated/client-structure-multiclient/client/structure/multiclient/_model_base.py b/packages/typespec-python/test/azure/generated/client-structure-multiclient/client/structure/multiclient/_model_base.py index 01c401e6324..247049f44d9 100644 --- a/packages/typespec-python/test/azure/generated/client-structure-multiclient/client/structure/multiclient/_model_base.py +++ b/packages/typespec-python/test/azure/generated/client-structure-multiclient/client/structure/multiclient/_model_base.py @@ -464,7 +464,7 @@ def _get_rest_field( def _create_value(rf: typing.Optional["_RestField"], value: typing.Any) -> typing.Any: if not rf: return _serialize(value, None) - if rf._is_multipart_file: + if rf._is_multipart_file_input: return value if rf._is_model: return _deserialize(rf._type, value) @@ -565,14 +565,14 @@ def as_dict(self, *, exclude_readonly: bool = False) -> typing.Dict[str, typing. for k, v in self.items(): if exclude_readonly and k in readonly_props: # pyright: ignore[reportUnboundVariable] continue - is_multipart_file = False + is_multipart_file_input = False try: - is_multipart_file = next( + is_multipart_file_input = next( rf for rf in self._attr_to_rest_field.values() if rf._rest_name == k - )._is_multipart_file + )._is_multipart_file_input except StopIteration: pass - result[k] = v if is_multipart_file else Model._as_dict_value(v, exclude_readonly=exclude_readonly) + result[k] = v if is_multipart_file_input else Model._as_dict_value(v, exclude_readonly=exclude_readonly) return result @staticmethod @@ -775,7 +775,7 @@ def __init__( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, - is_multipart_file: bool = False, + is_multipart_file_input: bool = False, ): self._type = type self._rest_name_input = name @@ -785,7 +785,7 @@ def __init__( self._is_model = False self._default = default self._format = format - self._is_multipart_file = is_multipart_file + self._is_multipart_file_input = is_multipart_file_input @property def _rest_name(self) -> str: @@ -831,10 +831,15 @@ def rest_field( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, - is_multipart_file: bool = False, + is_multipart_file_input: bool = False, ) -> typing.Any: return _RestField( - name=name, type=type, visibility=visibility, default=default, format=format, is_multipart_file=is_multipart_file + name=name, + type=type, + visibility=visibility, + default=default, + format=format, + is_multipart_file_input=is_multipart_file_input, ) diff --git a/packages/typespec-python/test/azure/generated/client-structure-renamedoperation/client/structure/renamedoperation/_model_base.py b/packages/typespec-python/test/azure/generated/client-structure-renamedoperation/client/structure/renamedoperation/_model_base.py index 01c401e6324..247049f44d9 100644 --- a/packages/typespec-python/test/azure/generated/client-structure-renamedoperation/client/structure/renamedoperation/_model_base.py +++ b/packages/typespec-python/test/azure/generated/client-structure-renamedoperation/client/structure/renamedoperation/_model_base.py @@ -464,7 +464,7 @@ def _get_rest_field( def _create_value(rf: typing.Optional["_RestField"], value: typing.Any) -> typing.Any: if not rf: return _serialize(value, None) - if rf._is_multipart_file: + if rf._is_multipart_file_input: return value if rf._is_model: return _deserialize(rf._type, value) @@ -565,14 +565,14 @@ def as_dict(self, *, exclude_readonly: bool = False) -> typing.Dict[str, typing. for k, v in self.items(): if exclude_readonly and k in readonly_props: # pyright: ignore[reportUnboundVariable] continue - is_multipart_file = False + is_multipart_file_input = False try: - is_multipart_file = next( + is_multipart_file_input = next( rf for rf in self._attr_to_rest_field.values() if rf._rest_name == k - )._is_multipart_file + )._is_multipart_file_input except StopIteration: pass - result[k] = v if is_multipart_file else Model._as_dict_value(v, exclude_readonly=exclude_readonly) + result[k] = v if is_multipart_file_input else Model._as_dict_value(v, exclude_readonly=exclude_readonly) return result @staticmethod @@ -775,7 +775,7 @@ def __init__( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, - is_multipart_file: bool = False, + is_multipart_file_input: bool = False, ): self._type = type self._rest_name_input = name @@ -785,7 +785,7 @@ def __init__( self._is_model = False self._default = default self._format = format - self._is_multipart_file = is_multipart_file + self._is_multipart_file_input = is_multipart_file_input @property def _rest_name(self) -> str: @@ -831,10 +831,15 @@ def rest_field( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, - is_multipart_file: bool = False, + is_multipart_file_input: bool = False, ) -> typing.Any: return _RestField( - name=name, type=type, visibility=visibility, default=default, format=format, is_multipart_file=is_multipart_file + name=name, + type=type, + visibility=visibility, + default=default, + format=format, + is_multipart_file_input=is_multipart_file_input, ) diff --git a/packages/typespec-python/test/azure/generated/client-structure-twooperationgroup/client/structure/twooperationgroup/_model_base.py b/packages/typespec-python/test/azure/generated/client-structure-twooperationgroup/client/structure/twooperationgroup/_model_base.py index 01c401e6324..247049f44d9 100644 --- a/packages/typespec-python/test/azure/generated/client-structure-twooperationgroup/client/structure/twooperationgroup/_model_base.py +++ b/packages/typespec-python/test/azure/generated/client-structure-twooperationgroup/client/structure/twooperationgroup/_model_base.py @@ -464,7 +464,7 @@ def _get_rest_field( def _create_value(rf: typing.Optional["_RestField"], value: typing.Any) -> typing.Any: if not rf: return _serialize(value, None) - if rf._is_multipart_file: + if rf._is_multipart_file_input: return value if rf._is_model: return _deserialize(rf._type, value) @@ -565,14 +565,14 @@ def as_dict(self, *, exclude_readonly: bool = False) -> typing.Dict[str, typing. for k, v in self.items(): if exclude_readonly and k in readonly_props: # pyright: ignore[reportUnboundVariable] continue - is_multipart_file = False + is_multipart_file_input = False try: - is_multipart_file = next( + is_multipart_file_input = next( rf for rf in self._attr_to_rest_field.values() if rf._rest_name == k - )._is_multipart_file + )._is_multipart_file_input except StopIteration: pass - result[k] = v if is_multipart_file else Model._as_dict_value(v, exclude_readonly=exclude_readonly) + result[k] = v if is_multipart_file_input else Model._as_dict_value(v, exclude_readonly=exclude_readonly) return result @staticmethod @@ -775,7 +775,7 @@ def __init__( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, - is_multipart_file: bool = False, + is_multipart_file_input: bool = False, ): self._type = type self._rest_name_input = name @@ -785,7 +785,7 @@ def __init__( self._is_model = False self._default = default self._format = format - self._is_multipart_file = is_multipart_file + self._is_multipart_file_input = is_multipart_file_input @property def _rest_name(self) -> str: @@ -831,10 +831,15 @@ def rest_field( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, - is_multipart_file: bool = False, + is_multipart_file_input: bool = False, ) -> typing.Any: return _RestField( - name=name, type=type, visibility=visibility, default=default, format=format, is_multipart_file=is_multipart_file + name=name, + type=type, + visibility=visibility, + default=default, + format=format, + is_multipart_file_input=is_multipart_file_input, ) diff --git a/packages/typespec-python/test/azure/generated/encode-bytes/encode/bytes/_model_base.py b/packages/typespec-python/test/azure/generated/encode-bytes/encode/bytes/_model_base.py index 01c401e6324..247049f44d9 100644 --- a/packages/typespec-python/test/azure/generated/encode-bytes/encode/bytes/_model_base.py +++ b/packages/typespec-python/test/azure/generated/encode-bytes/encode/bytes/_model_base.py @@ -464,7 +464,7 @@ def _get_rest_field( def _create_value(rf: typing.Optional["_RestField"], value: typing.Any) -> typing.Any: if not rf: return _serialize(value, None) - if rf._is_multipart_file: + if rf._is_multipart_file_input: return value if rf._is_model: return _deserialize(rf._type, value) @@ -565,14 +565,14 @@ def as_dict(self, *, exclude_readonly: bool = False) -> typing.Dict[str, typing. for k, v in self.items(): if exclude_readonly and k in readonly_props: # pyright: ignore[reportUnboundVariable] continue - is_multipart_file = False + is_multipart_file_input = False try: - is_multipart_file = next( + is_multipart_file_input = next( rf for rf in self._attr_to_rest_field.values() if rf._rest_name == k - )._is_multipart_file + )._is_multipart_file_input except StopIteration: pass - result[k] = v if is_multipart_file else Model._as_dict_value(v, exclude_readonly=exclude_readonly) + result[k] = v if is_multipart_file_input else Model._as_dict_value(v, exclude_readonly=exclude_readonly) return result @staticmethod @@ -775,7 +775,7 @@ def __init__( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, - is_multipart_file: bool = False, + is_multipart_file_input: bool = False, ): self._type = type self._rest_name_input = name @@ -785,7 +785,7 @@ def __init__( self._is_model = False self._default = default self._format = format - self._is_multipart_file = is_multipart_file + self._is_multipart_file_input = is_multipart_file_input @property def _rest_name(self) -> str: @@ -831,10 +831,15 @@ def rest_field( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, - is_multipart_file: bool = False, + is_multipart_file_input: bool = False, ) -> typing.Any: return _RestField( - name=name, type=type, visibility=visibility, default=default, format=format, is_multipart_file=is_multipart_file + name=name, + type=type, + visibility=visibility, + default=default, + format=format, + is_multipart_file_input=is_multipart_file_input, ) diff --git a/packages/typespec-python/test/azure/generated/encode-datetime/encode/datetime/_model_base.py b/packages/typespec-python/test/azure/generated/encode-datetime/encode/datetime/_model_base.py index 01c401e6324..247049f44d9 100644 --- a/packages/typespec-python/test/azure/generated/encode-datetime/encode/datetime/_model_base.py +++ b/packages/typespec-python/test/azure/generated/encode-datetime/encode/datetime/_model_base.py @@ -464,7 +464,7 @@ def _get_rest_field( def _create_value(rf: typing.Optional["_RestField"], value: typing.Any) -> typing.Any: if not rf: return _serialize(value, None) - if rf._is_multipart_file: + if rf._is_multipart_file_input: return value if rf._is_model: return _deserialize(rf._type, value) @@ -565,14 +565,14 @@ def as_dict(self, *, exclude_readonly: bool = False) -> typing.Dict[str, typing. for k, v in self.items(): if exclude_readonly and k in readonly_props: # pyright: ignore[reportUnboundVariable] continue - is_multipart_file = False + is_multipart_file_input = False try: - is_multipart_file = next( + is_multipart_file_input = next( rf for rf in self._attr_to_rest_field.values() if rf._rest_name == k - )._is_multipart_file + )._is_multipart_file_input except StopIteration: pass - result[k] = v if is_multipart_file else Model._as_dict_value(v, exclude_readonly=exclude_readonly) + result[k] = v if is_multipart_file_input else Model._as_dict_value(v, exclude_readonly=exclude_readonly) return result @staticmethod @@ -775,7 +775,7 @@ def __init__( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, - is_multipart_file: bool = False, + is_multipart_file_input: bool = False, ): self._type = type self._rest_name_input = name @@ -785,7 +785,7 @@ def __init__( self._is_model = False self._default = default self._format = format - self._is_multipart_file = is_multipart_file + self._is_multipart_file_input = is_multipart_file_input @property def _rest_name(self) -> str: @@ -831,10 +831,15 @@ def rest_field( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, - is_multipart_file: bool = False, + is_multipart_file_input: bool = False, ) -> typing.Any: return _RestField( - name=name, type=type, visibility=visibility, default=default, format=format, is_multipart_file=is_multipart_file + name=name, + type=type, + visibility=visibility, + default=default, + format=format, + is_multipart_file_input=is_multipart_file_input, ) diff --git a/packages/typespec-python/test/azure/generated/encode-duration/encode/duration/_model_base.py b/packages/typespec-python/test/azure/generated/encode-duration/encode/duration/_model_base.py index 01c401e6324..247049f44d9 100644 --- a/packages/typespec-python/test/azure/generated/encode-duration/encode/duration/_model_base.py +++ b/packages/typespec-python/test/azure/generated/encode-duration/encode/duration/_model_base.py @@ -464,7 +464,7 @@ def _get_rest_field( def _create_value(rf: typing.Optional["_RestField"], value: typing.Any) -> typing.Any: if not rf: return _serialize(value, None) - if rf._is_multipart_file: + if rf._is_multipart_file_input: return value if rf._is_model: return _deserialize(rf._type, value) @@ -565,14 +565,14 @@ def as_dict(self, *, exclude_readonly: bool = False) -> typing.Dict[str, typing. for k, v in self.items(): if exclude_readonly and k in readonly_props: # pyright: ignore[reportUnboundVariable] continue - is_multipart_file = False + is_multipart_file_input = False try: - is_multipart_file = next( + is_multipart_file_input = next( rf for rf in self._attr_to_rest_field.values() if rf._rest_name == k - )._is_multipart_file + )._is_multipart_file_input except StopIteration: pass - result[k] = v if is_multipart_file else Model._as_dict_value(v, exclude_readonly=exclude_readonly) + result[k] = v if is_multipart_file_input else Model._as_dict_value(v, exclude_readonly=exclude_readonly) return result @staticmethod @@ -775,7 +775,7 @@ def __init__( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, - is_multipart_file: bool = False, + is_multipart_file_input: bool = False, ): self._type = type self._rest_name_input = name @@ -785,7 +785,7 @@ def __init__( self._is_model = False self._default = default self._format = format - self._is_multipart_file = is_multipart_file + self._is_multipart_file_input = is_multipart_file_input @property def _rest_name(self) -> str: @@ -831,10 +831,15 @@ def rest_field( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, - is_multipart_file: bool = False, + is_multipart_file_input: bool = False, ) -> typing.Any: return _RestField( - name=name, type=type, visibility=visibility, default=default, format=format, is_multipart_file=is_multipart_file + name=name, + type=type, + visibility=visibility, + default=default, + format=format, + is_multipart_file_input=is_multipart_file_input, ) diff --git a/packages/typespec-python/test/azure/generated/headasbooleanfalse/headasbooleanfalse/_model_base.py b/packages/typespec-python/test/azure/generated/headasbooleanfalse/headasbooleanfalse/_model_base.py index 01c401e6324..247049f44d9 100644 --- a/packages/typespec-python/test/azure/generated/headasbooleanfalse/headasbooleanfalse/_model_base.py +++ b/packages/typespec-python/test/azure/generated/headasbooleanfalse/headasbooleanfalse/_model_base.py @@ -464,7 +464,7 @@ def _get_rest_field( def _create_value(rf: typing.Optional["_RestField"], value: typing.Any) -> typing.Any: if not rf: return _serialize(value, None) - if rf._is_multipart_file: + if rf._is_multipart_file_input: return value if rf._is_model: return _deserialize(rf._type, value) @@ -565,14 +565,14 @@ def as_dict(self, *, exclude_readonly: bool = False) -> typing.Dict[str, typing. for k, v in self.items(): if exclude_readonly and k in readonly_props: # pyright: ignore[reportUnboundVariable] continue - is_multipart_file = False + is_multipart_file_input = False try: - is_multipart_file = next( + is_multipart_file_input = next( rf for rf in self._attr_to_rest_field.values() if rf._rest_name == k - )._is_multipart_file + )._is_multipart_file_input except StopIteration: pass - result[k] = v if is_multipart_file else Model._as_dict_value(v, exclude_readonly=exclude_readonly) + result[k] = v if is_multipart_file_input else Model._as_dict_value(v, exclude_readonly=exclude_readonly) return result @staticmethod @@ -775,7 +775,7 @@ def __init__( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, - is_multipart_file: bool = False, + is_multipart_file_input: bool = False, ): self._type = type self._rest_name_input = name @@ -785,7 +785,7 @@ def __init__( self._is_model = False self._default = default self._format = format - self._is_multipart_file = is_multipart_file + self._is_multipart_file_input = is_multipart_file_input @property def _rest_name(self) -> str: @@ -831,10 +831,15 @@ def rest_field( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, - is_multipart_file: bool = False, + is_multipart_file_input: bool = False, ) -> typing.Any: return _RestField( - name=name, type=type, visibility=visibility, default=default, format=format, is_multipart_file=is_multipart_file + name=name, + type=type, + visibility=visibility, + default=default, + format=format, + is_multipart_file_input=is_multipart_file_input, ) diff --git a/packages/typespec-python/test/azure/generated/headasbooleantrue/headasbooleantrue/_model_base.py b/packages/typespec-python/test/azure/generated/headasbooleantrue/headasbooleantrue/_model_base.py index 01c401e6324..247049f44d9 100644 --- a/packages/typespec-python/test/azure/generated/headasbooleantrue/headasbooleantrue/_model_base.py +++ b/packages/typespec-python/test/azure/generated/headasbooleantrue/headasbooleantrue/_model_base.py @@ -464,7 +464,7 @@ def _get_rest_field( def _create_value(rf: typing.Optional["_RestField"], value: typing.Any) -> typing.Any: if not rf: return _serialize(value, None) - if rf._is_multipart_file: + if rf._is_multipart_file_input: return value if rf._is_model: return _deserialize(rf._type, value) @@ -565,14 +565,14 @@ def as_dict(self, *, exclude_readonly: bool = False) -> typing.Dict[str, typing. for k, v in self.items(): if exclude_readonly and k in readonly_props: # pyright: ignore[reportUnboundVariable] continue - is_multipart_file = False + is_multipart_file_input = False try: - is_multipart_file = next( + is_multipart_file_input = next( rf for rf in self._attr_to_rest_field.values() if rf._rest_name == k - )._is_multipart_file + )._is_multipart_file_input except StopIteration: pass - result[k] = v if is_multipart_file else Model._as_dict_value(v, exclude_readonly=exclude_readonly) + result[k] = v if is_multipart_file_input else Model._as_dict_value(v, exclude_readonly=exclude_readonly) return result @staticmethod @@ -775,7 +775,7 @@ def __init__( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, - is_multipart_file: bool = False, + is_multipart_file_input: bool = False, ): self._type = type self._rest_name_input = name @@ -785,7 +785,7 @@ def __init__( self._is_model = False self._default = default self._format = format - self._is_multipart_file = is_multipart_file + self._is_multipart_file_input = is_multipart_file_input @property def _rest_name(self) -> str: @@ -831,10 +831,15 @@ def rest_field( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, - is_multipart_file: bool = False, + is_multipart_file_input: bool = False, ) -> typing.Any: return _RestField( - name=name, type=type, visibility=visibility, default=default, format=format, is_multipart_file=is_multipart_file + name=name, + type=type, + visibility=visibility, + default=default, + format=format, + is_multipart_file_input=is_multipart_file_input, ) diff --git a/packages/typespec-python/test/azure/generated/parameters-body-optionality/parameters/bodyoptionality/_model_base.py b/packages/typespec-python/test/azure/generated/parameters-body-optionality/parameters/bodyoptionality/_model_base.py index 01c401e6324..247049f44d9 100644 --- a/packages/typespec-python/test/azure/generated/parameters-body-optionality/parameters/bodyoptionality/_model_base.py +++ b/packages/typespec-python/test/azure/generated/parameters-body-optionality/parameters/bodyoptionality/_model_base.py @@ -464,7 +464,7 @@ def _get_rest_field( def _create_value(rf: typing.Optional["_RestField"], value: typing.Any) -> typing.Any: if not rf: return _serialize(value, None) - if rf._is_multipart_file: + if rf._is_multipart_file_input: return value if rf._is_model: return _deserialize(rf._type, value) @@ -565,14 +565,14 @@ def as_dict(self, *, exclude_readonly: bool = False) -> typing.Dict[str, typing. for k, v in self.items(): if exclude_readonly and k in readonly_props: # pyright: ignore[reportUnboundVariable] continue - is_multipart_file = False + is_multipart_file_input = False try: - is_multipart_file = next( + is_multipart_file_input = next( rf for rf in self._attr_to_rest_field.values() if rf._rest_name == k - )._is_multipart_file + )._is_multipart_file_input except StopIteration: pass - result[k] = v if is_multipart_file else Model._as_dict_value(v, exclude_readonly=exclude_readonly) + result[k] = v if is_multipart_file_input else Model._as_dict_value(v, exclude_readonly=exclude_readonly) return result @staticmethod @@ -775,7 +775,7 @@ def __init__( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, - is_multipart_file: bool = False, + is_multipart_file_input: bool = False, ): self._type = type self._rest_name_input = name @@ -785,7 +785,7 @@ def __init__( self._is_model = False self._default = default self._format = format - self._is_multipart_file = is_multipart_file + self._is_multipart_file_input = is_multipart_file_input @property def _rest_name(self) -> str: @@ -831,10 +831,15 @@ def rest_field( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, - is_multipart_file: bool = False, + is_multipart_file_input: bool = False, ) -> typing.Any: return _RestField( - name=name, type=type, visibility=visibility, default=default, format=format, is_multipart_file=is_multipart_file + name=name, + type=type, + visibility=visibility, + default=default, + format=format, + is_multipart_file_input=is_multipart_file_input, ) diff --git a/packages/typespec-python/test/azure/generated/parameters-collection-format/parameters/collectionformat/_model_base.py b/packages/typespec-python/test/azure/generated/parameters-collection-format/parameters/collectionformat/_model_base.py index 01c401e6324..247049f44d9 100644 --- a/packages/typespec-python/test/azure/generated/parameters-collection-format/parameters/collectionformat/_model_base.py +++ b/packages/typespec-python/test/azure/generated/parameters-collection-format/parameters/collectionformat/_model_base.py @@ -464,7 +464,7 @@ def _get_rest_field( def _create_value(rf: typing.Optional["_RestField"], value: typing.Any) -> typing.Any: if not rf: return _serialize(value, None) - if rf._is_multipart_file: + if rf._is_multipart_file_input: return value if rf._is_model: return _deserialize(rf._type, value) @@ -565,14 +565,14 @@ def as_dict(self, *, exclude_readonly: bool = False) -> typing.Dict[str, typing. for k, v in self.items(): if exclude_readonly and k in readonly_props: # pyright: ignore[reportUnboundVariable] continue - is_multipart_file = False + is_multipart_file_input = False try: - is_multipart_file = next( + is_multipart_file_input = next( rf for rf in self._attr_to_rest_field.values() if rf._rest_name == k - )._is_multipart_file + )._is_multipart_file_input except StopIteration: pass - result[k] = v if is_multipart_file else Model._as_dict_value(v, exclude_readonly=exclude_readonly) + result[k] = v if is_multipart_file_input else Model._as_dict_value(v, exclude_readonly=exclude_readonly) return result @staticmethod @@ -775,7 +775,7 @@ def __init__( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, - is_multipart_file: bool = False, + is_multipart_file_input: bool = False, ): self._type = type self._rest_name_input = name @@ -785,7 +785,7 @@ def __init__( self._is_model = False self._default = default self._format = format - self._is_multipart_file = is_multipart_file + self._is_multipart_file_input = is_multipart_file_input @property def _rest_name(self) -> str: @@ -831,10 +831,15 @@ def rest_field( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, - is_multipart_file: bool = False, + is_multipart_file_input: bool = False, ) -> typing.Any: return _RestField( - name=name, type=type, visibility=visibility, default=default, format=format, is_multipart_file=is_multipart_file + name=name, + type=type, + visibility=visibility, + default=default, + format=format, + is_multipart_file_input=is_multipart_file_input, ) diff --git a/packages/typespec-python/test/azure/generated/parameters-spread/parameters/spread/_model_base.py b/packages/typespec-python/test/azure/generated/parameters-spread/parameters/spread/_model_base.py index 01c401e6324..247049f44d9 100644 --- a/packages/typespec-python/test/azure/generated/parameters-spread/parameters/spread/_model_base.py +++ b/packages/typespec-python/test/azure/generated/parameters-spread/parameters/spread/_model_base.py @@ -464,7 +464,7 @@ def _get_rest_field( def _create_value(rf: typing.Optional["_RestField"], value: typing.Any) -> typing.Any: if not rf: return _serialize(value, None) - if rf._is_multipart_file: + if rf._is_multipart_file_input: return value if rf._is_model: return _deserialize(rf._type, value) @@ -565,14 +565,14 @@ def as_dict(self, *, exclude_readonly: bool = False) -> typing.Dict[str, typing. for k, v in self.items(): if exclude_readonly and k in readonly_props: # pyright: ignore[reportUnboundVariable] continue - is_multipart_file = False + is_multipart_file_input = False try: - is_multipart_file = next( + is_multipart_file_input = next( rf for rf in self._attr_to_rest_field.values() if rf._rest_name == k - )._is_multipart_file + )._is_multipart_file_input except StopIteration: pass - result[k] = v if is_multipart_file else Model._as_dict_value(v, exclude_readonly=exclude_readonly) + result[k] = v if is_multipart_file_input else Model._as_dict_value(v, exclude_readonly=exclude_readonly) return result @staticmethod @@ -775,7 +775,7 @@ def __init__( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, - is_multipart_file: bool = False, + is_multipart_file_input: bool = False, ): self._type = type self._rest_name_input = name @@ -785,7 +785,7 @@ def __init__( self._is_model = False self._default = default self._format = format - self._is_multipart_file = is_multipart_file + self._is_multipart_file_input = is_multipart_file_input @property def _rest_name(self) -> str: @@ -831,10 +831,15 @@ def rest_field( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, - is_multipart_file: bool = False, + is_multipart_file_input: bool = False, ) -> typing.Any: return _RestField( - name=name, type=type, visibility=visibility, default=default, format=format, is_multipart_file=is_multipart_file + name=name, + type=type, + visibility=visibility, + default=default, + format=format, + is_multipart_file_input=is_multipart_file_input, ) diff --git a/packages/typespec-python/test/azure/generated/payload-content-negotiation/payload/contentnegotiation/_model_base.py b/packages/typespec-python/test/azure/generated/payload-content-negotiation/payload/contentnegotiation/_model_base.py index 01c401e6324..247049f44d9 100644 --- a/packages/typespec-python/test/azure/generated/payload-content-negotiation/payload/contentnegotiation/_model_base.py +++ b/packages/typespec-python/test/azure/generated/payload-content-negotiation/payload/contentnegotiation/_model_base.py @@ -464,7 +464,7 @@ def _get_rest_field( def _create_value(rf: typing.Optional["_RestField"], value: typing.Any) -> typing.Any: if not rf: return _serialize(value, None) - if rf._is_multipart_file: + if rf._is_multipart_file_input: return value if rf._is_model: return _deserialize(rf._type, value) @@ -565,14 +565,14 @@ def as_dict(self, *, exclude_readonly: bool = False) -> typing.Dict[str, typing. for k, v in self.items(): if exclude_readonly and k in readonly_props: # pyright: ignore[reportUnboundVariable] continue - is_multipart_file = False + is_multipart_file_input = False try: - is_multipart_file = next( + is_multipart_file_input = next( rf for rf in self._attr_to_rest_field.values() if rf._rest_name == k - )._is_multipart_file + )._is_multipart_file_input except StopIteration: pass - result[k] = v if is_multipart_file else Model._as_dict_value(v, exclude_readonly=exclude_readonly) + result[k] = v if is_multipart_file_input else Model._as_dict_value(v, exclude_readonly=exclude_readonly) return result @staticmethod @@ -775,7 +775,7 @@ def __init__( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, - is_multipart_file: bool = False, + is_multipart_file_input: bool = False, ): self._type = type self._rest_name_input = name @@ -785,7 +785,7 @@ def __init__( self._is_model = False self._default = default self._format = format - self._is_multipart_file = is_multipart_file + self._is_multipart_file_input = is_multipart_file_input @property def _rest_name(self) -> str: @@ -831,10 +831,15 @@ def rest_field( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, - is_multipart_file: bool = False, + is_multipart_file_input: bool = False, ) -> typing.Any: return _RestField( - name=name, type=type, visibility=visibility, default=default, format=format, is_multipart_file=is_multipart_file + name=name, + type=type, + visibility=visibility, + default=default, + format=format, + is_multipart_file_input=is_multipart_file_input, ) diff --git a/packages/typespec-python/test/azure/generated/payload-media-type/payload/mediatype/_model_base.py b/packages/typespec-python/test/azure/generated/payload-media-type/payload/mediatype/_model_base.py index 01c401e6324..247049f44d9 100644 --- a/packages/typespec-python/test/azure/generated/payload-media-type/payload/mediatype/_model_base.py +++ b/packages/typespec-python/test/azure/generated/payload-media-type/payload/mediatype/_model_base.py @@ -464,7 +464,7 @@ def _get_rest_field( def _create_value(rf: typing.Optional["_RestField"], value: typing.Any) -> typing.Any: if not rf: return _serialize(value, None) - if rf._is_multipart_file: + if rf._is_multipart_file_input: return value if rf._is_model: return _deserialize(rf._type, value) @@ -565,14 +565,14 @@ def as_dict(self, *, exclude_readonly: bool = False) -> typing.Dict[str, typing. for k, v in self.items(): if exclude_readonly and k in readonly_props: # pyright: ignore[reportUnboundVariable] continue - is_multipart_file = False + is_multipart_file_input = False try: - is_multipart_file = next( + is_multipart_file_input = next( rf for rf in self._attr_to_rest_field.values() if rf._rest_name == k - )._is_multipart_file + )._is_multipart_file_input except StopIteration: pass - result[k] = v if is_multipart_file else Model._as_dict_value(v, exclude_readonly=exclude_readonly) + result[k] = v if is_multipart_file_input else Model._as_dict_value(v, exclude_readonly=exclude_readonly) return result @staticmethod @@ -775,7 +775,7 @@ def __init__( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, - is_multipart_file: bool = False, + is_multipart_file_input: bool = False, ): self._type = type self._rest_name_input = name @@ -785,7 +785,7 @@ def __init__( self._is_model = False self._default = default self._format = format - self._is_multipart_file = is_multipart_file + self._is_multipart_file_input = is_multipart_file_input @property def _rest_name(self) -> str: @@ -831,10 +831,15 @@ def rest_field( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, - is_multipart_file: bool = False, + is_multipart_file_input: bool = False, ) -> typing.Any: return _RestField( - name=name, type=type, visibility=visibility, default=default, format=format, is_multipart_file=is_multipart_file + name=name, + type=type, + visibility=visibility, + default=default, + format=format, + is_multipart_file_input=is_multipart_file_input, ) diff --git a/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/_model_base.py b/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/_model_base.py index 01c401e6324..247049f44d9 100644 --- a/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/_model_base.py +++ b/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/_model_base.py @@ -464,7 +464,7 @@ def _get_rest_field( def _create_value(rf: typing.Optional["_RestField"], value: typing.Any) -> typing.Any: if not rf: return _serialize(value, None) - if rf._is_multipart_file: + if rf._is_multipart_file_input: return value if rf._is_model: return _deserialize(rf._type, value) @@ -565,14 +565,14 @@ def as_dict(self, *, exclude_readonly: bool = False) -> typing.Dict[str, typing. for k, v in self.items(): if exclude_readonly and k in readonly_props: # pyright: ignore[reportUnboundVariable] continue - is_multipart_file = False + is_multipart_file_input = False try: - is_multipart_file = next( + is_multipart_file_input = next( rf for rf in self._attr_to_rest_field.values() if rf._rest_name == k - )._is_multipart_file + )._is_multipart_file_input except StopIteration: pass - result[k] = v if is_multipart_file else Model._as_dict_value(v, exclude_readonly=exclude_readonly) + result[k] = v if is_multipart_file_input else Model._as_dict_value(v, exclude_readonly=exclude_readonly) return result @staticmethod @@ -775,7 +775,7 @@ def __init__( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, - is_multipart_file: bool = False, + is_multipart_file_input: bool = False, ): self._type = type self._rest_name_input = name @@ -785,7 +785,7 @@ def __init__( self._is_model = False self._default = default self._format = format - self._is_multipart_file = is_multipart_file + self._is_multipart_file_input = is_multipart_file_input @property def _rest_name(self) -> str: @@ -831,10 +831,15 @@ def rest_field( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, - is_multipart_file: bool = False, + is_multipart_file_input: bool = False, ) -> typing.Any: return _RestField( - name=name, type=type, visibility=visibility, default=default, format=format, is_multipart_file=is_multipart_file + name=name, + type=type, + visibility=visibility, + default=default, + format=format, + is_multipart_file_input=is_multipart_file_input, ) diff --git a/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/aio/operations/_operations.py b/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/aio/operations/_operations.py index a901550360c..65c01f73a5a 100644 --- a/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/aio/operations/_operations.py +++ b/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/aio/operations/_operations.py @@ -77,7 +77,7 @@ async def basic( # pylint: disable=inconsistent-return-statements # JSON input template you can fill out and use as your body input. body = { "id": "str", # Required. - "profileImage": FileInputType # Required. + "profileImage": filetype } """ @@ -110,7 +110,7 @@ async def basic( # pylint: disable=inconsistent-return-statements # JSON input template you can fill out and use as your body input. body = { "id": "str", # Required. - "profileImage": FileInputType # Required. + "profileImage": filetype } """ error_map = { @@ -126,21 +126,17 @@ async def basic( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) - content_type = content_type or "multipart/form-data" - _content = None - if isinstance(body, _model_base.Model): - _body = body.as_dict() if isinstance(body, _model_base.Model) else body - _files = [] - _data = {} - if _body.get("id") is not None: - _data["id"] = _body["id"] - if _body.get("profileImage") is not None: - _files.append(("profileImage", _body["profileImage"])) - elif isinstance(body, MutableMapping): - _content = body + _body = body.as_dict() if isinstance(body, _model_base.Model) else body + _files = [] + _data = {} + if _body.get("id") is not None: + _data["id"] = _body["id"] + if _body.get("profileImage") is not None: + _files.append(("profileImage", _body["profileImage"])) _request = build_form_data_basic_request( - content=_content, + files=_files, + data=_data, headers=_headers, params=_params, ) @@ -183,15 +179,13 @@ async def complex( # pylint: disable=inconsistent-return-statements "city": "str" # Required. }, "id": "str", # Required. - "pictures": [ - FileInputType # Required. - ], + "pictures": [filetype], "previousAddresses": [ { "city": "str" # Required. } ], - "profileImage": FileInputType # Required. + "profileImage": filetype } """ @@ -227,15 +221,13 @@ async def complex( # pylint: disable=inconsistent-return-statements "city": "str" # Required. }, "id": "str", # Required. - "pictures": [ - FileInputType # Required. - ], + "pictures": [filetype], "previousAddresses": [ { "city": "str" # Required. } ], - "profileImage": FileInputType # Required. + "profileImage": filetype } """ error_map = { @@ -251,27 +243,25 @@ async def complex( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) - content_type = content_type or "multipart/form-data" - _content = None - if isinstance(body, _model_base.Model): - _body = body.as_dict() if isinstance(body, _model_base.Model) else body - _files = [] - _data = {} - if _body.get("id") is not None: - _data["id"] = _body["id"] - if _body.get("address") is not None: - _data["address"] = _body["address"] - if _body.get("profileImage") is not None: - _files.append(("profileImage", _body["profileImage"])) - if _body.get("previousAddresses") is not None: - _data["previousAddresses"] = _body["previousAddresses"] - if _body.get("pictures") is not None: - _files.extend([("pictures", p) for p in _body["pictures"]]) - elif isinstance(body, MutableMapping): - _content = body + _body = body.as_dict() if isinstance(body, _model_base.Model) else body + _files = [] + _data = {} + if _body.get("id") is not None: + _data["id"] = _body["id"] + if _body.get("address") is not None: + _data["address"] = json.dumps(_body["address"], cls=SdkJSONEncoder, exclude_readonly=True) + if _body.get("profileImage") is not None: + _files.append(("profileImage", _body["profileImage"])) + if _body.get("previousAddresses") is not None: + _data["previousAddresses"] = json.dumps( + _body["previousAddresses"], cls=SdkJSONEncoder, exclude_readonly=True + ) + if _body.get("pictures") is not None: + _files.extend([("pictures", p) for p in _body["pictures"]]) _request = build_form_data_complex_request( - content=_content, + files=_files, + data=_data, headers=_headers, params=_params, ) @@ -313,7 +303,7 @@ async def json_part( # pylint: disable=inconsistent-return-statements "address": { "city": "str" # Required. }, - "profileImage": FileInputType # Required. + "profileImage": filetype } """ @@ -348,7 +338,7 @@ async def json_part( # pylint: disable=inconsistent-return-statements "address": { "city": "str" # Required. }, - "profileImage": FileInputType # Required. + "profileImage": filetype } """ error_map = { @@ -364,21 +354,17 @@ async def json_part( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) - content_type = content_type or "multipart/form-data" - _content = None - if isinstance(body, _model_base.Model): - _body = body.as_dict() if isinstance(body, _model_base.Model) else body - _files = [] - _data = {} - if _body.get("address") is not None: - _data["address"] = _body["address"] - if _body.get("profileImage") is not None: - _files.append(("profileImage", _body["profileImage"])) - elif isinstance(body, MutableMapping): - _content = body + _body = body.as_dict() if isinstance(body, _model_base.Model) else body + _files = [] + _data = {} + if _body.get("address") is not None: + _data["address"] = json.dumps(_body["address"], cls=SdkJSONEncoder, exclude_readonly=True) + if _body.get("profileImage") is not None: + _files.append(("profileImage", _body["profileImage"])) _request = build_form_data_json_part_request( - content=_content, + files=_files, + data=_data, headers=_headers, params=_params, ) @@ -418,9 +404,7 @@ async def binary_array_parts( # pylint: disable=inconsistent-return-statements # JSON input template you can fill out and use as your body input. body = { "id": "str", # Required. - "pictures": [ - FileInputType # Required. - ] + "pictures": [filetype] } """ @@ -455,9 +439,7 @@ async def binary_array_parts( # pylint: disable=inconsistent-return-statements # JSON input template you can fill out and use as your body input. body = { "id": "str", # Required. - "pictures": [ - FileInputType # Required. - ] + "pictures": [filetype] } """ error_map = { @@ -473,21 +455,17 @@ async def binary_array_parts( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) - content_type = content_type or "multipart/form-data" - _content = None - if isinstance(body, _model_base.Model): - _body = body.as_dict() if isinstance(body, _model_base.Model) else body - _files = [] - _data = {} - if _body.get("id") is not None: - _data["id"] = _body["id"] - if _body.get("pictures") is not None: - _files.extend([("pictures", p) for p in _body["pictures"]]) - elif isinstance(body, MutableMapping): - _content = body + _body = body.as_dict() if isinstance(body, _model_base.Model) else body + _files = [] + _data = {} + if _body.get("id") is not None: + _data["id"] = _body["id"] + if _body.get("pictures") is not None: + _files.extend([("pictures", p) for p in _body["pictures"]]) _request = build_form_data_binary_array_parts_request( - content=_content, + files=_files, + data=_data, headers=_headers, params=_params, ) @@ -531,7 +509,7 @@ async def json_array_parts( # pylint: disable=inconsistent-return-statements "city": "str" # Required. } ], - "profileImage": FileInputType # Required. + "profileImage": filetype } """ @@ -570,7 +548,7 @@ async def json_array_parts( # pylint: disable=inconsistent-return-statements "city": "str" # Required. } ], - "profileImage": FileInputType # Required. + "profileImage": filetype } """ error_map = { @@ -586,21 +564,19 @@ async def json_array_parts( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) - content_type = content_type or "multipart/form-data" - _content = None - if isinstance(body, _model_base.Model): - _body = body.as_dict() if isinstance(body, _model_base.Model) else body - _files = [] - _data = {} - if _body.get("profileImage") is not None: - _files.append(("profileImage", _body["profileImage"])) - if _body.get("previousAddresses") is not None: - _data["previousAddresses"] = _body["previousAddresses"] - elif isinstance(body, MutableMapping): - _content = body + _body = body.as_dict() if isinstance(body, _model_base.Model) else body + _files = [] + _data = {} + if _body.get("profileImage") is not None: + _files.append(("profileImage", _body["profileImage"])) + if _body.get("previousAddresses") is not None: + _data["previousAddresses"] = json.dumps( + _body["previousAddresses"], cls=SdkJSONEncoder, exclude_readonly=True + ) _request = build_form_data_json_array_parts_request( - content=_content, + files=_files, + data=_data, headers=_headers, params=_params, ) @@ -639,8 +615,8 @@ async def multi_binary_parts( # pylint: disable=inconsistent-return-statements # JSON input template you can fill out and use as your body input. body = { - "profileImage": FileInputType, # Required. - "picture": FileInputType # Optional. + "profileImage": filetype, + "picture": filetype } """ @@ -674,8 +650,8 @@ async def multi_binary_parts( # pylint: disable=inconsistent-return-statements # JSON input template you can fill out and use as your body input. body = { - "profileImage": FileInputType, # Required. - "picture": FileInputType # Optional. + "profileImage": filetype, + "picture": filetype } """ error_map = { @@ -691,21 +667,17 @@ async def multi_binary_parts( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) - content_type = content_type or "multipart/form-data" - _content = None - if isinstance(body, _model_base.Model): - _body = body.as_dict() if isinstance(body, _model_base.Model) else body - _files = [] - _data = {} - if _body.get("profileImage") is not None: - _files.append(("profileImage", _body["profileImage"])) - if _body.get("picture") is not None: - _files.append(("picture", _body["picture"])) - elif isinstance(body, MutableMapping): - _content = body + _body = body.as_dict() if isinstance(body, _model_base.Model) else body + _files = [] + _data = {} + if _body.get("profileImage") is not None: + _files.append(("profileImage", _body["profileImage"])) + if _body.get("picture") is not None: + _files.append(("picture", _body["picture"])) _request = build_form_data_multi_binary_parts_request( - content=_content, + files=_files, + data=_data, headers=_headers, params=_params, ) diff --git a/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/models/_models.py b/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/models/_models.py index 012bda1e2d8..759895ff114 100644 --- a/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/models/_models.py +++ b/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/models/_models.py @@ -7,11 +7,11 @@ # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from .._vendor import FileType from typing import Any, List, Mapping, Optional, TYPE_CHECKING, overload from .. import _model_base from .._model_base import rest_field +from .._vendor import FileType if TYPE_CHECKING: # pylint: disable=unused-import,ungrouped-imports @@ -57,12 +57,12 @@ class BinaryArrayPartsRequest(_model_base.Model): :ivar id: Required. :vartype id: str :ivar pictures: Required. - :vartype pictures: list[filetype] + :vartype pictures: list[bytes] """ id: str = rest_field() """Required.""" - pictures: List[FileType] = rest_field(is_multipart_file=True) + pictures: List[FileType] = rest_field(is_multipart_file_input=True) """Required.""" @overload @@ -95,22 +95,22 @@ class ComplexPartsRequest(_model_base.Model): :ivar address: Required. :vartype address: ~payload.multipart.models.Address :ivar profile_image: Required. - :vartype profile_image: filetype + :vartype profile_image: bytes :ivar previous_addresses: Required. :vartype previous_addresses: list[~payload.multipart.models.Address] :ivar pictures: Required. - :vartype pictures: list[filetype] + :vartype pictures: list[bytes] """ id: str = rest_field() """Required.""" address: "_models.Address" = rest_field() """Required.""" - profile_image: FileType = rest_field(name="profileImage", is_multipart_file=True) + profile_image: FileType = rest_field(name="profileImage", is_multipart_file_input=True) """Required.""" previous_addresses: List["_models.Address"] = rest_field(name="previousAddresses") """Required.""" - pictures: List[FileType] = rest_field(is_multipart_file=True) + pictures: List[FileType] = rest_field(is_multipart_file_input=True) """Required.""" @overload @@ -142,12 +142,12 @@ class JsonArrayPartsRequest(_model_base.Model): All required parameters must be populated in order to send to server. :ivar profile_image: Required. - :vartype profile_image: filetype + :vartype profile_image: bytes :ivar previous_addresses: Required. :vartype previous_addresses: list[~payload.multipart.models.Address] """ - profile_image: FileType = rest_field(name="profileImage", is_multipart_file=True) + profile_image: FileType = rest_field(name="profileImage", is_multipart_file_input=True) """Required.""" previous_addresses: List["_models.Address"] = rest_field(name="previousAddresses") """Required.""" @@ -180,12 +180,12 @@ class JsonPartRequest(_model_base.Model): :ivar address: Required. :vartype address: ~payload.multipart.models.Address :ivar profile_image: Required. - :vartype profile_image: filetype + :vartype profile_image: bytes """ address: "_models.Address" = rest_field() """Required.""" - profile_image: FileType = rest_field(name="profileImage", is_multipart_file=True) + profile_image: FileType = rest_field(name="profileImage", is_multipart_file_input=True) """Required.""" @overload @@ -214,21 +214,21 @@ class MultiBinaryPartsRequest(_model_base.Model): All required parameters must be populated in order to send to server. :ivar profile_image: Required. - :vartype profile_image: filetype + :vartype profile_image: bytes :ivar picture: - :vartype picture: filetype + :vartype picture: bytes """ - profile_image: FileType = rest_field(name="profileImage", is_multipart_file=True) + profile_image: FileType = rest_field(name="profileImage", is_multipart_file_input=True) """Required.""" - picture: Optional[FileType] = rest_field(is_multipart_file=True) + picture: FileType = rest_field(is_multipart_file_input=True) @overload def __init__( self, *, profile_image: FileType, - picture: Optional[FileType] = None, + picture: FileType = None, ): ... @@ -251,12 +251,12 @@ class MultiPartRequest(_model_base.Model): :ivar id: Required. :vartype id: str :ivar profile_image: Required. - :vartype profile_image: filetype + :vartype profile_image: bytes """ id: str = rest_field() """Required.""" - profile_image: FileType = rest_field(name="profileImage", is_multipart_file=True) + profile_image: FileType = rest_field(name="profileImage", is_multipart_file_input=True) """Required.""" @overload diff --git a/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/operations/_operations.py b/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/operations/_operations.py index 7e26b076e42..f394cfffc5f 100644 --- a/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/operations/_operations.py +++ b/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/operations/_operations.py @@ -45,10 +45,6 @@ def build_form_data_basic_request(**kwargs: Any) -> HttpRequest: # Construct URL _url = "/multipart/form-data/mixed-parts" - # Construct headers - if content_type is not None: - _headers["content-type"] = _SERIALIZER.header("content_type", content_type, "str") - return HttpRequest(method="POST", url=_url, headers=_headers, **kwargs) @@ -58,10 +54,6 @@ def build_form_data_complex_request(**kwargs: Any) -> HttpRequest: # Construct URL _url = "/multipart/form-data/complex-parts" - # Construct headers - if content_type is not None: - _headers["content-type"] = _SERIALIZER.header("content_type", content_type, "str") - return HttpRequest(method="POST", url=_url, headers=_headers, **kwargs) @@ -71,10 +63,6 @@ def build_form_data_json_part_request(**kwargs: Any) -> HttpRequest: # Construct URL _url = "/multipart/form-data/json-part" - # Construct headers - if content_type is not None: - _headers["content-type"] = _SERIALIZER.header("content_type", content_type, "str") - return HttpRequest(method="POST", url=_url, headers=_headers, **kwargs) @@ -84,10 +72,6 @@ def build_form_data_binary_array_parts_request(**kwargs: Any) -> HttpRequest: # # Construct URL _url = "/multipart/form-data/binary-array-parts" - # Construct headers - if content_type is not None: - _headers["content-type"] = _SERIALIZER.header("content_type", content_type, "str") - return HttpRequest(method="POST", url=_url, headers=_headers, **kwargs) @@ -97,10 +81,6 @@ def build_form_data_json_array_parts_request(**kwargs: Any) -> HttpRequest: # Construct URL _url = "/multipart/form-data/json-array-parts" - # Construct headers - if content_type is not None: - _headers["content-type"] = _SERIALIZER.header("content_type", content_type, "str") - return HttpRequest(method="POST", url=_url, headers=_headers, **kwargs) @@ -110,10 +90,6 @@ def build_form_data_multi_binary_parts_request(**kwargs: Any) -> HttpRequest: # # Construct URL _url = "/multipart/form-data/multi-binary-parts" - # Construct headers - if content_type is not None: - _headers["content-type"] = _SERIALIZER.header("content_type", content_type, "str") - return HttpRequest(method="POST", url=_url, headers=_headers, **kwargs) @@ -152,7 +128,7 @@ def basic( # pylint: disable=inconsistent-return-statements # JSON input template you can fill out and use as your body input. body = { "id": "str", # Required. - "profileImage": FileInputType # Required. + "profileImage": filetype } """ @@ -185,7 +161,7 @@ def basic( # pylint: disable=inconsistent-return-statements # JSON input template you can fill out and use as your body input. body = { "id": "str", # Required. - "profileImage": FileInputType # Required. + "profileImage": filetype } """ error_map = { @@ -201,21 +177,17 @@ def basic( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) - content_type = content_type or "multipart/form-data" - _content = None - if isinstance(body, _model_base.Model): - _body = body.as_dict() if isinstance(body, _model_base.Model) else body - _files = [] - _data = {} - if _body.get("id") is not None: - _data["id"] = _body["id"] - if _body.get("profileImage") is not None: - _files.append(("profileImage", _body["profileImage"])) - elif isinstance(body, MutableMapping): - _content = body + _body = body.as_dict() if isinstance(body, _model_base.Model) else body + _files = [] + _data = {} + if _body.get("id") is not None: + _data["id"] = _body["id"] + if _body.get("profileImage") is not None: + _files.append(("profileImage", _body["profileImage"])) _request = build_form_data_basic_request( - content=_content, + files=_files, + data=_data, headers=_headers, params=_params, ) @@ -258,15 +230,13 @@ def complex( # pylint: disable=inconsistent-return-statements "city": "str" # Required. }, "id": "str", # Required. - "pictures": [ - FileInputType # Required. - ], + "pictures": [filetype], "previousAddresses": [ { "city": "str" # Required. } ], - "profileImage": FileInputType # Required. + "profileImage": filetype } """ @@ -302,15 +272,13 @@ def complex( # pylint: disable=inconsistent-return-statements "city": "str" # Required. }, "id": "str", # Required. - "pictures": [ - FileInputType # Required. - ], + "pictures": [filetype], "previousAddresses": [ { "city": "str" # Required. } ], - "profileImage": FileInputType # Required. + "profileImage": filetype } """ error_map = { @@ -326,27 +294,25 @@ def complex( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) - content_type = content_type or "multipart/form-data" - _content = None - if isinstance(body, _model_base.Model): - _body = body.as_dict() if isinstance(body, _model_base.Model) else body - _files = [] - _data = {} - if _body.get("id") is not None: - _data["id"] = _body["id"] - if _body.get("address") is not None: - _data["address"] = _body["address"] - if _body.get("profileImage") is not None: - _files.append(("profileImage", _body["profileImage"])) - if _body.get("previousAddresses") is not None: - _data["previousAddresses"] = _body["previousAddresses"] - if _body.get("pictures") is not None: - _files.extend([("pictures", p) for p in _body["pictures"]]) - elif isinstance(body, MutableMapping): - _content = body + _body = body.as_dict() if isinstance(body, _model_base.Model) else body + _files = [] + _data = {} + if _body.get("id") is not None: + _data["id"] = _body["id"] + if _body.get("address") is not None: + _data["address"] = json.dumps(_body["address"], cls=SdkJSONEncoder, exclude_readonly=True) + if _body.get("profileImage") is not None: + _files.append(("profileImage", _body["profileImage"])) + if _body.get("previousAddresses") is not None: + _data["previousAddresses"] = json.dumps( + _body["previousAddresses"], cls=SdkJSONEncoder, exclude_readonly=True + ) + if _body.get("pictures") is not None: + _files.extend([("pictures", p) for p in _body["pictures"]]) _request = build_form_data_complex_request( - content=_content, + files=_files, + data=_data, headers=_headers, params=_params, ) @@ -388,7 +354,7 @@ def json_part( # pylint: disable=inconsistent-return-statements "address": { "city": "str" # Required. }, - "profileImage": FileInputType # Required. + "profileImage": filetype } """ @@ -423,7 +389,7 @@ def json_part( # pylint: disable=inconsistent-return-statements "address": { "city": "str" # Required. }, - "profileImage": FileInputType # Required. + "profileImage": filetype } """ error_map = { @@ -439,21 +405,17 @@ def json_part( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) - content_type = content_type or "multipart/form-data" - _content = None - if isinstance(body, _model_base.Model): - _body = body.as_dict() if isinstance(body, _model_base.Model) else body - _files = [] - _data = {} - if _body.get("address") is not None: - _data["address"] = _body["address"] - if _body.get("profileImage") is not None: - _files.append(("profileImage", _body["profileImage"])) - elif isinstance(body, MutableMapping): - _content = body + _body = body.as_dict() if isinstance(body, _model_base.Model) else body + _files = [] + _data = {} + if _body.get("address") is not None: + _data["address"] = json.dumps(_body["address"], cls=SdkJSONEncoder, exclude_readonly=True) + if _body.get("profileImage") is not None: + _files.append(("profileImage", _body["profileImage"])) _request = build_form_data_json_part_request( - content=_content, + files=_files, + data=_data, headers=_headers, params=_params, ) @@ -493,9 +455,7 @@ def binary_array_parts( # pylint: disable=inconsistent-return-statements # JSON input template you can fill out and use as your body input. body = { "id": "str", # Required. - "pictures": [ - FileInputType # Required. - ] + "pictures": [filetype] } """ @@ -528,9 +488,7 @@ def binary_array_parts( # pylint: disable=inconsistent-return-statements # JSON input template you can fill out and use as your body input. body = { "id": "str", # Required. - "pictures": [ - FileInputType # Required. - ] + "pictures": [filetype] } """ error_map = { @@ -546,21 +504,17 @@ def binary_array_parts( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) - content_type = content_type or "multipart/form-data" - _content = None - if isinstance(body, _model_base.Model): - _body = body.as_dict() if isinstance(body, _model_base.Model) else body - _files = [] - _data = {} - if _body.get("id") is not None: - _data["id"] = _body["id"] - if _body.get("pictures") is not None: - _files.extend([("pictures", p) for p in _body["pictures"]]) - elif isinstance(body, MutableMapping): - _content = body + _body = body.as_dict() if isinstance(body, _model_base.Model) else body + _files = [] + _data = {} + if _body.get("id") is not None: + _data["id"] = _body["id"] + if _body.get("pictures") is not None: + _files.extend([("pictures", p) for p in _body["pictures"]]) _request = build_form_data_binary_array_parts_request( - content=_content, + files=_files, + data=_data, headers=_headers, params=_params, ) @@ -604,7 +558,7 @@ def json_array_parts( # pylint: disable=inconsistent-return-statements "city": "str" # Required. } ], - "profileImage": FileInputType # Required. + "profileImage": filetype } """ @@ -641,7 +595,7 @@ def json_array_parts( # pylint: disable=inconsistent-return-statements "city": "str" # Required. } ], - "profileImage": FileInputType # Required. + "profileImage": filetype } """ error_map = { @@ -657,21 +611,19 @@ def json_array_parts( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) - content_type = content_type or "multipart/form-data" - _content = None - if isinstance(body, _model_base.Model): - _body = body.as_dict() if isinstance(body, _model_base.Model) else body - _files = [] - _data = {} - if _body.get("profileImage") is not None: - _files.append(("profileImage", _body["profileImage"])) - if _body.get("previousAddresses") is not None: - _data["previousAddresses"] = _body["previousAddresses"] - elif isinstance(body, MutableMapping): - _content = body + _body = body.as_dict() if isinstance(body, _model_base.Model) else body + _files = [] + _data = {} + if _body.get("profileImage") is not None: + _files.append(("profileImage", _body["profileImage"])) + if _body.get("previousAddresses") is not None: + _data["previousAddresses"] = json.dumps( + _body["previousAddresses"], cls=SdkJSONEncoder, exclude_readonly=True + ) _request = build_form_data_json_array_parts_request( - content=_content, + files=_files, + data=_data, headers=_headers, params=_params, ) @@ -710,8 +662,8 @@ def multi_binary_parts( # pylint: disable=inconsistent-return-statements # JSON input template you can fill out and use as your body input. body = { - "profileImage": FileInputType, # Required. - "picture": FileInputType # Optional. + "profileImage": filetype, + "picture": filetype } """ @@ -743,8 +695,8 @@ def multi_binary_parts( # pylint: disable=inconsistent-return-statements # JSON input template you can fill out and use as your body input. body = { - "profileImage": FileInputType, # Required. - "picture": FileInputType # Optional. + "profileImage": filetype, + "picture": filetype } """ error_map = { @@ -760,21 +712,17 @@ def multi_binary_parts( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) - content_type = content_type or "multipart/form-data" - _content = None - if isinstance(body, _model_base.Model): - _body = body.as_dict() if isinstance(body, _model_base.Model) else body - _files = [] - _data = {} - if _body.get("profileImage") is not None: - _files.append(("profileImage", _body["profileImage"])) - if _body.get("picture") is not None: - _files.append(("picture", _body["picture"])) - elif isinstance(body, MutableMapping): - _content = body + _body = body.as_dict() if isinstance(body, _model_base.Model) else body + _files = [] + _data = {} + if _body.get("profileImage") is not None: + _files.append(("profileImage", _body["profileImage"])) + if _body.get("picture") is not None: + _files.append(("picture", _body["picture"])) _request = build_form_data_multi_binary_parts_request( - content=_content, + files=_files, + data=_data, headers=_headers, params=_params, ) diff --git a/packages/typespec-python/test/azure/generated/payload-pageable/payload/pageable/_model_base.py b/packages/typespec-python/test/azure/generated/payload-pageable/payload/pageable/_model_base.py index 01c401e6324..247049f44d9 100644 --- a/packages/typespec-python/test/azure/generated/payload-pageable/payload/pageable/_model_base.py +++ b/packages/typespec-python/test/azure/generated/payload-pageable/payload/pageable/_model_base.py @@ -464,7 +464,7 @@ def _get_rest_field( def _create_value(rf: typing.Optional["_RestField"], value: typing.Any) -> typing.Any: if not rf: return _serialize(value, None) - if rf._is_multipart_file: + if rf._is_multipart_file_input: return value if rf._is_model: return _deserialize(rf._type, value) @@ -565,14 +565,14 @@ def as_dict(self, *, exclude_readonly: bool = False) -> typing.Dict[str, typing. for k, v in self.items(): if exclude_readonly and k in readonly_props: # pyright: ignore[reportUnboundVariable] continue - is_multipart_file = False + is_multipart_file_input = False try: - is_multipart_file = next( + is_multipart_file_input = next( rf for rf in self._attr_to_rest_field.values() if rf._rest_name == k - )._is_multipart_file + )._is_multipart_file_input except StopIteration: pass - result[k] = v if is_multipart_file else Model._as_dict_value(v, exclude_readonly=exclude_readonly) + result[k] = v if is_multipart_file_input else Model._as_dict_value(v, exclude_readonly=exclude_readonly) return result @staticmethod @@ -775,7 +775,7 @@ def __init__( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, - is_multipart_file: bool = False, + is_multipart_file_input: bool = False, ): self._type = type self._rest_name_input = name @@ -785,7 +785,7 @@ def __init__( self._is_model = False self._default = default self._format = format - self._is_multipart_file = is_multipart_file + self._is_multipart_file_input = is_multipart_file_input @property def _rest_name(self) -> str: @@ -831,10 +831,15 @@ def rest_field( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, - is_multipart_file: bool = False, + is_multipart_file_input: bool = False, ) -> typing.Any: return _RestField( - name=name, type=type, visibility=visibility, default=default, format=format, is_multipart_file=is_multipart_file + name=name, + type=type, + visibility=visibility, + default=default, + format=format, + is_multipart_file_input=is_multipart_file_input, ) diff --git a/packages/typespec-python/test/azure/generated/projection-projected-name/projection/projectedname/_model_base.py b/packages/typespec-python/test/azure/generated/projection-projected-name/projection/projectedname/_model_base.py index 01c401e6324..247049f44d9 100644 --- a/packages/typespec-python/test/azure/generated/projection-projected-name/projection/projectedname/_model_base.py +++ b/packages/typespec-python/test/azure/generated/projection-projected-name/projection/projectedname/_model_base.py @@ -464,7 +464,7 @@ def _get_rest_field( def _create_value(rf: typing.Optional["_RestField"], value: typing.Any) -> typing.Any: if not rf: return _serialize(value, None) - if rf._is_multipart_file: + if rf._is_multipart_file_input: return value if rf._is_model: return _deserialize(rf._type, value) @@ -565,14 +565,14 @@ def as_dict(self, *, exclude_readonly: bool = False) -> typing.Dict[str, typing. for k, v in self.items(): if exclude_readonly and k in readonly_props: # pyright: ignore[reportUnboundVariable] continue - is_multipart_file = False + is_multipart_file_input = False try: - is_multipart_file = next( + is_multipart_file_input = next( rf for rf in self._attr_to_rest_field.values() if rf._rest_name == k - )._is_multipart_file + )._is_multipart_file_input except StopIteration: pass - result[k] = v if is_multipart_file else Model._as_dict_value(v, exclude_readonly=exclude_readonly) + result[k] = v if is_multipart_file_input else Model._as_dict_value(v, exclude_readonly=exclude_readonly) return result @staticmethod @@ -775,7 +775,7 @@ def __init__( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, - is_multipart_file: bool = False, + is_multipart_file_input: bool = False, ): self._type = type self._rest_name_input = name @@ -785,7 +785,7 @@ def __init__( self._is_model = False self._default = default self._format = format - self._is_multipart_file = is_multipart_file + self._is_multipart_file_input = is_multipart_file_input @property def _rest_name(self) -> str: @@ -831,10 +831,15 @@ def rest_field( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, - is_multipart_file: bool = False, + is_multipart_file_input: bool = False, ) -> typing.Any: return _RestField( - name=name, type=type, visibility=visibility, default=default, format=format, is_multipart_file=is_multipart_file + name=name, + type=type, + visibility=visibility, + default=default, + format=format, + is_multipart_file_input=is_multipart_file_input, ) diff --git a/packages/typespec-python/test/azure/generated/resiliency-srv-driven1/resiliency/srv/driven1/_model_base.py b/packages/typespec-python/test/azure/generated/resiliency-srv-driven1/resiliency/srv/driven1/_model_base.py index 585ccb0e0f9..247049f44d9 100644 --- a/packages/typespec-python/test/azure/generated/resiliency-srv-driven1/resiliency/srv/driven1/_model_base.py +++ b/packages/typespec-python/test/azure/generated/resiliency-srv-driven1/resiliency/srv/driven1/_model_base.py @@ -462,7 +462,13 @@ def _get_rest_field( def _create_value(rf: typing.Optional["_RestField"], value: typing.Any) -> typing.Any: - return _deserialize(rf._type, value) if (rf and rf._is_model) else _serialize(value, rf._format if rf else None) + if not rf: + return _serialize(value, None) + if rf._is_multipart_file_input: + return value + if rf._is_model: + return _deserialize(rf._type, value) + return _serialize(value, rf._format) class Model(_MyMutableMapping): @@ -559,7 +565,14 @@ def as_dict(self, *, exclude_readonly: bool = False) -> typing.Dict[str, typing. for k, v in self.items(): if exclude_readonly and k in readonly_props: # pyright: ignore[reportUnboundVariable] continue - result[k] = Model._as_dict_value(v, exclude_readonly=exclude_readonly) + is_multipart_file_input = False + try: + is_multipart_file_input = next( + rf for rf in self._attr_to_rest_field.values() if rf._rest_name == k + )._is_multipart_file_input + except StopIteration: + pass + result[k] = v if is_multipart_file_input else Model._as_dict_value(v, exclude_readonly=exclude_readonly) return result @staticmethod @@ -567,7 +580,7 @@ def _as_dict_value(v: typing.Any, exclude_readonly: bool = False) -> typing.Any: if v is None or isinstance(v, _Null): return None if isinstance(v, (list, tuple, set)): - return [Model._as_dict_value(x, exclude_readonly=exclude_readonly) for x in v] + return type(v)(Model._as_dict_value(x, exclude_readonly=exclude_readonly) for x in v) if isinstance(v, dict): return {dk: Model._as_dict_value(dv, exclude_readonly=exclude_readonly) for dk, dv in v.items()} return v.as_dict(exclude_readonly=exclude_readonly) if hasattr(v, "as_dict") else v @@ -762,6 +775,7 @@ def __init__( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, + is_multipart_file_input: bool = False, ): self._type = type self._rest_name_input = name @@ -771,6 +785,7 @@ def __init__( self._is_model = False self._default = default self._format = format + self._is_multipart_file_input = is_multipart_file_input @property def _rest_name(self) -> str: @@ -816,8 +831,16 @@ def rest_field( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, + is_multipart_file_input: bool = False, ) -> typing.Any: - return _RestField(name=name, type=type, visibility=visibility, default=default, format=format) + return _RestField( + name=name, + type=type, + visibility=visibility, + default=default, + format=format, + is_multipart_file_input=is_multipart_file_input, + ) def rest_discriminator( diff --git a/packages/typespec-python/test/azure/generated/resiliency-srv-driven2/resiliency/srv/driven2/_model_base.py b/packages/typespec-python/test/azure/generated/resiliency-srv-driven2/resiliency/srv/driven2/_model_base.py index 01c401e6324..247049f44d9 100644 --- a/packages/typespec-python/test/azure/generated/resiliency-srv-driven2/resiliency/srv/driven2/_model_base.py +++ b/packages/typespec-python/test/azure/generated/resiliency-srv-driven2/resiliency/srv/driven2/_model_base.py @@ -464,7 +464,7 @@ def _get_rest_field( def _create_value(rf: typing.Optional["_RestField"], value: typing.Any) -> typing.Any: if not rf: return _serialize(value, None) - if rf._is_multipart_file: + if rf._is_multipart_file_input: return value if rf._is_model: return _deserialize(rf._type, value) @@ -565,14 +565,14 @@ def as_dict(self, *, exclude_readonly: bool = False) -> typing.Dict[str, typing. for k, v in self.items(): if exclude_readonly and k in readonly_props: # pyright: ignore[reportUnboundVariable] continue - is_multipart_file = False + is_multipart_file_input = False try: - is_multipart_file = next( + is_multipart_file_input = next( rf for rf in self._attr_to_rest_field.values() if rf._rest_name == k - )._is_multipart_file + )._is_multipart_file_input except StopIteration: pass - result[k] = v if is_multipart_file else Model._as_dict_value(v, exclude_readonly=exclude_readonly) + result[k] = v if is_multipart_file_input else Model._as_dict_value(v, exclude_readonly=exclude_readonly) return result @staticmethod @@ -775,7 +775,7 @@ def __init__( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, - is_multipart_file: bool = False, + is_multipart_file_input: bool = False, ): self._type = type self._rest_name_input = name @@ -785,7 +785,7 @@ def __init__( self._is_model = False self._default = default self._format = format - self._is_multipart_file = is_multipart_file + self._is_multipart_file_input = is_multipart_file_input @property def _rest_name(self) -> str: @@ -831,10 +831,15 @@ def rest_field( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, - is_multipart_file: bool = False, + is_multipart_file_input: bool = False, ) -> typing.Any: return _RestField( - name=name, type=type, visibility=visibility, default=default, format=format, is_multipart_file=is_multipart_file + name=name, + type=type, + visibility=visibility, + default=default, + format=format, + is_multipart_file_input=is_multipart_file_input, ) diff --git a/packages/typespec-python/test/azure/generated/server-path-multiple/server/path/multiple/_model_base.py b/packages/typespec-python/test/azure/generated/server-path-multiple/server/path/multiple/_model_base.py index 01c401e6324..247049f44d9 100644 --- a/packages/typespec-python/test/azure/generated/server-path-multiple/server/path/multiple/_model_base.py +++ b/packages/typespec-python/test/azure/generated/server-path-multiple/server/path/multiple/_model_base.py @@ -464,7 +464,7 @@ def _get_rest_field( def _create_value(rf: typing.Optional["_RestField"], value: typing.Any) -> typing.Any: if not rf: return _serialize(value, None) - if rf._is_multipart_file: + if rf._is_multipart_file_input: return value if rf._is_model: return _deserialize(rf._type, value) @@ -565,14 +565,14 @@ def as_dict(self, *, exclude_readonly: bool = False) -> typing.Dict[str, typing. for k, v in self.items(): if exclude_readonly and k in readonly_props: # pyright: ignore[reportUnboundVariable] continue - is_multipart_file = False + is_multipart_file_input = False try: - is_multipart_file = next( + is_multipart_file_input = next( rf for rf in self._attr_to_rest_field.values() if rf._rest_name == k - )._is_multipart_file + )._is_multipart_file_input except StopIteration: pass - result[k] = v if is_multipart_file else Model._as_dict_value(v, exclude_readonly=exclude_readonly) + result[k] = v if is_multipart_file_input else Model._as_dict_value(v, exclude_readonly=exclude_readonly) return result @staticmethod @@ -775,7 +775,7 @@ def __init__( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, - is_multipart_file: bool = False, + is_multipart_file_input: bool = False, ): self._type = type self._rest_name_input = name @@ -785,7 +785,7 @@ def __init__( self._is_model = False self._default = default self._format = format - self._is_multipart_file = is_multipart_file + self._is_multipart_file_input = is_multipart_file_input @property def _rest_name(self) -> str: @@ -831,10 +831,15 @@ def rest_field( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, - is_multipart_file: bool = False, + is_multipart_file_input: bool = False, ) -> typing.Any: return _RestField( - name=name, type=type, visibility=visibility, default=default, format=format, is_multipart_file=is_multipart_file + name=name, + type=type, + visibility=visibility, + default=default, + format=format, + is_multipart_file_input=is_multipart_file_input, ) diff --git a/packages/typespec-python/test/azure/generated/server-path-single/server/path/single/_model_base.py b/packages/typespec-python/test/azure/generated/server-path-single/server/path/single/_model_base.py index 01c401e6324..247049f44d9 100644 --- a/packages/typespec-python/test/azure/generated/server-path-single/server/path/single/_model_base.py +++ b/packages/typespec-python/test/azure/generated/server-path-single/server/path/single/_model_base.py @@ -464,7 +464,7 @@ def _get_rest_field( def _create_value(rf: typing.Optional["_RestField"], value: typing.Any) -> typing.Any: if not rf: return _serialize(value, None) - if rf._is_multipart_file: + if rf._is_multipart_file_input: return value if rf._is_model: return _deserialize(rf._type, value) @@ -565,14 +565,14 @@ def as_dict(self, *, exclude_readonly: bool = False) -> typing.Dict[str, typing. for k, v in self.items(): if exclude_readonly and k in readonly_props: # pyright: ignore[reportUnboundVariable] continue - is_multipart_file = False + is_multipart_file_input = False try: - is_multipart_file = next( + is_multipart_file_input = next( rf for rf in self._attr_to_rest_field.values() if rf._rest_name == k - )._is_multipart_file + )._is_multipart_file_input except StopIteration: pass - result[k] = v if is_multipart_file else Model._as_dict_value(v, exclude_readonly=exclude_readonly) + result[k] = v if is_multipart_file_input else Model._as_dict_value(v, exclude_readonly=exclude_readonly) return result @staticmethod @@ -775,7 +775,7 @@ def __init__( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, - is_multipart_file: bool = False, + is_multipart_file_input: bool = False, ): self._type = type self._rest_name_input = name @@ -785,7 +785,7 @@ def __init__( self._is_model = False self._default = default self._format = format - self._is_multipart_file = is_multipart_file + self._is_multipart_file_input = is_multipart_file_input @property def _rest_name(self) -> str: @@ -831,10 +831,15 @@ def rest_field( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, - is_multipart_file: bool = False, + is_multipart_file_input: bool = False, ) -> typing.Any: return _RestField( - name=name, type=type, visibility=visibility, default=default, format=format, is_multipart_file=is_multipart_file + name=name, + type=type, + visibility=visibility, + default=default, + format=format, + is_multipart_file_input=is_multipart_file_input, ) diff --git a/packages/typespec-python/test/azure/generated/server-versions-not-versioned/server/versions/notversioned/_model_base.py b/packages/typespec-python/test/azure/generated/server-versions-not-versioned/server/versions/notversioned/_model_base.py index 01c401e6324..247049f44d9 100644 --- a/packages/typespec-python/test/azure/generated/server-versions-not-versioned/server/versions/notversioned/_model_base.py +++ b/packages/typespec-python/test/azure/generated/server-versions-not-versioned/server/versions/notversioned/_model_base.py @@ -464,7 +464,7 @@ def _get_rest_field( def _create_value(rf: typing.Optional["_RestField"], value: typing.Any) -> typing.Any: if not rf: return _serialize(value, None) - if rf._is_multipart_file: + if rf._is_multipart_file_input: return value if rf._is_model: return _deserialize(rf._type, value) @@ -565,14 +565,14 @@ def as_dict(self, *, exclude_readonly: bool = False) -> typing.Dict[str, typing. for k, v in self.items(): if exclude_readonly and k in readonly_props: # pyright: ignore[reportUnboundVariable] continue - is_multipart_file = False + is_multipart_file_input = False try: - is_multipart_file = next( + is_multipart_file_input = next( rf for rf in self._attr_to_rest_field.values() if rf._rest_name == k - )._is_multipart_file + )._is_multipart_file_input except StopIteration: pass - result[k] = v if is_multipart_file else Model._as_dict_value(v, exclude_readonly=exclude_readonly) + result[k] = v if is_multipart_file_input else Model._as_dict_value(v, exclude_readonly=exclude_readonly) return result @staticmethod @@ -775,7 +775,7 @@ def __init__( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, - is_multipart_file: bool = False, + is_multipart_file_input: bool = False, ): self._type = type self._rest_name_input = name @@ -785,7 +785,7 @@ def __init__( self._is_model = False self._default = default self._format = format - self._is_multipart_file = is_multipart_file + self._is_multipart_file_input = is_multipart_file_input @property def _rest_name(self) -> str: @@ -831,10 +831,15 @@ def rest_field( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, - is_multipart_file: bool = False, + is_multipart_file_input: bool = False, ) -> typing.Any: return _RestField( - name=name, type=type, visibility=visibility, default=default, format=format, is_multipart_file=is_multipart_file + name=name, + type=type, + visibility=visibility, + default=default, + format=format, + is_multipart_file_input=is_multipart_file_input, ) diff --git a/packages/typespec-python/test/azure/generated/server-versions-versioned/server/versions/versioned/_model_base.py b/packages/typespec-python/test/azure/generated/server-versions-versioned/server/versions/versioned/_model_base.py index 01c401e6324..247049f44d9 100644 --- a/packages/typespec-python/test/azure/generated/server-versions-versioned/server/versions/versioned/_model_base.py +++ b/packages/typespec-python/test/azure/generated/server-versions-versioned/server/versions/versioned/_model_base.py @@ -464,7 +464,7 @@ def _get_rest_field( def _create_value(rf: typing.Optional["_RestField"], value: typing.Any) -> typing.Any: if not rf: return _serialize(value, None) - if rf._is_multipart_file: + if rf._is_multipart_file_input: return value if rf._is_model: return _deserialize(rf._type, value) @@ -565,14 +565,14 @@ def as_dict(self, *, exclude_readonly: bool = False) -> typing.Dict[str, typing. for k, v in self.items(): if exclude_readonly and k in readonly_props: # pyright: ignore[reportUnboundVariable] continue - is_multipart_file = False + is_multipart_file_input = False try: - is_multipart_file = next( + is_multipart_file_input = next( rf for rf in self._attr_to_rest_field.values() if rf._rest_name == k - )._is_multipart_file + )._is_multipart_file_input except StopIteration: pass - result[k] = v if is_multipart_file else Model._as_dict_value(v, exclude_readonly=exclude_readonly) + result[k] = v if is_multipart_file_input else Model._as_dict_value(v, exclude_readonly=exclude_readonly) return result @staticmethod @@ -775,7 +775,7 @@ def __init__( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, - is_multipart_file: bool = False, + is_multipart_file_input: bool = False, ): self._type = type self._rest_name_input = name @@ -785,7 +785,7 @@ def __init__( self._is_model = False self._default = default self._format = format - self._is_multipart_file = is_multipart_file + self._is_multipart_file_input = is_multipart_file_input @property def _rest_name(self) -> str: @@ -831,10 +831,15 @@ def rest_field( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, - is_multipart_file: bool = False, + is_multipart_file_input: bool = False, ) -> typing.Any: return _RestField( - name=name, type=type, visibility=visibility, default=default, format=format, is_multipart_file=is_multipart_file + name=name, + type=type, + visibility=visibility, + default=default, + format=format, + is_multipart_file_input=is_multipart_file_input, ) diff --git a/packages/typespec-python/test/azure/generated/special-headers-client-request-id/specialheaders/clientrequestid/_model_base.py b/packages/typespec-python/test/azure/generated/special-headers-client-request-id/specialheaders/clientrequestid/_model_base.py index 01c401e6324..247049f44d9 100644 --- a/packages/typespec-python/test/azure/generated/special-headers-client-request-id/specialheaders/clientrequestid/_model_base.py +++ b/packages/typespec-python/test/azure/generated/special-headers-client-request-id/specialheaders/clientrequestid/_model_base.py @@ -464,7 +464,7 @@ def _get_rest_field( def _create_value(rf: typing.Optional["_RestField"], value: typing.Any) -> typing.Any: if not rf: return _serialize(value, None) - if rf._is_multipart_file: + if rf._is_multipart_file_input: return value if rf._is_model: return _deserialize(rf._type, value) @@ -565,14 +565,14 @@ def as_dict(self, *, exclude_readonly: bool = False) -> typing.Dict[str, typing. for k, v in self.items(): if exclude_readonly and k in readonly_props: # pyright: ignore[reportUnboundVariable] continue - is_multipart_file = False + is_multipart_file_input = False try: - is_multipart_file = next( + is_multipart_file_input = next( rf for rf in self._attr_to_rest_field.values() if rf._rest_name == k - )._is_multipart_file + )._is_multipart_file_input except StopIteration: pass - result[k] = v if is_multipart_file else Model._as_dict_value(v, exclude_readonly=exclude_readonly) + result[k] = v if is_multipart_file_input else Model._as_dict_value(v, exclude_readonly=exclude_readonly) return result @staticmethod @@ -775,7 +775,7 @@ def __init__( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, - is_multipart_file: bool = False, + is_multipart_file_input: bool = False, ): self._type = type self._rest_name_input = name @@ -785,7 +785,7 @@ def __init__( self._is_model = False self._default = default self._format = format - self._is_multipart_file = is_multipart_file + self._is_multipart_file_input = is_multipart_file_input @property def _rest_name(self) -> str: @@ -831,10 +831,15 @@ def rest_field( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, - is_multipart_file: bool = False, + is_multipart_file_input: bool = False, ) -> typing.Any: return _RestField( - name=name, type=type, visibility=visibility, default=default, format=format, is_multipart_file=is_multipart_file + name=name, + type=type, + visibility=visibility, + default=default, + format=format, + is_multipart_file_input=is_multipart_file_input, ) diff --git a/packages/typespec-python/test/azure/generated/special-headers-conditional-request/specialheaders/conditionalrequest/_model_base.py b/packages/typespec-python/test/azure/generated/special-headers-conditional-request/specialheaders/conditionalrequest/_model_base.py index 01c401e6324..247049f44d9 100644 --- a/packages/typespec-python/test/azure/generated/special-headers-conditional-request/specialheaders/conditionalrequest/_model_base.py +++ b/packages/typespec-python/test/azure/generated/special-headers-conditional-request/specialheaders/conditionalrequest/_model_base.py @@ -464,7 +464,7 @@ def _get_rest_field( def _create_value(rf: typing.Optional["_RestField"], value: typing.Any) -> typing.Any: if not rf: return _serialize(value, None) - if rf._is_multipart_file: + if rf._is_multipart_file_input: return value if rf._is_model: return _deserialize(rf._type, value) @@ -565,14 +565,14 @@ def as_dict(self, *, exclude_readonly: bool = False) -> typing.Dict[str, typing. for k, v in self.items(): if exclude_readonly and k in readonly_props: # pyright: ignore[reportUnboundVariable] continue - is_multipart_file = False + is_multipart_file_input = False try: - is_multipart_file = next( + is_multipart_file_input = next( rf for rf in self._attr_to_rest_field.values() if rf._rest_name == k - )._is_multipart_file + )._is_multipart_file_input except StopIteration: pass - result[k] = v if is_multipart_file else Model._as_dict_value(v, exclude_readonly=exclude_readonly) + result[k] = v if is_multipart_file_input else Model._as_dict_value(v, exclude_readonly=exclude_readonly) return result @staticmethod @@ -775,7 +775,7 @@ def __init__( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, - is_multipart_file: bool = False, + is_multipart_file_input: bool = False, ): self._type = type self._rest_name_input = name @@ -785,7 +785,7 @@ def __init__( self._is_model = False self._default = default self._format = format - self._is_multipart_file = is_multipart_file + self._is_multipart_file_input = is_multipart_file_input @property def _rest_name(self) -> str: @@ -831,10 +831,15 @@ def rest_field( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, - is_multipart_file: bool = False, + is_multipart_file_input: bool = False, ) -> typing.Any: return _RestField( - name=name, type=type, visibility=visibility, default=default, format=format, is_multipart_file=is_multipart_file + name=name, + type=type, + visibility=visibility, + default=default, + format=format, + is_multipart_file_input=is_multipart_file_input, ) diff --git a/packages/typespec-python/test/azure/generated/special-headers-repeatability/specialheaders/repeatability/_model_base.py b/packages/typespec-python/test/azure/generated/special-headers-repeatability/specialheaders/repeatability/_model_base.py index 01c401e6324..247049f44d9 100644 --- a/packages/typespec-python/test/azure/generated/special-headers-repeatability/specialheaders/repeatability/_model_base.py +++ b/packages/typespec-python/test/azure/generated/special-headers-repeatability/specialheaders/repeatability/_model_base.py @@ -464,7 +464,7 @@ def _get_rest_field( def _create_value(rf: typing.Optional["_RestField"], value: typing.Any) -> typing.Any: if not rf: return _serialize(value, None) - if rf._is_multipart_file: + if rf._is_multipart_file_input: return value if rf._is_model: return _deserialize(rf._type, value) @@ -565,14 +565,14 @@ def as_dict(self, *, exclude_readonly: bool = False) -> typing.Dict[str, typing. for k, v in self.items(): if exclude_readonly and k in readonly_props: # pyright: ignore[reportUnboundVariable] continue - is_multipart_file = False + is_multipart_file_input = False try: - is_multipart_file = next( + is_multipart_file_input = next( rf for rf in self._attr_to_rest_field.values() if rf._rest_name == k - )._is_multipart_file + )._is_multipart_file_input except StopIteration: pass - result[k] = v if is_multipart_file else Model._as_dict_value(v, exclude_readonly=exclude_readonly) + result[k] = v if is_multipart_file_input else Model._as_dict_value(v, exclude_readonly=exclude_readonly) return result @staticmethod @@ -775,7 +775,7 @@ def __init__( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, - is_multipart_file: bool = False, + is_multipart_file_input: bool = False, ): self._type = type self._rest_name_input = name @@ -785,7 +785,7 @@ def __init__( self._is_model = False self._default = default self._format = format - self._is_multipart_file = is_multipart_file + self._is_multipart_file_input = is_multipart_file_input @property def _rest_name(self) -> str: @@ -831,10 +831,15 @@ def rest_field( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, - is_multipart_file: bool = False, + is_multipart_file_input: bool = False, ) -> typing.Any: return _RestField( - name=name, type=type, visibility=visibility, default=default, format=format, is_multipart_file=is_multipart_file + name=name, + type=type, + visibility=visibility, + default=default, + format=format, + is_multipart_file_input=is_multipart_file_input, ) diff --git a/packages/typespec-python/test/azure/generated/special-words/specialwords/_model_base.py b/packages/typespec-python/test/azure/generated/special-words/specialwords/_model_base.py index 01c401e6324..247049f44d9 100644 --- a/packages/typespec-python/test/azure/generated/special-words/specialwords/_model_base.py +++ b/packages/typespec-python/test/azure/generated/special-words/specialwords/_model_base.py @@ -464,7 +464,7 @@ def _get_rest_field( def _create_value(rf: typing.Optional["_RestField"], value: typing.Any) -> typing.Any: if not rf: return _serialize(value, None) - if rf._is_multipart_file: + if rf._is_multipart_file_input: return value if rf._is_model: return _deserialize(rf._type, value) @@ -565,14 +565,14 @@ def as_dict(self, *, exclude_readonly: bool = False) -> typing.Dict[str, typing. for k, v in self.items(): if exclude_readonly and k in readonly_props: # pyright: ignore[reportUnboundVariable] continue - is_multipart_file = False + is_multipart_file_input = False try: - is_multipart_file = next( + is_multipart_file_input = next( rf for rf in self._attr_to_rest_field.values() if rf._rest_name == k - )._is_multipart_file + )._is_multipart_file_input except StopIteration: pass - result[k] = v if is_multipart_file else Model._as_dict_value(v, exclude_readonly=exclude_readonly) + result[k] = v if is_multipart_file_input else Model._as_dict_value(v, exclude_readonly=exclude_readonly) return result @staticmethod @@ -775,7 +775,7 @@ def __init__( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, - is_multipart_file: bool = False, + is_multipart_file_input: bool = False, ): self._type = type self._rest_name_input = name @@ -785,7 +785,7 @@ def __init__( self._is_model = False self._default = default self._format = format - self._is_multipart_file = is_multipart_file + self._is_multipart_file_input = is_multipart_file_input @property def _rest_name(self) -> str: @@ -831,10 +831,15 @@ def rest_field( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, - is_multipart_file: bool = False, + is_multipart_file_input: bool = False, ) -> typing.Any: return _RestField( - name=name, type=type, visibility=visibility, default=default, format=format, is_multipart_file=is_multipart_file + name=name, + type=type, + visibility=visibility, + default=default, + format=format, + is_multipart_file_input=is_multipart_file_input, ) diff --git a/packages/typespec-python/test/azure/generated/typetest-array/typetest/array/_model_base.py b/packages/typespec-python/test/azure/generated/typetest-array/typetest/array/_model_base.py index 01c401e6324..247049f44d9 100644 --- a/packages/typespec-python/test/azure/generated/typetest-array/typetest/array/_model_base.py +++ b/packages/typespec-python/test/azure/generated/typetest-array/typetest/array/_model_base.py @@ -464,7 +464,7 @@ def _get_rest_field( def _create_value(rf: typing.Optional["_RestField"], value: typing.Any) -> typing.Any: if not rf: return _serialize(value, None) - if rf._is_multipart_file: + if rf._is_multipart_file_input: return value if rf._is_model: return _deserialize(rf._type, value) @@ -565,14 +565,14 @@ def as_dict(self, *, exclude_readonly: bool = False) -> typing.Dict[str, typing. for k, v in self.items(): if exclude_readonly and k in readonly_props: # pyright: ignore[reportUnboundVariable] continue - is_multipart_file = False + is_multipart_file_input = False try: - is_multipart_file = next( + is_multipart_file_input = next( rf for rf in self._attr_to_rest_field.values() if rf._rest_name == k - )._is_multipart_file + )._is_multipart_file_input except StopIteration: pass - result[k] = v if is_multipart_file else Model._as_dict_value(v, exclude_readonly=exclude_readonly) + result[k] = v if is_multipart_file_input else Model._as_dict_value(v, exclude_readonly=exclude_readonly) return result @staticmethod @@ -775,7 +775,7 @@ def __init__( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, - is_multipart_file: bool = False, + is_multipart_file_input: bool = False, ): self._type = type self._rest_name_input = name @@ -785,7 +785,7 @@ def __init__( self._is_model = False self._default = default self._format = format - self._is_multipart_file = is_multipart_file + self._is_multipart_file_input = is_multipart_file_input @property def _rest_name(self) -> str: @@ -831,10 +831,15 @@ def rest_field( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, - is_multipart_file: bool = False, + is_multipart_file_input: bool = False, ) -> typing.Any: return _RestField( - name=name, type=type, visibility=visibility, default=default, format=format, is_multipart_file=is_multipart_file + name=name, + type=type, + visibility=visibility, + default=default, + format=format, + is_multipart_file_input=is_multipart_file_input, ) diff --git a/packages/typespec-python/test/azure/generated/typetest-dictionary/typetest/dictionary/_model_base.py b/packages/typespec-python/test/azure/generated/typetest-dictionary/typetest/dictionary/_model_base.py index 01c401e6324..247049f44d9 100644 --- a/packages/typespec-python/test/azure/generated/typetest-dictionary/typetest/dictionary/_model_base.py +++ b/packages/typespec-python/test/azure/generated/typetest-dictionary/typetest/dictionary/_model_base.py @@ -464,7 +464,7 @@ def _get_rest_field( def _create_value(rf: typing.Optional["_RestField"], value: typing.Any) -> typing.Any: if not rf: return _serialize(value, None) - if rf._is_multipart_file: + if rf._is_multipart_file_input: return value if rf._is_model: return _deserialize(rf._type, value) @@ -565,14 +565,14 @@ def as_dict(self, *, exclude_readonly: bool = False) -> typing.Dict[str, typing. for k, v in self.items(): if exclude_readonly and k in readonly_props: # pyright: ignore[reportUnboundVariable] continue - is_multipart_file = False + is_multipart_file_input = False try: - is_multipart_file = next( + is_multipart_file_input = next( rf for rf in self._attr_to_rest_field.values() if rf._rest_name == k - )._is_multipart_file + )._is_multipart_file_input except StopIteration: pass - result[k] = v if is_multipart_file else Model._as_dict_value(v, exclude_readonly=exclude_readonly) + result[k] = v if is_multipart_file_input else Model._as_dict_value(v, exclude_readonly=exclude_readonly) return result @staticmethod @@ -775,7 +775,7 @@ def __init__( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, - is_multipart_file: bool = False, + is_multipart_file_input: bool = False, ): self._type = type self._rest_name_input = name @@ -785,7 +785,7 @@ def __init__( self._is_model = False self._default = default self._format = format - self._is_multipart_file = is_multipart_file + self._is_multipart_file_input = is_multipart_file_input @property def _rest_name(self) -> str: @@ -831,10 +831,15 @@ def rest_field( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, - is_multipart_file: bool = False, + is_multipart_file_input: bool = False, ) -> typing.Any: return _RestField( - name=name, type=type, visibility=visibility, default=default, format=format, is_multipart_file=is_multipart_file + name=name, + type=type, + visibility=visibility, + default=default, + format=format, + is_multipart_file_input=is_multipart_file_input, ) diff --git a/packages/typespec-python/test/azure/generated/typetest-enum-extensible/typetest/enum/extensible/_model_base.py b/packages/typespec-python/test/azure/generated/typetest-enum-extensible/typetest/enum/extensible/_model_base.py index 01c401e6324..247049f44d9 100644 --- a/packages/typespec-python/test/azure/generated/typetest-enum-extensible/typetest/enum/extensible/_model_base.py +++ b/packages/typespec-python/test/azure/generated/typetest-enum-extensible/typetest/enum/extensible/_model_base.py @@ -464,7 +464,7 @@ def _get_rest_field( def _create_value(rf: typing.Optional["_RestField"], value: typing.Any) -> typing.Any: if not rf: return _serialize(value, None) - if rf._is_multipart_file: + if rf._is_multipart_file_input: return value if rf._is_model: return _deserialize(rf._type, value) @@ -565,14 +565,14 @@ def as_dict(self, *, exclude_readonly: bool = False) -> typing.Dict[str, typing. for k, v in self.items(): if exclude_readonly and k in readonly_props: # pyright: ignore[reportUnboundVariable] continue - is_multipart_file = False + is_multipart_file_input = False try: - is_multipart_file = next( + is_multipart_file_input = next( rf for rf in self._attr_to_rest_field.values() if rf._rest_name == k - )._is_multipart_file + )._is_multipart_file_input except StopIteration: pass - result[k] = v if is_multipart_file else Model._as_dict_value(v, exclude_readonly=exclude_readonly) + result[k] = v if is_multipart_file_input else Model._as_dict_value(v, exclude_readonly=exclude_readonly) return result @staticmethod @@ -775,7 +775,7 @@ def __init__( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, - is_multipart_file: bool = False, + is_multipart_file_input: bool = False, ): self._type = type self._rest_name_input = name @@ -785,7 +785,7 @@ def __init__( self._is_model = False self._default = default self._format = format - self._is_multipart_file = is_multipart_file + self._is_multipart_file_input = is_multipart_file_input @property def _rest_name(self) -> str: @@ -831,10 +831,15 @@ def rest_field( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, - is_multipart_file: bool = False, + is_multipart_file_input: bool = False, ) -> typing.Any: return _RestField( - name=name, type=type, visibility=visibility, default=default, format=format, is_multipart_file=is_multipart_file + name=name, + type=type, + visibility=visibility, + default=default, + format=format, + is_multipart_file_input=is_multipart_file_input, ) diff --git a/packages/typespec-python/test/azure/generated/typetest-enum-fixed/typetest/enum/fixed/_model_base.py b/packages/typespec-python/test/azure/generated/typetest-enum-fixed/typetest/enum/fixed/_model_base.py index 01c401e6324..247049f44d9 100644 --- a/packages/typespec-python/test/azure/generated/typetest-enum-fixed/typetest/enum/fixed/_model_base.py +++ b/packages/typespec-python/test/azure/generated/typetest-enum-fixed/typetest/enum/fixed/_model_base.py @@ -464,7 +464,7 @@ def _get_rest_field( def _create_value(rf: typing.Optional["_RestField"], value: typing.Any) -> typing.Any: if not rf: return _serialize(value, None) - if rf._is_multipart_file: + if rf._is_multipart_file_input: return value if rf._is_model: return _deserialize(rf._type, value) @@ -565,14 +565,14 @@ def as_dict(self, *, exclude_readonly: bool = False) -> typing.Dict[str, typing. for k, v in self.items(): if exclude_readonly and k in readonly_props: # pyright: ignore[reportUnboundVariable] continue - is_multipart_file = False + is_multipart_file_input = False try: - is_multipart_file = next( + is_multipart_file_input = next( rf for rf in self._attr_to_rest_field.values() if rf._rest_name == k - )._is_multipart_file + )._is_multipart_file_input except StopIteration: pass - result[k] = v if is_multipart_file else Model._as_dict_value(v, exclude_readonly=exclude_readonly) + result[k] = v if is_multipart_file_input else Model._as_dict_value(v, exclude_readonly=exclude_readonly) return result @staticmethod @@ -775,7 +775,7 @@ def __init__( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, - is_multipart_file: bool = False, + is_multipart_file_input: bool = False, ): self._type = type self._rest_name_input = name @@ -785,7 +785,7 @@ def __init__( self._is_model = False self._default = default self._format = format - self._is_multipart_file = is_multipart_file + self._is_multipart_file_input = is_multipart_file_input @property def _rest_name(self) -> str: @@ -831,10 +831,15 @@ def rest_field( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, - is_multipart_file: bool = False, + is_multipart_file_input: bool = False, ) -> typing.Any: return _RestField( - name=name, type=type, visibility=visibility, default=default, format=format, is_multipart_file=is_multipart_file + name=name, + type=type, + visibility=visibility, + default=default, + format=format, + is_multipart_file_input=is_multipart_file_input, ) diff --git a/packages/typespec-python/test/azure/generated/typetest-model-empty/typetest/model/empty/_model_base.py b/packages/typespec-python/test/azure/generated/typetest-model-empty/typetest/model/empty/_model_base.py index 01c401e6324..247049f44d9 100644 --- a/packages/typespec-python/test/azure/generated/typetest-model-empty/typetest/model/empty/_model_base.py +++ b/packages/typespec-python/test/azure/generated/typetest-model-empty/typetest/model/empty/_model_base.py @@ -464,7 +464,7 @@ def _get_rest_field( def _create_value(rf: typing.Optional["_RestField"], value: typing.Any) -> typing.Any: if not rf: return _serialize(value, None) - if rf._is_multipart_file: + if rf._is_multipart_file_input: return value if rf._is_model: return _deserialize(rf._type, value) @@ -565,14 +565,14 @@ def as_dict(self, *, exclude_readonly: bool = False) -> typing.Dict[str, typing. for k, v in self.items(): if exclude_readonly and k in readonly_props: # pyright: ignore[reportUnboundVariable] continue - is_multipart_file = False + is_multipart_file_input = False try: - is_multipart_file = next( + is_multipart_file_input = next( rf for rf in self._attr_to_rest_field.values() if rf._rest_name == k - )._is_multipart_file + )._is_multipart_file_input except StopIteration: pass - result[k] = v if is_multipart_file else Model._as_dict_value(v, exclude_readonly=exclude_readonly) + result[k] = v if is_multipart_file_input else Model._as_dict_value(v, exclude_readonly=exclude_readonly) return result @staticmethod @@ -775,7 +775,7 @@ def __init__( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, - is_multipart_file: bool = False, + is_multipart_file_input: bool = False, ): self._type = type self._rest_name_input = name @@ -785,7 +785,7 @@ def __init__( self._is_model = False self._default = default self._format = format - self._is_multipart_file = is_multipart_file + self._is_multipart_file_input = is_multipart_file_input @property def _rest_name(self) -> str: @@ -831,10 +831,15 @@ def rest_field( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, - is_multipart_file: bool = False, + is_multipart_file_input: bool = False, ) -> typing.Any: return _RestField( - name=name, type=type, visibility=visibility, default=default, format=format, is_multipart_file=is_multipart_file + name=name, + type=type, + visibility=visibility, + default=default, + format=format, + is_multipart_file_input=is_multipart_file_input, ) diff --git a/packages/typespec-python/test/azure/generated/typetest-model-enumdiscriminator/typetest/model/enumdiscriminator/_model_base.py b/packages/typespec-python/test/azure/generated/typetest-model-enumdiscriminator/typetest/model/enumdiscriminator/_model_base.py index 01c401e6324..247049f44d9 100644 --- a/packages/typespec-python/test/azure/generated/typetest-model-enumdiscriminator/typetest/model/enumdiscriminator/_model_base.py +++ b/packages/typespec-python/test/azure/generated/typetest-model-enumdiscriminator/typetest/model/enumdiscriminator/_model_base.py @@ -464,7 +464,7 @@ def _get_rest_field( def _create_value(rf: typing.Optional["_RestField"], value: typing.Any) -> typing.Any: if not rf: return _serialize(value, None) - if rf._is_multipart_file: + if rf._is_multipart_file_input: return value if rf._is_model: return _deserialize(rf._type, value) @@ -565,14 +565,14 @@ def as_dict(self, *, exclude_readonly: bool = False) -> typing.Dict[str, typing. for k, v in self.items(): if exclude_readonly and k in readonly_props: # pyright: ignore[reportUnboundVariable] continue - is_multipart_file = False + is_multipart_file_input = False try: - is_multipart_file = next( + is_multipart_file_input = next( rf for rf in self._attr_to_rest_field.values() if rf._rest_name == k - )._is_multipart_file + )._is_multipart_file_input except StopIteration: pass - result[k] = v if is_multipart_file else Model._as_dict_value(v, exclude_readonly=exclude_readonly) + result[k] = v if is_multipart_file_input else Model._as_dict_value(v, exclude_readonly=exclude_readonly) return result @staticmethod @@ -775,7 +775,7 @@ def __init__( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, - is_multipart_file: bool = False, + is_multipart_file_input: bool = False, ): self._type = type self._rest_name_input = name @@ -785,7 +785,7 @@ def __init__( self._is_model = False self._default = default self._format = format - self._is_multipart_file = is_multipart_file + self._is_multipart_file_input = is_multipart_file_input @property def _rest_name(self) -> str: @@ -831,10 +831,15 @@ def rest_field( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, - is_multipart_file: bool = False, + is_multipart_file_input: bool = False, ) -> typing.Any: return _RestField( - name=name, type=type, visibility=visibility, default=default, format=format, is_multipart_file=is_multipart_file + name=name, + type=type, + visibility=visibility, + default=default, + format=format, + is_multipart_file_input=is_multipart_file_input, ) diff --git a/packages/typespec-python/test/azure/generated/typetest-model-nesteddiscriminator/typetest/model/nesteddiscriminator/_model_base.py b/packages/typespec-python/test/azure/generated/typetest-model-nesteddiscriminator/typetest/model/nesteddiscriminator/_model_base.py index 01c401e6324..247049f44d9 100644 --- a/packages/typespec-python/test/azure/generated/typetest-model-nesteddiscriminator/typetest/model/nesteddiscriminator/_model_base.py +++ b/packages/typespec-python/test/azure/generated/typetest-model-nesteddiscriminator/typetest/model/nesteddiscriminator/_model_base.py @@ -464,7 +464,7 @@ def _get_rest_field( def _create_value(rf: typing.Optional["_RestField"], value: typing.Any) -> typing.Any: if not rf: return _serialize(value, None) - if rf._is_multipart_file: + if rf._is_multipart_file_input: return value if rf._is_model: return _deserialize(rf._type, value) @@ -565,14 +565,14 @@ def as_dict(self, *, exclude_readonly: bool = False) -> typing.Dict[str, typing. for k, v in self.items(): if exclude_readonly and k in readonly_props: # pyright: ignore[reportUnboundVariable] continue - is_multipart_file = False + is_multipart_file_input = False try: - is_multipart_file = next( + is_multipart_file_input = next( rf for rf in self._attr_to_rest_field.values() if rf._rest_name == k - )._is_multipart_file + )._is_multipart_file_input except StopIteration: pass - result[k] = v if is_multipart_file else Model._as_dict_value(v, exclude_readonly=exclude_readonly) + result[k] = v if is_multipart_file_input else Model._as_dict_value(v, exclude_readonly=exclude_readonly) return result @staticmethod @@ -775,7 +775,7 @@ def __init__( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, - is_multipart_file: bool = False, + is_multipart_file_input: bool = False, ): self._type = type self._rest_name_input = name @@ -785,7 +785,7 @@ def __init__( self._is_model = False self._default = default self._format = format - self._is_multipart_file = is_multipart_file + self._is_multipart_file_input = is_multipart_file_input @property def _rest_name(self) -> str: @@ -831,10 +831,15 @@ def rest_field( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, - is_multipart_file: bool = False, + is_multipart_file_input: bool = False, ) -> typing.Any: return _RestField( - name=name, type=type, visibility=visibility, default=default, format=format, is_multipart_file=is_multipart_file + name=name, + type=type, + visibility=visibility, + default=default, + format=format, + is_multipart_file_input=is_multipart_file_input, ) diff --git a/packages/typespec-python/test/azure/generated/typetest-model-notdiscriminated/typetest/model/notdiscriminated/_model_base.py b/packages/typespec-python/test/azure/generated/typetest-model-notdiscriminated/typetest/model/notdiscriminated/_model_base.py index 01c401e6324..247049f44d9 100644 --- a/packages/typespec-python/test/azure/generated/typetest-model-notdiscriminated/typetest/model/notdiscriminated/_model_base.py +++ b/packages/typespec-python/test/azure/generated/typetest-model-notdiscriminated/typetest/model/notdiscriminated/_model_base.py @@ -464,7 +464,7 @@ def _get_rest_field( def _create_value(rf: typing.Optional["_RestField"], value: typing.Any) -> typing.Any: if not rf: return _serialize(value, None) - if rf._is_multipart_file: + if rf._is_multipart_file_input: return value if rf._is_model: return _deserialize(rf._type, value) @@ -565,14 +565,14 @@ def as_dict(self, *, exclude_readonly: bool = False) -> typing.Dict[str, typing. for k, v in self.items(): if exclude_readonly and k in readonly_props: # pyright: ignore[reportUnboundVariable] continue - is_multipart_file = False + is_multipart_file_input = False try: - is_multipart_file = next( + is_multipart_file_input = next( rf for rf in self._attr_to_rest_field.values() if rf._rest_name == k - )._is_multipart_file + )._is_multipart_file_input except StopIteration: pass - result[k] = v if is_multipart_file else Model._as_dict_value(v, exclude_readonly=exclude_readonly) + result[k] = v if is_multipart_file_input else Model._as_dict_value(v, exclude_readonly=exclude_readonly) return result @staticmethod @@ -775,7 +775,7 @@ def __init__( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, - is_multipart_file: bool = False, + is_multipart_file_input: bool = False, ): self._type = type self._rest_name_input = name @@ -785,7 +785,7 @@ def __init__( self._is_model = False self._default = default self._format = format - self._is_multipart_file = is_multipart_file + self._is_multipart_file_input = is_multipart_file_input @property def _rest_name(self) -> str: @@ -831,10 +831,15 @@ def rest_field( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, - is_multipart_file: bool = False, + is_multipart_file_input: bool = False, ) -> typing.Any: return _RestField( - name=name, type=type, visibility=visibility, default=default, format=format, is_multipart_file=is_multipart_file + name=name, + type=type, + visibility=visibility, + default=default, + format=format, + is_multipart_file_input=is_multipart_file_input, ) diff --git a/packages/typespec-python/test/azure/generated/typetest-model-recursive/typetest/model/recursive/_model_base.py b/packages/typespec-python/test/azure/generated/typetest-model-recursive/typetest/model/recursive/_model_base.py index 01c401e6324..247049f44d9 100644 --- a/packages/typespec-python/test/azure/generated/typetest-model-recursive/typetest/model/recursive/_model_base.py +++ b/packages/typespec-python/test/azure/generated/typetest-model-recursive/typetest/model/recursive/_model_base.py @@ -464,7 +464,7 @@ def _get_rest_field( def _create_value(rf: typing.Optional["_RestField"], value: typing.Any) -> typing.Any: if not rf: return _serialize(value, None) - if rf._is_multipart_file: + if rf._is_multipart_file_input: return value if rf._is_model: return _deserialize(rf._type, value) @@ -565,14 +565,14 @@ def as_dict(self, *, exclude_readonly: bool = False) -> typing.Dict[str, typing. for k, v in self.items(): if exclude_readonly and k in readonly_props: # pyright: ignore[reportUnboundVariable] continue - is_multipart_file = False + is_multipart_file_input = False try: - is_multipart_file = next( + is_multipart_file_input = next( rf for rf in self._attr_to_rest_field.values() if rf._rest_name == k - )._is_multipart_file + )._is_multipart_file_input except StopIteration: pass - result[k] = v if is_multipart_file else Model._as_dict_value(v, exclude_readonly=exclude_readonly) + result[k] = v if is_multipart_file_input else Model._as_dict_value(v, exclude_readonly=exclude_readonly) return result @staticmethod @@ -775,7 +775,7 @@ def __init__( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, - is_multipart_file: bool = False, + is_multipart_file_input: bool = False, ): self._type = type self._rest_name_input = name @@ -785,7 +785,7 @@ def __init__( self._is_model = False self._default = default self._format = format - self._is_multipart_file = is_multipart_file + self._is_multipart_file_input = is_multipart_file_input @property def _rest_name(self) -> str: @@ -831,10 +831,15 @@ def rest_field( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, - is_multipart_file: bool = False, + is_multipart_file_input: bool = False, ) -> typing.Any: return _RestField( - name=name, type=type, visibility=visibility, default=default, format=format, is_multipart_file=is_multipart_file + name=name, + type=type, + visibility=visibility, + default=default, + format=format, + is_multipart_file_input=is_multipart_file_input, ) diff --git a/packages/typespec-python/test/azure/generated/typetest-model-singlediscriminator/typetest/model/singlediscriminator/_model_base.py b/packages/typespec-python/test/azure/generated/typetest-model-singlediscriminator/typetest/model/singlediscriminator/_model_base.py index 01c401e6324..247049f44d9 100644 --- a/packages/typespec-python/test/azure/generated/typetest-model-singlediscriminator/typetest/model/singlediscriminator/_model_base.py +++ b/packages/typespec-python/test/azure/generated/typetest-model-singlediscriminator/typetest/model/singlediscriminator/_model_base.py @@ -464,7 +464,7 @@ def _get_rest_field( def _create_value(rf: typing.Optional["_RestField"], value: typing.Any) -> typing.Any: if not rf: return _serialize(value, None) - if rf._is_multipart_file: + if rf._is_multipart_file_input: return value if rf._is_model: return _deserialize(rf._type, value) @@ -565,14 +565,14 @@ def as_dict(self, *, exclude_readonly: bool = False) -> typing.Dict[str, typing. for k, v in self.items(): if exclude_readonly and k in readonly_props: # pyright: ignore[reportUnboundVariable] continue - is_multipart_file = False + is_multipart_file_input = False try: - is_multipart_file = next( + is_multipart_file_input = next( rf for rf in self._attr_to_rest_field.values() if rf._rest_name == k - )._is_multipart_file + )._is_multipart_file_input except StopIteration: pass - result[k] = v if is_multipart_file else Model._as_dict_value(v, exclude_readonly=exclude_readonly) + result[k] = v if is_multipart_file_input else Model._as_dict_value(v, exclude_readonly=exclude_readonly) return result @staticmethod @@ -775,7 +775,7 @@ def __init__( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, - is_multipart_file: bool = False, + is_multipart_file_input: bool = False, ): self._type = type self._rest_name_input = name @@ -785,7 +785,7 @@ def __init__( self._is_model = False self._default = default self._format = format - self._is_multipart_file = is_multipart_file + self._is_multipart_file_input = is_multipart_file_input @property def _rest_name(self) -> str: @@ -831,10 +831,15 @@ def rest_field( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, - is_multipart_file: bool = False, + is_multipart_file_input: bool = False, ) -> typing.Any: return _RestField( - name=name, type=type, visibility=visibility, default=default, format=format, is_multipart_file=is_multipart_file + name=name, + type=type, + visibility=visibility, + default=default, + format=format, + is_multipart_file_input=is_multipart_file_input, ) diff --git a/packages/typespec-python/test/azure/generated/typetest-model-usage/typetest/model/usage/_model_base.py b/packages/typespec-python/test/azure/generated/typetest-model-usage/typetest/model/usage/_model_base.py index 01c401e6324..247049f44d9 100644 --- a/packages/typespec-python/test/azure/generated/typetest-model-usage/typetest/model/usage/_model_base.py +++ b/packages/typespec-python/test/azure/generated/typetest-model-usage/typetest/model/usage/_model_base.py @@ -464,7 +464,7 @@ def _get_rest_field( def _create_value(rf: typing.Optional["_RestField"], value: typing.Any) -> typing.Any: if not rf: return _serialize(value, None) - if rf._is_multipart_file: + if rf._is_multipart_file_input: return value if rf._is_model: return _deserialize(rf._type, value) @@ -565,14 +565,14 @@ def as_dict(self, *, exclude_readonly: bool = False) -> typing.Dict[str, typing. for k, v in self.items(): if exclude_readonly and k in readonly_props: # pyright: ignore[reportUnboundVariable] continue - is_multipart_file = False + is_multipart_file_input = False try: - is_multipart_file = next( + is_multipart_file_input = next( rf for rf in self._attr_to_rest_field.values() if rf._rest_name == k - )._is_multipart_file + )._is_multipart_file_input except StopIteration: pass - result[k] = v if is_multipart_file else Model._as_dict_value(v, exclude_readonly=exclude_readonly) + result[k] = v if is_multipart_file_input else Model._as_dict_value(v, exclude_readonly=exclude_readonly) return result @staticmethod @@ -775,7 +775,7 @@ def __init__( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, - is_multipart_file: bool = False, + is_multipart_file_input: bool = False, ): self._type = type self._rest_name_input = name @@ -785,7 +785,7 @@ def __init__( self._is_model = False self._default = default self._format = format - self._is_multipart_file = is_multipart_file + self._is_multipart_file_input = is_multipart_file_input @property def _rest_name(self) -> str: @@ -831,10 +831,15 @@ def rest_field( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, - is_multipart_file: bool = False, + is_multipart_file_input: bool = False, ) -> typing.Any: return _RestField( - name=name, type=type, visibility=visibility, default=default, format=format, is_multipart_file=is_multipart_file + name=name, + type=type, + visibility=visibility, + default=default, + format=format, + is_multipart_file_input=is_multipart_file_input, ) diff --git a/packages/typespec-python/test/azure/generated/typetest-model-visibility/typetest/model/visibility/_model_base.py b/packages/typespec-python/test/azure/generated/typetest-model-visibility/typetest/model/visibility/_model_base.py index 01c401e6324..247049f44d9 100644 --- a/packages/typespec-python/test/azure/generated/typetest-model-visibility/typetest/model/visibility/_model_base.py +++ b/packages/typespec-python/test/azure/generated/typetest-model-visibility/typetest/model/visibility/_model_base.py @@ -464,7 +464,7 @@ def _get_rest_field( def _create_value(rf: typing.Optional["_RestField"], value: typing.Any) -> typing.Any: if not rf: return _serialize(value, None) - if rf._is_multipart_file: + if rf._is_multipart_file_input: return value if rf._is_model: return _deserialize(rf._type, value) @@ -565,14 +565,14 @@ def as_dict(self, *, exclude_readonly: bool = False) -> typing.Dict[str, typing. for k, v in self.items(): if exclude_readonly and k in readonly_props: # pyright: ignore[reportUnboundVariable] continue - is_multipart_file = False + is_multipart_file_input = False try: - is_multipart_file = next( + is_multipart_file_input = next( rf for rf in self._attr_to_rest_field.values() if rf._rest_name == k - )._is_multipart_file + )._is_multipart_file_input except StopIteration: pass - result[k] = v if is_multipart_file else Model._as_dict_value(v, exclude_readonly=exclude_readonly) + result[k] = v if is_multipart_file_input else Model._as_dict_value(v, exclude_readonly=exclude_readonly) return result @staticmethod @@ -775,7 +775,7 @@ def __init__( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, - is_multipart_file: bool = False, + is_multipart_file_input: bool = False, ): self._type = type self._rest_name_input = name @@ -785,7 +785,7 @@ def __init__( self._is_model = False self._default = default self._format = format - self._is_multipart_file = is_multipart_file + self._is_multipart_file_input = is_multipart_file_input @property def _rest_name(self) -> str: @@ -831,10 +831,15 @@ def rest_field( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, - is_multipart_file: bool = False, + is_multipart_file_input: bool = False, ) -> typing.Any: return _RestField( - name=name, type=type, visibility=visibility, default=default, format=format, is_multipart_file=is_multipart_file + name=name, + type=type, + visibility=visibility, + default=default, + format=format, + is_multipart_file_input=is_multipart_file_input, ) diff --git a/packages/typespec-python/test/azure/generated/typetest-property-additionalproperties/typetest/property/additionalproperties/_model_base.py b/packages/typespec-python/test/azure/generated/typetest-property-additionalproperties/typetest/property/additionalproperties/_model_base.py index 01c401e6324..247049f44d9 100644 --- a/packages/typespec-python/test/azure/generated/typetest-property-additionalproperties/typetest/property/additionalproperties/_model_base.py +++ b/packages/typespec-python/test/azure/generated/typetest-property-additionalproperties/typetest/property/additionalproperties/_model_base.py @@ -464,7 +464,7 @@ def _get_rest_field( def _create_value(rf: typing.Optional["_RestField"], value: typing.Any) -> typing.Any: if not rf: return _serialize(value, None) - if rf._is_multipart_file: + if rf._is_multipart_file_input: return value if rf._is_model: return _deserialize(rf._type, value) @@ -565,14 +565,14 @@ def as_dict(self, *, exclude_readonly: bool = False) -> typing.Dict[str, typing. for k, v in self.items(): if exclude_readonly and k in readonly_props: # pyright: ignore[reportUnboundVariable] continue - is_multipart_file = False + is_multipart_file_input = False try: - is_multipart_file = next( + is_multipart_file_input = next( rf for rf in self._attr_to_rest_field.values() if rf._rest_name == k - )._is_multipart_file + )._is_multipart_file_input except StopIteration: pass - result[k] = v if is_multipart_file else Model._as_dict_value(v, exclude_readonly=exclude_readonly) + result[k] = v if is_multipart_file_input else Model._as_dict_value(v, exclude_readonly=exclude_readonly) return result @staticmethod @@ -775,7 +775,7 @@ def __init__( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, - is_multipart_file: bool = False, + is_multipart_file_input: bool = False, ): self._type = type self._rest_name_input = name @@ -785,7 +785,7 @@ def __init__( self._is_model = False self._default = default self._format = format - self._is_multipart_file = is_multipart_file + self._is_multipart_file_input = is_multipart_file_input @property def _rest_name(self) -> str: @@ -831,10 +831,15 @@ def rest_field( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, - is_multipart_file: bool = False, + is_multipart_file_input: bool = False, ) -> typing.Any: return _RestField( - name=name, type=type, visibility=visibility, default=default, format=format, is_multipart_file=is_multipart_file + name=name, + type=type, + visibility=visibility, + default=default, + format=format, + is_multipart_file_input=is_multipart_file_input, ) diff --git a/packages/typespec-python/test/azure/generated/typetest-property-nullable/typetest/property/nullable/_model_base.py b/packages/typespec-python/test/azure/generated/typetest-property-nullable/typetest/property/nullable/_model_base.py index 01c401e6324..247049f44d9 100644 --- a/packages/typespec-python/test/azure/generated/typetest-property-nullable/typetest/property/nullable/_model_base.py +++ b/packages/typespec-python/test/azure/generated/typetest-property-nullable/typetest/property/nullable/_model_base.py @@ -464,7 +464,7 @@ def _get_rest_field( def _create_value(rf: typing.Optional["_RestField"], value: typing.Any) -> typing.Any: if not rf: return _serialize(value, None) - if rf._is_multipart_file: + if rf._is_multipart_file_input: return value if rf._is_model: return _deserialize(rf._type, value) @@ -565,14 +565,14 @@ def as_dict(self, *, exclude_readonly: bool = False) -> typing.Dict[str, typing. for k, v in self.items(): if exclude_readonly and k in readonly_props: # pyright: ignore[reportUnboundVariable] continue - is_multipart_file = False + is_multipart_file_input = False try: - is_multipart_file = next( + is_multipart_file_input = next( rf for rf in self._attr_to_rest_field.values() if rf._rest_name == k - )._is_multipart_file + )._is_multipart_file_input except StopIteration: pass - result[k] = v if is_multipart_file else Model._as_dict_value(v, exclude_readonly=exclude_readonly) + result[k] = v if is_multipart_file_input else Model._as_dict_value(v, exclude_readonly=exclude_readonly) return result @staticmethod @@ -775,7 +775,7 @@ def __init__( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, - is_multipart_file: bool = False, + is_multipart_file_input: bool = False, ): self._type = type self._rest_name_input = name @@ -785,7 +785,7 @@ def __init__( self._is_model = False self._default = default self._format = format - self._is_multipart_file = is_multipart_file + self._is_multipart_file_input = is_multipart_file_input @property def _rest_name(self) -> str: @@ -831,10 +831,15 @@ def rest_field( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, - is_multipart_file: bool = False, + is_multipart_file_input: bool = False, ) -> typing.Any: return _RestField( - name=name, type=type, visibility=visibility, default=default, format=format, is_multipart_file=is_multipart_file + name=name, + type=type, + visibility=visibility, + default=default, + format=format, + is_multipart_file_input=is_multipart_file_input, ) diff --git a/packages/typespec-python/test/azure/generated/typetest-property-optional/typetest/property/optional/_model_base.py b/packages/typespec-python/test/azure/generated/typetest-property-optional/typetest/property/optional/_model_base.py index 01c401e6324..247049f44d9 100644 --- a/packages/typespec-python/test/azure/generated/typetest-property-optional/typetest/property/optional/_model_base.py +++ b/packages/typespec-python/test/azure/generated/typetest-property-optional/typetest/property/optional/_model_base.py @@ -464,7 +464,7 @@ def _get_rest_field( def _create_value(rf: typing.Optional["_RestField"], value: typing.Any) -> typing.Any: if not rf: return _serialize(value, None) - if rf._is_multipart_file: + if rf._is_multipart_file_input: return value if rf._is_model: return _deserialize(rf._type, value) @@ -565,14 +565,14 @@ def as_dict(self, *, exclude_readonly: bool = False) -> typing.Dict[str, typing. for k, v in self.items(): if exclude_readonly and k in readonly_props: # pyright: ignore[reportUnboundVariable] continue - is_multipart_file = False + is_multipart_file_input = False try: - is_multipart_file = next( + is_multipart_file_input = next( rf for rf in self._attr_to_rest_field.values() if rf._rest_name == k - )._is_multipart_file + )._is_multipart_file_input except StopIteration: pass - result[k] = v if is_multipart_file else Model._as_dict_value(v, exclude_readonly=exclude_readonly) + result[k] = v if is_multipart_file_input else Model._as_dict_value(v, exclude_readonly=exclude_readonly) return result @staticmethod @@ -775,7 +775,7 @@ def __init__( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, - is_multipart_file: bool = False, + is_multipart_file_input: bool = False, ): self._type = type self._rest_name_input = name @@ -785,7 +785,7 @@ def __init__( self._is_model = False self._default = default self._format = format - self._is_multipart_file = is_multipart_file + self._is_multipart_file_input = is_multipart_file_input @property def _rest_name(self) -> str: @@ -831,10 +831,15 @@ def rest_field( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, - is_multipart_file: bool = False, + is_multipart_file_input: bool = False, ) -> typing.Any: return _RestField( - name=name, type=type, visibility=visibility, default=default, format=format, is_multipart_file=is_multipart_file + name=name, + type=type, + visibility=visibility, + default=default, + format=format, + is_multipart_file_input=is_multipart_file_input, ) diff --git a/packages/typespec-python/test/azure/generated/typetest-property-valuetypes/typetest/property/valuetypes/_model_base.py b/packages/typespec-python/test/azure/generated/typetest-property-valuetypes/typetest/property/valuetypes/_model_base.py index 01c401e6324..247049f44d9 100644 --- a/packages/typespec-python/test/azure/generated/typetest-property-valuetypes/typetest/property/valuetypes/_model_base.py +++ b/packages/typespec-python/test/azure/generated/typetest-property-valuetypes/typetest/property/valuetypes/_model_base.py @@ -464,7 +464,7 @@ def _get_rest_field( def _create_value(rf: typing.Optional["_RestField"], value: typing.Any) -> typing.Any: if not rf: return _serialize(value, None) - if rf._is_multipart_file: + if rf._is_multipart_file_input: return value if rf._is_model: return _deserialize(rf._type, value) @@ -565,14 +565,14 @@ def as_dict(self, *, exclude_readonly: bool = False) -> typing.Dict[str, typing. for k, v in self.items(): if exclude_readonly and k in readonly_props: # pyright: ignore[reportUnboundVariable] continue - is_multipart_file = False + is_multipart_file_input = False try: - is_multipart_file = next( + is_multipart_file_input = next( rf for rf in self._attr_to_rest_field.values() if rf._rest_name == k - )._is_multipart_file + )._is_multipart_file_input except StopIteration: pass - result[k] = v if is_multipart_file else Model._as_dict_value(v, exclude_readonly=exclude_readonly) + result[k] = v if is_multipart_file_input else Model._as_dict_value(v, exclude_readonly=exclude_readonly) return result @staticmethod @@ -775,7 +775,7 @@ def __init__( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, - is_multipart_file: bool = False, + is_multipart_file_input: bool = False, ): self._type = type self._rest_name_input = name @@ -785,7 +785,7 @@ def __init__( self._is_model = False self._default = default self._format = format - self._is_multipart_file = is_multipart_file + self._is_multipart_file_input = is_multipart_file_input @property def _rest_name(self) -> str: @@ -831,10 +831,15 @@ def rest_field( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, - is_multipart_file: bool = False, + is_multipart_file_input: bool = False, ) -> typing.Any: return _RestField( - name=name, type=type, visibility=visibility, default=default, format=format, is_multipart_file=is_multipart_file + name=name, + type=type, + visibility=visibility, + default=default, + format=format, + is_multipart_file_input=is_multipart_file_input, ) diff --git a/packages/typespec-python/test/azure/generated/typetest-scalar/typetest/scalar/_model_base.py b/packages/typespec-python/test/azure/generated/typetest-scalar/typetest/scalar/_model_base.py index 01c401e6324..247049f44d9 100644 --- a/packages/typespec-python/test/azure/generated/typetest-scalar/typetest/scalar/_model_base.py +++ b/packages/typespec-python/test/azure/generated/typetest-scalar/typetest/scalar/_model_base.py @@ -464,7 +464,7 @@ def _get_rest_field( def _create_value(rf: typing.Optional["_RestField"], value: typing.Any) -> typing.Any: if not rf: return _serialize(value, None) - if rf._is_multipart_file: + if rf._is_multipart_file_input: return value if rf._is_model: return _deserialize(rf._type, value) @@ -565,14 +565,14 @@ def as_dict(self, *, exclude_readonly: bool = False) -> typing.Dict[str, typing. for k, v in self.items(): if exclude_readonly and k in readonly_props: # pyright: ignore[reportUnboundVariable] continue - is_multipart_file = False + is_multipart_file_input = False try: - is_multipart_file = next( + is_multipart_file_input = next( rf for rf in self._attr_to_rest_field.values() if rf._rest_name == k - )._is_multipart_file + )._is_multipart_file_input except StopIteration: pass - result[k] = v if is_multipart_file else Model._as_dict_value(v, exclude_readonly=exclude_readonly) + result[k] = v if is_multipart_file_input else Model._as_dict_value(v, exclude_readonly=exclude_readonly) return result @staticmethod @@ -775,7 +775,7 @@ def __init__( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, - is_multipart_file: bool = False, + is_multipart_file_input: bool = False, ): self._type = type self._rest_name_input = name @@ -785,7 +785,7 @@ def __init__( self._is_model = False self._default = default self._format = format - self._is_multipart_file = is_multipart_file + self._is_multipart_file_input = is_multipart_file_input @property def _rest_name(self) -> str: @@ -831,10 +831,15 @@ def rest_field( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, - is_multipart_file: bool = False, + is_multipart_file_input: bool = False, ) -> typing.Any: return _RestField( - name=name, type=type, visibility=visibility, default=default, format=format, is_multipart_file=is_multipart_file + name=name, + type=type, + visibility=visibility, + default=default, + format=format, + is_multipart_file_input=is_multipart_file_input, ) diff --git a/packages/typespec-python/test/azure/generated/typetest-union/typetest/union/_model_base.py b/packages/typespec-python/test/azure/generated/typetest-union/typetest/union/_model_base.py index 01c401e6324..247049f44d9 100644 --- a/packages/typespec-python/test/azure/generated/typetest-union/typetest/union/_model_base.py +++ b/packages/typespec-python/test/azure/generated/typetest-union/typetest/union/_model_base.py @@ -464,7 +464,7 @@ def _get_rest_field( def _create_value(rf: typing.Optional["_RestField"], value: typing.Any) -> typing.Any: if not rf: return _serialize(value, None) - if rf._is_multipart_file: + if rf._is_multipart_file_input: return value if rf._is_model: return _deserialize(rf._type, value) @@ -565,14 +565,14 @@ def as_dict(self, *, exclude_readonly: bool = False) -> typing.Dict[str, typing. for k, v in self.items(): if exclude_readonly and k in readonly_props: # pyright: ignore[reportUnboundVariable] continue - is_multipart_file = False + is_multipart_file_input = False try: - is_multipart_file = next( + is_multipart_file_input = next( rf for rf in self._attr_to_rest_field.values() if rf._rest_name == k - )._is_multipart_file + )._is_multipart_file_input except StopIteration: pass - result[k] = v if is_multipart_file else Model._as_dict_value(v, exclude_readonly=exclude_readonly) + result[k] = v if is_multipart_file_input else Model._as_dict_value(v, exclude_readonly=exclude_readonly) return result @staticmethod @@ -775,7 +775,7 @@ def __init__( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, - is_multipart_file: bool = False, + is_multipart_file_input: bool = False, ): self._type = type self._rest_name_input = name @@ -785,7 +785,7 @@ def __init__( self._is_model = False self._default = default self._format = format - self._is_multipart_file = is_multipart_file + self._is_multipart_file_input = is_multipart_file_input @property def _rest_name(self) -> str: @@ -831,10 +831,15 @@ def rest_field( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, - is_multipart_file: bool = False, + is_multipart_file_input: bool = False, ) -> typing.Any: return _RestField( - name=name, type=type, visibility=visibility, default=default, format=format, is_multipart_file=is_multipart_file + name=name, + type=type, + visibility=visibility, + default=default, + format=format, + is_multipart_file_input=is_multipart_file_input, ) diff --git a/packages/typespec-python/test/unbranded/generated/authentication-api-key/authentication/apikey/_model_base.py b/packages/typespec-python/test/unbranded/generated/authentication-api-key/authentication/apikey/_model_base.py index 18fc4d77a91..849db7e8e49 100644 --- a/packages/typespec-python/test/unbranded/generated/authentication-api-key/authentication/apikey/_model_base.py +++ b/packages/typespec-python/test/unbranded/generated/authentication-api-key/authentication/apikey/_model_base.py @@ -464,7 +464,7 @@ def _get_rest_field( def _create_value(rf: typing.Optional["_RestField"], value: typing.Any) -> typing.Any: if not rf: return _serialize(value, None) - if rf._is_multipart_file: + if rf._is_multipart_file_input: return value if rf._is_model: return _deserialize(rf._type, value) @@ -565,14 +565,14 @@ def as_dict(self, *, exclude_readonly: bool = False) -> typing.Dict[str, typing. for k, v in self.items(): if exclude_readonly and k in readonly_props: # pyright: ignore[reportUnboundVariable] continue - is_multipart_file = False + is_multipart_file_input = False try: - is_multipart_file = next( + is_multipart_file_input = next( rf for rf in self._attr_to_rest_field.values() if rf._rest_name == k - )._is_multipart_file + )._is_multipart_file_input except StopIteration: pass - result[k] = v if is_multipart_file else Model._as_dict_value(v, exclude_readonly=exclude_readonly) + result[k] = v if is_multipart_file_input else Model._as_dict_value(v, exclude_readonly=exclude_readonly) return result @staticmethod @@ -775,7 +775,7 @@ def __init__( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, - is_multipart_file: bool = False, + is_multipart_file_input: bool = False, ): self._type = type self._rest_name_input = name @@ -785,7 +785,7 @@ def __init__( self._is_model = False self._default = default self._format = format - self._is_multipart_file = is_multipart_file + self._is_multipart_file_input = is_multipart_file_input @property def _rest_name(self) -> str: @@ -831,10 +831,15 @@ def rest_field( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, - is_multipart_file: bool = False, + is_multipart_file_input: bool = False, ) -> typing.Any: return _RestField( - name=name, type=type, visibility=visibility, default=default, format=format, is_multipart_file=is_multipart_file + name=name, + type=type, + visibility=visibility, + default=default, + format=format, + is_multipart_file_input=is_multipart_file_input, ) diff --git a/packages/typespec-python/test/unbranded/generated/authentication-http-custom/authentication/http/custom/_model_base.py b/packages/typespec-python/test/unbranded/generated/authentication-http-custom/authentication/http/custom/_model_base.py index 18fc4d77a91..849db7e8e49 100644 --- a/packages/typespec-python/test/unbranded/generated/authentication-http-custom/authentication/http/custom/_model_base.py +++ b/packages/typespec-python/test/unbranded/generated/authentication-http-custom/authentication/http/custom/_model_base.py @@ -464,7 +464,7 @@ def _get_rest_field( def _create_value(rf: typing.Optional["_RestField"], value: typing.Any) -> typing.Any: if not rf: return _serialize(value, None) - if rf._is_multipart_file: + if rf._is_multipart_file_input: return value if rf._is_model: return _deserialize(rf._type, value) @@ -565,14 +565,14 @@ def as_dict(self, *, exclude_readonly: bool = False) -> typing.Dict[str, typing. for k, v in self.items(): if exclude_readonly and k in readonly_props: # pyright: ignore[reportUnboundVariable] continue - is_multipart_file = False + is_multipart_file_input = False try: - is_multipart_file = next( + is_multipart_file_input = next( rf for rf in self._attr_to_rest_field.values() if rf._rest_name == k - )._is_multipart_file + )._is_multipart_file_input except StopIteration: pass - result[k] = v if is_multipart_file else Model._as_dict_value(v, exclude_readonly=exclude_readonly) + result[k] = v if is_multipart_file_input else Model._as_dict_value(v, exclude_readonly=exclude_readonly) return result @staticmethod @@ -775,7 +775,7 @@ def __init__( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, - is_multipart_file: bool = False, + is_multipart_file_input: bool = False, ): self._type = type self._rest_name_input = name @@ -785,7 +785,7 @@ def __init__( self._is_model = False self._default = default self._format = format - self._is_multipart_file = is_multipart_file + self._is_multipart_file_input = is_multipart_file_input @property def _rest_name(self) -> str: @@ -831,10 +831,15 @@ def rest_field( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, - is_multipart_file: bool = False, + is_multipart_file_input: bool = False, ) -> typing.Any: return _RestField( - name=name, type=type, visibility=visibility, default=default, format=format, is_multipart_file=is_multipart_file + name=name, + type=type, + visibility=visibility, + default=default, + format=format, + is_multipart_file_input=is_multipart_file_input, ) diff --git a/packages/typespec-python/test/unbranded/generated/authentication-oauth2/authentication/oauth2/_model_base.py b/packages/typespec-python/test/unbranded/generated/authentication-oauth2/authentication/oauth2/_model_base.py index 18fc4d77a91..849db7e8e49 100644 --- a/packages/typespec-python/test/unbranded/generated/authentication-oauth2/authentication/oauth2/_model_base.py +++ b/packages/typespec-python/test/unbranded/generated/authentication-oauth2/authentication/oauth2/_model_base.py @@ -464,7 +464,7 @@ def _get_rest_field( def _create_value(rf: typing.Optional["_RestField"], value: typing.Any) -> typing.Any: if not rf: return _serialize(value, None) - if rf._is_multipart_file: + if rf._is_multipart_file_input: return value if rf._is_model: return _deserialize(rf._type, value) @@ -565,14 +565,14 @@ def as_dict(self, *, exclude_readonly: bool = False) -> typing.Dict[str, typing. for k, v in self.items(): if exclude_readonly and k in readonly_props: # pyright: ignore[reportUnboundVariable] continue - is_multipart_file = False + is_multipart_file_input = False try: - is_multipart_file = next( + is_multipart_file_input = next( rf for rf in self._attr_to_rest_field.values() if rf._rest_name == k - )._is_multipart_file + )._is_multipart_file_input except StopIteration: pass - result[k] = v if is_multipart_file else Model._as_dict_value(v, exclude_readonly=exclude_readonly) + result[k] = v if is_multipart_file_input else Model._as_dict_value(v, exclude_readonly=exclude_readonly) return result @staticmethod @@ -775,7 +775,7 @@ def __init__( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, - is_multipart_file: bool = False, + is_multipart_file_input: bool = False, ): self._type = type self._rest_name_input = name @@ -785,7 +785,7 @@ def __init__( self._is_model = False self._default = default self._format = format - self._is_multipart_file = is_multipart_file + self._is_multipart_file_input = is_multipart_file_input @property def _rest_name(self) -> str: @@ -831,10 +831,15 @@ def rest_field( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, - is_multipart_file: bool = False, + is_multipart_file_input: bool = False, ) -> typing.Any: return _RestField( - name=name, type=type, visibility=visibility, default=default, format=format, is_multipart_file=is_multipart_file + name=name, + type=type, + visibility=visibility, + default=default, + format=format, + is_multipart_file_input=is_multipart_file_input, ) diff --git a/packages/typespec-python/test/unbranded/generated/authentication-union/authentication/union/_model_base.py b/packages/typespec-python/test/unbranded/generated/authentication-union/authentication/union/_model_base.py index 18fc4d77a91..849db7e8e49 100644 --- a/packages/typespec-python/test/unbranded/generated/authentication-union/authentication/union/_model_base.py +++ b/packages/typespec-python/test/unbranded/generated/authentication-union/authentication/union/_model_base.py @@ -464,7 +464,7 @@ def _get_rest_field( def _create_value(rf: typing.Optional["_RestField"], value: typing.Any) -> typing.Any: if not rf: return _serialize(value, None) - if rf._is_multipart_file: + if rf._is_multipart_file_input: return value if rf._is_model: return _deserialize(rf._type, value) @@ -565,14 +565,14 @@ def as_dict(self, *, exclude_readonly: bool = False) -> typing.Dict[str, typing. for k, v in self.items(): if exclude_readonly and k in readonly_props: # pyright: ignore[reportUnboundVariable] continue - is_multipart_file = False + is_multipart_file_input = False try: - is_multipart_file = next( + is_multipart_file_input = next( rf for rf in self._attr_to_rest_field.values() if rf._rest_name == k - )._is_multipart_file + )._is_multipart_file_input except StopIteration: pass - result[k] = v if is_multipart_file else Model._as_dict_value(v, exclude_readonly=exclude_readonly) + result[k] = v if is_multipart_file_input else Model._as_dict_value(v, exclude_readonly=exclude_readonly) return result @staticmethod @@ -775,7 +775,7 @@ def __init__( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, - is_multipart_file: bool = False, + is_multipart_file_input: bool = False, ): self._type = type self._rest_name_input = name @@ -785,7 +785,7 @@ def __init__( self._is_model = False self._default = default self._format = format - self._is_multipart_file = is_multipart_file + self._is_multipart_file_input = is_multipart_file_input @property def _rest_name(self) -> str: @@ -831,10 +831,15 @@ def rest_field( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, - is_multipart_file: bool = False, + is_multipart_file_input: bool = False, ) -> typing.Any: return _RestField( - name=name, type=type, visibility=visibility, default=default, format=format, is_multipart_file=is_multipart_file + name=name, + type=type, + visibility=visibility, + default=default, + format=format, + is_multipart_file_input=is_multipart_file_input, ) diff --git a/packages/typespec-python/test/unbranded/generated/client-structure-default/client/structure/service/_model_base.py b/packages/typespec-python/test/unbranded/generated/client-structure-default/client/structure/service/_model_base.py index 18fc4d77a91..849db7e8e49 100644 --- a/packages/typespec-python/test/unbranded/generated/client-structure-default/client/structure/service/_model_base.py +++ b/packages/typespec-python/test/unbranded/generated/client-structure-default/client/structure/service/_model_base.py @@ -464,7 +464,7 @@ def _get_rest_field( def _create_value(rf: typing.Optional["_RestField"], value: typing.Any) -> typing.Any: if not rf: return _serialize(value, None) - if rf._is_multipart_file: + if rf._is_multipart_file_input: return value if rf._is_model: return _deserialize(rf._type, value) @@ -565,14 +565,14 @@ def as_dict(self, *, exclude_readonly: bool = False) -> typing.Dict[str, typing. for k, v in self.items(): if exclude_readonly and k in readonly_props: # pyright: ignore[reportUnboundVariable] continue - is_multipart_file = False + is_multipart_file_input = False try: - is_multipart_file = next( + is_multipart_file_input = next( rf for rf in self._attr_to_rest_field.values() if rf._rest_name == k - )._is_multipart_file + )._is_multipart_file_input except StopIteration: pass - result[k] = v if is_multipart_file else Model._as_dict_value(v, exclude_readonly=exclude_readonly) + result[k] = v if is_multipart_file_input else Model._as_dict_value(v, exclude_readonly=exclude_readonly) return result @staticmethod @@ -775,7 +775,7 @@ def __init__( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, - is_multipart_file: bool = False, + is_multipart_file_input: bool = False, ): self._type = type self._rest_name_input = name @@ -785,7 +785,7 @@ def __init__( self._is_model = False self._default = default self._format = format - self._is_multipart_file = is_multipart_file + self._is_multipart_file_input = is_multipart_file_input @property def _rest_name(self) -> str: @@ -831,10 +831,15 @@ def rest_field( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, - is_multipart_file: bool = False, + is_multipart_file_input: bool = False, ) -> typing.Any: return _RestField( - name=name, type=type, visibility=visibility, default=default, format=format, is_multipart_file=is_multipart_file + name=name, + type=type, + visibility=visibility, + default=default, + format=format, + is_multipart_file_input=is_multipart_file_input, ) diff --git a/packages/typespec-python/test/unbranded/generated/client-structure-multiclient/client/structure/multiclient/_model_base.py b/packages/typespec-python/test/unbranded/generated/client-structure-multiclient/client/structure/multiclient/_model_base.py index 18fc4d77a91..849db7e8e49 100644 --- a/packages/typespec-python/test/unbranded/generated/client-structure-multiclient/client/structure/multiclient/_model_base.py +++ b/packages/typespec-python/test/unbranded/generated/client-structure-multiclient/client/structure/multiclient/_model_base.py @@ -464,7 +464,7 @@ def _get_rest_field( def _create_value(rf: typing.Optional["_RestField"], value: typing.Any) -> typing.Any: if not rf: return _serialize(value, None) - if rf._is_multipart_file: + if rf._is_multipart_file_input: return value if rf._is_model: return _deserialize(rf._type, value) @@ -565,14 +565,14 @@ def as_dict(self, *, exclude_readonly: bool = False) -> typing.Dict[str, typing. for k, v in self.items(): if exclude_readonly and k in readonly_props: # pyright: ignore[reportUnboundVariable] continue - is_multipart_file = False + is_multipart_file_input = False try: - is_multipart_file = next( + is_multipart_file_input = next( rf for rf in self._attr_to_rest_field.values() if rf._rest_name == k - )._is_multipart_file + )._is_multipart_file_input except StopIteration: pass - result[k] = v if is_multipart_file else Model._as_dict_value(v, exclude_readonly=exclude_readonly) + result[k] = v if is_multipart_file_input else Model._as_dict_value(v, exclude_readonly=exclude_readonly) return result @staticmethod @@ -775,7 +775,7 @@ def __init__( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, - is_multipart_file: bool = False, + is_multipart_file_input: bool = False, ): self._type = type self._rest_name_input = name @@ -785,7 +785,7 @@ def __init__( self._is_model = False self._default = default self._format = format - self._is_multipart_file = is_multipart_file + self._is_multipart_file_input = is_multipart_file_input @property def _rest_name(self) -> str: @@ -831,10 +831,15 @@ def rest_field( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, - is_multipart_file: bool = False, + is_multipart_file_input: bool = False, ) -> typing.Any: return _RestField( - name=name, type=type, visibility=visibility, default=default, format=format, is_multipart_file=is_multipart_file + name=name, + type=type, + visibility=visibility, + default=default, + format=format, + is_multipart_file_input=is_multipart_file_input, ) diff --git a/packages/typespec-python/test/unbranded/generated/client-structure-renamedoperation/client/structure/renamedoperation/_model_base.py b/packages/typespec-python/test/unbranded/generated/client-structure-renamedoperation/client/structure/renamedoperation/_model_base.py index 18fc4d77a91..849db7e8e49 100644 --- a/packages/typespec-python/test/unbranded/generated/client-structure-renamedoperation/client/structure/renamedoperation/_model_base.py +++ b/packages/typespec-python/test/unbranded/generated/client-structure-renamedoperation/client/structure/renamedoperation/_model_base.py @@ -464,7 +464,7 @@ def _get_rest_field( def _create_value(rf: typing.Optional["_RestField"], value: typing.Any) -> typing.Any: if not rf: return _serialize(value, None) - if rf._is_multipart_file: + if rf._is_multipart_file_input: return value if rf._is_model: return _deserialize(rf._type, value) @@ -565,14 +565,14 @@ def as_dict(self, *, exclude_readonly: bool = False) -> typing.Dict[str, typing. for k, v in self.items(): if exclude_readonly and k in readonly_props: # pyright: ignore[reportUnboundVariable] continue - is_multipart_file = False + is_multipart_file_input = False try: - is_multipart_file = next( + is_multipart_file_input = next( rf for rf in self._attr_to_rest_field.values() if rf._rest_name == k - )._is_multipart_file + )._is_multipart_file_input except StopIteration: pass - result[k] = v if is_multipart_file else Model._as_dict_value(v, exclude_readonly=exclude_readonly) + result[k] = v if is_multipart_file_input else Model._as_dict_value(v, exclude_readonly=exclude_readonly) return result @staticmethod @@ -775,7 +775,7 @@ def __init__( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, - is_multipart_file: bool = False, + is_multipart_file_input: bool = False, ): self._type = type self._rest_name_input = name @@ -785,7 +785,7 @@ def __init__( self._is_model = False self._default = default self._format = format - self._is_multipart_file = is_multipart_file + self._is_multipart_file_input = is_multipart_file_input @property def _rest_name(self) -> str: @@ -831,10 +831,15 @@ def rest_field( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, - is_multipart_file: bool = False, + is_multipart_file_input: bool = False, ) -> typing.Any: return _RestField( - name=name, type=type, visibility=visibility, default=default, format=format, is_multipart_file=is_multipart_file + name=name, + type=type, + visibility=visibility, + default=default, + format=format, + is_multipart_file_input=is_multipart_file_input, ) diff --git a/packages/typespec-python/test/unbranded/generated/client-structure-twooperationgroup/client/structure/twooperationgroup/_model_base.py b/packages/typespec-python/test/unbranded/generated/client-structure-twooperationgroup/client/structure/twooperationgroup/_model_base.py index 18fc4d77a91..849db7e8e49 100644 --- a/packages/typespec-python/test/unbranded/generated/client-structure-twooperationgroup/client/structure/twooperationgroup/_model_base.py +++ b/packages/typespec-python/test/unbranded/generated/client-structure-twooperationgroup/client/structure/twooperationgroup/_model_base.py @@ -464,7 +464,7 @@ def _get_rest_field( def _create_value(rf: typing.Optional["_RestField"], value: typing.Any) -> typing.Any: if not rf: return _serialize(value, None) - if rf._is_multipart_file: + if rf._is_multipart_file_input: return value if rf._is_model: return _deserialize(rf._type, value) @@ -565,14 +565,14 @@ def as_dict(self, *, exclude_readonly: bool = False) -> typing.Dict[str, typing. for k, v in self.items(): if exclude_readonly and k in readonly_props: # pyright: ignore[reportUnboundVariable] continue - is_multipart_file = False + is_multipart_file_input = False try: - is_multipart_file = next( + is_multipart_file_input = next( rf for rf in self._attr_to_rest_field.values() if rf._rest_name == k - )._is_multipart_file + )._is_multipart_file_input except StopIteration: pass - result[k] = v if is_multipart_file else Model._as_dict_value(v, exclude_readonly=exclude_readonly) + result[k] = v if is_multipart_file_input else Model._as_dict_value(v, exclude_readonly=exclude_readonly) return result @staticmethod @@ -775,7 +775,7 @@ def __init__( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, - is_multipart_file: bool = False, + is_multipart_file_input: bool = False, ): self._type = type self._rest_name_input = name @@ -785,7 +785,7 @@ def __init__( self._is_model = False self._default = default self._format = format - self._is_multipart_file = is_multipart_file + self._is_multipart_file_input = is_multipart_file_input @property def _rest_name(self) -> str: @@ -831,10 +831,15 @@ def rest_field( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, - is_multipart_file: bool = False, + is_multipart_file_input: bool = False, ) -> typing.Any: return _RestField( - name=name, type=type, visibility=visibility, default=default, format=format, is_multipart_file=is_multipart_file + name=name, + type=type, + visibility=visibility, + default=default, + format=format, + is_multipart_file_input=is_multipart_file_input, ) diff --git a/packages/typespec-python/test/unbranded/generated/encode-bytes/encode/bytes/_model_base.py b/packages/typespec-python/test/unbranded/generated/encode-bytes/encode/bytes/_model_base.py index 18fc4d77a91..849db7e8e49 100644 --- a/packages/typespec-python/test/unbranded/generated/encode-bytes/encode/bytes/_model_base.py +++ b/packages/typespec-python/test/unbranded/generated/encode-bytes/encode/bytes/_model_base.py @@ -464,7 +464,7 @@ def _get_rest_field( def _create_value(rf: typing.Optional["_RestField"], value: typing.Any) -> typing.Any: if not rf: return _serialize(value, None) - if rf._is_multipart_file: + if rf._is_multipart_file_input: return value if rf._is_model: return _deserialize(rf._type, value) @@ -565,14 +565,14 @@ def as_dict(self, *, exclude_readonly: bool = False) -> typing.Dict[str, typing. for k, v in self.items(): if exclude_readonly and k in readonly_props: # pyright: ignore[reportUnboundVariable] continue - is_multipart_file = False + is_multipart_file_input = False try: - is_multipart_file = next( + is_multipart_file_input = next( rf for rf in self._attr_to_rest_field.values() if rf._rest_name == k - )._is_multipart_file + )._is_multipart_file_input except StopIteration: pass - result[k] = v if is_multipart_file else Model._as_dict_value(v, exclude_readonly=exclude_readonly) + result[k] = v if is_multipart_file_input else Model._as_dict_value(v, exclude_readonly=exclude_readonly) return result @staticmethod @@ -775,7 +775,7 @@ def __init__( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, - is_multipart_file: bool = False, + is_multipart_file_input: bool = False, ): self._type = type self._rest_name_input = name @@ -785,7 +785,7 @@ def __init__( self._is_model = False self._default = default self._format = format - self._is_multipart_file = is_multipart_file + self._is_multipart_file_input = is_multipart_file_input @property def _rest_name(self) -> str: @@ -831,10 +831,15 @@ def rest_field( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, - is_multipart_file: bool = False, + is_multipart_file_input: bool = False, ) -> typing.Any: return _RestField( - name=name, type=type, visibility=visibility, default=default, format=format, is_multipart_file=is_multipart_file + name=name, + type=type, + visibility=visibility, + default=default, + format=format, + is_multipart_file_input=is_multipart_file_input, ) diff --git a/packages/typespec-python/test/unbranded/generated/encode-datetime/encode/datetime/_model_base.py b/packages/typespec-python/test/unbranded/generated/encode-datetime/encode/datetime/_model_base.py index 18fc4d77a91..849db7e8e49 100644 --- a/packages/typespec-python/test/unbranded/generated/encode-datetime/encode/datetime/_model_base.py +++ b/packages/typespec-python/test/unbranded/generated/encode-datetime/encode/datetime/_model_base.py @@ -464,7 +464,7 @@ def _get_rest_field( def _create_value(rf: typing.Optional["_RestField"], value: typing.Any) -> typing.Any: if not rf: return _serialize(value, None) - if rf._is_multipart_file: + if rf._is_multipart_file_input: return value if rf._is_model: return _deserialize(rf._type, value) @@ -565,14 +565,14 @@ def as_dict(self, *, exclude_readonly: bool = False) -> typing.Dict[str, typing. for k, v in self.items(): if exclude_readonly and k in readonly_props: # pyright: ignore[reportUnboundVariable] continue - is_multipart_file = False + is_multipart_file_input = False try: - is_multipart_file = next( + is_multipart_file_input = next( rf for rf in self._attr_to_rest_field.values() if rf._rest_name == k - )._is_multipart_file + )._is_multipart_file_input except StopIteration: pass - result[k] = v if is_multipart_file else Model._as_dict_value(v, exclude_readonly=exclude_readonly) + result[k] = v if is_multipart_file_input else Model._as_dict_value(v, exclude_readonly=exclude_readonly) return result @staticmethod @@ -775,7 +775,7 @@ def __init__( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, - is_multipart_file: bool = False, + is_multipart_file_input: bool = False, ): self._type = type self._rest_name_input = name @@ -785,7 +785,7 @@ def __init__( self._is_model = False self._default = default self._format = format - self._is_multipart_file = is_multipart_file + self._is_multipart_file_input = is_multipart_file_input @property def _rest_name(self) -> str: @@ -831,10 +831,15 @@ def rest_field( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, - is_multipart_file: bool = False, + is_multipart_file_input: bool = False, ) -> typing.Any: return _RestField( - name=name, type=type, visibility=visibility, default=default, format=format, is_multipart_file=is_multipart_file + name=name, + type=type, + visibility=visibility, + default=default, + format=format, + is_multipart_file_input=is_multipart_file_input, ) diff --git a/packages/typespec-python/test/unbranded/generated/encode-duration/encode/duration/_model_base.py b/packages/typespec-python/test/unbranded/generated/encode-duration/encode/duration/_model_base.py index 18fc4d77a91..849db7e8e49 100644 --- a/packages/typespec-python/test/unbranded/generated/encode-duration/encode/duration/_model_base.py +++ b/packages/typespec-python/test/unbranded/generated/encode-duration/encode/duration/_model_base.py @@ -464,7 +464,7 @@ def _get_rest_field( def _create_value(rf: typing.Optional["_RestField"], value: typing.Any) -> typing.Any: if not rf: return _serialize(value, None) - if rf._is_multipart_file: + if rf._is_multipart_file_input: return value if rf._is_model: return _deserialize(rf._type, value) @@ -565,14 +565,14 @@ def as_dict(self, *, exclude_readonly: bool = False) -> typing.Dict[str, typing. for k, v in self.items(): if exclude_readonly and k in readonly_props: # pyright: ignore[reportUnboundVariable] continue - is_multipart_file = False + is_multipart_file_input = False try: - is_multipart_file = next( + is_multipart_file_input = next( rf for rf in self._attr_to_rest_field.values() if rf._rest_name == k - )._is_multipart_file + )._is_multipart_file_input except StopIteration: pass - result[k] = v if is_multipart_file else Model._as_dict_value(v, exclude_readonly=exclude_readonly) + result[k] = v if is_multipart_file_input else Model._as_dict_value(v, exclude_readonly=exclude_readonly) return result @staticmethod @@ -775,7 +775,7 @@ def __init__( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, - is_multipart_file: bool = False, + is_multipart_file_input: bool = False, ): self._type = type self._rest_name_input = name @@ -785,7 +785,7 @@ def __init__( self._is_model = False self._default = default self._format = format - self._is_multipart_file = is_multipart_file + self._is_multipart_file_input = is_multipart_file_input @property def _rest_name(self) -> str: @@ -831,10 +831,15 @@ def rest_field( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, - is_multipart_file: bool = False, + is_multipart_file_input: bool = False, ) -> typing.Any: return _RestField( - name=name, type=type, visibility=visibility, default=default, format=format, is_multipart_file=is_multipart_file + name=name, + type=type, + visibility=visibility, + default=default, + format=format, + is_multipart_file_input=is_multipart_file_input, ) diff --git a/packages/typespec-python/test/unbranded/generated/headasbooleanfalse/headasbooleanfalse/_model_base.py b/packages/typespec-python/test/unbranded/generated/headasbooleanfalse/headasbooleanfalse/_model_base.py index 18fc4d77a91..849db7e8e49 100644 --- a/packages/typespec-python/test/unbranded/generated/headasbooleanfalse/headasbooleanfalse/_model_base.py +++ b/packages/typespec-python/test/unbranded/generated/headasbooleanfalse/headasbooleanfalse/_model_base.py @@ -464,7 +464,7 @@ def _get_rest_field( def _create_value(rf: typing.Optional["_RestField"], value: typing.Any) -> typing.Any: if not rf: return _serialize(value, None) - if rf._is_multipart_file: + if rf._is_multipart_file_input: return value if rf._is_model: return _deserialize(rf._type, value) @@ -565,14 +565,14 @@ def as_dict(self, *, exclude_readonly: bool = False) -> typing.Dict[str, typing. for k, v in self.items(): if exclude_readonly and k in readonly_props: # pyright: ignore[reportUnboundVariable] continue - is_multipart_file = False + is_multipart_file_input = False try: - is_multipart_file = next( + is_multipart_file_input = next( rf for rf in self._attr_to_rest_field.values() if rf._rest_name == k - )._is_multipart_file + )._is_multipart_file_input except StopIteration: pass - result[k] = v if is_multipart_file else Model._as_dict_value(v, exclude_readonly=exclude_readonly) + result[k] = v if is_multipart_file_input else Model._as_dict_value(v, exclude_readonly=exclude_readonly) return result @staticmethod @@ -775,7 +775,7 @@ def __init__( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, - is_multipart_file: bool = False, + is_multipart_file_input: bool = False, ): self._type = type self._rest_name_input = name @@ -785,7 +785,7 @@ def __init__( self._is_model = False self._default = default self._format = format - self._is_multipart_file = is_multipart_file + self._is_multipart_file_input = is_multipart_file_input @property def _rest_name(self) -> str: @@ -831,10 +831,15 @@ def rest_field( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, - is_multipart_file: bool = False, + is_multipart_file_input: bool = False, ) -> typing.Any: return _RestField( - name=name, type=type, visibility=visibility, default=default, format=format, is_multipart_file=is_multipart_file + name=name, + type=type, + visibility=visibility, + default=default, + format=format, + is_multipart_file_input=is_multipart_file_input, ) diff --git a/packages/typespec-python/test/unbranded/generated/headasbooleantrue/headasbooleantrue/_model_base.py b/packages/typespec-python/test/unbranded/generated/headasbooleantrue/headasbooleantrue/_model_base.py index 18fc4d77a91..849db7e8e49 100644 --- a/packages/typespec-python/test/unbranded/generated/headasbooleantrue/headasbooleantrue/_model_base.py +++ b/packages/typespec-python/test/unbranded/generated/headasbooleantrue/headasbooleantrue/_model_base.py @@ -464,7 +464,7 @@ def _get_rest_field( def _create_value(rf: typing.Optional["_RestField"], value: typing.Any) -> typing.Any: if not rf: return _serialize(value, None) - if rf._is_multipart_file: + if rf._is_multipart_file_input: return value if rf._is_model: return _deserialize(rf._type, value) @@ -565,14 +565,14 @@ def as_dict(self, *, exclude_readonly: bool = False) -> typing.Dict[str, typing. for k, v in self.items(): if exclude_readonly and k in readonly_props: # pyright: ignore[reportUnboundVariable] continue - is_multipart_file = False + is_multipart_file_input = False try: - is_multipart_file = next( + is_multipart_file_input = next( rf for rf in self._attr_to_rest_field.values() if rf._rest_name == k - )._is_multipart_file + )._is_multipart_file_input except StopIteration: pass - result[k] = v if is_multipart_file else Model._as_dict_value(v, exclude_readonly=exclude_readonly) + result[k] = v if is_multipart_file_input else Model._as_dict_value(v, exclude_readonly=exclude_readonly) return result @staticmethod @@ -775,7 +775,7 @@ def __init__( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, - is_multipart_file: bool = False, + is_multipart_file_input: bool = False, ): self._type = type self._rest_name_input = name @@ -785,7 +785,7 @@ def __init__( self._is_model = False self._default = default self._format = format - self._is_multipart_file = is_multipart_file + self._is_multipart_file_input = is_multipart_file_input @property def _rest_name(self) -> str: @@ -831,10 +831,15 @@ def rest_field( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, - is_multipart_file: bool = False, + is_multipart_file_input: bool = False, ) -> typing.Any: return _RestField( - name=name, type=type, visibility=visibility, default=default, format=format, is_multipart_file=is_multipart_file + name=name, + type=type, + visibility=visibility, + default=default, + format=format, + is_multipart_file_input=is_multipart_file_input, ) diff --git a/packages/typespec-python/test/unbranded/generated/parameters-body-optionality/parameters/bodyoptionality/_model_base.py b/packages/typespec-python/test/unbranded/generated/parameters-body-optionality/parameters/bodyoptionality/_model_base.py index 18fc4d77a91..849db7e8e49 100644 --- a/packages/typespec-python/test/unbranded/generated/parameters-body-optionality/parameters/bodyoptionality/_model_base.py +++ b/packages/typespec-python/test/unbranded/generated/parameters-body-optionality/parameters/bodyoptionality/_model_base.py @@ -464,7 +464,7 @@ def _get_rest_field( def _create_value(rf: typing.Optional["_RestField"], value: typing.Any) -> typing.Any: if not rf: return _serialize(value, None) - if rf._is_multipart_file: + if rf._is_multipart_file_input: return value if rf._is_model: return _deserialize(rf._type, value) @@ -565,14 +565,14 @@ def as_dict(self, *, exclude_readonly: bool = False) -> typing.Dict[str, typing. for k, v in self.items(): if exclude_readonly and k in readonly_props: # pyright: ignore[reportUnboundVariable] continue - is_multipart_file = False + is_multipart_file_input = False try: - is_multipart_file = next( + is_multipart_file_input = next( rf for rf in self._attr_to_rest_field.values() if rf._rest_name == k - )._is_multipart_file + )._is_multipart_file_input except StopIteration: pass - result[k] = v if is_multipart_file else Model._as_dict_value(v, exclude_readonly=exclude_readonly) + result[k] = v if is_multipart_file_input else Model._as_dict_value(v, exclude_readonly=exclude_readonly) return result @staticmethod @@ -775,7 +775,7 @@ def __init__( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, - is_multipart_file: bool = False, + is_multipart_file_input: bool = False, ): self._type = type self._rest_name_input = name @@ -785,7 +785,7 @@ def __init__( self._is_model = False self._default = default self._format = format - self._is_multipart_file = is_multipart_file + self._is_multipart_file_input = is_multipart_file_input @property def _rest_name(self) -> str: @@ -831,10 +831,15 @@ def rest_field( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, - is_multipart_file: bool = False, + is_multipart_file_input: bool = False, ) -> typing.Any: return _RestField( - name=name, type=type, visibility=visibility, default=default, format=format, is_multipart_file=is_multipart_file + name=name, + type=type, + visibility=visibility, + default=default, + format=format, + is_multipart_file_input=is_multipart_file_input, ) diff --git a/packages/typespec-python/test/unbranded/generated/parameters-collection-format/parameters/collectionformat/_model_base.py b/packages/typespec-python/test/unbranded/generated/parameters-collection-format/parameters/collectionformat/_model_base.py index 18fc4d77a91..849db7e8e49 100644 --- a/packages/typespec-python/test/unbranded/generated/parameters-collection-format/parameters/collectionformat/_model_base.py +++ b/packages/typespec-python/test/unbranded/generated/parameters-collection-format/parameters/collectionformat/_model_base.py @@ -464,7 +464,7 @@ def _get_rest_field( def _create_value(rf: typing.Optional["_RestField"], value: typing.Any) -> typing.Any: if not rf: return _serialize(value, None) - if rf._is_multipart_file: + if rf._is_multipart_file_input: return value if rf._is_model: return _deserialize(rf._type, value) @@ -565,14 +565,14 @@ def as_dict(self, *, exclude_readonly: bool = False) -> typing.Dict[str, typing. for k, v in self.items(): if exclude_readonly and k in readonly_props: # pyright: ignore[reportUnboundVariable] continue - is_multipart_file = False + is_multipart_file_input = False try: - is_multipart_file = next( + is_multipart_file_input = next( rf for rf in self._attr_to_rest_field.values() if rf._rest_name == k - )._is_multipart_file + )._is_multipart_file_input except StopIteration: pass - result[k] = v if is_multipart_file else Model._as_dict_value(v, exclude_readonly=exclude_readonly) + result[k] = v if is_multipart_file_input else Model._as_dict_value(v, exclude_readonly=exclude_readonly) return result @staticmethod @@ -775,7 +775,7 @@ def __init__( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, - is_multipart_file: bool = False, + is_multipart_file_input: bool = False, ): self._type = type self._rest_name_input = name @@ -785,7 +785,7 @@ def __init__( self._is_model = False self._default = default self._format = format - self._is_multipart_file = is_multipart_file + self._is_multipart_file_input = is_multipart_file_input @property def _rest_name(self) -> str: @@ -831,10 +831,15 @@ def rest_field( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, - is_multipart_file: bool = False, + is_multipart_file_input: bool = False, ) -> typing.Any: return _RestField( - name=name, type=type, visibility=visibility, default=default, format=format, is_multipart_file=is_multipart_file + name=name, + type=type, + visibility=visibility, + default=default, + format=format, + is_multipart_file_input=is_multipart_file_input, ) diff --git a/packages/typespec-python/test/unbranded/generated/parameters-spread/parameters/spread/_model_base.py b/packages/typespec-python/test/unbranded/generated/parameters-spread/parameters/spread/_model_base.py index 18fc4d77a91..849db7e8e49 100644 --- a/packages/typespec-python/test/unbranded/generated/parameters-spread/parameters/spread/_model_base.py +++ b/packages/typespec-python/test/unbranded/generated/parameters-spread/parameters/spread/_model_base.py @@ -464,7 +464,7 @@ def _get_rest_field( def _create_value(rf: typing.Optional["_RestField"], value: typing.Any) -> typing.Any: if not rf: return _serialize(value, None) - if rf._is_multipart_file: + if rf._is_multipart_file_input: return value if rf._is_model: return _deserialize(rf._type, value) @@ -565,14 +565,14 @@ def as_dict(self, *, exclude_readonly: bool = False) -> typing.Dict[str, typing. for k, v in self.items(): if exclude_readonly and k in readonly_props: # pyright: ignore[reportUnboundVariable] continue - is_multipart_file = False + is_multipart_file_input = False try: - is_multipart_file = next( + is_multipart_file_input = next( rf for rf in self._attr_to_rest_field.values() if rf._rest_name == k - )._is_multipart_file + )._is_multipart_file_input except StopIteration: pass - result[k] = v if is_multipart_file else Model._as_dict_value(v, exclude_readonly=exclude_readonly) + result[k] = v if is_multipart_file_input else Model._as_dict_value(v, exclude_readonly=exclude_readonly) return result @staticmethod @@ -775,7 +775,7 @@ def __init__( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, - is_multipart_file: bool = False, + is_multipart_file_input: bool = False, ): self._type = type self._rest_name_input = name @@ -785,7 +785,7 @@ def __init__( self._is_model = False self._default = default self._format = format - self._is_multipart_file = is_multipart_file + self._is_multipart_file_input = is_multipart_file_input @property def _rest_name(self) -> str: @@ -831,10 +831,15 @@ def rest_field( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, - is_multipart_file: bool = False, + is_multipart_file_input: bool = False, ) -> typing.Any: return _RestField( - name=name, type=type, visibility=visibility, default=default, format=format, is_multipart_file=is_multipart_file + name=name, + type=type, + visibility=visibility, + default=default, + format=format, + is_multipart_file_input=is_multipart_file_input, ) diff --git a/packages/typespec-python/test/unbranded/generated/payload-content-negotiation/payload/contentnegotiation/_model_base.py b/packages/typespec-python/test/unbranded/generated/payload-content-negotiation/payload/contentnegotiation/_model_base.py index 18fc4d77a91..849db7e8e49 100644 --- a/packages/typespec-python/test/unbranded/generated/payload-content-negotiation/payload/contentnegotiation/_model_base.py +++ b/packages/typespec-python/test/unbranded/generated/payload-content-negotiation/payload/contentnegotiation/_model_base.py @@ -464,7 +464,7 @@ def _get_rest_field( def _create_value(rf: typing.Optional["_RestField"], value: typing.Any) -> typing.Any: if not rf: return _serialize(value, None) - if rf._is_multipart_file: + if rf._is_multipart_file_input: return value if rf._is_model: return _deserialize(rf._type, value) @@ -565,14 +565,14 @@ def as_dict(self, *, exclude_readonly: bool = False) -> typing.Dict[str, typing. for k, v in self.items(): if exclude_readonly and k in readonly_props: # pyright: ignore[reportUnboundVariable] continue - is_multipart_file = False + is_multipart_file_input = False try: - is_multipart_file = next( + is_multipart_file_input = next( rf for rf in self._attr_to_rest_field.values() if rf._rest_name == k - )._is_multipart_file + )._is_multipart_file_input except StopIteration: pass - result[k] = v if is_multipart_file else Model._as_dict_value(v, exclude_readonly=exclude_readonly) + result[k] = v if is_multipart_file_input else Model._as_dict_value(v, exclude_readonly=exclude_readonly) return result @staticmethod @@ -775,7 +775,7 @@ def __init__( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, - is_multipart_file: bool = False, + is_multipart_file_input: bool = False, ): self._type = type self._rest_name_input = name @@ -785,7 +785,7 @@ def __init__( self._is_model = False self._default = default self._format = format - self._is_multipart_file = is_multipart_file + self._is_multipart_file_input = is_multipart_file_input @property def _rest_name(self) -> str: @@ -831,10 +831,15 @@ def rest_field( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, - is_multipart_file: bool = False, + is_multipart_file_input: bool = False, ) -> typing.Any: return _RestField( - name=name, type=type, visibility=visibility, default=default, format=format, is_multipart_file=is_multipart_file + name=name, + type=type, + visibility=visibility, + default=default, + format=format, + is_multipart_file_input=is_multipart_file_input, ) diff --git a/packages/typespec-python/test/unbranded/generated/payload-media-type/payload/mediatype/_model_base.py b/packages/typespec-python/test/unbranded/generated/payload-media-type/payload/mediatype/_model_base.py index 18fc4d77a91..849db7e8e49 100644 --- a/packages/typespec-python/test/unbranded/generated/payload-media-type/payload/mediatype/_model_base.py +++ b/packages/typespec-python/test/unbranded/generated/payload-media-type/payload/mediatype/_model_base.py @@ -464,7 +464,7 @@ def _get_rest_field( def _create_value(rf: typing.Optional["_RestField"], value: typing.Any) -> typing.Any: if not rf: return _serialize(value, None) - if rf._is_multipart_file: + if rf._is_multipart_file_input: return value if rf._is_model: return _deserialize(rf._type, value) @@ -565,14 +565,14 @@ def as_dict(self, *, exclude_readonly: bool = False) -> typing.Dict[str, typing. for k, v in self.items(): if exclude_readonly and k in readonly_props: # pyright: ignore[reportUnboundVariable] continue - is_multipart_file = False + is_multipart_file_input = False try: - is_multipart_file = next( + is_multipart_file_input = next( rf for rf in self._attr_to_rest_field.values() if rf._rest_name == k - )._is_multipart_file + )._is_multipart_file_input except StopIteration: pass - result[k] = v if is_multipart_file else Model._as_dict_value(v, exclude_readonly=exclude_readonly) + result[k] = v if is_multipart_file_input else Model._as_dict_value(v, exclude_readonly=exclude_readonly) return result @staticmethod @@ -775,7 +775,7 @@ def __init__( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, - is_multipart_file: bool = False, + is_multipart_file_input: bool = False, ): self._type = type self._rest_name_input = name @@ -785,7 +785,7 @@ def __init__( self._is_model = False self._default = default self._format = format - self._is_multipart_file = is_multipart_file + self._is_multipart_file_input = is_multipart_file_input @property def _rest_name(self) -> str: @@ -831,10 +831,15 @@ def rest_field( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, - is_multipart_file: bool = False, + is_multipart_file_input: bool = False, ) -> typing.Any: return _RestField( - name=name, type=type, visibility=visibility, default=default, format=format, is_multipart_file=is_multipart_file + name=name, + type=type, + visibility=visibility, + default=default, + format=format, + is_multipart_file_input=is_multipart_file_input, ) diff --git a/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/_model_base.py b/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/_model_base.py index 18fc4d77a91..849db7e8e49 100644 --- a/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/_model_base.py +++ b/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/_model_base.py @@ -464,7 +464,7 @@ def _get_rest_field( def _create_value(rf: typing.Optional["_RestField"], value: typing.Any) -> typing.Any: if not rf: return _serialize(value, None) - if rf._is_multipart_file: + if rf._is_multipart_file_input: return value if rf._is_model: return _deserialize(rf._type, value) @@ -565,14 +565,14 @@ def as_dict(self, *, exclude_readonly: bool = False) -> typing.Dict[str, typing. for k, v in self.items(): if exclude_readonly and k in readonly_props: # pyright: ignore[reportUnboundVariable] continue - is_multipart_file = False + is_multipart_file_input = False try: - is_multipart_file = next( + is_multipart_file_input = next( rf for rf in self._attr_to_rest_field.values() if rf._rest_name == k - )._is_multipart_file + )._is_multipart_file_input except StopIteration: pass - result[k] = v if is_multipart_file else Model._as_dict_value(v, exclude_readonly=exclude_readonly) + result[k] = v if is_multipart_file_input else Model._as_dict_value(v, exclude_readonly=exclude_readonly) return result @staticmethod @@ -775,7 +775,7 @@ def __init__( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, - is_multipart_file: bool = False, + is_multipart_file_input: bool = False, ): self._type = type self._rest_name_input = name @@ -785,7 +785,7 @@ def __init__( self._is_model = False self._default = default self._format = format - self._is_multipart_file = is_multipart_file + self._is_multipart_file_input = is_multipart_file_input @property def _rest_name(self) -> str: @@ -831,10 +831,15 @@ def rest_field( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, - is_multipart_file: bool = False, + is_multipart_file_input: bool = False, ) -> typing.Any: return _RestField( - name=name, type=type, visibility=visibility, default=default, format=format, is_multipart_file=is_multipart_file + name=name, + type=type, + visibility=visibility, + default=default, + format=format, + is_multipart_file_input=is_multipart_file_input, ) diff --git a/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/aio/operations/_operations.py b/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/aio/operations/_operations.py index 28242500d74..261ed6b7d8b 100644 --- a/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/aio/operations/_operations.py +++ b/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/aio/operations/_operations.py @@ -76,7 +76,7 @@ async def basic( # pylint: disable=inconsistent-return-statements # JSON input template you can fill out and use as your body input. body = { "id": "str", # Required. - "profileImage": FileInputType # Required. + "profileImage": filetype } """ @@ -108,7 +108,7 @@ async def basic( # pylint: disable=inconsistent-return-statements # JSON input template you can fill out and use as your body input. body = { "id": "str", # Required. - "profileImage": FileInputType # Required. + "profileImage": filetype } """ error_map = { @@ -124,21 +124,17 @@ async def basic( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) - content_type = content_type or "multipart/form-data" - _content = None - if isinstance(body, _model_base.Model): - _body = body.as_dict() if isinstance(body, _model_base.Model) else body - _files = [] - _data = {} - if _body.get("id") is not None: - _data["id"] = _body["id"] - if _body.get("profileImage") is not None: - _files.append(("profileImage", _body["profileImage"])) - elif isinstance(body, MutableMapping): - _content = body + _body = body.as_dict() if isinstance(body, _model_base.Model) else body + _files = [] + _data = {} + if _body.get("id") is not None: + _data["id"] = _body["id"] + if _body.get("profileImage") is not None: + _files.append(("profileImage", _body["profileImage"])) _request = build_form_data_basic_request( - content=_content, + files=_files, + data=_data, headers=_headers, params=_params, ) @@ -181,15 +177,13 @@ async def complex( # pylint: disable=inconsistent-return-statements "city": "str" # Required. }, "id": "str", # Required. - "pictures": [ - FileInputType # Required. - ], + "pictures": [filetype], "previousAddresses": [ { "city": "str" # Required. } ], - "profileImage": FileInputType # Required. + "profileImage": filetype } """ @@ -224,15 +218,13 @@ async def complex( # pylint: disable=inconsistent-return-statements "city": "str" # Required. }, "id": "str", # Required. - "pictures": [ - FileInputType # Required. - ], + "pictures": [filetype], "previousAddresses": [ { "city": "str" # Required. } ], - "profileImage": FileInputType # Required. + "profileImage": filetype } """ error_map = { @@ -248,27 +240,25 @@ async def complex( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) - content_type = content_type or "multipart/form-data" - _content = None - if isinstance(body, _model_base.Model): - _body = body.as_dict() if isinstance(body, _model_base.Model) else body - _files = [] - _data = {} - if _body.get("id") is not None: - _data["id"] = _body["id"] - if _body.get("address") is not None: - _data["address"] = _body["address"] - if _body.get("profileImage") is not None: - _files.append(("profileImage", _body["profileImage"])) - if _body.get("previousAddresses") is not None: - _data["previousAddresses"] = _body["previousAddresses"] - if _body.get("pictures") is not None: - _files.extend([("pictures", p) for p in _body["pictures"]]) - elif isinstance(body, MutableMapping): - _content = body + _body = body.as_dict() if isinstance(body, _model_base.Model) else body + _files = [] + _data = {} + if _body.get("id") is not None: + _data["id"] = _body["id"] + if _body.get("address") is not None: + _data["address"] = json.dumps(_body["address"], cls=SdkJSONEncoder, exclude_readonly=True) + if _body.get("profileImage") is not None: + _files.append(("profileImage", _body["profileImage"])) + if _body.get("previousAddresses") is not None: + _data["previousAddresses"] = json.dumps( + _body["previousAddresses"], cls=SdkJSONEncoder, exclude_readonly=True + ) + if _body.get("pictures") is not None: + _files.extend([("pictures", p) for p in _body["pictures"]]) _request = build_form_data_complex_request( - content=_content, + files=_files, + data=_data, headers=_headers, params=_params, ) @@ -310,7 +300,7 @@ async def json_part( # pylint: disable=inconsistent-return-statements "address": { "city": "str" # Required. }, - "profileImage": FileInputType # Required. + "profileImage": filetype } """ @@ -344,7 +334,7 @@ async def json_part( # pylint: disable=inconsistent-return-statements "address": { "city": "str" # Required. }, - "profileImage": FileInputType # Required. + "profileImage": filetype } """ error_map = { @@ -360,21 +350,17 @@ async def json_part( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) - content_type = content_type or "multipart/form-data" - _content = None - if isinstance(body, _model_base.Model): - _body = body.as_dict() if isinstance(body, _model_base.Model) else body - _files = [] - _data = {} - if _body.get("address") is not None: - _data["address"] = _body["address"] - if _body.get("profileImage") is not None: - _files.append(("profileImage", _body["profileImage"])) - elif isinstance(body, MutableMapping): - _content = body + _body = body.as_dict() if isinstance(body, _model_base.Model) else body + _files = [] + _data = {} + if _body.get("address") is not None: + _data["address"] = json.dumps(_body["address"], cls=SdkJSONEncoder, exclude_readonly=True) + if _body.get("profileImage") is not None: + _files.append(("profileImage", _body["profileImage"])) _request = build_form_data_json_part_request( - content=_content, + files=_files, + data=_data, headers=_headers, params=_params, ) @@ -414,9 +400,7 @@ async def binary_array_parts( # pylint: disable=inconsistent-return-statements # JSON input template you can fill out and use as your body input. body = { "id": "str", # Required. - "pictures": [ - FileInputType # Required. - ] + "pictures": [filetype] } """ @@ -450,9 +434,7 @@ async def binary_array_parts( # pylint: disable=inconsistent-return-statements # JSON input template you can fill out and use as your body input. body = { "id": "str", # Required. - "pictures": [ - FileInputType # Required. - ] + "pictures": [filetype] } """ error_map = { @@ -468,21 +450,17 @@ async def binary_array_parts( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) - content_type = content_type or "multipart/form-data" - _content = None - if isinstance(body, _model_base.Model): - _body = body.as_dict() if isinstance(body, _model_base.Model) else body - _files = [] - _data = {} - if _body.get("id") is not None: - _data["id"] = _body["id"] - if _body.get("pictures") is not None: - _files.extend([("pictures", p) for p in _body["pictures"]]) - elif isinstance(body, MutableMapping): - _content = body + _body = body.as_dict() if isinstance(body, _model_base.Model) else body + _files = [] + _data = {} + if _body.get("id") is not None: + _data["id"] = _body["id"] + if _body.get("pictures") is not None: + _files.extend([("pictures", p) for p in _body["pictures"]]) _request = build_form_data_binary_array_parts_request( - content=_content, + files=_files, + data=_data, headers=_headers, params=_params, ) @@ -526,7 +504,7 @@ async def json_array_parts( # pylint: disable=inconsistent-return-statements "city": "str" # Required. } ], - "profileImage": FileInputType # Required. + "profileImage": filetype } """ @@ -564,7 +542,7 @@ async def json_array_parts( # pylint: disable=inconsistent-return-statements "city": "str" # Required. } ], - "profileImage": FileInputType # Required. + "profileImage": filetype } """ error_map = { @@ -580,21 +558,19 @@ async def json_array_parts( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) - content_type = content_type or "multipart/form-data" - _content = None - if isinstance(body, _model_base.Model): - _body = body.as_dict() if isinstance(body, _model_base.Model) else body - _files = [] - _data = {} - if _body.get("profileImage") is not None: - _files.append(("profileImage", _body["profileImage"])) - if _body.get("previousAddresses") is not None: - _data["previousAddresses"] = _body["previousAddresses"] - elif isinstance(body, MutableMapping): - _content = body + _body = body.as_dict() if isinstance(body, _model_base.Model) else body + _files = [] + _data = {} + if _body.get("profileImage") is not None: + _files.append(("profileImage", _body["profileImage"])) + if _body.get("previousAddresses") is not None: + _data["previousAddresses"] = json.dumps( + _body["previousAddresses"], cls=SdkJSONEncoder, exclude_readonly=True + ) _request = build_form_data_json_array_parts_request( - content=_content, + files=_files, + data=_data, headers=_headers, params=_params, ) @@ -633,8 +609,8 @@ async def multi_binary_parts( # pylint: disable=inconsistent-return-statements # JSON input template you can fill out and use as your body input. body = { - "profileImage": FileInputType, # Required. - "picture": FileInputType # Optional. + "profileImage": filetype, + "picture": filetype } """ @@ -667,8 +643,8 @@ async def multi_binary_parts( # pylint: disable=inconsistent-return-statements # JSON input template you can fill out and use as your body input. body = { - "profileImage": FileInputType, # Required. - "picture": FileInputType # Optional. + "profileImage": filetype, + "picture": filetype } """ error_map = { @@ -684,21 +660,17 @@ async def multi_binary_parts( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) - content_type = content_type or "multipart/form-data" - _content = None - if isinstance(body, _model_base.Model): - _body = body.as_dict() if isinstance(body, _model_base.Model) else body - _files = [] - _data = {} - if _body.get("profileImage") is not None: - _files.append(("profileImage", _body["profileImage"])) - if _body.get("picture") is not None: - _files.append(("picture", _body["picture"])) - elif isinstance(body, MutableMapping): - _content = body + _body = body.as_dict() if isinstance(body, _model_base.Model) else body + _files = [] + _data = {} + if _body.get("profileImage") is not None: + _files.append(("profileImage", _body["profileImage"])) + if _body.get("picture") is not None: + _files.append(("picture", _body["picture"])) _request = build_form_data_multi_binary_parts_request( - content=_content, + files=_files, + data=_data, headers=_headers, params=_params, ) diff --git a/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/models/_models.py b/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/models/_models.py index f85e80aa665..c058265a799 100644 --- a/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/models/_models.py +++ b/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/models/_models.py @@ -7,11 +7,11 @@ # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from .._vendor import FileType from typing import Any, List, Mapping, Optional, TYPE_CHECKING, overload from .. import _model_base from .._model_base import rest_field +from .._vendor import FileType if TYPE_CHECKING: # pylint: disable=unused-import,ungrouped-imports @@ -57,12 +57,12 @@ class BinaryArrayPartsRequest(_model_base.Model): :ivar id: Required. :vartype id: str :ivar pictures: Required. - :vartype pictures: list[filetype] + :vartype pictures: list[bytes] """ id: str = rest_field() """Required.""" - pictures: List[FileType] = rest_field(is_multipart_file=True) + pictures: List[FileType] = rest_field(is_multipart_file_input=True) """Required.""" @overload @@ -95,22 +95,22 @@ class ComplexPartsRequest(_model_base.Model): :ivar address: Required. :vartype address: ~payload.multipart.models.Address :ivar profile_image: Required. - :vartype profile_image: filetype + :vartype profile_image: bytes :ivar previous_addresses: Required. :vartype previous_addresses: list[~payload.multipart.models.Address] :ivar pictures: Required. - :vartype pictures: list[filetype] + :vartype pictures: list[bytes] """ id: str = rest_field() """Required.""" address: "_models.Address" = rest_field() """Required.""" - profile_image: FileType = rest_field(name="profileImage", is_multipart_file=True) + profile_image: FileType = rest_field(name="profileImage", is_multipart_file_input=True) """Required.""" previous_addresses: List["_models.Address"] = rest_field(name="previousAddresses") """Required.""" - pictures: List[FileType] = rest_field(is_multipart_file=True) + pictures: List[FileType] = rest_field(is_multipart_file_input=True) """Required.""" @overload @@ -142,12 +142,12 @@ class JsonArrayPartsRequest(_model_base.Model): All required parameters must be populated in order to send to server. :ivar profile_image: Required. - :vartype profile_image: filetype + :vartype profile_image: bytes :ivar previous_addresses: Required. :vartype previous_addresses: list[~payload.multipart.models.Address] """ - profile_image: FileType = rest_field(name="profileImage", is_multipart_file=True) + profile_image: FileType = rest_field(name="profileImage", is_multipart_file_input=True) """Required.""" previous_addresses: List["_models.Address"] = rest_field(name="previousAddresses") """Required.""" @@ -180,12 +180,12 @@ class JsonPartRequest(_model_base.Model): :ivar address: Required. :vartype address: ~payload.multipart.models.Address :ivar profile_image: Required. - :vartype profile_image: filetype + :vartype profile_image: bytes """ address: "_models.Address" = rest_field() """Required.""" - profile_image: FileType = rest_field(name="profileImage", is_multipart_file=True) + profile_image: FileType = rest_field(name="profileImage", is_multipart_file_input=True) """Required.""" @overload @@ -214,21 +214,21 @@ class MultiBinaryPartsRequest(_model_base.Model): All required parameters must be populated in order to send to server. :ivar profile_image: Required. - :vartype profile_image: filetype + :vartype profile_image: bytes :ivar picture: - :vartype picture: filetype + :vartype picture: bytes """ - profile_image: FileType = rest_field(name="profileImage", is_multipart_file=True) + profile_image: FileType = rest_field(name="profileImage", is_multipart_file_input=True) """Required.""" - picture: Optional[FileType] = rest_field(is_multipart_file=True) + picture: FileType = rest_field(is_multipart_file_input=True) @overload def __init__( self, *, profile_image: FileType, - picture: Optional[FileType] = None, + picture: FileType = None, ): ... @@ -251,12 +251,12 @@ class MultiPartRequest(_model_base.Model): :ivar id: Required. :vartype id: str :ivar profile_image: Required. - :vartype profile_image: filetype + :vartype profile_image: bytes """ id: str = rest_field() """Required.""" - profile_image: FileType = rest_field(name="profileImage", is_multipart_file=True) + profile_image: FileType = rest_field(name="profileImage", is_multipart_file_input=True) """Required.""" @overload diff --git a/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/operations/_operations.py b/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/operations/_operations.py index 4b034dd35bb..58ffb6b9193 100644 --- a/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/operations/_operations.py +++ b/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/operations/_operations.py @@ -44,10 +44,6 @@ def build_form_data_basic_request(**kwargs: Any) -> HttpRequest: # Construct URL _url = "/multipart/form-data/mixed-parts" - # Construct headers - if content_type is not None: - _headers["content-type"] = _SERIALIZER.header("content_type", content_type, "str") - return HttpRequest(method="POST", url=_url, headers=_headers, **kwargs) @@ -57,10 +53,6 @@ def build_form_data_complex_request(**kwargs: Any) -> HttpRequest: # Construct URL _url = "/multipart/form-data/complex-parts" - # Construct headers - if content_type is not None: - _headers["content-type"] = _SERIALIZER.header("content_type", content_type, "str") - return HttpRequest(method="POST", url=_url, headers=_headers, **kwargs) @@ -70,10 +62,6 @@ def build_form_data_json_part_request(**kwargs: Any) -> HttpRequest: # Construct URL _url = "/multipart/form-data/json-part" - # Construct headers - if content_type is not None: - _headers["content-type"] = _SERIALIZER.header("content_type", content_type, "str") - return HttpRequest(method="POST", url=_url, headers=_headers, **kwargs) @@ -83,10 +71,6 @@ def build_form_data_binary_array_parts_request(**kwargs: Any) -> HttpRequest: # # Construct URL _url = "/multipart/form-data/binary-array-parts" - # Construct headers - if content_type is not None: - _headers["content-type"] = _SERIALIZER.header("content_type", content_type, "str") - return HttpRequest(method="POST", url=_url, headers=_headers, **kwargs) @@ -96,10 +80,6 @@ def build_form_data_json_array_parts_request(**kwargs: Any) -> HttpRequest: # Construct URL _url = "/multipart/form-data/json-array-parts" - # Construct headers - if content_type is not None: - _headers["content-type"] = _SERIALIZER.header("content_type", content_type, "str") - return HttpRequest(method="POST", url=_url, headers=_headers, **kwargs) @@ -109,10 +89,6 @@ def build_form_data_multi_binary_parts_request(**kwargs: Any) -> HttpRequest: # # Construct URL _url = "/multipart/form-data/multi-binary-parts" - # Construct headers - if content_type is not None: - _headers["content-type"] = _SERIALIZER.header("content_type", content_type, "str") - return HttpRequest(method="POST", url=_url, headers=_headers, **kwargs) @@ -151,7 +127,7 @@ def basic( # pylint: disable=inconsistent-return-statements # JSON input template you can fill out and use as your body input. body = { "id": "str", # Required. - "profileImage": FileInputType # Required. + "profileImage": filetype } """ @@ -183,7 +159,7 @@ def basic( # pylint: disable=inconsistent-return-statements # JSON input template you can fill out and use as your body input. body = { "id": "str", # Required. - "profileImage": FileInputType # Required. + "profileImage": filetype } """ error_map = { @@ -199,21 +175,17 @@ def basic( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) - content_type = content_type or "multipart/form-data" - _content = None - if isinstance(body, _model_base.Model): - _body = body.as_dict() if isinstance(body, _model_base.Model) else body - _files = [] - _data = {} - if _body.get("id") is not None: - _data["id"] = _body["id"] - if _body.get("profileImage") is not None: - _files.append(("profileImage", _body["profileImage"])) - elif isinstance(body, MutableMapping): - _content = body + _body = body.as_dict() if isinstance(body, _model_base.Model) else body + _files = [] + _data = {} + if _body.get("id") is not None: + _data["id"] = _body["id"] + if _body.get("profileImage") is not None: + _files.append(("profileImage", _body["profileImage"])) _request = build_form_data_basic_request( - content=_content, + files=_files, + data=_data, headers=_headers, params=_params, ) @@ -256,15 +228,13 @@ def complex( # pylint: disable=inconsistent-return-statements "city": "str" # Required. }, "id": "str", # Required. - "pictures": [ - FileInputType # Required. - ], + "pictures": [filetype], "previousAddresses": [ { "city": "str" # Required. } ], - "profileImage": FileInputType # Required. + "profileImage": filetype } """ @@ -299,15 +269,13 @@ def complex( # pylint: disable=inconsistent-return-statements "city": "str" # Required. }, "id": "str", # Required. - "pictures": [ - FileInputType # Required. - ], + "pictures": [filetype], "previousAddresses": [ { "city": "str" # Required. } ], - "profileImage": FileInputType # Required. + "profileImage": filetype } """ error_map = { @@ -323,27 +291,25 @@ def complex( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) - content_type = content_type or "multipart/form-data" - _content = None - if isinstance(body, _model_base.Model): - _body = body.as_dict() if isinstance(body, _model_base.Model) else body - _files = [] - _data = {} - if _body.get("id") is not None: - _data["id"] = _body["id"] - if _body.get("address") is not None: - _data["address"] = _body["address"] - if _body.get("profileImage") is not None: - _files.append(("profileImage", _body["profileImage"])) - if _body.get("previousAddresses") is not None: - _data["previousAddresses"] = _body["previousAddresses"] - if _body.get("pictures") is not None: - _files.extend([("pictures", p) for p in _body["pictures"]]) - elif isinstance(body, MutableMapping): - _content = body + _body = body.as_dict() if isinstance(body, _model_base.Model) else body + _files = [] + _data = {} + if _body.get("id") is not None: + _data["id"] = _body["id"] + if _body.get("address") is not None: + _data["address"] = json.dumps(_body["address"], cls=SdkJSONEncoder, exclude_readonly=True) + if _body.get("profileImage") is not None: + _files.append(("profileImage", _body["profileImage"])) + if _body.get("previousAddresses") is not None: + _data["previousAddresses"] = json.dumps( + _body["previousAddresses"], cls=SdkJSONEncoder, exclude_readonly=True + ) + if _body.get("pictures") is not None: + _files.extend([("pictures", p) for p in _body["pictures"]]) _request = build_form_data_complex_request( - content=_content, + files=_files, + data=_data, headers=_headers, params=_params, ) @@ -385,7 +351,7 @@ def json_part( # pylint: disable=inconsistent-return-statements "address": { "city": "str" # Required. }, - "profileImage": FileInputType # Required. + "profileImage": filetype } """ @@ -419,7 +385,7 @@ def json_part( # pylint: disable=inconsistent-return-statements "address": { "city": "str" # Required. }, - "profileImage": FileInputType # Required. + "profileImage": filetype } """ error_map = { @@ -435,21 +401,17 @@ def json_part( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) - content_type = content_type or "multipart/form-data" - _content = None - if isinstance(body, _model_base.Model): - _body = body.as_dict() if isinstance(body, _model_base.Model) else body - _files = [] - _data = {} - if _body.get("address") is not None: - _data["address"] = _body["address"] - if _body.get("profileImage") is not None: - _files.append(("profileImage", _body["profileImage"])) - elif isinstance(body, MutableMapping): - _content = body + _body = body.as_dict() if isinstance(body, _model_base.Model) else body + _files = [] + _data = {} + if _body.get("address") is not None: + _data["address"] = json.dumps(_body["address"], cls=SdkJSONEncoder, exclude_readonly=True) + if _body.get("profileImage") is not None: + _files.append(("profileImage", _body["profileImage"])) _request = build_form_data_json_part_request( - content=_content, + files=_files, + data=_data, headers=_headers, params=_params, ) @@ -489,9 +451,7 @@ def binary_array_parts( # pylint: disable=inconsistent-return-statements # JSON input template you can fill out and use as your body input. body = { "id": "str", # Required. - "pictures": [ - FileInputType # Required. - ] + "pictures": [filetype] } """ @@ -523,9 +483,7 @@ def binary_array_parts( # pylint: disable=inconsistent-return-statements # JSON input template you can fill out and use as your body input. body = { "id": "str", # Required. - "pictures": [ - FileInputType # Required. - ] + "pictures": [filetype] } """ error_map = { @@ -541,21 +499,17 @@ def binary_array_parts( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) - content_type = content_type or "multipart/form-data" - _content = None - if isinstance(body, _model_base.Model): - _body = body.as_dict() if isinstance(body, _model_base.Model) else body - _files = [] - _data = {} - if _body.get("id") is not None: - _data["id"] = _body["id"] - if _body.get("pictures") is not None: - _files.extend([("pictures", p) for p in _body["pictures"]]) - elif isinstance(body, MutableMapping): - _content = body + _body = body.as_dict() if isinstance(body, _model_base.Model) else body + _files = [] + _data = {} + if _body.get("id") is not None: + _data["id"] = _body["id"] + if _body.get("pictures") is not None: + _files.extend([("pictures", p) for p in _body["pictures"]]) _request = build_form_data_binary_array_parts_request( - content=_content, + files=_files, + data=_data, headers=_headers, params=_params, ) @@ -599,7 +553,7 @@ def json_array_parts( # pylint: disable=inconsistent-return-statements "city": "str" # Required. } ], - "profileImage": FileInputType # Required. + "profileImage": filetype } """ @@ -635,7 +589,7 @@ def json_array_parts( # pylint: disable=inconsistent-return-statements "city": "str" # Required. } ], - "profileImage": FileInputType # Required. + "profileImage": filetype } """ error_map = { @@ -651,21 +605,19 @@ def json_array_parts( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) - content_type = content_type or "multipart/form-data" - _content = None - if isinstance(body, _model_base.Model): - _body = body.as_dict() if isinstance(body, _model_base.Model) else body - _files = [] - _data = {} - if _body.get("profileImage") is not None: - _files.append(("profileImage", _body["profileImage"])) - if _body.get("previousAddresses") is not None: - _data["previousAddresses"] = _body["previousAddresses"] - elif isinstance(body, MutableMapping): - _content = body + _body = body.as_dict() if isinstance(body, _model_base.Model) else body + _files = [] + _data = {} + if _body.get("profileImage") is not None: + _files.append(("profileImage", _body["profileImage"])) + if _body.get("previousAddresses") is not None: + _data["previousAddresses"] = json.dumps( + _body["previousAddresses"], cls=SdkJSONEncoder, exclude_readonly=True + ) _request = build_form_data_json_array_parts_request( - content=_content, + files=_files, + data=_data, headers=_headers, params=_params, ) @@ -704,8 +656,8 @@ def multi_binary_parts( # pylint: disable=inconsistent-return-statements # JSON input template you can fill out and use as your body input. body = { - "profileImage": FileInputType, # Required. - "picture": FileInputType # Optional. + "profileImage": filetype, + "picture": filetype } """ @@ -736,8 +688,8 @@ def multi_binary_parts( # pylint: disable=inconsistent-return-statements # JSON input template you can fill out and use as your body input. body = { - "profileImage": FileInputType, # Required. - "picture": FileInputType # Optional. + "profileImage": filetype, + "picture": filetype } """ error_map = { @@ -753,21 +705,17 @@ def multi_binary_parts( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) - content_type = content_type or "multipart/form-data" - _content = None - if isinstance(body, _model_base.Model): - _body = body.as_dict() if isinstance(body, _model_base.Model) else body - _files = [] - _data = {} - if _body.get("profileImage") is not None: - _files.append(("profileImage", _body["profileImage"])) - if _body.get("picture") is not None: - _files.append(("picture", _body["picture"])) - elif isinstance(body, MutableMapping): - _content = body + _body = body.as_dict() if isinstance(body, _model_base.Model) else body + _files = [] + _data = {} + if _body.get("profileImage") is not None: + _files.append(("profileImage", _body["profileImage"])) + if _body.get("picture") is not None: + _files.append(("picture", _body["picture"])) _request = build_form_data_multi_binary_parts_request( - content=_content, + files=_files, + data=_data, headers=_headers, params=_params, ) diff --git a/packages/typespec-python/test/unbranded/generated/payload-pageable/payload/pageable/_model_base.py b/packages/typespec-python/test/unbranded/generated/payload-pageable/payload/pageable/_model_base.py index 18fc4d77a91..849db7e8e49 100644 --- a/packages/typespec-python/test/unbranded/generated/payload-pageable/payload/pageable/_model_base.py +++ b/packages/typespec-python/test/unbranded/generated/payload-pageable/payload/pageable/_model_base.py @@ -464,7 +464,7 @@ def _get_rest_field( def _create_value(rf: typing.Optional["_RestField"], value: typing.Any) -> typing.Any: if not rf: return _serialize(value, None) - if rf._is_multipart_file: + if rf._is_multipart_file_input: return value if rf._is_model: return _deserialize(rf._type, value) @@ -565,14 +565,14 @@ def as_dict(self, *, exclude_readonly: bool = False) -> typing.Dict[str, typing. for k, v in self.items(): if exclude_readonly and k in readonly_props: # pyright: ignore[reportUnboundVariable] continue - is_multipart_file = False + is_multipart_file_input = False try: - is_multipart_file = next( + is_multipart_file_input = next( rf for rf in self._attr_to_rest_field.values() if rf._rest_name == k - )._is_multipart_file + )._is_multipart_file_input except StopIteration: pass - result[k] = v if is_multipart_file else Model._as_dict_value(v, exclude_readonly=exclude_readonly) + result[k] = v if is_multipart_file_input else Model._as_dict_value(v, exclude_readonly=exclude_readonly) return result @staticmethod @@ -775,7 +775,7 @@ def __init__( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, - is_multipart_file: bool = False, + is_multipart_file_input: bool = False, ): self._type = type self._rest_name_input = name @@ -785,7 +785,7 @@ def __init__( self._is_model = False self._default = default self._format = format - self._is_multipart_file = is_multipart_file + self._is_multipart_file_input = is_multipart_file_input @property def _rest_name(self) -> str: @@ -831,10 +831,15 @@ def rest_field( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, - is_multipart_file: bool = False, + is_multipart_file_input: bool = False, ) -> typing.Any: return _RestField( - name=name, type=type, visibility=visibility, default=default, format=format, is_multipart_file=is_multipart_file + name=name, + type=type, + visibility=visibility, + default=default, + format=format, + is_multipart_file_input=is_multipart_file_input, ) diff --git a/packages/typespec-python/test/unbranded/generated/projection-projected-name/projection/projectedname/_model_base.py b/packages/typespec-python/test/unbranded/generated/projection-projected-name/projection/projectedname/_model_base.py index 18fc4d77a91..849db7e8e49 100644 --- a/packages/typespec-python/test/unbranded/generated/projection-projected-name/projection/projectedname/_model_base.py +++ b/packages/typespec-python/test/unbranded/generated/projection-projected-name/projection/projectedname/_model_base.py @@ -464,7 +464,7 @@ def _get_rest_field( def _create_value(rf: typing.Optional["_RestField"], value: typing.Any) -> typing.Any: if not rf: return _serialize(value, None) - if rf._is_multipart_file: + if rf._is_multipart_file_input: return value if rf._is_model: return _deserialize(rf._type, value) @@ -565,14 +565,14 @@ def as_dict(self, *, exclude_readonly: bool = False) -> typing.Dict[str, typing. for k, v in self.items(): if exclude_readonly and k in readonly_props: # pyright: ignore[reportUnboundVariable] continue - is_multipart_file = False + is_multipart_file_input = False try: - is_multipart_file = next( + is_multipart_file_input = next( rf for rf in self._attr_to_rest_field.values() if rf._rest_name == k - )._is_multipart_file + )._is_multipart_file_input except StopIteration: pass - result[k] = v if is_multipart_file else Model._as_dict_value(v, exclude_readonly=exclude_readonly) + result[k] = v if is_multipart_file_input else Model._as_dict_value(v, exclude_readonly=exclude_readonly) return result @staticmethod @@ -775,7 +775,7 @@ def __init__( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, - is_multipart_file: bool = False, + is_multipart_file_input: bool = False, ): self._type = type self._rest_name_input = name @@ -785,7 +785,7 @@ def __init__( self._is_model = False self._default = default self._format = format - self._is_multipart_file = is_multipart_file + self._is_multipart_file_input = is_multipart_file_input @property def _rest_name(self) -> str: @@ -831,10 +831,15 @@ def rest_field( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, - is_multipart_file: bool = False, + is_multipart_file_input: bool = False, ) -> typing.Any: return _RestField( - name=name, type=type, visibility=visibility, default=default, format=format, is_multipart_file=is_multipart_file + name=name, + type=type, + visibility=visibility, + default=default, + format=format, + is_multipart_file_input=is_multipart_file_input, ) diff --git a/packages/typespec-python/test/unbranded/generated/resiliency-srv-driven1/resiliency/srv/driven1/_model_base.py b/packages/typespec-python/test/unbranded/generated/resiliency-srv-driven1/resiliency/srv/driven1/_model_base.py index 18fc4d77a91..849db7e8e49 100644 --- a/packages/typespec-python/test/unbranded/generated/resiliency-srv-driven1/resiliency/srv/driven1/_model_base.py +++ b/packages/typespec-python/test/unbranded/generated/resiliency-srv-driven1/resiliency/srv/driven1/_model_base.py @@ -464,7 +464,7 @@ def _get_rest_field( def _create_value(rf: typing.Optional["_RestField"], value: typing.Any) -> typing.Any: if not rf: return _serialize(value, None) - if rf._is_multipart_file: + if rf._is_multipart_file_input: return value if rf._is_model: return _deserialize(rf._type, value) @@ -565,14 +565,14 @@ def as_dict(self, *, exclude_readonly: bool = False) -> typing.Dict[str, typing. for k, v in self.items(): if exclude_readonly and k in readonly_props: # pyright: ignore[reportUnboundVariable] continue - is_multipart_file = False + is_multipart_file_input = False try: - is_multipart_file = next( + is_multipart_file_input = next( rf for rf in self._attr_to_rest_field.values() if rf._rest_name == k - )._is_multipart_file + )._is_multipart_file_input except StopIteration: pass - result[k] = v if is_multipart_file else Model._as_dict_value(v, exclude_readonly=exclude_readonly) + result[k] = v if is_multipart_file_input else Model._as_dict_value(v, exclude_readonly=exclude_readonly) return result @staticmethod @@ -775,7 +775,7 @@ def __init__( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, - is_multipart_file: bool = False, + is_multipart_file_input: bool = False, ): self._type = type self._rest_name_input = name @@ -785,7 +785,7 @@ def __init__( self._is_model = False self._default = default self._format = format - self._is_multipart_file = is_multipart_file + self._is_multipart_file_input = is_multipart_file_input @property def _rest_name(self) -> str: @@ -831,10 +831,15 @@ def rest_field( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, - is_multipart_file: bool = False, + is_multipart_file_input: bool = False, ) -> typing.Any: return _RestField( - name=name, type=type, visibility=visibility, default=default, format=format, is_multipart_file=is_multipart_file + name=name, + type=type, + visibility=visibility, + default=default, + format=format, + is_multipart_file_input=is_multipart_file_input, ) diff --git a/packages/typespec-python/test/unbranded/generated/resiliency-srv-driven2/resiliency/srv/driven2/_model_base.py b/packages/typespec-python/test/unbranded/generated/resiliency-srv-driven2/resiliency/srv/driven2/_model_base.py index 18fc4d77a91..849db7e8e49 100644 --- a/packages/typespec-python/test/unbranded/generated/resiliency-srv-driven2/resiliency/srv/driven2/_model_base.py +++ b/packages/typespec-python/test/unbranded/generated/resiliency-srv-driven2/resiliency/srv/driven2/_model_base.py @@ -464,7 +464,7 @@ def _get_rest_field( def _create_value(rf: typing.Optional["_RestField"], value: typing.Any) -> typing.Any: if not rf: return _serialize(value, None) - if rf._is_multipart_file: + if rf._is_multipart_file_input: return value if rf._is_model: return _deserialize(rf._type, value) @@ -565,14 +565,14 @@ def as_dict(self, *, exclude_readonly: bool = False) -> typing.Dict[str, typing. for k, v in self.items(): if exclude_readonly and k in readonly_props: # pyright: ignore[reportUnboundVariable] continue - is_multipart_file = False + is_multipart_file_input = False try: - is_multipart_file = next( + is_multipart_file_input = next( rf for rf in self._attr_to_rest_field.values() if rf._rest_name == k - )._is_multipart_file + )._is_multipart_file_input except StopIteration: pass - result[k] = v if is_multipart_file else Model._as_dict_value(v, exclude_readonly=exclude_readonly) + result[k] = v if is_multipart_file_input else Model._as_dict_value(v, exclude_readonly=exclude_readonly) return result @staticmethod @@ -775,7 +775,7 @@ def __init__( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, - is_multipart_file: bool = False, + is_multipart_file_input: bool = False, ): self._type = type self._rest_name_input = name @@ -785,7 +785,7 @@ def __init__( self._is_model = False self._default = default self._format = format - self._is_multipart_file = is_multipart_file + self._is_multipart_file_input = is_multipart_file_input @property def _rest_name(self) -> str: @@ -831,10 +831,15 @@ def rest_field( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, - is_multipart_file: bool = False, + is_multipart_file_input: bool = False, ) -> typing.Any: return _RestField( - name=name, type=type, visibility=visibility, default=default, format=format, is_multipart_file=is_multipart_file + name=name, + type=type, + visibility=visibility, + default=default, + format=format, + is_multipart_file_input=is_multipart_file_input, ) diff --git a/packages/typespec-python/test/unbranded/generated/server-path-multiple/server/path/multiple/_model_base.py b/packages/typespec-python/test/unbranded/generated/server-path-multiple/server/path/multiple/_model_base.py index 18fc4d77a91..849db7e8e49 100644 --- a/packages/typespec-python/test/unbranded/generated/server-path-multiple/server/path/multiple/_model_base.py +++ b/packages/typespec-python/test/unbranded/generated/server-path-multiple/server/path/multiple/_model_base.py @@ -464,7 +464,7 @@ def _get_rest_field( def _create_value(rf: typing.Optional["_RestField"], value: typing.Any) -> typing.Any: if not rf: return _serialize(value, None) - if rf._is_multipart_file: + if rf._is_multipart_file_input: return value if rf._is_model: return _deserialize(rf._type, value) @@ -565,14 +565,14 @@ def as_dict(self, *, exclude_readonly: bool = False) -> typing.Dict[str, typing. for k, v in self.items(): if exclude_readonly and k in readonly_props: # pyright: ignore[reportUnboundVariable] continue - is_multipart_file = False + is_multipart_file_input = False try: - is_multipart_file = next( + is_multipart_file_input = next( rf for rf in self._attr_to_rest_field.values() if rf._rest_name == k - )._is_multipart_file + )._is_multipart_file_input except StopIteration: pass - result[k] = v if is_multipart_file else Model._as_dict_value(v, exclude_readonly=exclude_readonly) + result[k] = v if is_multipart_file_input else Model._as_dict_value(v, exclude_readonly=exclude_readonly) return result @staticmethod @@ -775,7 +775,7 @@ def __init__( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, - is_multipart_file: bool = False, + is_multipart_file_input: bool = False, ): self._type = type self._rest_name_input = name @@ -785,7 +785,7 @@ def __init__( self._is_model = False self._default = default self._format = format - self._is_multipart_file = is_multipart_file + self._is_multipart_file_input = is_multipart_file_input @property def _rest_name(self) -> str: @@ -831,10 +831,15 @@ def rest_field( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, - is_multipart_file: bool = False, + is_multipart_file_input: bool = False, ) -> typing.Any: return _RestField( - name=name, type=type, visibility=visibility, default=default, format=format, is_multipart_file=is_multipart_file + name=name, + type=type, + visibility=visibility, + default=default, + format=format, + is_multipart_file_input=is_multipart_file_input, ) diff --git a/packages/typespec-python/test/unbranded/generated/server-path-single/server/path/single/_model_base.py b/packages/typespec-python/test/unbranded/generated/server-path-single/server/path/single/_model_base.py index 18fc4d77a91..849db7e8e49 100644 --- a/packages/typespec-python/test/unbranded/generated/server-path-single/server/path/single/_model_base.py +++ b/packages/typespec-python/test/unbranded/generated/server-path-single/server/path/single/_model_base.py @@ -464,7 +464,7 @@ def _get_rest_field( def _create_value(rf: typing.Optional["_RestField"], value: typing.Any) -> typing.Any: if not rf: return _serialize(value, None) - if rf._is_multipart_file: + if rf._is_multipart_file_input: return value if rf._is_model: return _deserialize(rf._type, value) @@ -565,14 +565,14 @@ def as_dict(self, *, exclude_readonly: bool = False) -> typing.Dict[str, typing. for k, v in self.items(): if exclude_readonly and k in readonly_props: # pyright: ignore[reportUnboundVariable] continue - is_multipart_file = False + is_multipart_file_input = False try: - is_multipart_file = next( + is_multipart_file_input = next( rf for rf in self._attr_to_rest_field.values() if rf._rest_name == k - )._is_multipart_file + )._is_multipart_file_input except StopIteration: pass - result[k] = v if is_multipart_file else Model._as_dict_value(v, exclude_readonly=exclude_readonly) + result[k] = v if is_multipart_file_input else Model._as_dict_value(v, exclude_readonly=exclude_readonly) return result @staticmethod @@ -775,7 +775,7 @@ def __init__( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, - is_multipart_file: bool = False, + is_multipart_file_input: bool = False, ): self._type = type self._rest_name_input = name @@ -785,7 +785,7 @@ def __init__( self._is_model = False self._default = default self._format = format - self._is_multipart_file = is_multipart_file + self._is_multipart_file_input = is_multipart_file_input @property def _rest_name(self) -> str: @@ -831,10 +831,15 @@ def rest_field( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, - is_multipart_file: bool = False, + is_multipart_file_input: bool = False, ) -> typing.Any: return _RestField( - name=name, type=type, visibility=visibility, default=default, format=format, is_multipart_file=is_multipart_file + name=name, + type=type, + visibility=visibility, + default=default, + format=format, + is_multipart_file_input=is_multipart_file_input, ) diff --git a/packages/typespec-python/test/unbranded/generated/server-versions-not-versioned/server/versions/notversioned/_model_base.py b/packages/typespec-python/test/unbranded/generated/server-versions-not-versioned/server/versions/notversioned/_model_base.py index 18fc4d77a91..849db7e8e49 100644 --- a/packages/typespec-python/test/unbranded/generated/server-versions-not-versioned/server/versions/notversioned/_model_base.py +++ b/packages/typespec-python/test/unbranded/generated/server-versions-not-versioned/server/versions/notversioned/_model_base.py @@ -464,7 +464,7 @@ def _get_rest_field( def _create_value(rf: typing.Optional["_RestField"], value: typing.Any) -> typing.Any: if not rf: return _serialize(value, None) - if rf._is_multipart_file: + if rf._is_multipart_file_input: return value if rf._is_model: return _deserialize(rf._type, value) @@ -565,14 +565,14 @@ def as_dict(self, *, exclude_readonly: bool = False) -> typing.Dict[str, typing. for k, v in self.items(): if exclude_readonly and k in readonly_props: # pyright: ignore[reportUnboundVariable] continue - is_multipart_file = False + is_multipart_file_input = False try: - is_multipart_file = next( + is_multipart_file_input = next( rf for rf in self._attr_to_rest_field.values() if rf._rest_name == k - )._is_multipart_file + )._is_multipart_file_input except StopIteration: pass - result[k] = v if is_multipart_file else Model._as_dict_value(v, exclude_readonly=exclude_readonly) + result[k] = v if is_multipart_file_input else Model._as_dict_value(v, exclude_readonly=exclude_readonly) return result @staticmethod @@ -775,7 +775,7 @@ def __init__( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, - is_multipart_file: bool = False, + is_multipart_file_input: bool = False, ): self._type = type self._rest_name_input = name @@ -785,7 +785,7 @@ def __init__( self._is_model = False self._default = default self._format = format - self._is_multipart_file = is_multipart_file + self._is_multipart_file_input = is_multipart_file_input @property def _rest_name(self) -> str: @@ -831,10 +831,15 @@ def rest_field( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, - is_multipart_file: bool = False, + is_multipart_file_input: bool = False, ) -> typing.Any: return _RestField( - name=name, type=type, visibility=visibility, default=default, format=format, is_multipart_file=is_multipart_file + name=name, + type=type, + visibility=visibility, + default=default, + format=format, + is_multipart_file_input=is_multipart_file_input, ) diff --git a/packages/typespec-python/test/unbranded/generated/server-versions-versioned/server/versions/versioned/_model_base.py b/packages/typespec-python/test/unbranded/generated/server-versions-versioned/server/versions/versioned/_model_base.py index 18fc4d77a91..849db7e8e49 100644 --- a/packages/typespec-python/test/unbranded/generated/server-versions-versioned/server/versions/versioned/_model_base.py +++ b/packages/typespec-python/test/unbranded/generated/server-versions-versioned/server/versions/versioned/_model_base.py @@ -464,7 +464,7 @@ def _get_rest_field( def _create_value(rf: typing.Optional["_RestField"], value: typing.Any) -> typing.Any: if not rf: return _serialize(value, None) - if rf._is_multipart_file: + if rf._is_multipart_file_input: return value if rf._is_model: return _deserialize(rf._type, value) @@ -565,14 +565,14 @@ def as_dict(self, *, exclude_readonly: bool = False) -> typing.Dict[str, typing. for k, v in self.items(): if exclude_readonly and k in readonly_props: # pyright: ignore[reportUnboundVariable] continue - is_multipart_file = False + is_multipart_file_input = False try: - is_multipart_file = next( + is_multipart_file_input = next( rf for rf in self._attr_to_rest_field.values() if rf._rest_name == k - )._is_multipart_file + )._is_multipart_file_input except StopIteration: pass - result[k] = v if is_multipart_file else Model._as_dict_value(v, exclude_readonly=exclude_readonly) + result[k] = v if is_multipart_file_input else Model._as_dict_value(v, exclude_readonly=exclude_readonly) return result @staticmethod @@ -775,7 +775,7 @@ def __init__( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, - is_multipart_file: bool = False, + is_multipart_file_input: bool = False, ): self._type = type self._rest_name_input = name @@ -785,7 +785,7 @@ def __init__( self._is_model = False self._default = default self._format = format - self._is_multipart_file = is_multipart_file + self._is_multipart_file_input = is_multipart_file_input @property def _rest_name(self) -> str: @@ -831,10 +831,15 @@ def rest_field( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, - is_multipart_file: bool = False, + is_multipart_file_input: bool = False, ) -> typing.Any: return _RestField( - name=name, type=type, visibility=visibility, default=default, format=format, is_multipart_file=is_multipart_file + name=name, + type=type, + visibility=visibility, + default=default, + format=format, + is_multipart_file_input=is_multipart_file_input, ) diff --git a/packages/typespec-python/test/unbranded/generated/special-headers-conditional-request/specialheaders/conditionalrequest/_model_base.py b/packages/typespec-python/test/unbranded/generated/special-headers-conditional-request/specialheaders/conditionalrequest/_model_base.py index 18fc4d77a91..849db7e8e49 100644 --- a/packages/typespec-python/test/unbranded/generated/special-headers-conditional-request/specialheaders/conditionalrequest/_model_base.py +++ b/packages/typespec-python/test/unbranded/generated/special-headers-conditional-request/specialheaders/conditionalrequest/_model_base.py @@ -464,7 +464,7 @@ def _get_rest_field( def _create_value(rf: typing.Optional["_RestField"], value: typing.Any) -> typing.Any: if not rf: return _serialize(value, None) - if rf._is_multipart_file: + if rf._is_multipart_file_input: return value if rf._is_model: return _deserialize(rf._type, value) @@ -565,14 +565,14 @@ def as_dict(self, *, exclude_readonly: bool = False) -> typing.Dict[str, typing. for k, v in self.items(): if exclude_readonly and k in readonly_props: # pyright: ignore[reportUnboundVariable] continue - is_multipart_file = False + is_multipart_file_input = False try: - is_multipart_file = next( + is_multipart_file_input = next( rf for rf in self._attr_to_rest_field.values() if rf._rest_name == k - )._is_multipart_file + )._is_multipart_file_input except StopIteration: pass - result[k] = v if is_multipart_file else Model._as_dict_value(v, exclude_readonly=exclude_readonly) + result[k] = v if is_multipart_file_input else Model._as_dict_value(v, exclude_readonly=exclude_readonly) return result @staticmethod @@ -775,7 +775,7 @@ def __init__( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, - is_multipart_file: bool = False, + is_multipart_file_input: bool = False, ): self._type = type self._rest_name_input = name @@ -785,7 +785,7 @@ def __init__( self._is_model = False self._default = default self._format = format - self._is_multipart_file = is_multipart_file + self._is_multipart_file_input = is_multipart_file_input @property def _rest_name(self) -> str: @@ -831,10 +831,15 @@ def rest_field( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, - is_multipart_file: bool = False, + is_multipart_file_input: bool = False, ) -> typing.Any: return _RestField( - name=name, type=type, visibility=visibility, default=default, format=format, is_multipart_file=is_multipart_file + name=name, + type=type, + visibility=visibility, + default=default, + format=format, + is_multipart_file_input=is_multipart_file_input, ) diff --git a/packages/typespec-python/test/unbranded/generated/special-headers-repeatability/specialheaders/repeatability/_model_base.py b/packages/typespec-python/test/unbranded/generated/special-headers-repeatability/specialheaders/repeatability/_model_base.py index 18fc4d77a91..849db7e8e49 100644 --- a/packages/typespec-python/test/unbranded/generated/special-headers-repeatability/specialheaders/repeatability/_model_base.py +++ b/packages/typespec-python/test/unbranded/generated/special-headers-repeatability/specialheaders/repeatability/_model_base.py @@ -464,7 +464,7 @@ def _get_rest_field( def _create_value(rf: typing.Optional["_RestField"], value: typing.Any) -> typing.Any: if not rf: return _serialize(value, None) - if rf._is_multipart_file: + if rf._is_multipart_file_input: return value if rf._is_model: return _deserialize(rf._type, value) @@ -565,14 +565,14 @@ def as_dict(self, *, exclude_readonly: bool = False) -> typing.Dict[str, typing. for k, v in self.items(): if exclude_readonly and k in readonly_props: # pyright: ignore[reportUnboundVariable] continue - is_multipart_file = False + is_multipart_file_input = False try: - is_multipart_file = next( + is_multipart_file_input = next( rf for rf in self._attr_to_rest_field.values() if rf._rest_name == k - )._is_multipart_file + )._is_multipart_file_input except StopIteration: pass - result[k] = v if is_multipart_file else Model._as_dict_value(v, exclude_readonly=exclude_readonly) + result[k] = v if is_multipart_file_input else Model._as_dict_value(v, exclude_readonly=exclude_readonly) return result @staticmethod @@ -775,7 +775,7 @@ def __init__( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, - is_multipart_file: bool = False, + is_multipart_file_input: bool = False, ): self._type = type self._rest_name_input = name @@ -785,7 +785,7 @@ def __init__( self._is_model = False self._default = default self._format = format - self._is_multipart_file = is_multipart_file + self._is_multipart_file_input = is_multipart_file_input @property def _rest_name(self) -> str: @@ -831,10 +831,15 @@ def rest_field( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, - is_multipart_file: bool = False, + is_multipart_file_input: bool = False, ) -> typing.Any: return _RestField( - name=name, type=type, visibility=visibility, default=default, format=format, is_multipart_file=is_multipart_file + name=name, + type=type, + visibility=visibility, + default=default, + format=format, + is_multipart_file_input=is_multipart_file_input, ) diff --git a/packages/typespec-python/test/unbranded/generated/special-words/specialwords/_model_base.py b/packages/typespec-python/test/unbranded/generated/special-words/specialwords/_model_base.py index 18fc4d77a91..849db7e8e49 100644 --- a/packages/typespec-python/test/unbranded/generated/special-words/specialwords/_model_base.py +++ b/packages/typespec-python/test/unbranded/generated/special-words/specialwords/_model_base.py @@ -464,7 +464,7 @@ def _get_rest_field( def _create_value(rf: typing.Optional["_RestField"], value: typing.Any) -> typing.Any: if not rf: return _serialize(value, None) - if rf._is_multipart_file: + if rf._is_multipart_file_input: return value if rf._is_model: return _deserialize(rf._type, value) @@ -565,14 +565,14 @@ def as_dict(self, *, exclude_readonly: bool = False) -> typing.Dict[str, typing. for k, v in self.items(): if exclude_readonly and k in readonly_props: # pyright: ignore[reportUnboundVariable] continue - is_multipart_file = False + is_multipart_file_input = False try: - is_multipart_file = next( + is_multipart_file_input = next( rf for rf in self._attr_to_rest_field.values() if rf._rest_name == k - )._is_multipart_file + )._is_multipart_file_input except StopIteration: pass - result[k] = v if is_multipart_file else Model._as_dict_value(v, exclude_readonly=exclude_readonly) + result[k] = v if is_multipart_file_input else Model._as_dict_value(v, exclude_readonly=exclude_readonly) return result @staticmethod @@ -775,7 +775,7 @@ def __init__( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, - is_multipart_file: bool = False, + is_multipart_file_input: bool = False, ): self._type = type self._rest_name_input = name @@ -785,7 +785,7 @@ def __init__( self._is_model = False self._default = default self._format = format - self._is_multipart_file = is_multipart_file + self._is_multipart_file_input = is_multipart_file_input @property def _rest_name(self) -> str: @@ -831,10 +831,15 @@ def rest_field( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, - is_multipart_file: bool = False, + is_multipart_file_input: bool = False, ) -> typing.Any: return _RestField( - name=name, type=type, visibility=visibility, default=default, format=format, is_multipart_file=is_multipart_file + name=name, + type=type, + visibility=visibility, + default=default, + format=format, + is_multipart_file_input=is_multipart_file_input, ) diff --git a/packages/typespec-python/test/unbranded/generated/typetest-array/typetest/array/_model_base.py b/packages/typespec-python/test/unbranded/generated/typetest-array/typetest/array/_model_base.py index 18fc4d77a91..849db7e8e49 100644 --- a/packages/typespec-python/test/unbranded/generated/typetest-array/typetest/array/_model_base.py +++ b/packages/typespec-python/test/unbranded/generated/typetest-array/typetest/array/_model_base.py @@ -464,7 +464,7 @@ def _get_rest_field( def _create_value(rf: typing.Optional["_RestField"], value: typing.Any) -> typing.Any: if not rf: return _serialize(value, None) - if rf._is_multipart_file: + if rf._is_multipart_file_input: return value if rf._is_model: return _deserialize(rf._type, value) @@ -565,14 +565,14 @@ def as_dict(self, *, exclude_readonly: bool = False) -> typing.Dict[str, typing. for k, v in self.items(): if exclude_readonly and k in readonly_props: # pyright: ignore[reportUnboundVariable] continue - is_multipart_file = False + is_multipart_file_input = False try: - is_multipart_file = next( + is_multipart_file_input = next( rf for rf in self._attr_to_rest_field.values() if rf._rest_name == k - )._is_multipart_file + )._is_multipart_file_input except StopIteration: pass - result[k] = v if is_multipart_file else Model._as_dict_value(v, exclude_readonly=exclude_readonly) + result[k] = v if is_multipart_file_input else Model._as_dict_value(v, exclude_readonly=exclude_readonly) return result @staticmethod @@ -775,7 +775,7 @@ def __init__( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, - is_multipart_file: bool = False, + is_multipart_file_input: bool = False, ): self._type = type self._rest_name_input = name @@ -785,7 +785,7 @@ def __init__( self._is_model = False self._default = default self._format = format - self._is_multipart_file = is_multipart_file + self._is_multipart_file_input = is_multipart_file_input @property def _rest_name(self) -> str: @@ -831,10 +831,15 @@ def rest_field( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, - is_multipart_file: bool = False, + is_multipart_file_input: bool = False, ) -> typing.Any: return _RestField( - name=name, type=type, visibility=visibility, default=default, format=format, is_multipart_file=is_multipart_file + name=name, + type=type, + visibility=visibility, + default=default, + format=format, + is_multipart_file_input=is_multipart_file_input, ) diff --git a/packages/typespec-python/test/unbranded/generated/typetest-dictionary/typetest/dictionary/_model_base.py b/packages/typespec-python/test/unbranded/generated/typetest-dictionary/typetest/dictionary/_model_base.py index 18fc4d77a91..849db7e8e49 100644 --- a/packages/typespec-python/test/unbranded/generated/typetest-dictionary/typetest/dictionary/_model_base.py +++ b/packages/typespec-python/test/unbranded/generated/typetest-dictionary/typetest/dictionary/_model_base.py @@ -464,7 +464,7 @@ def _get_rest_field( def _create_value(rf: typing.Optional["_RestField"], value: typing.Any) -> typing.Any: if not rf: return _serialize(value, None) - if rf._is_multipart_file: + if rf._is_multipart_file_input: return value if rf._is_model: return _deserialize(rf._type, value) @@ -565,14 +565,14 @@ def as_dict(self, *, exclude_readonly: bool = False) -> typing.Dict[str, typing. for k, v in self.items(): if exclude_readonly and k in readonly_props: # pyright: ignore[reportUnboundVariable] continue - is_multipart_file = False + is_multipart_file_input = False try: - is_multipart_file = next( + is_multipart_file_input = next( rf for rf in self._attr_to_rest_field.values() if rf._rest_name == k - )._is_multipart_file + )._is_multipart_file_input except StopIteration: pass - result[k] = v if is_multipart_file else Model._as_dict_value(v, exclude_readonly=exclude_readonly) + result[k] = v if is_multipart_file_input else Model._as_dict_value(v, exclude_readonly=exclude_readonly) return result @staticmethod @@ -775,7 +775,7 @@ def __init__( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, - is_multipart_file: bool = False, + is_multipart_file_input: bool = False, ): self._type = type self._rest_name_input = name @@ -785,7 +785,7 @@ def __init__( self._is_model = False self._default = default self._format = format - self._is_multipart_file = is_multipart_file + self._is_multipart_file_input = is_multipart_file_input @property def _rest_name(self) -> str: @@ -831,10 +831,15 @@ def rest_field( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, - is_multipart_file: bool = False, + is_multipart_file_input: bool = False, ) -> typing.Any: return _RestField( - name=name, type=type, visibility=visibility, default=default, format=format, is_multipart_file=is_multipart_file + name=name, + type=type, + visibility=visibility, + default=default, + format=format, + is_multipart_file_input=is_multipart_file_input, ) diff --git a/packages/typespec-python/test/unbranded/generated/typetest-enum-extensible/typetest/enum/extensible/_model_base.py b/packages/typespec-python/test/unbranded/generated/typetest-enum-extensible/typetest/enum/extensible/_model_base.py index 18fc4d77a91..849db7e8e49 100644 --- a/packages/typespec-python/test/unbranded/generated/typetest-enum-extensible/typetest/enum/extensible/_model_base.py +++ b/packages/typespec-python/test/unbranded/generated/typetest-enum-extensible/typetest/enum/extensible/_model_base.py @@ -464,7 +464,7 @@ def _get_rest_field( def _create_value(rf: typing.Optional["_RestField"], value: typing.Any) -> typing.Any: if not rf: return _serialize(value, None) - if rf._is_multipart_file: + if rf._is_multipart_file_input: return value if rf._is_model: return _deserialize(rf._type, value) @@ -565,14 +565,14 @@ def as_dict(self, *, exclude_readonly: bool = False) -> typing.Dict[str, typing. for k, v in self.items(): if exclude_readonly and k in readonly_props: # pyright: ignore[reportUnboundVariable] continue - is_multipart_file = False + is_multipart_file_input = False try: - is_multipart_file = next( + is_multipart_file_input = next( rf for rf in self._attr_to_rest_field.values() if rf._rest_name == k - )._is_multipart_file + )._is_multipart_file_input except StopIteration: pass - result[k] = v if is_multipart_file else Model._as_dict_value(v, exclude_readonly=exclude_readonly) + result[k] = v if is_multipart_file_input else Model._as_dict_value(v, exclude_readonly=exclude_readonly) return result @staticmethod @@ -775,7 +775,7 @@ def __init__( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, - is_multipart_file: bool = False, + is_multipart_file_input: bool = False, ): self._type = type self._rest_name_input = name @@ -785,7 +785,7 @@ def __init__( self._is_model = False self._default = default self._format = format - self._is_multipart_file = is_multipart_file + self._is_multipart_file_input = is_multipart_file_input @property def _rest_name(self) -> str: @@ -831,10 +831,15 @@ def rest_field( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, - is_multipart_file: bool = False, + is_multipart_file_input: bool = False, ) -> typing.Any: return _RestField( - name=name, type=type, visibility=visibility, default=default, format=format, is_multipart_file=is_multipart_file + name=name, + type=type, + visibility=visibility, + default=default, + format=format, + is_multipart_file_input=is_multipart_file_input, ) diff --git a/packages/typespec-python/test/unbranded/generated/typetest-enum-fixed/typetest/enum/fixed/_model_base.py b/packages/typespec-python/test/unbranded/generated/typetest-enum-fixed/typetest/enum/fixed/_model_base.py index 18fc4d77a91..849db7e8e49 100644 --- a/packages/typespec-python/test/unbranded/generated/typetest-enum-fixed/typetest/enum/fixed/_model_base.py +++ b/packages/typespec-python/test/unbranded/generated/typetest-enum-fixed/typetest/enum/fixed/_model_base.py @@ -464,7 +464,7 @@ def _get_rest_field( def _create_value(rf: typing.Optional["_RestField"], value: typing.Any) -> typing.Any: if not rf: return _serialize(value, None) - if rf._is_multipart_file: + if rf._is_multipart_file_input: return value if rf._is_model: return _deserialize(rf._type, value) @@ -565,14 +565,14 @@ def as_dict(self, *, exclude_readonly: bool = False) -> typing.Dict[str, typing. for k, v in self.items(): if exclude_readonly and k in readonly_props: # pyright: ignore[reportUnboundVariable] continue - is_multipart_file = False + is_multipart_file_input = False try: - is_multipart_file = next( + is_multipart_file_input = next( rf for rf in self._attr_to_rest_field.values() if rf._rest_name == k - )._is_multipart_file + )._is_multipart_file_input except StopIteration: pass - result[k] = v if is_multipart_file else Model._as_dict_value(v, exclude_readonly=exclude_readonly) + result[k] = v if is_multipart_file_input else Model._as_dict_value(v, exclude_readonly=exclude_readonly) return result @staticmethod @@ -775,7 +775,7 @@ def __init__( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, - is_multipart_file: bool = False, + is_multipart_file_input: bool = False, ): self._type = type self._rest_name_input = name @@ -785,7 +785,7 @@ def __init__( self._is_model = False self._default = default self._format = format - self._is_multipart_file = is_multipart_file + self._is_multipart_file_input = is_multipart_file_input @property def _rest_name(self) -> str: @@ -831,10 +831,15 @@ def rest_field( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, - is_multipart_file: bool = False, + is_multipart_file_input: bool = False, ) -> typing.Any: return _RestField( - name=name, type=type, visibility=visibility, default=default, format=format, is_multipart_file=is_multipart_file + name=name, + type=type, + visibility=visibility, + default=default, + format=format, + is_multipart_file_input=is_multipart_file_input, ) diff --git a/packages/typespec-python/test/unbranded/generated/typetest-model-empty/typetest/model/empty/_model_base.py b/packages/typespec-python/test/unbranded/generated/typetest-model-empty/typetest/model/empty/_model_base.py index 18fc4d77a91..849db7e8e49 100644 --- a/packages/typespec-python/test/unbranded/generated/typetest-model-empty/typetest/model/empty/_model_base.py +++ b/packages/typespec-python/test/unbranded/generated/typetest-model-empty/typetest/model/empty/_model_base.py @@ -464,7 +464,7 @@ def _get_rest_field( def _create_value(rf: typing.Optional["_RestField"], value: typing.Any) -> typing.Any: if not rf: return _serialize(value, None) - if rf._is_multipart_file: + if rf._is_multipart_file_input: return value if rf._is_model: return _deserialize(rf._type, value) @@ -565,14 +565,14 @@ def as_dict(self, *, exclude_readonly: bool = False) -> typing.Dict[str, typing. for k, v in self.items(): if exclude_readonly and k in readonly_props: # pyright: ignore[reportUnboundVariable] continue - is_multipart_file = False + is_multipart_file_input = False try: - is_multipart_file = next( + is_multipart_file_input = next( rf for rf in self._attr_to_rest_field.values() if rf._rest_name == k - )._is_multipart_file + )._is_multipart_file_input except StopIteration: pass - result[k] = v if is_multipart_file else Model._as_dict_value(v, exclude_readonly=exclude_readonly) + result[k] = v if is_multipart_file_input else Model._as_dict_value(v, exclude_readonly=exclude_readonly) return result @staticmethod @@ -775,7 +775,7 @@ def __init__( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, - is_multipart_file: bool = False, + is_multipart_file_input: bool = False, ): self._type = type self._rest_name_input = name @@ -785,7 +785,7 @@ def __init__( self._is_model = False self._default = default self._format = format - self._is_multipart_file = is_multipart_file + self._is_multipart_file_input = is_multipart_file_input @property def _rest_name(self) -> str: @@ -831,10 +831,15 @@ def rest_field( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, - is_multipart_file: bool = False, + is_multipart_file_input: bool = False, ) -> typing.Any: return _RestField( - name=name, type=type, visibility=visibility, default=default, format=format, is_multipart_file=is_multipart_file + name=name, + type=type, + visibility=visibility, + default=default, + format=format, + is_multipart_file_input=is_multipart_file_input, ) diff --git a/packages/typespec-python/test/unbranded/generated/typetest-model-enumdiscriminator/typetest/model/enumdiscriminator/_model_base.py b/packages/typespec-python/test/unbranded/generated/typetest-model-enumdiscriminator/typetest/model/enumdiscriminator/_model_base.py index 18fc4d77a91..849db7e8e49 100644 --- a/packages/typespec-python/test/unbranded/generated/typetest-model-enumdiscriminator/typetest/model/enumdiscriminator/_model_base.py +++ b/packages/typespec-python/test/unbranded/generated/typetest-model-enumdiscriminator/typetest/model/enumdiscriminator/_model_base.py @@ -464,7 +464,7 @@ def _get_rest_field( def _create_value(rf: typing.Optional["_RestField"], value: typing.Any) -> typing.Any: if not rf: return _serialize(value, None) - if rf._is_multipart_file: + if rf._is_multipart_file_input: return value if rf._is_model: return _deserialize(rf._type, value) @@ -565,14 +565,14 @@ def as_dict(self, *, exclude_readonly: bool = False) -> typing.Dict[str, typing. for k, v in self.items(): if exclude_readonly and k in readonly_props: # pyright: ignore[reportUnboundVariable] continue - is_multipart_file = False + is_multipart_file_input = False try: - is_multipart_file = next( + is_multipart_file_input = next( rf for rf in self._attr_to_rest_field.values() if rf._rest_name == k - )._is_multipart_file + )._is_multipart_file_input except StopIteration: pass - result[k] = v if is_multipart_file else Model._as_dict_value(v, exclude_readonly=exclude_readonly) + result[k] = v if is_multipart_file_input else Model._as_dict_value(v, exclude_readonly=exclude_readonly) return result @staticmethod @@ -775,7 +775,7 @@ def __init__( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, - is_multipart_file: bool = False, + is_multipart_file_input: bool = False, ): self._type = type self._rest_name_input = name @@ -785,7 +785,7 @@ def __init__( self._is_model = False self._default = default self._format = format - self._is_multipart_file = is_multipart_file + self._is_multipart_file_input = is_multipart_file_input @property def _rest_name(self) -> str: @@ -831,10 +831,15 @@ def rest_field( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, - is_multipart_file: bool = False, + is_multipart_file_input: bool = False, ) -> typing.Any: return _RestField( - name=name, type=type, visibility=visibility, default=default, format=format, is_multipart_file=is_multipart_file + name=name, + type=type, + visibility=visibility, + default=default, + format=format, + is_multipart_file_input=is_multipart_file_input, ) diff --git a/packages/typespec-python/test/unbranded/generated/typetest-model-nesteddiscriminator/typetest/model/nesteddiscriminator/_model_base.py b/packages/typespec-python/test/unbranded/generated/typetest-model-nesteddiscriminator/typetest/model/nesteddiscriminator/_model_base.py index 18fc4d77a91..849db7e8e49 100644 --- a/packages/typespec-python/test/unbranded/generated/typetest-model-nesteddiscriminator/typetest/model/nesteddiscriminator/_model_base.py +++ b/packages/typespec-python/test/unbranded/generated/typetest-model-nesteddiscriminator/typetest/model/nesteddiscriminator/_model_base.py @@ -464,7 +464,7 @@ def _get_rest_field( def _create_value(rf: typing.Optional["_RestField"], value: typing.Any) -> typing.Any: if not rf: return _serialize(value, None) - if rf._is_multipart_file: + if rf._is_multipart_file_input: return value if rf._is_model: return _deserialize(rf._type, value) @@ -565,14 +565,14 @@ def as_dict(self, *, exclude_readonly: bool = False) -> typing.Dict[str, typing. for k, v in self.items(): if exclude_readonly and k in readonly_props: # pyright: ignore[reportUnboundVariable] continue - is_multipart_file = False + is_multipart_file_input = False try: - is_multipart_file = next( + is_multipart_file_input = next( rf for rf in self._attr_to_rest_field.values() if rf._rest_name == k - )._is_multipart_file + )._is_multipart_file_input except StopIteration: pass - result[k] = v if is_multipart_file else Model._as_dict_value(v, exclude_readonly=exclude_readonly) + result[k] = v if is_multipart_file_input else Model._as_dict_value(v, exclude_readonly=exclude_readonly) return result @staticmethod @@ -775,7 +775,7 @@ def __init__( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, - is_multipart_file: bool = False, + is_multipart_file_input: bool = False, ): self._type = type self._rest_name_input = name @@ -785,7 +785,7 @@ def __init__( self._is_model = False self._default = default self._format = format - self._is_multipart_file = is_multipart_file + self._is_multipart_file_input = is_multipart_file_input @property def _rest_name(self) -> str: @@ -831,10 +831,15 @@ def rest_field( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, - is_multipart_file: bool = False, + is_multipart_file_input: bool = False, ) -> typing.Any: return _RestField( - name=name, type=type, visibility=visibility, default=default, format=format, is_multipart_file=is_multipart_file + name=name, + type=type, + visibility=visibility, + default=default, + format=format, + is_multipart_file_input=is_multipart_file_input, ) diff --git a/packages/typespec-python/test/unbranded/generated/typetest-model-notdiscriminated/typetest/model/notdiscriminated/_model_base.py b/packages/typespec-python/test/unbranded/generated/typetest-model-notdiscriminated/typetest/model/notdiscriminated/_model_base.py index 18fc4d77a91..849db7e8e49 100644 --- a/packages/typespec-python/test/unbranded/generated/typetest-model-notdiscriminated/typetest/model/notdiscriminated/_model_base.py +++ b/packages/typespec-python/test/unbranded/generated/typetest-model-notdiscriminated/typetest/model/notdiscriminated/_model_base.py @@ -464,7 +464,7 @@ def _get_rest_field( def _create_value(rf: typing.Optional["_RestField"], value: typing.Any) -> typing.Any: if not rf: return _serialize(value, None) - if rf._is_multipart_file: + if rf._is_multipart_file_input: return value if rf._is_model: return _deserialize(rf._type, value) @@ -565,14 +565,14 @@ def as_dict(self, *, exclude_readonly: bool = False) -> typing.Dict[str, typing. for k, v in self.items(): if exclude_readonly and k in readonly_props: # pyright: ignore[reportUnboundVariable] continue - is_multipart_file = False + is_multipart_file_input = False try: - is_multipart_file = next( + is_multipart_file_input = next( rf for rf in self._attr_to_rest_field.values() if rf._rest_name == k - )._is_multipart_file + )._is_multipart_file_input except StopIteration: pass - result[k] = v if is_multipart_file else Model._as_dict_value(v, exclude_readonly=exclude_readonly) + result[k] = v if is_multipart_file_input else Model._as_dict_value(v, exclude_readonly=exclude_readonly) return result @staticmethod @@ -775,7 +775,7 @@ def __init__( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, - is_multipart_file: bool = False, + is_multipart_file_input: bool = False, ): self._type = type self._rest_name_input = name @@ -785,7 +785,7 @@ def __init__( self._is_model = False self._default = default self._format = format - self._is_multipart_file = is_multipart_file + self._is_multipart_file_input = is_multipart_file_input @property def _rest_name(self) -> str: @@ -831,10 +831,15 @@ def rest_field( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, - is_multipart_file: bool = False, + is_multipart_file_input: bool = False, ) -> typing.Any: return _RestField( - name=name, type=type, visibility=visibility, default=default, format=format, is_multipart_file=is_multipart_file + name=name, + type=type, + visibility=visibility, + default=default, + format=format, + is_multipart_file_input=is_multipart_file_input, ) diff --git a/packages/typespec-python/test/unbranded/generated/typetest-model-recursive/typetest/model/recursive/_model_base.py b/packages/typespec-python/test/unbranded/generated/typetest-model-recursive/typetest/model/recursive/_model_base.py index 18fc4d77a91..849db7e8e49 100644 --- a/packages/typespec-python/test/unbranded/generated/typetest-model-recursive/typetest/model/recursive/_model_base.py +++ b/packages/typespec-python/test/unbranded/generated/typetest-model-recursive/typetest/model/recursive/_model_base.py @@ -464,7 +464,7 @@ def _get_rest_field( def _create_value(rf: typing.Optional["_RestField"], value: typing.Any) -> typing.Any: if not rf: return _serialize(value, None) - if rf._is_multipart_file: + if rf._is_multipart_file_input: return value if rf._is_model: return _deserialize(rf._type, value) @@ -565,14 +565,14 @@ def as_dict(self, *, exclude_readonly: bool = False) -> typing.Dict[str, typing. for k, v in self.items(): if exclude_readonly and k in readonly_props: # pyright: ignore[reportUnboundVariable] continue - is_multipart_file = False + is_multipart_file_input = False try: - is_multipart_file = next( + is_multipart_file_input = next( rf for rf in self._attr_to_rest_field.values() if rf._rest_name == k - )._is_multipart_file + )._is_multipart_file_input except StopIteration: pass - result[k] = v if is_multipart_file else Model._as_dict_value(v, exclude_readonly=exclude_readonly) + result[k] = v if is_multipart_file_input else Model._as_dict_value(v, exclude_readonly=exclude_readonly) return result @staticmethod @@ -775,7 +775,7 @@ def __init__( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, - is_multipart_file: bool = False, + is_multipart_file_input: bool = False, ): self._type = type self._rest_name_input = name @@ -785,7 +785,7 @@ def __init__( self._is_model = False self._default = default self._format = format - self._is_multipart_file = is_multipart_file + self._is_multipart_file_input = is_multipart_file_input @property def _rest_name(self) -> str: @@ -831,10 +831,15 @@ def rest_field( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, - is_multipart_file: bool = False, + is_multipart_file_input: bool = False, ) -> typing.Any: return _RestField( - name=name, type=type, visibility=visibility, default=default, format=format, is_multipart_file=is_multipart_file + name=name, + type=type, + visibility=visibility, + default=default, + format=format, + is_multipart_file_input=is_multipart_file_input, ) diff --git a/packages/typespec-python/test/unbranded/generated/typetest-model-singlediscriminator/typetest/model/singlediscriminator/_model_base.py b/packages/typespec-python/test/unbranded/generated/typetest-model-singlediscriminator/typetest/model/singlediscriminator/_model_base.py index 18fc4d77a91..849db7e8e49 100644 --- a/packages/typespec-python/test/unbranded/generated/typetest-model-singlediscriminator/typetest/model/singlediscriminator/_model_base.py +++ b/packages/typespec-python/test/unbranded/generated/typetest-model-singlediscriminator/typetest/model/singlediscriminator/_model_base.py @@ -464,7 +464,7 @@ def _get_rest_field( def _create_value(rf: typing.Optional["_RestField"], value: typing.Any) -> typing.Any: if not rf: return _serialize(value, None) - if rf._is_multipart_file: + if rf._is_multipart_file_input: return value if rf._is_model: return _deserialize(rf._type, value) @@ -565,14 +565,14 @@ def as_dict(self, *, exclude_readonly: bool = False) -> typing.Dict[str, typing. for k, v in self.items(): if exclude_readonly and k in readonly_props: # pyright: ignore[reportUnboundVariable] continue - is_multipart_file = False + is_multipart_file_input = False try: - is_multipart_file = next( + is_multipart_file_input = next( rf for rf in self._attr_to_rest_field.values() if rf._rest_name == k - )._is_multipart_file + )._is_multipart_file_input except StopIteration: pass - result[k] = v if is_multipart_file else Model._as_dict_value(v, exclude_readonly=exclude_readonly) + result[k] = v if is_multipart_file_input else Model._as_dict_value(v, exclude_readonly=exclude_readonly) return result @staticmethod @@ -775,7 +775,7 @@ def __init__( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, - is_multipart_file: bool = False, + is_multipart_file_input: bool = False, ): self._type = type self._rest_name_input = name @@ -785,7 +785,7 @@ def __init__( self._is_model = False self._default = default self._format = format - self._is_multipart_file = is_multipart_file + self._is_multipart_file_input = is_multipart_file_input @property def _rest_name(self) -> str: @@ -831,10 +831,15 @@ def rest_field( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, - is_multipart_file: bool = False, + is_multipart_file_input: bool = False, ) -> typing.Any: return _RestField( - name=name, type=type, visibility=visibility, default=default, format=format, is_multipart_file=is_multipart_file + name=name, + type=type, + visibility=visibility, + default=default, + format=format, + is_multipart_file_input=is_multipart_file_input, ) diff --git a/packages/typespec-python/test/unbranded/generated/typetest-model-usage/typetest/model/usage/_model_base.py b/packages/typespec-python/test/unbranded/generated/typetest-model-usage/typetest/model/usage/_model_base.py index 18fc4d77a91..849db7e8e49 100644 --- a/packages/typespec-python/test/unbranded/generated/typetest-model-usage/typetest/model/usage/_model_base.py +++ b/packages/typespec-python/test/unbranded/generated/typetest-model-usage/typetest/model/usage/_model_base.py @@ -464,7 +464,7 @@ def _get_rest_field( def _create_value(rf: typing.Optional["_RestField"], value: typing.Any) -> typing.Any: if not rf: return _serialize(value, None) - if rf._is_multipart_file: + if rf._is_multipart_file_input: return value if rf._is_model: return _deserialize(rf._type, value) @@ -565,14 +565,14 @@ def as_dict(self, *, exclude_readonly: bool = False) -> typing.Dict[str, typing. for k, v in self.items(): if exclude_readonly and k in readonly_props: # pyright: ignore[reportUnboundVariable] continue - is_multipart_file = False + is_multipart_file_input = False try: - is_multipart_file = next( + is_multipart_file_input = next( rf for rf in self._attr_to_rest_field.values() if rf._rest_name == k - )._is_multipart_file + )._is_multipart_file_input except StopIteration: pass - result[k] = v if is_multipart_file else Model._as_dict_value(v, exclude_readonly=exclude_readonly) + result[k] = v if is_multipart_file_input else Model._as_dict_value(v, exclude_readonly=exclude_readonly) return result @staticmethod @@ -775,7 +775,7 @@ def __init__( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, - is_multipart_file: bool = False, + is_multipart_file_input: bool = False, ): self._type = type self._rest_name_input = name @@ -785,7 +785,7 @@ def __init__( self._is_model = False self._default = default self._format = format - self._is_multipart_file = is_multipart_file + self._is_multipart_file_input = is_multipart_file_input @property def _rest_name(self) -> str: @@ -831,10 +831,15 @@ def rest_field( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, - is_multipart_file: bool = False, + is_multipart_file_input: bool = False, ) -> typing.Any: return _RestField( - name=name, type=type, visibility=visibility, default=default, format=format, is_multipart_file=is_multipart_file + name=name, + type=type, + visibility=visibility, + default=default, + format=format, + is_multipart_file_input=is_multipart_file_input, ) diff --git a/packages/typespec-python/test/unbranded/generated/typetest-model-visibility/typetest/model/visibility/_model_base.py b/packages/typespec-python/test/unbranded/generated/typetest-model-visibility/typetest/model/visibility/_model_base.py index 18fc4d77a91..849db7e8e49 100644 --- a/packages/typespec-python/test/unbranded/generated/typetest-model-visibility/typetest/model/visibility/_model_base.py +++ b/packages/typespec-python/test/unbranded/generated/typetest-model-visibility/typetest/model/visibility/_model_base.py @@ -464,7 +464,7 @@ def _get_rest_field( def _create_value(rf: typing.Optional["_RestField"], value: typing.Any) -> typing.Any: if not rf: return _serialize(value, None) - if rf._is_multipart_file: + if rf._is_multipart_file_input: return value if rf._is_model: return _deserialize(rf._type, value) @@ -565,14 +565,14 @@ def as_dict(self, *, exclude_readonly: bool = False) -> typing.Dict[str, typing. for k, v in self.items(): if exclude_readonly and k in readonly_props: # pyright: ignore[reportUnboundVariable] continue - is_multipart_file = False + is_multipart_file_input = False try: - is_multipart_file = next( + is_multipart_file_input = next( rf for rf in self._attr_to_rest_field.values() if rf._rest_name == k - )._is_multipart_file + )._is_multipart_file_input except StopIteration: pass - result[k] = v if is_multipart_file else Model._as_dict_value(v, exclude_readonly=exclude_readonly) + result[k] = v if is_multipart_file_input else Model._as_dict_value(v, exclude_readonly=exclude_readonly) return result @staticmethod @@ -775,7 +775,7 @@ def __init__( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, - is_multipart_file: bool = False, + is_multipart_file_input: bool = False, ): self._type = type self._rest_name_input = name @@ -785,7 +785,7 @@ def __init__( self._is_model = False self._default = default self._format = format - self._is_multipart_file = is_multipart_file + self._is_multipart_file_input = is_multipart_file_input @property def _rest_name(self) -> str: @@ -831,10 +831,15 @@ def rest_field( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, - is_multipart_file: bool = False, + is_multipart_file_input: bool = False, ) -> typing.Any: return _RestField( - name=name, type=type, visibility=visibility, default=default, format=format, is_multipart_file=is_multipart_file + name=name, + type=type, + visibility=visibility, + default=default, + format=format, + is_multipart_file_input=is_multipart_file_input, ) diff --git a/packages/typespec-python/test/unbranded/generated/typetest-property-additionalproperties/typetest/property/additionalproperties/_model_base.py b/packages/typespec-python/test/unbranded/generated/typetest-property-additionalproperties/typetest/property/additionalproperties/_model_base.py index 18fc4d77a91..849db7e8e49 100644 --- a/packages/typespec-python/test/unbranded/generated/typetest-property-additionalproperties/typetest/property/additionalproperties/_model_base.py +++ b/packages/typespec-python/test/unbranded/generated/typetest-property-additionalproperties/typetest/property/additionalproperties/_model_base.py @@ -464,7 +464,7 @@ def _get_rest_field( def _create_value(rf: typing.Optional["_RestField"], value: typing.Any) -> typing.Any: if not rf: return _serialize(value, None) - if rf._is_multipart_file: + if rf._is_multipart_file_input: return value if rf._is_model: return _deserialize(rf._type, value) @@ -565,14 +565,14 @@ def as_dict(self, *, exclude_readonly: bool = False) -> typing.Dict[str, typing. for k, v in self.items(): if exclude_readonly and k in readonly_props: # pyright: ignore[reportUnboundVariable] continue - is_multipart_file = False + is_multipart_file_input = False try: - is_multipart_file = next( + is_multipart_file_input = next( rf for rf in self._attr_to_rest_field.values() if rf._rest_name == k - )._is_multipart_file + )._is_multipart_file_input except StopIteration: pass - result[k] = v if is_multipart_file else Model._as_dict_value(v, exclude_readonly=exclude_readonly) + result[k] = v if is_multipart_file_input else Model._as_dict_value(v, exclude_readonly=exclude_readonly) return result @staticmethod @@ -775,7 +775,7 @@ def __init__( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, - is_multipart_file: bool = False, + is_multipart_file_input: bool = False, ): self._type = type self._rest_name_input = name @@ -785,7 +785,7 @@ def __init__( self._is_model = False self._default = default self._format = format - self._is_multipart_file = is_multipart_file + self._is_multipart_file_input = is_multipart_file_input @property def _rest_name(self) -> str: @@ -831,10 +831,15 @@ def rest_field( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, - is_multipart_file: bool = False, + is_multipart_file_input: bool = False, ) -> typing.Any: return _RestField( - name=name, type=type, visibility=visibility, default=default, format=format, is_multipart_file=is_multipart_file + name=name, + type=type, + visibility=visibility, + default=default, + format=format, + is_multipart_file_input=is_multipart_file_input, ) diff --git a/packages/typespec-python/test/unbranded/generated/typetest-property-nullable/typetest/property/nullable/_model_base.py b/packages/typespec-python/test/unbranded/generated/typetest-property-nullable/typetest/property/nullable/_model_base.py index 18fc4d77a91..849db7e8e49 100644 --- a/packages/typespec-python/test/unbranded/generated/typetest-property-nullable/typetest/property/nullable/_model_base.py +++ b/packages/typespec-python/test/unbranded/generated/typetest-property-nullable/typetest/property/nullable/_model_base.py @@ -464,7 +464,7 @@ def _get_rest_field( def _create_value(rf: typing.Optional["_RestField"], value: typing.Any) -> typing.Any: if not rf: return _serialize(value, None) - if rf._is_multipart_file: + if rf._is_multipart_file_input: return value if rf._is_model: return _deserialize(rf._type, value) @@ -565,14 +565,14 @@ def as_dict(self, *, exclude_readonly: bool = False) -> typing.Dict[str, typing. for k, v in self.items(): if exclude_readonly and k in readonly_props: # pyright: ignore[reportUnboundVariable] continue - is_multipart_file = False + is_multipart_file_input = False try: - is_multipart_file = next( + is_multipart_file_input = next( rf for rf in self._attr_to_rest_field.values() if rf._rest_name == k - )._is_multipart_file + )._is_multipart_file_input except StopIteration: pass - result[k] = v if is_multipart_file else Model._as_dict_value(v, exclude_readonly=exclude_readonly) + result[k] = v if is_multipart_file_input else Model._as_dict_value(v, exclude_readonly=exclude_readonly) return result @staticmethod @@ -775,7 +775,7 @@ def __init__( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, - is_multipart_file: bool = False, + is_multipart_file_input: bool = False, ): self._type = type self._rest_name_input = name @@ -785,7 +785,7 @@ def __init__( self._is_model = False self._default = default self._format = format - self._is_multipart_file = is_multipart_file + self._is_multipart_file_input = is_multipart_file_input @property def _rest_name(self) -> str: @@ -831,10 +831,15 @@ def rest_field( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, - is_multipart_file: bool = False, + is_multipart_file_input: bool = False, ) -> typing.Any: return _RestField( - name=name, type=type, visibility=visibility, default=default, format=format, is_multipart_file=is_multipart_file + name=name, + type=type, + visibility=visibility, + default=default, + format=format, + is_multipart_file_input=is_multipart_file_input, ) diff --git a/packages/typespec-python/test/unbranded/generated/typetest-property-optional/typetest/property/optional/_model_base.py b/packages/typespec-python/test/unbranded/generated/typetest-property-optional/typetest/property/optional/_model_base.py index 18fc4d77a91..849db7e8e49 100644 --- a/packages/typespec-python/test/unbranded/generated/typetest-property-optional/typetest/property/optional/_model_base.py +++ b/packages/typespec-python/test/unbranded/generated/typetest-property-optional/typetest/property/optional/_model_base.py @@ -464,7 +464,7 @@ def _get_rest_field( def _create_value(rf: typing.Optional["_RestField"], value: typing.Any) -> typing.Any: if not rf: return _serialize(value, None) - if rf._is_multipart_file: + if rf._is_multipart_file_input: return value if rf._is_model: return _deserialize(rf._type, value) @@ -565,14 +565,14 @@ def as_dict(self, *, exclude_readonly: bool = False) -> typing.Dict[str, typing. for k, v in self.items(): if exclude_readonly and k in readonly_props: # pyright: ignore[reportUnboundVariable] continue - is_multipart_file = False + is_multipart_file_input = False try: - is_multipart_file = next( + is_multipart_file_input = next( rf for rf in self._attr_to_rest_field.values() if rf._rest_name == k - )._is_multipart_file + )._is_multipart_file_input except StopIteration: pass - result[k] = v if is_multipart_file else Model._as_dict_value(v, exclude_readonly=exclude_readonly) + result[k] = v if is_multipart_file_input else Model._as_dict_value(v, exclude_readonly=exclude_readonly) return result @staticmethod @@ -775,7 +775,7 @@ def __init__( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, - is_multipart_file: bool = False, + is_multipart_file_input: bool = False, ): self._type = type self._rest_name_input = name @@ -785,7 +785,7 @@ def __init__( self._is_model = False self._default = default self._format = format - self._is_multipart_file = is_multipart_file + self._is_multipart_file_input = is_multipart_file_input @property def _rest_name(self) -> str: @@ -831,10 +831,15 @@ def rest_field( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, - is_multipart_file: bool = False, + is_multipart_file_input: bool = False, ) -> typing.Any: return _RestField( - name=name, type=type, visibility=visibility, default=default, format=format, is_multipart_file=is_multipart_file + name=name, + type=type, + visibility=visibility, + default=default, + format=format, + is_multipart_file_input=is_multipart_file_input, ) diff --git a/packages/typespec-python/test/unbranded/generated/typetest-property-valuetypes/typetest/property/valuetypes/_model_base.py b/packages/typespec-python/test/unbranded/generated/typetest-property-valuetypes/typetest/property/valuetypes/_model_base.py index 18fc4d77a91..849db7e8e49 100644 --- a/packages/typespec-python/test/unbranded/generated/typetest-property-valuetypes/typetest/property/valuetypes/_model_base.py +++ b/packages/typespec-python/test/unbranded/generated/typetest-property-valuetypes/typetest/property/valuetypes/_model_base.py @@ -464,7 +464,7 @@ def _get_rest_field( def _create_value(rf: typing.Optional["_RestField"], value: typing.Any) -> typing.Any: if not rf: return _serialize(value, None) - if rf._is_multipart_file: + if rf._is_multipart_file_input: return value if rf._is_model: return _deserialize(rf._type, value) @@ -565,14 +565,14 @@ def as_dict(self, *, exclude_readonly: bool = False) -> typing.Dict[str, typing. for k, v in self.items(): if exclude_readonly and k in readonly_props: # pyright: ignore[reportUnboundVariable] continue - is_multipart_file = False + is_multipart_file_input = False try: - is_multipart_file = next( + is_multipart_file_input = next( rf for rf in self._attr_to_rest_field.values() if rf._rest_name == k - )._is_multipart_file + )._is_multipart_file_input except StopIteration: pass - result[k] = v if is_multipart_file else Model._as_dict_value(v, exclude_readonly=exclude_readonly) + result[k] = v if is_multipart_file_input else Model._as_dict_value(v, exclude_readonly=exclude_readonly) return result @staticmethod @@ -775,7 +775,7 @@ def __init__( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, - is_multipart_file: bool = False, + is_multipart_file_input: bool = False, ): self._type = type self._rest_name_input = name @@ -785,7 +785,7 @@ def __init__( self._is_model = False self._default = default self._format = format - self._is_multipart_file = is_multipart_file + self._is_multipart_file_input = is_multipart_file_input @property def _rest_name(self) -> str: @@ -831,10 +831,15 @@ def rest_field( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, - is_multipart_file: bool = False, + is_multipart_file_input: bool = False, ) -> typing.Any: return _RestField( - name=name, type=type, visibility=visibility, default=default, format=format, is_multipart_file=is_multipart_file + name=name, + type=type, + visibility=visibility, + default=default, + format=format, + is_multipart_file_input=is_multipart_file_input, ) diff --git a/packages/typespec-python/test/unbranded/generated/typetest-scalar/typetest/scalar/_model_base.py b/packages/typespec-python/test/unbranded/generated/typetest-scalar/typetest/scalar/_model_base.py index 18fc4d77a91..849db7e8e49 100644 --- a/packages/typespec-python/test/unbranded/generated/typetest-scalar/typetest/scalar/_model_base.py +++ b/packages/typespec-python/test/unbranded/generated/typetest-scalar/typetest/scalar/_model_base.py @@ -464,7 +464,7 @@ def _get_rest_field( def _create_value(rf: typing.Optional["_RestField"], value: typing.Any) -> typing.Any: if not rf: return _serialize(value, None) - if rf._is_multipart_file: + if rf._is_multipart_file_input: return value if rf._is_model: return _deserialize(rf._type, value) @@ -565,14 +565,14 @@ def as_dict(self, *, exclude_readonly: bool = False) -> typing.Dict[str, typing. for k, v in self.items(): if exclude_readonly and k in readonly_props: # pyright: ignore[reportUnboundVariable] continue - is_multipart_file = False + is_multipart_file_input = False try: - is_multipart_file = next( + is_multipart_file_input = next( rf for rf in self._attr_to_rest_field.values() if rf._rest_name == k - )._is_multipart_file + )._is_multipart_file_input except StopIteration: pass - result[k] = v if is_multipart_file else Model._as_dict_value(v, exclude_readonly=exclude_readonly) + result[k] = v if is_multipart_file_input else Model._as_dict_value(v, exclude_readonly=exclude_readonly) return result @staticmethod @@ -775,7 +775,7 @@ def __init__( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, - is_multipart_file: bool = False, + is_multipart_file_input: bool = False, ): self._type = type self._rest_name_input = name @@ -785,7 +785,7 @@ def __init__( self._is_model = False self._default = default self._format = format - self._is_multipart_file = is_multipart_file + self._is_multipart_file_input = is_multipart_file_input @property def _rest_name(self) -> str: @@ -831,10 +831,15 @@ def rest_field( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, - is_multipart_file: bool = False, + is_multipart_file_input: bool = False, ) -> typing.Any: return _RestField( - name=name, type=type, visibility=visibility, default=default, format=format, is_multipart_file=is_multipart_file + name=name, + type=type, + visibility=visibility, + default=default, + format=format, + is_multipart_file_input=is_multipart_file_input, ) diff --git a/packages/typespec-python/test/unbranded/generated/typetest-union/typetest/union/_model_base.py b/packages/typespec-python/test/unbranded/generated/typetest-union/typetest/union/_model_base.py index 18fc4d77a91..849db7e8e49 100644 --- a/packages/typespec-python/test/unbranded/generated/typetest-union/typetest/union/_model_base.py +++ b/packages/typespec-python/test/unbranded/generated/typetest-union/typetest/union/_model_base.py @@ -464,7 +464,7 @@ def _get_rest_field( def _create_value(rf: typing.Optional["_RestField"], value: typing.Any) -> typing.Any: if not rf: return _serialize(value, None) - if rf._is_multipart_file: + if rf._is_multipart_file_input: return value if rf._is_model: return _deserialize(rf._type, value) @@ -565,14 +565,14 @@ def as_dict(self, *, exclude_readonly: bool = False) -> typing.Dict[str, typing. for k, v in self.items(): if exclude_readonly and k in readonly_props: # pyright: ignore[reportUnboundVariable] continue - is_multipart_file = False + is_multipart_file_input = False try: - is_multipart_file = next( + is_multipart_file_input = next( rf for rf in self._attr_to_rest_field.values() if rf._rest_name == k - )._is_multipart_file + )._is_multipart_file_input except StopIteration: pass - result[k] = v if is_multipart_file else Model._as_dict_value(v, exclude_readonly=exclude_readonly) + result[k] = v if is_multipart_file_input else Model._as_dict_value(v, exclude_readonly=exclude_readonly) return result @staticmethod @@ -775,7 +775,7 @@ def __init__( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, - is_multipart_file: bool = False, + is_multipart_file_input: bool = False, ): self._type = type self._rest_name_input = name @@ -785,7 +785,7 @@ def __init__( self._is_model = False self._default = default self._format = format - self._is_multipart_file = is_multipart_file + self._is_multipart_file_input = is_multipart_file_input @property def _rest_name(self) -> str: @@ -831,10 +831,15 @@ def rest_field( visibility: typing.Optional[typing.List[str]] = None, default: typing.Any = _UNSET, format: typing.Optional[str] = None, - is_multipart_file: bool = False, + is_multipart_file_input: bool = False, ) -> typing.Any: return _RestField( - name=name, type=type, visibility=visibility, default=default, format=format, is_multipart_file=is_multipart_file + name=name, + type=type, + visibility=visibility, + default=default, + format=format, + is_multipart_file_input=is_multipart_file_input, ) From 3e70bac024727d6f83d089c1d2e1f111cd5ae3b3 Mon Sep 17 00:00:00 2001 From: iscai-msft Date: Wed, 31 Jan 2024 22:49:49 -0500 Subject: [PATCH 18/45] almost there with legacy --- .../autorest/codegen/models/parameter.py | 12 +++++++++- .../codegen/serializers/builder_serializer.py | 22 ++++++++++++++++++- .../BodyFormData/bodyformdata/_vendor.py | 17 ++++++++++++++ .../operations/_formdata_operations.py | 4 ---- .../bodyformurlencodeddata/_vendor.py | 17 ++++++++++++++ .../_formdataurlencoded_operations.py | 10 ++++----- .../_formdataurlencoded_operations.py | 18 +++++---------- .../ReservedWords/reservedwords/_vendor.py | 17 +++++++++++++- .../reservedwords/aio/_vendor.py | 17 +++++++++++++- .../_reserved_words_client_operations.py | 2 +- .../_reserved_words_client_operations.py | 6 +---- 11 files changed, 110 insertions(+), 32 deletions(-) diff --git a/packages/autorest.python/autorest/codegen/models/parameter.py b/packages/autorest.python/autorest/codegen/models/parameter.py index 22bec5078ac..8e26f82d9a7 100644 --- a/packages/autorest.python/autorest/codegen/models/parameter.py +++ b/packages/autorest.python/autorest/codegen/models/parameter.py @@ -245,9 +245,15 @@ def method_signature(self, async_mode: bool) -> str: class BodyParameter(_ParameterBase): """Body parameter.""" + @property + def entries(self) -> List[str]: + return [BodyParameter.from_yaml(e, self.code_model) for e in self.yaml_data.get("entries", [])] + @property def is_form_data(self) -> bool: - return self.type.is_form_data + # hacky, but rn in legacy, there is no formdata model type, it's just a dict + # with all of the entries splatted out + return self.type.is_form_data or self.entries @property def is_partial_body(self) -> bool: @@ -264,6 +270,10 @@ def method_location(self) -> ParameterMethodLocation: @property def in_method_signature(self) -> bool: + if self.yaml_data.get("entries"): + # Right now, only legacy generates with multipart bodies and entries + # and legacy generates with the multipart body arguments splatted out + return False return not (self.flattened or self.grouped_by) @property diff --git a/packages/autorest.python/autorest/codegen/serializers/builder_serializer.py b/packages/autorest.python/autorest/codegen/serializers/builder_serializer.py index c550f56be88..2f9ea4da124 100644 --- a/packages/autorest.python/autorest/codegen/serializers/builder_serializer.py +++ b/packages/autorest.python/autorest/codegen/serializers/builder_serializer.py @@ -203,6 +203,17 @@ def _serialize_json_model_body( retval.append(" }") return retval +def _serialize_multipart_body(builder: BuilderType) -> List[str]: + retval: List[str] = [] + body_param = builder.parameters.body_parameter + # we have to construct our form data before passing to the request as well + retval.append("# Construct form data") + retval.append(f"_{body_param.client_name} = {{") + for param in body_param.entries: + retval.append(f' "{param.wire_name}": {param.client_name},') + retval.append("}") + return retval + def _get_json_response_template_to_status_codes( builder: OperationType, ) -> Dict[str, List[str]]: @@ -739,6 +750,9 @@ def _serialize_body_parameter(self, builder: OperationType) -> List[str]: This function serializes the body params that need to be serialized. """ body_param = builder.parameters.body_parameter + if body_param.entries: + """This means we're in legacy code bc m4 gives us the formdata entries as a list of body params""" + return _serialize_multipart_body(builder) if body_param.is_form_data: retval = [ f"_body = {body_param.client_name}.as_dict() if isinstance({body_param.client_name}, _model_base.Model) else {body_param.client_name}", @@ -812,6 +826,8 @@ def _create_body_parameter( """Create the body parameter before we pass it as either json or content to the request builder""" retval = [] body_param = builder.parameters.body_parameter + if body_param.entries: + return _serialize_multipart_body(builder) body_kwarg_name = builder.request_builder.parameters.body_parameter.client_name body_param_type = body_param.type if isinstance(body_param_type, BinaryType) or ( @@ -971,7 +987,11 @@ def _create_request_builder_call( f" {parameter.client_name}={parameter.name_in_high_level_operation}," f"{' # type: ignore' if type_ignore else ''}" ) - if request_builder.has_form_data_body: + if builder.parameters.has_body and builder.parameters.body_parameter.entries: + # this is for legacy + client_name = builder.parameters.body_parameter.client_name + retval.append(f" {client_name}=_{client_name},") + elif request_builder.has_form_data_body: retval.append(" files=_files,") retval.append(" data=_data,") elif request_builder.overloads: diff --git a/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/BodyFormData/bodyformdata/_vendor.py b/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/BodyFormData/bodyformdata/_vendor.py index 0dafe0e287f..d51e5941911 100644 --- a/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/BodyFormData/bodyformdata/_vendor.py +++ b/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/BodyFormData/bodyformdata/_vendor.py @@ -5,6 +5,8 @@ # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- +from typing import IO, Mapping, Optional, Sequence, Tuple, Union + from azure.core.pipeline.transport import HttpRequest @@ -14,3 +16,18 @@ def _convert_request(request, files=None): if files: request.set_formdata_body(files) return request + + +# file-like tuple could be `(filename, IO (or bytes))` or `(filename, IO (or bytes), content_type)` +FileContent = Union[str, bytes, IO[str], IO[bytes]] + +FileType = Union[ + # file (or bytes) + FileContent, + # (filename, file (or bytes)) + Tuple[Optional[str], FileContent], + # (filename, file (or bytes), content_type) + Tuple[Optional[str], FileContent, Optional[str]], +] + +FilesType = Union[Mapping[str, FileType], Sequence[Tuple[str, FileType]]] diff --git a/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/BodyFormData/bodyformdata/operations/_formdata_operations.py b/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/BodyFormData/bodyformdata/operations/_formdata_operations.py index ea9caede046..b9277f81b55 100644 --- a/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/BodyFormData/bodyformdata/operations/_formdata_operations.py +++ b/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/BodyFormData/bodyformdata/operations/_formdata_operations.py @@ -43,8 +43,6 @@ def build_upload_file_request(**kwargs: Any) -> HttpRequest: _url = kwargs.pop("template_url", "/formdata/stream/uploadfile") # Construct headers - if content_type is not None: - _headers["Content-Type"] = _SERIALIZER.header("content_type", content_type, "str") _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") return HttpRequest(method="POST", url=_url, headers=_headers, **kwargs) @@ -77,8 +75,6 @@ def build_upload_files_request(**kwargs: Any) -> HttpRequest: _url = kwargs.pop("template_url", "/formdata/stream/uploadfiles") # Construct headers - if content_type is not None: - _headers["Content-Type"] = _SERIALIZER.header("content_type", content_type, "str") _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") return HttpRequest(method="POST", url=_url, headers=_headers, **kwargs) diff --git a/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/BodyFormUrlEncodedData/bodyformurlencodeddata/_vendor.py b/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/BodyFormUrlEncodedData/bodyformurlencodeddata/_vendor.py index 0dafe0e287f..d51e5941911 100644 --- a/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/BodyFormUrlEncodedData/bodyformurlencodeddata/_vendor.py +++ b/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/BodyFormUrlEncodedData/bodyformurlencodeddata/_vendor.py @@ -5,6 +5,8 @@ # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- +from typing import IO, Mapping, Optional, Sequence, Tuple, Union + from azure.core.pipeline.transport import HttpRequest @@ -14,3 +16,18 @@ def _convert_request(request, files=None): if files: request.set_formdata_body(files) return request + + +# file-like tuple could be `(filename, IO (or bytes))` or `(filename, IO (or bytes), content_type)` +FileContent = Union[str, bytes, IO[str], IO[bytes]] + +FileType = Union[ + # file (or bytes) + FileContent, + # (filename, file (or bytes)) + Tuple[Optional[str], FileContent], + # (filename, file (or bytes), content_type) + Tuple[Optional[str], FileContent, Optional[str]], +] + +FilesType = Union[Mapping[str, FileType], Sequence[Tuple[str, FileType]]] diff --git a/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/BodyFormUrlEncodedData/bodyformurlencodeddata/aio/operations/_formdataurlencoded_operations.py b/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/BodyFormUrlEncodedData/bodyformurlencodeddata/aio/operations/_formdataurlencoded_operations.py index 4f6fb3e23d3..438f836642b 100644 --- a/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/BodyFormUrlEncodedData/bodyformurlencodeddata/aio/operations/_formdataurlencoded_operations.py +++ b/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/BodyFormUrlEncodedData/bodyformurlencodeddata/aio/operations/_formdataurlencoded_operations.py @@ -69,17 +69,17 @@ async def update_pet_with_form( # pylint: disable=inconsistent-return-statement :param pet_id: ID of pet that needs to be updated. Required. :type pet_id: int - :param pet_type: Can take a value of dog, or cat, or fish. Known values are: "dog", "cat", and + :param pet_type: Can take a value of dog, or cat, or fish Known values are: "dog", "cat", and "fish". Required. :type pet_type: str or ~bodyformurlencodeddata.models.PetType - :param pet_food: Can take a value of meat, or fish, or plant. Known values are: "meat", "fish", + :param pet_food: Can take a value of meat, or fish, or plant Known values are: "meat", "fish", and "plant". Required. :type pet_food: str or ~bodyformurlencodeddata.models.PetFood - :param pet_age: How many years is it old?. Required. + :param pet_age: How many years is it old? Required. :type pet_age: int - :param name: Updated name of the pet. Default value is None. + :param name: Updated name of the pet Default value is None. :type name: str - :param status: Updated status of the pet. Default value is None. + :param status: Updated status of the pet Default value is None. :type status: str :return: None or the result of cls(response) :rtype: None diff --git a/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/BodyFormUrlEncodedData/bodyformurlencodeddata/operations/_formdataurlencoded_operations.py b/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/BodyFormUrlEncodedData/bodyformurlencodeddata/operations/_formdataurlencoded_operations.py index d433472feed..cf0cf3b527a 100644 --- a/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/BodyFormUrlEncodedData/bodyformurlencodeddata/operations/_formdataurlencoded_operations.py +++ b/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/BodyFormUrlEncodedData/bodyformurlencodeddata/operations/_formdataurlencoded_operations.py @@ -45,10 +45,6 @@ def build_update_pet_with_form_request(pet_id: int, **kwargs: Any) -> HttpReques _url: str = _url.format(**path_format_arguments) # type: ignore - # Construct headers - if content_type is not None: - _headers["Content-Type"] = _SERIALIZER.header("content_type", content_type, "str") - return HttpRequest(method="POST", url=_url, headers=_headers, **kwargs) @@ -59,10 +55,6 @@ def build_partial_constant_body_request(**kwargs: Any) -> HttpRequest: # Construct URL _url = kwargs.pop("template_url", "/formsdataurlencoded/partialConstantBody") - # Construct headers - if content_type is not None: - _headers["Content-Type"] = _SERIALIZER.header("content_type", content_type, "str") - return HttpRequest(method="POST", url=_url, headers=_headers, **kwargs) @@ -102,17 +94,17 @@ def update_pet_with_form( # pylint: disable=inconsistent-return-statements :param pet_id: ID of pet that needs to be updated. Required. :type pet_id: int - :param pet_type: Can take a value of dog, or cat, or fish. Known values are: "dog", "cat", and + :param pet_type: Can take a value of dog, or cat, or fish Known values are: "dog", "cat", and "fish". Required. :type pet_type: str or ~bodyformurlencodeddata.models.PetType - :param pet_food: Can take a value of meat, or fish, or plant. Known values are: "meat", "fish", + :param pet_food: Can take a value of meat, or fish, or plant Known values are: "meat", "fish", and "plant". Required. :type pet_food: str or ~bodyformurlencodeddata.models.PetFood - :param pet_age: How many years is it old?. Required. + :param pet_age: How many years is it old? Required. :type pet_age: int - :param name: Updated name of the pet. Default value is None. + :param name: Updated name of the pet Default value is None. :type name: str - :param status: Updated status of the pet. Default value is None. + :param status: Updated status of the pet Default value is None. :type status: str :return: None or the result of cls(response) :rtype: None diff --git a/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/ReservedWords/reservedwords/_vendor.py b/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/ReservedWords/reservedwords/_vendor.py index 3cde08fb119..139a35090aa 100644 --- a/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/ReservedWords/reservedwords/_vendor.py +++ b/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/ReservedWords/reservedwords/_vendor.py @@ -6,7 +6,7 @@ # -------------------------------------------------------------------------- from abc import ABC -from typing import TYPE_CHECKING +from typing import IO, Mapping, Optional, Sequence, TYPE_CHECKING, Tuple, Union from azure.core.pipeline.transport import HttpRequest @@ -34,3 +34,18 @@ class ReservedWordsClientMixinABC(ABC): _config: ReservedWordsClientConfiguration _serialize: "Serializer" _deserialize: "Deserializer" + + +# file-like tuple could be `(filename, IO (or bytes))` or `(filename, IO (or bytes), content_type)` +FileContent = Union[str, bytes, IO[str], IO[bytes]] + +FileType = Union[ + # file (or bytes) + FileContent, + # (filename, file (or bytes)) + Tuple[Optional[str], FileContent], + # (filename, file (or bytes), content_type) + Tuple[Optional[str], FileContent, Optional[str]], +] + +FilesType = Union[Mapping[str, FileType], Sequence[Tuple[str, FileType]]] diff --git a/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/ReservedWords/reservedwords/aio/_vendor.py b/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/ReservedWords/reservedwords/aio/_vendor.py index 6546cfae4fe..af0c05d9373 100644 --- a/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/ReservedWords/reservedwords/aio/_vendor.py +++ b/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/ReservedWords/reservedwords/aio/_vendor.py @@ -6,7 +6,7 @@ # -------------------------------------------------------------------------- from abc import ABC -from typing import TYPE_CHECKING +from typing import IO, Mapping, Optional, Sequence, TYPE_CHECKING, Tuple, Union from azure.core.pipeline.transport import HttpRequest @@ -26,3 +26,18 @@ class ReservedWordsClientMixinABC(ABC): _config: ReservedWordsClientConfiguration _serialize: "Serializer" _deserialize: "Deserializer" + + +# file-like tuple could be `(filename, IO (or bytes))` or `(filename, IO (or bytes), content_type)` +FileContent = Union[str, bytes, IO[str], IO[bytes]] + +FileType = Union[ + # file (or bytes) + FileContent, + # (filename, file (or bytes)) + Tuple[Optional[str], FileContent], + # (filename, file (or bytes), content_type) + Tuple[Optional[str], FileContent, Optional[str]], +] + +FilesType = Union[Mapping[str, FileType], Sequence[Tuple[str, FileType]]] 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 f8102daa913..5323b6bef9c 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 @@ -216,7 +216,7 @@ async def operation_with_data_param(self, data: str, world: str, **kwargs: Any) async def operation_with_files_param(self, files: IO[bytes], file_name: str, **kwargs: Any) -> JSON: """Operation with multipart body param called 'files'. - :param files: Files to upload. Pass in list of input streams. Required. + :param files: Files to upload. Pass in list of input streams Required. :type files: IO[bytes] :param file_name: File name to upload. Pass in 'my.txt'. Required. :type file_name: str 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 454473bb63b..b845d77ac69 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 @@ -85,8 +85,6 @@ def build_operation_with_data_param_request(**kwargs: Any) -> HttpRequest: _url = kwargs.pop("template_url", "/reservedWords/operation/data") # Construct headers - if content_type is not None: - _headers["Content-Type"] = _SERIALIZER.header("content_type", content_type, "str") _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") return HttpRequest(method="PUT", url=_url, headers=_headers, **kwargs) @@ -102,8 +100,6 @@ def build_operation_with_files_param_request(**kwargs: Any) -> HttpRequest: _url = kwargs.pop("template_url", "/reservedWords/operation/files") # Construct headers - if content_type is not None: - _headers["Content-Type"] = _SERIALIZER.header("content_type", content_type, "str") _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") return HttpRequest(method="PUT", url=_url, headers=_headers, **kwargs) @@ -325,7 +321,7 @@ def operation_with_data_param(self, data: str, world: str, **kwargs: Any) -> JSO def operation_with_files_param(self, files: IO[bytes], file_name: str, **kwargs: Any) -> JSON: """Operation with multipart body param called 'files'. - :param files: Files to upload. Pass in list of input streams. Required. + :param files: Files to upload. Pass in list of input streams Required. :type files: IO[bytes] :param file_name: File name to upload. Pass in 'my.txt'. Required. :type file_name: str From 913c3f562a1be827d8eaf54562871a8c9af9db45 Mon Sep 17 00:00:00 2001 From: iscai-msft Date: Wed, 31 Jan 2024 22:56:56 -0500 Subject: [PATCH 19/45] remove file_properties --- .../autorest/codegen/models/parameter.py | 19 ------------------- 1 file changed, 19 deletions(-) diff --git a/packages/autorest.python/autorest/codegen/models/parameter.py b/packages/autorest.python/autorest/codegen/models/parameter.py index 8e26f82d9a7..74434d72a3f 100644 --- a/packages/autorest.python/autorest/codegen/models/parameter.py +++ b/packages/autorest.python/autorest/codegen/models/parameter.py @@ -290,25 +290,6 @@ def has_json_model_type(self) -> bool: return self.type.target_model_subtype((JSONModelType,)) is not None return isinstance(self.type, JSONModelType) - @property - def file_properties(self) -> List[str]: - model_type = None - if isinstance(self.type, CombinedType): - model_type = self.type.target_model_subtype((JSONModelType, DPGModelType)) - elif isinstance(self.type, (JSONModelType, DPGModelType)): - model_type = self.type - if model_type is None: - return [] - return [ - prop.wire_name - for prop in model_type.properties - if isinstance(prop.type, ByteArraySchema) - or ( - isinstance(prop.type, ListType) - and isinstance(prop.type.element_type, ByteArraySchema) - ) - ] - @classmethod def from_yaml( cls, yaml_data: Dict[str, Any], code_model: "CodeModel" From 34d97256a344b4759dbe31b2cf20acf50f3da554 Mon Sep 17 00:00:00 2001 From: iscai-msft Date: Wed, 31 Jan 2024 23:02:21 -0500 Subject: [PATCH 20/45] add back doc formatting --- .../autorest/codegen/serializers/builder_serializer.py | 3 --- .../autorest.python/autorest/preprocess/__init__.py | 2 ++ .../aio/operations/_formdataurlencoded_operations.py | 10 +++++----- .../operations/_formdataurlencoded_operations.py | 10 +++++----- .../operations/_reserved_words_client_operations.py | 2 +- .../operations/_reserved_words_client_operations.py | 2 +- 6 files changed, 14 insertions(+), 15 deletions(-) diff --git a/packages/autorest.python/autorest/codegen/serializers/builder_serializer.py b/packages/autorest.python/autorest/codegen/serializers/builder_serializer.py index 2f9ea4da124..bebe81baa41 100644 --- a/packages/autorest.python/autorest/codegen/serializers/builder_serializer.py +++ b/packages/autorest.python/autorest/codegen/serializers/builder_serializer.py @@ -750,9 +750,6 @@ def _serialize_body_parameter(self, builder: OperationType) -> List[str]: This function serializes the body params that need to be serialized. """ body_param = builder.parameters.body_parameter - if body_param.entries: - """This means we're in legacy code bc m4 gives us the formdata entries as a list of body params""" - return _serialize_multipart_body(builder) if body_param.is_form_data: retval = [ f"_body = {body_param.client_name}.as_dict() if isinstance({body_param.client_name}, _model_base.Model) else {body_param.client_name}", diff --git a/packages/autorest.python/autorest/preprocess/__init__.py b/packages/autorest.python/autorest/preprocess/__init__.py index 45f0ea2c2d9..51d3073af6c 100644 --- a/packages/autorest.python/autorest/preprocess/__init__.py +++ b/packages/autorest.python/autorest/preprocess/__init__.py @@ -421,6 +421,8 @@ def update_operation( self.update_parameter(parameter) if yaml_data.get("bodyParameter"): self.update_parameter(yaml_data["bodyParameter"]) + for entry in yaml_data["bodyParameter"].get("entries", []): + self.update_parameter(entry) for overload in yaml_data.get("overloads", []): self.update_operation(code_model, overload, is_overload=True) for response in yaml_data.get("responses", []): diff --git a/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/BodyFormUrlEncodedData/bodyformurlencodeddata/aio/operations/_formdataurlencoded_operations.py b/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/BodyFormUrlEncodedData/bodyformurlencodeddata/aio/operations/_formdataurlencoded_operations.py index 438f836642b..4f6fb3e23d3 100644 --- a/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/BodyFormUrlEncodedData/bodyformurlencodeddata/aio/operations/_formdataurlencoded_operations.py +++ b/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/BodyFormUrlEncodedData/bodyformurlencodeddata/aio/operations/_formdataurlencoded_operations.py @@ -69,17 +69,17 @@ async def update_pet_with_form( # pylint: disable=inconsistent-return-statement :param pet_id: ID of pet that needs to be updated. Required. :type pet_id: int - :param pet_type: Can take a value of dog, or cat, or fish Known values are: "dog", "cat", and + :param pet_type: Can take a value of dog, or cat, or fish. Known values are: "dog", "cat", and "fish". Required. :type pet_type: str or ~bodyformurlencodeddata.models.PetType - :param pet_food: Can take a value of meat, or fish, or plant Known values are: "meat", "fish", + :param pet_food: Can take a value of meat, or fish, or plant. Known values are: "meat", "fish", and "plant". Required. :type pet_food: str or ~bodyformurlencodeddata.models.PetFood - :param pet_age: How many years is it old? Required. + :param pet_age: How many years is it old?. Required. :type pet_age: int - :param name: Updated name of the pet Default value is None. + :param name: Updated name of the pet. Default value is None. :type name: str - :param status: Updated status of the pet Default value is None. + :param status: Updated status of the pet. Default value is None. :type status: str :return: None or the result of cls(response) :rtype: None diff --git a/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/BodyFormUrlEncodedData/bodyformurlencodeddata/operations/_formdataurlencoded_operations.py b/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/BodyFormUrlEncodedData/bodyformurlencodeddata/operations/_formdataurlencoded_operations.py index cf0cf3b527a..d9ec7d6a4e9 100644 --- a/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/BodyFormUrlEncodedData/bodyformurlencodeddata/operations/_formdataurlencoded_operations.py +++ b/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/BodyFormUrlEncodedData/bodyformurlencodeddata/operations/_formdataurlencoded_operations.py @@ -94,17 +94,17 @@ def update_pet_with_form( # pylint: disable=inconsistent-return-statements :param pet_id: ID of pet that needs to be updated. Required. :type pet_id: int - :param pet_type: Can take a value of dog, or cat, or fish Known values are: "dog", "cat", and + :param pet_type: Can take a value of dog, or cat, or fish. Known values are: "dog", "cat", and "fish". Required. :type pet_type: str or ~bodyformurlencodeddata.models.PetType - :param pet_food: Can take a value of meat, or fish, or plant Known values are: "meat", "fish", + :param pet_food: Can take a value of meat, or fish, or plant. Known values are: "meat", "fish", and "plant". Required. :type pet_food: str or ~bodyformurlencodeddata.models.PetFood - :param pet_age: How many years is it old? Required. + :param pet_age: How many years is it old?. Required. :type pet_age: int - :param name: Updated name of the pet Default value is None. + :param name: Updated name of the pet. Default value is None. :type name: str - :param status: Updated status of the pet Default value is None. + :param status: Updated status of the pet. Default value is None. :type status: str :return: None or the result of cls(response) :rtype: None 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 5323b6bef9c..f8102daa913 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 @@ -216,7 +216,7 @@ async def operation_with_data_param(self, data: str, world: str, **kwargs: Any) async def operation_with_files_param(self, files: IO[bytes], file_name: str, **kwargs: Any) -> JSON: """Operation with multipart body param called 'files'. - :param files: Files to upload. Pass in list of input streams Required. + :param files: Files to upload. Pass in list of input streams. Required. :type files: IO[bytes] :param file_name: File name to upload. Pass in 'my.txt'. Required. :type file_name: str 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 b845d77ac69..992255d37fc 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 @@ -321,7 +321,7 @@ def operation_with_data_param(self, data: str, world: str, **kwargs: Any) -> JSO def operation_with_files_param(self, files: IO[bytes], file_name: str, **kwargs: Any) -> JSON: """Operation with multipart body param called 'files'. - :param files: Files to upload. Pass in list of input streams Required. + :param files: Files to upload. Pass in list of input streams. Required. :type files: IO[bytes] :param file_name: File name to upload. Pass in 'my.txt'. Required. :type file_name: str From 915f34b36fea32d7f1557130f5ccefdac6aafb39 Mon Sep 17 00:00:00 2001 From: iscai-msft Date: Wed, 31 Jan 2024 23:05:51 -0500 Subject: [PATCH 21/45] black --- .../autorest/codegen/models/base.py | 2 +- .../autorest/codegen/models/combined_type.py | 2 +- .../autorest/codegen/models/model_type.py | 14 ++++++------ .../autorest/codegen/models/parameter.py | 6 ++++- .../autorest/codegen/models/parameter_list.py | 4 +--- .../codegen/models/primitive_types.py | 1 + .../autorest/codegen/models/property.py | 4 +++- .../models/request_builder_parameter.py | 1 + .../codegen/serializers/builder_serializer.py | 22 +++++++++++++++---- .../codegen/serializers/model_serializer.py | 2 +- 10 files changed, 39 insertions(+), 19 deletions(-) diff --git a/packages/autorest.python/autorest/codegen/models/base.py b/packages/autorest.python/autorest/codegen/models/base.py index 01b4fa2b264..a7e1c1a398f 100644 --- a/packages/autorest.python/autorest/codegen/models/base.py +++ b/packages/autorest.python/autorest/codegen/models/base.py @@ -186,7 +186,7 @@ def serialization_constraints(self) -> List[str]: @property def type_description(self) -> str: return self.type_annotation() - + @property def is_form_data(self) -> bool: return False diff --git a/packages/autorest.python/autorest/codegen/models/combined_type.py b/packages/autorest.python/autorest/codegen/models/combined_type.py index 9bb239fb17b..601d3cda3ec 100644 --- a/packages/autorest.python/autorest/codegen/models/combined_type.py +++ b/packages/autorest.python/autorest/codegen/models/combined_type.py @@ -78,7 +78,7 @@ def type_definition(self, **kwargs: Any) -> str: # If the inside types has been a Union, peel first and then re-union pattern = re.compile(r"Union\[.*\]") return f'Union[{", ".join(map(lambda x: x[6: -1] if pattern.match(x) else x, inside_types))}]' - + @property def is_form_data(self) -> bool: return any(t.is_form_data for t in self.types) diff --git a/packages/autorest.python/autorest/codegen/models/model_type.py b/packages/autorest.python/autorest/codegen/models/model_type.py index ecc8e9f2f95..54068689efb 100644 --- a/packages/autorest.python/autorest/codegen/models/model_type.py +++ b/packages/autorest.python/autorest/codegen/models/model_type.py @@ -320,13 +320,13 @@ def imports(self, **kwargs: Any) -> FileImport: ) if self.is_form_data: file_import.add_submodule_import( - relative_path, - "_model_base", - ImportType.LOCAL, - typing_section=TypingSection.TYPING - if kwargs.get("model_typing") - else TypingSection.REGULAR, - ) + relative_path, + "_model_base", + ImportType.LOCAL, + typing_section=TypingSection.TYPING + if kwargs.get("model_typing") + else TypingSection.REGULAR, + ) if any(not p.is_multipart_file_input for p in self.properties): file_import.add_submodule_import( f"{relative_path}_model_base", diff --git a/packages/autorest.python/autorest/codegen/models/parameter.py b/packages/autorest.python/autorest/codegen/models/parameter.py index 74434d72a3f..0f5e506f05f 100644 --- a/packages/autorest.python/autorest/codegen/models/parameter.py +++ b/packages/autorest.python/autorest/codegen/models/parameter.py @@ -247,7 +247,10 @@ class BodyParameter(_ParameterBase): @property def entries(self) -> List[str]: - return [BodyParameter.from_yaml(e, self.code_model) for e in self.yaml_data.get("entries", [])] + return [ + BodyParameter.from_yaml(e, self.code_model) + for e in self.yaml_data.get("entries", []) + ] @property def is_form_data(self) -> bool: @@ -305,6 +308,7 @@ def from_yaml( "EntryBodyParameterType", bound=Union[BodyParameter, "RequestBuilderBodyParameter"] ) + class Parameter(_ParameterBase): """Basic Parameter class""" diff --git a/packages/autorest.python/autorest/codegen/models/parameter_list.py b/packages/autorest.python/autorest/codegen/models/parameter_list.py index f57e8be91a5..72d4db4cebb 100644 --- a/packages/autorest.python/autorest/codegen/models/parameter_list.py +++ b/packages/autorest.python/autorest/codegen/models/parameter_list.py @@ -317,9 +317,7 @@ def parameter_creator() -> Callable[[Dict[str, Any], "CodeModel"], Parameter]: @staticmethod def body_parameter_creator() -> ( - Callable[ - [Dict[str, Any], "CodeModel"], BodyParameter - ] + Callable[[Dict[str, Any], "CodeModel"], BodyParameter] ): return BodyParameter.from_yaml diff --git a/packages/autorest.python/autorest/codegen/models/primitive_types.py b/packages/autorest.python/autorest/codegen/models/primitive_types.py index 3b265e634d3..9c1d8d29e5d 100644 --- a/packages/autorest.python/autorest/codegen/models/primitive_types.py +++ b/packages/autorest.python/autorest/codegen/models/primitive_types.py @@ -81,6 +81,7 @@ def docstring_type(self, **kwargs: Any) -> str: def instance_check_template(self) -> str: return "isinstance({}, bool)" + class BinaryType(PrimitiveType): def __init__(self, yaml_data: Dict[str, Any], code_model: "CodeModel") -> None: super().__init__(yaml_data=yaml_data, code_model=code_model) diff --git a/packages/autorest.python/autorest/codegen/models/property.py b/packages/autorest.python/autorest/codegen/models/property.py index 3de87054560..62142a19316 100644 --- a/packages/autorest.python/autorest/codegen/models/property.py +++ b/packages/autorest.python/autorest/codegen/models/property.py @@ -37,7 +37,9 @@ def __init__( if self.client_default_value is None: self.client_default_value = self.type.client_default_value self.flattened_names: List[str] = yaml_data.get("flattenedNames", []) - self.is_multipart_file_input: bool = yaml_data.get("isMultipartFileInput", False) + self.is_multipart_file_input: bool = yaml_data.get( + "isMultipartFileInput", False + ) @property def pylint_disable(self) -> str: diff --git a/packages/autorest.python/autorest/codegen/models/request_builder_parameter.py b/packages/autorest.python/autorest/codegen/models/request_builder_parameter.py index b980959cafe..33542aca289 100644 --- a/packages/autorest.python/autorest/codegen/models/request_builder_parameter.py +++ b/packages/autorest.python/autorest/codegen/models/request_builder_parameter.py @@ -65,6 +65,7 @@ def name_in_high_level_operation(self) -> str: return "_json" return "_content" + class RequestBuilderParameter(Parameter): """Basic RequestBuilder Parameter.""" diff --git a/packages/autorest.python/autorest/codegen/serializers/builder_serializer.py b/packages/autorest.python/autorest/codegen/serializers/builder_serializer.py index bebe81baa41..fd67fbf80f4 100644 --- a/packages/autorest.python/autorest/codegen/serializers/builder_serializer.py +++ b/packages/autorest.python/autorest/codegen/serializers/builder_serializer.py @@ -203,6 +203,7 @@ def _serialize_json_model_body( retval.append(" }") return retval + def _serialize_multipart_body(builder: BuilderType) -> List[str]: retval: List[str] = [] body_param = builder.parameters.body_parameter @@ -214,6 +215,7 @@ def _serialize_multipart_body(builder: BuilderType) -> List[str]: retval.append("}") return retval + def _get_json_response_template_to_status_codes( builder: OperationType, ) -> Dict[str, List[str]]: @@ -756,18 +758,30 @@ def _serialize_body_parameter(self, builder: OperationType) -> List[str]: "_files = []", "_data = {}", ] - model_type = body_param.type.target_model_subtype((JSONModelType, DPGModelType)) if isinstance(body_param.type, CombinedType) else body_param.type + model_type = ( + body_param.type.target_model_subtype((JSONModelType, DPGModelType)) + if isinstance(body_param.type, CombinedType) + else body_param.type + ) for prop in model_type.properties: prop_access = f'_body["{prop.wire_name}"]' retval.append(f'if _body.get("{prop.wire_name}") is not None:') if prop.is_multipart_file_input: if isinstance(prop.type, ListType): - retval.append(f' _files.extend([("{prop.wire_name}", {prop.wire_name[0]}) for {prop.wire_name[0]} in {prop_access}])') + retval.append( + f' _files.extend([("{prop.wire_name}", {prop.wire_name[0]}) for {prop.wire_name[0]} in {prop_access}])' + ) else: # we assume that it's just a single multipart file input - retval.append(f' _files.append(("{prop.wire_name}", {prop_access}))') + retval.append( + f' _files.append(("{prop.wire_name}", {prop_access}))' + ) else: - serialization = f"json.dumps({prop_access}, cls=SdkJSONEncoder, exclude_readonly=True)" if prop.type.type in ["list", "tuple", "dict", "model"] else prop_access + serialization = ( + f"json.dumps({prop_access}, cls=SdkJSONEncoder, exclude_readonly=True)" + if prop.type.type in ["list", "tuple", "dict", "model"] + else prop_access + ) retval.append(f' _data["{prop.wire_name}"] = {serialization}') return retval retval: List[str] = [] diff --git a/packages/autorest.python/autorest/codegen/serializers/model_serializer.py b/packages/autorest.python/autorest/codegen/serializers/model_serializer.py index d143ff16793..2fb37d15279 100644 --- a/packages/autorest.python/autorest/codegen/serializers/model_serializer.py +++ b/packages/autorest.python/autorest/codegen/serializers/model_serializer.py @@ -257,7 +257,7 @@ def declare_property(prop: Property) -> str: args.append(f"visibility=[{v_list}]") if prop.client_default_value is not None: args.append(f"default={prop.client_default_value_declaration}") - + if prop.is_multipart_file_input: args.append("is_multipart_file_input=True") elif hasattr(prop.type, "encode") and prop.type.encode: # type: ignore From 4a887a10e803483955131de0ced3bb1c878ec0b8 Mon Sep 17 00:00:00 2001 From: iscai-msft Date: Thu, 1 Feb 2024 13:19:05 -0500 Subject: [PATCH 22/45] linting checks --- .../autorest/codegen/models/parameter.py | 9 ++---- .../models/request_builder_parameter.py | 2 +- .../codegen/serializers/builder_serializer.py | 30 +++++++++++++------ 3 files changed, 25 insertions(+), 16 deletions(-) diff --git a/packages/autorest.python/autorest/codegen/models/parameter.py b/packages/autorest.python/autorest/codegen/models/parameter.py index 0f5e506f05f..49fa21c2a54 100644 --- a/packages/autorest.python/autorest/codegen/models/parameter.py +++ b/packages/autorest.python/autorest/codegen/models/parameter.py @@ -14,7 +14,6 @@ Optional, TypeVar, Union, - Generic, ) from .imports import FileImport, ImportType, TypingSection @@ -23,9 +22,7 @@ from .constant_type import ConstantType from .utils import add_to_description from .combined_type import CombinedType -from .model_type import JSONModelType, DPGModelType, ModelType -from .primitive_types import ByteArraySchema -from .list_type import ListType +from .model_type import JSONModelType if TYPE_CHECKING: from .code_model import CodeModel @@ -246,7 +243,7 @@ class BodyParameter(_ParameterBase): """Body parameter.""" @property - def entries(self) -> List[str]: + def entries(self) -> List["BodyParameter"]: return [ BodyParameter.from_yaml(e, self.code_model) for e in self.yaml_data.get("entries", []) @@ -256,7 +253,7 @@ def entries(self) -> List[str]: def is_form_data(self) -> bool: # hacky, but rn in legacy, there is no formdata model type, it's just a dict # with all of the entries splatted out - return self.type.is_form_data or self.entries + return self.type.is_form_data or bool(self.entries) @property def is_partial_body(self) -> bool: diff --git a/packages/autorest.python/autorest/codegen/models/request_builder_parameter.py b/packages/autorest.python/autorest/codegen/models/request_builder_parameter.py index 33542aca289..fb6488b7b57 100644 --- a/packages/autorest.python/autorest/codegen/models/request_builder_parameter.py +++ b/packages/autorest.python/autorest/codegen/models/request_builder_parameter.py @@ -3,7 +3,7 @@ # Licensed under the MIT License. See License.txt in the project root for # license information. # -------------------------------------------------------------------------- -from typing import TYPE_CHECKING, Any, Dict, Union +from typing import TYPE_CHECKING, Any, Dict from .parameter import ( ParameterLocation, ParameterMethodLocation, diff --git a/packages/autorest.python/autorest/codegen/serializers/builder_serializer.py b/packages/autorest.python/autorest/codegen/serializers/builder_serializer.py index fd67fbf80f4..6d6250bab67 100644 --- a/packages/autorest.python/autorest/codegen/serializers/builder_serializer.py +++ b/packages/autorest.python/autorest/codegen/serializers/builder_serializer.py @@ -751,25 +751,37 @@ def _serialize_body_parameter(self, builder: OperationType) -> List[str]: This function serializes the body params that need to be serialized. """ + retval: List[str] = [] body_param = builder.parameters.body_parameter if body_param.is_form_data: - retval = [ - f"_body = {body_param.client_name}.as_dict() if isinstance({body_param.client_name}, _model_base.Model) else {body_param.client_name}", - "_files = []", - "_data = {}", - ] + retval.extend( + [ + "_body = (", + f" {body_param.client_name}.as_dict()", + f" if isinstance({body_param.client_name}, _model_base.Model) else", + f" {body_param.client_name}", + ")", + "_files = []", + "_data = {}", + ] + ) model_type = ( body_param.type.target_model_subtype((JSONModelType, DPGModelType)) if isinstance(body_param.type, CombinedType) else body_param.type ) - for prop in model_type.properties: + # we know that body param is a model type because it's a formdata + for prop in cast(ModelType, model_type).properties: prop_access = f'_body["{prop.wire_name}"]' retval.append(f'if _body.get("{prop.wire_name}") is not None:') if prop.is_multipart_file_input: if isinstance(prop.type, ListType): - retval.append( - f' _files.extend([("{prop.wire_name}", {prop.wire_name[0]}) for {prop.wire_name[0]} in {prop_access}])' + retval.extend( + [ + " _files.extend([", + f' ("{prop.wire_name}", {prop.wire_name[0]})', + f'"for {prop.wire_name[0]} in {prop_access}])', + ] ) else: # we assume that it's just a single multipart file input @@ -784,7 +796,7 @@ def _serialize_body_parameter(self, builder: OperationType) -> List[str]: ) retval.append(f' _data["{prop.wire_name}"] = {serialization}') return retval - retval: List[str] = [] + body_kwarg_name = builder.request_builder.parameters.body_parameter.client_name send_xml = builder.parameters.body_parameter.type.is_xml xml_serialization_ctxt = ( From b41e539e93f2f21144a4401d61938cce169bfeda Mon Sep 17 00:00:00 2001 From: iscai-msft Date: Thu, 1 Feb 2024 13:34:21 -0500 Subject: [PATCH 23/45] fix gen and add dpg changes --- .../codegen/serializers/builder_serializer.py | 7 ++++--- .../bodyformdataversiontolerant/_vendor.py | 17 +++++++++++++++++ .../bodyformdataversiontolerant/aio/_vendor.py | 17 +++++++++++++++++ .../_vendor.py | 17 +++++++++++++++++ .../aio/_vendor.py | 17 +++++++++++++++++ .../reservedwordsversiontolerant/_vendor.py | 17 ++++++++++++++++- .../reservedwordsversiontolerant/aio/_vendor.py | 17 ++++++++++++++++- 7 files changed, 104 insertions(+), 5 deletions(-) diff --git a/packages/autorest.python/autorest/codegen/serializers/builder_serializer.py b/packages/autorest.python/autorest/codegen/serializers/builder_serializer.py index 6d6250bab67..db249b5b885 100644 --- a/packages/autorest.python/autorest/codegen/serializers/builder_serializer.py +++ b/packages/autorest.python/autorest/codegen/serializers/builder_serializer.py @@ -778,9 +778,10 @@ def _serialize_body_parameter(self, builder: OperationType) -> List[str]: if isinstance(prop.type, ListType): retval.extend( [ - " _files.extend([", - f' ("{prop.wire_name}", {prop.wire_name[0]})', - f'"for {prop.wire_name[0]} in {prop_access}])', + " _files.extend([", + f' ("{prop.wire_name}", {prop.wire_name[0]})', + f' for {prop.wire_name[0]} in {prop_access}', + "])", ] ) else: diff --git a/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/BodyFormDataVersionTolerant/bodyformdataversiontolerant/_vendor.py b/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/BodyFormDataVersionTolerant/bodyformdataversiontolerant/_vendor.py index 3e21ea6effc..0f5eae1293e 100644 --- a/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/BodyFormDataVersionTolerant/bodyformdataversiontolerant/_vendor.py +++ b/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/BodyFormDataVersionTolerant/bodyformdataversiontolerant/_vendor.py @@ -5,6 +5,8 @@ # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- +from typing import IO, Mapping, Optional, Sequence, Tuple, Union + def raise_if_not_implemented(cls, abstract_methods): not_implemented = [f for f in abstract_methods if not callable(getattr(cls, f, None))] @@ -15,3 +17,18 @@ def raise_if_not_implemented(cls, abstract_methods): cls.__name__, "', '".join(not_implemented) ) ) + + +# file-like tuple could be `(filename, IO (or bytes))` or `(filename, IO (or bytes), content_type)` +FileContent = Union[str, bytes, IO[str], IO[bytes]] + +FileType = Union[ + # file (or bytes) + FileContent, + # (filename, file (or bytes)) + Tuple[Optional[str], FileContent], + # (filename, file (or bytes), content_type) + Tuple[Optional[str], FileContent, Optional[str]], +] + +FilesType = Union[Mapping[str, FileType], Sequence[Tuple[str, FileType]]] diff --git a/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/BodyFormDataVersionTolerant/bodyformdataversiontolerant/aio/_vendor.py b/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/BodyFormDataVersionTolerant/bodyformdataversiontolerant/aio/_vendor.py index 3e21ea6effc..0f5eae1293e 100644 --- a/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/BodyFormDataVersionTolerant/bodyformdataversiontolerant/aio/_vendor.py +++ b/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/BodyFormDataVersionTolerant/bodyformdataversiontolerant/aio/_vendor.py @@ -5,6 +5,8 @@ # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- +from typing import IO, Mapping, Optional, Sequence, Tuple, Union + def raise_if_not_implemented(cls, abstract_methods): not_implemented = [f for f in abstract_methods if not callable(getattr(cls, f, None))] @@ -15,3 +17,18 @@ def raise_if_not_implemented(cls, abstract_methods): cls.__name__, "', '".join(not_implemented) ) ) + + +# file-like tuple could be `(filename, IO (or bytes))` or `(filename, IO (or bytes), content_type)` +FileContent = Union[str, bytes, IO[str], IO[bytes]] + +FileType = Union[ + # file (or bytes) + FileContent, + # (filename, file (or bytes)) + Tuple[Optional[str], FileContent], + # (filename, file (or bytes), content_type) + Tuple[Optional[str], FileContent, Optional[str]], +] + +FilesType = Union[Mapping[str, FileType], Sequence[Tuple[str, FileType]]] diff --git a/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/BodyFormUrlEncodedDataVersionTolerant/bodyformurlencodeddataversiontolerant/_vendor.py b/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/BodyFormUrlEncodedDataVersionTolerant/bodyformurlencodeddataversiontolerant/_vendor.py index 3e21ea6effc..0f5eae1293e 100644 --- a/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/BodyFormUrlEncodedDataVersionTolerant/bodyformurlencodeddataversiontolerant/_vendor.py +++ b/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/BodyFormUrlEncodedDataVersionTolerant/bodyformurlencodeddataversiontolerant/_vendor.py @@ -5,6 +5,8 @@ # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- +from typing import IO, Mapping, Optional, Sequence, Tuple, Union + def raise_if_not_implemented(cls, abstract_methods): not_implemented = [f for f in abstract_methods if not callable(getattr(cls, f, None))] @@ -15,3 +17,18 @@ def raise_if_not_implemented(cls, abstract_methods): cls.__name__, "', '".join(not_implemented) ) ) + + +# file-like tuple could be `(filename, IO (or bytes))` or `(filename, IO (or bytes), content_type)` +FileContent = Union[str, bytes, IO[str], IO[bytes]] + +FileType = Union[ + # file (or bytes) + FileContent, + # (filename, file (or bytes)) + Tuple[Optional[str], FileContent], + # (filename, file (or bytes), content_type) + Tuple[Optional[str], FileContent, Optional[str]], +] + +FilesType = Union[Mapping[str, FileType], Sequence[Tuple[str, FileType]]] diff --git a/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/BodyFormUrlEncodedDataVersionTolerant/bodyformurlencodeddataversiontolerant/aio/_vendor.py b/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/BodyFormUrlEncodedDataVersionTolerant/bodyformurlencodeddataversiontolerant/aio/_vendor.py index 3e21ea6effc..0f5eae1293e 100644 --- a/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/BodyFormUrlEncodedDataVersionTolerant/bodyformurlencodeddataversiontolerant/aio/_vendor.py +++ b/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/BodyFormUrlEncodedDataVersionTolerant/bodyformurlencodeddataversiontolerant/aio/_vendor.py @@ -5,6 +5,8 @@ # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- +from typing import IO, Mapping, Optional, Sequence, Tuple, Union + def raise_if_not_implemented(cls, abstract_methods): not_implemented = [f for f in abstract_methods if not callable(getattr(cls, f, None))] @@ -15,3 +17,18 @@ def raise_if_not_implemented(cls, abstract_methods): cls.__name__, "', '".join(not_implemented) ) ) + + +# file-like tuple could be `(filename, IO (or bytes))` or `(filename, IO (or bytes), content_type)` +FileContent = Union[str, bytes, IO[str], IO[bytes]] + +FileType = Union[ + # file (or bytes) + FileContent, + # (filename, file (or bytes)) + Tuple[Optional[str], FileContent], + # (filename, file (or bytes), content_type) + Tuple[Optional[str], FileContent, Optional[str]], +] + +FilesType = Union[Mapping[str, FileType], Sequence[Tuple[str, FileType]]] diff --git a/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/ReservedWordsVersionTolerant/reservedwordsversiontolerant/_vendor.py b/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/ReservedWordsVersionTolerant/reservedwordsversiontolerant/_vendor.py index e74c45edd94..aecce20a506 100644 --- a/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/ReservedWordsVersionTolerant/reservedwordsversiontolerant/_vendor.py +++ b/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/ReservedWordsVersionTolerant/reservedwordsversiontolerant/_vendor.py @@ -6,7 +6,7 @@ # -------------------------------------------------------------------------- from abc import ABC -from typing import TYPE_CHECKING +from typing import IO, Mapping, Optional, Sequence, TYPE_CHECKING, Tuple, Union from ._configuration import ReservedWordsClientConfiguration @@ -35,3 +35,18 @@ def raise_if_not_implemented(cls, abstract_methods): cls.__name__, "', '".join(not_implemented) ) ) + + +# file-like tuple could be `(filename, IO (or bytes))` or `(filename, IO (or bytes), content_type)` +FileContent = Union[str, bytes, IO[str], IO[bytes]] + +FileType = Union[ + # file (or bytes) + FileContent, + # (filename, file (or bytes)) + Tuple[Optional[str], FileContent], + # (filename, file (or bytes), content_type) + Tuple[Optional[str], FileContent, Optional[str]], +] + +FilesType = Union[Mapping[str, FileType], Sequence[Tuple[str, FileType]]] diff --git a/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/ReservedWordsVersionTolerant/reservedwordsversiontolerant/aio/_vendor.py b/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/ReservedWordsVersionTolerant/reservedwordsversiontolerant/aio/_vendor.py index 9f9d18ebb0e..6e90d195d87 100644 --- a/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/ReservedWordsVersionTolerant/reservedwordsversiontolerant/aio/_vendor.py +++ b/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/ReservedWordsVersionTolerant/reservedwordsversiontolerant/aio/_vendor.py @@ -6,7 +6,7 @@ # -------------------------------------------------------------------------- from abc import ABC -from typing import TYPE_CHECKING +from typing import IO, Mapping, Optional, Sequence, TYPE_CHECKING, Tuple, Union from ._configuration import ReservedWordsClientConfiguration @@ -35,3 +35,18 @@ def raise_if_not_implemented(cls, abstract_methods): cls.__name__, "', '".join(not_implemented) ) ) + + +# file-like tuple could be `(filename, IO (or bytes))` or `(filename, IO (or bytes), content_type)` +FileContent = Union[str, bytes, IO[str], IO[bytes]] + +FileType = Union[ + # file (or bytes) + FileContent, + # (filename, file (or bytes)) + Tuple[Optional[str], FileContent], + # (filename, file (or bytes), content_type) + Tuple[Optional[str], FileContent, Optional[str]], +] + +FilesType = Union[Mapping[str, FileType], Sequence[Tuple[str, FileType]]] From ca6646803f7e3a3c9de257f26e9066e3a44c6964 Mon Sep 17 00:00:00 2001 From: iscai-msft Date: Thu, 1 Feb 2024 13:42:33 -0500 Subject: [PATCH 24/45] remove multipartFile section from types --- packages/typespec-python/src/types.ts | 5 ----- 1 file changed, 5 deletions(-) diff --git a/packages/typespec-python/src/types.ts b/packages/typespec-python/src/types.ts index af95d7bd3ed..69b6cc979e0 100644 --- a/packages/typespec-python/src/types.ts +++ b/packages/typespec-python/src/types.ts @@ -85,11 +85,6 @@ export function getType( return emitDurationOrDateType(type); case "enumvalue": return emitEnumMember(type, emitEnum(type.enumType)); - case "multipartFile": - return getSimpleTypeResult({ - type: "bytes", - encode: "base64", - }); case "bytes": case "boolean": case "date": From 8734335fdcbf2344a6eb006dce11a43f8522df50 Mon Sep 17 00:00:00 2001 From: iscai-msft Date: Thu, 1 Feb 2024 13:49:17 -0500 Subject: [PATCH 25/45] run black --- .../autorest/codegen/serializers/builder_serializer.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/autorest.python/autorest/codegen/serializers/builder_serializer.py b/packages/autorest.python/autorest/codegen/serializers/builder_serializer.py index db249b5b885..bf69d02f4cb 100644 --- a/packages/autorest.python/autorest/codegen/serializers/builder_serializer.py +++ b/packages/autorest.python/autorest/codegen/serializers/builder_serializer.py @@ -780,7 +780,7 @@ def _serialize_body_parameter(self, builder: OperationType) -> List[str]: [ " _files.extend([", f' ("{prop.wire_name}", {prop.wire_name[0]})', - f' for {prop.wire_name[0]} in {prop_access}', + f" for {prop.wire_name[0]} in {prop_access}", "])", ] ) From fe191415a066c754063af216f741306a609b19cc Mon Sep 17 00:00:00 2001 From: iscai-msft Date: Thu, 1 Feb 2024 14:03:40 -0500 Subject: [PATCH 26/45] remove files added to azure mock api tests --- .../test_payload_multipart_async.py | 96 ------------ .../mock_api_tests/test_payload_multipart.py | 139 ------------------ 2 files changed, 235 deletions(-) delete mode 100644 packages/typespec-python/test/azure/mock_api_tests/asynctests/test_payload_multipart_async.py delete mode 100644 packages/typespec-python/test/azure/mock_api_tests/test_payload_multipart.py diff --git a/packages/typespec-python/test/azure/mock_api_tests/asynctests/test_payload_multipart_async.py b/packages/typespec-python/test/azure/mock_api_tests/asynctests/test_payload_multipart_async.py deleted file mode 100644 index f7f84666b03..00000000000 --- a/packages/typespec-python/test/azure/mock_api_tests/asynctests/test_payload_multipart_async.py +++ /dev/null @@ -1,96 +0,0 @@ -# ------------------------------------------------------------------------- -# Copyright (c) Microsoft Corporation. All rights reserved. -# Licensed under the MIT License. See License.txt in the project root for -# license information. -# -------------------------------------------------------------------------- -import uuid -from typing import Dict, Any -from pathlib import Path -import pytest -from payload.multipart.aio import MultiPartClient -from payload.multipart import models -from payload.multipart._model_base import Model - -JPG = Path(__file__).parent.parent.parent.parent / "generic_mock_api_tests/data/image.jpg" -PNG = Path(__file__).parent.parent.parent.parent / "generic_mock_api_tests/data/image.png" - - -@pytest.fixture -async def client(): - async with MultiPartClient(endpoint="http://localhost:3000") as client: - yield client - - -@pytest.mark.asyncio -@pytest.mark.parametrize( - "op_name,model_class,data,file,file_info", - [ - ("basic", models.MultiPartRequest, {"id": "123"}, {"profileImage": JPG}, {}), - ( - "multi_binary_parts", - models.MultiBinaryPartsRequest, - {}, - {"profileImage": JPG, "picture": PNG}, - {} - ), - ( - "multi_binary_parts", - models.MultiBinaryPartsRequest, - {}, - {"profileImage": JPG}, - {} - ), - ( - "json_part", - models.JsonPartRequest, - {"address": models.Address(city="X")}, - {"profileImage": JPG}, - {}, - ), - ( - "json_array_parts", - models.JsonArrayPartsRequest, - {"previousAddresses": [models.Address(city="Y"), models.Address(city="Z")]}, - {"profileImage": JPG}, - {}, - ), - ( - "binary_array_parts", - models.BinaryArrayPartsRequest, - {"id": "123"}, - {"pictures": [PNG, PNG]}, - {}, - ), - ( - "complex", - models.ComplexPartsRequest, - {"id": "123", "previousAddresses": [models.Address(city="Y"), models.Address(city="Z")], "address": models.Address(city="X")}, - {"pictures": [PNG, PNG], "profileImage": JPG}, - {}, - ), - ], -) -async def test_multi_part(client: MultiPartClient, op_name, model_class, data, file, file_info): - def add_info(file_path, is_bytes): - file_content = open(str(file_path), "rb").read() if is_bytes else open(str(file_path), "rb") - name = str(uuid.uuid4()) if file_info.get("file_name") is None else file_info.get("file_name") - content_type = "application/octet-stream" if file_info.get("content_type") is None else file_info.get("content_type") - return (name, file_content, content_type) - def convert(is_bytes=False): - files_part = {k: ([add_info(vi, is_bytes) for vi in v] if isinstance(v, list) else add_info(v, is_bytes)) for k, v in file.items()} - files_part.update(data) - return files_part - op = getattr(client.form_data, op_name) - # test bytes (raw dict) - body = convert(True) - await op(body) - - # test io (raw dict) - body = convert() - await op(body) - - # test io (model) - body = convert() - with pytest.raises(TypeError): - # caused by deepcopy when DPG model init - await op(model_class(body)) diff --git a/packages/typespec-python/test/azure/mock_api_tests/test_payload_multipart.py b/packages/typespec-python/test/azure/mock_api_tests/test_payload_multipart.py deleted file mode 100644 index b64b187b69a..00000000000 --- a/packages/typespec-python/test/azure/mock_api_tests/test_payload_multipart.py +++ /dev/null @@ -1,139 +0,0 @@ -# ------------------------------------------------------------------------- -# Copyright (c) Microsoft Corporation. All rights reserved. -# Licensed under the MIT License. See License.txt in the project root for -# license information. -# -------------------------------------------------------------------------- -import uuid -from typing import Dict, Any -from pathlib import Path -import pytest -from payload.multipart import MultiPartClient, models -from payload.multipart._model_base import Model - -JPG = Path(__file__).parent.parent.parent / "generic_mock_api_tests/data/image.jpg" -PNG = Path(__file__).parent.parent.parent / "generic_mock_api_tests/data/image.png" - - -@pytest.fixture -def client(): - with MultiPartClient(endpoint="http://localhost:3000") as client: - yield client - - -@pytest.mark.parametrize( - "op_name,model_class,data,file,file_info", - [ - ("basic", models.MultiPartRequest, {"id": "123"}, {"profileImage": JPG}, {}), - ( - "multi_binary_parts", - models.MultiBinaryPartsRequest, - {}, - {"profileImage": JPG, "picture": PNG}, - {} - ), - ( - "multi_binary_parts", - models.MultiBinaryPartsRequest, - {}, - {"profileImage": JPG}, - {} - ), - ( - "json_part", - models.JsonPartRequest, - {"address": models.Address(city="X")}, - {"profileImage": JPG}, - {}, - ), - ( - "json_array_parts", - models.JsonArrayPartsRequest, - {"previousAddresses": [models.Address(city="Y"), models.Address(city="Z")]}, - {"profileImage": JPG}, - {}, - ), - ( - "binary_array_parts", - models.BinaryArrayPartsRequest, - {"id": "123"}, - {"pictures": [PNG, PNG]}, - {}, - ), - ( - "complex", - models.ComplexPartsRequest, - {"id": "123", "previousAddresses": [models.Address(city="Y"), models.Address(city="Z")], "address": models.Address(city="X")}, - {"pictures": [PNG, PNG], "profileImage": JPG}, - {}, - ), - ], -) -def test_multi_part(client: MultiPartClient, op_name, model_class, data, file, file_info): - def add_info(file_path, is_bytes): - file_content = open(str(file_path), "rb").read() if is_bytes else open(str(file_path), "rb") - name = str(uuid.uuid4()) if file_info.get("file_name") is None else file_info.get("file_name") - content_type = "application/octet-stream" if file_info.get("content_type") is None else file_info.get("content_type") - return (name, file_content, content_type) - def convert(is_bytes=False): - files_part = {k: ([add_info(vi, is_bytes) for vi in v] if isinstance(v, list) else add_info(v, is_bytes)) for k, v in file.items()} - files_part.update(data) - return files_part - op = getattr(client.form_data, op_name) - # test bytes (raw dict) - body = convert(True) - op(body) - - # test io (raw dict) - body = convert() - op(body) - - # test io (model) - body = convert() - with pytest.raises(TypeError): - # caused by deepcopy when DPG model init - op(model_class(body)) - -def _test_sample_single_file(client: MultiPartClient): - # Python SDK support several kinds of file format for multipart/form-data and users can choose any of them - # 1. bytes - client.form_data.basic({"id": "123", "profileImage": open(str(PNG), "rb").read()}) - - # 2. file io - client.form_data.basic({"id": "123", "profileImage": open(str(PNG), "rb")}) - - # 3. file tuple (only set file name) - client.form_data.basic({"id": "123", "profileImage": ("my_image.jpg", open(str(JPG), "rb"))}) - # or - client.form_data.basic({"id": "123", "profileImage": ("my_image.jpg", open(str(JPG), "rb").read())}) - - # 4. file tuple (set file name and content type) - client.form_data.basic({"id": "123", "profileImage": ("my_image.jpg", open(str(JPG), "rb"), "image/jpeg")}) - # or - client.form_data.basic({"id": "123", "profileImage": ("my_image.jpg", open(str(JPG), "rb").read(), "image/jpeg")}) - -def _test_sample_array_file(client: MultiPartClient): - # If users want to upload array files for same field name, they can use list, and users can - # choose any of the above file format for each file. e.g. - - # List[bytes, io] - client.form_data.binary_array_parts({"id": "123", "pictures": [open(str(PNG), "rb").read(), open(str(PNG), "rb")]}) - - # List[bytes, tuple] - client.form_data.binary_array_parts({ - "id": "123", - "pictures": [open(str(PNG), "rb").read(), ("my_image.png", open(str(PNG), "rb"))] - }) - # or - client.form_data.binary_array_parts({ - "id": "123", - "pictures": [open(str(PNG), "rb").read(), ("my_image.png", open(str(PNG), "rb"), "image/png")] - }) - # List[io, bytes] - client.form_data.binary_array_parts({"id": "123", "pictures": [open(str(PNG), "rb"), open(str(PNG), "rb").read()]}) - - # List[tuple, tuple] - client.form_data.binary_array_parts({ - "id": "123", - "pictures": [("my_image1.png", open(str(PNG), "rb"), "image/png"), ("my_image2.png", open(str(PNG), "rb"), "image/png")] - }) - # ... From 0375e3d61d7687fe0b947061ad95e199d12864ef Mon Sep 17 00:00:00 2001 From: iscai-msft Date: Thu, 1 Feb 2024 14:19:40 -0500 Subject: [PATCH 27/45] use eggs for azure-core and corehttp in main --- packages/autorest.python/test/azure/legacy/requirements.txt | 2 +- .../test/azure/version-tolerant/requirements.txt | 2 +- .../autorest.python/test/dpg/version-tolerant/requirements.txt | 2 +- packages/autorest.python/test/multiapi/requirements.txt | 2 +- packages/autorest.python/test/unittests/requirements.txt | 2 +- packages/autorest.python/test/vanilla/legacy/requirements.txt | 2 +- .../test/vanilla/version-tolerant/requirements.txt | 2 +- packages/typespec-python/test/azure/requirements.txt | 2 +- packages/typespec-python/test/unbranded/requirements.txt | 2 +- 9 files changed, 9 insertions(+), 9 deletions(-) diff --git a/packages/autorest.python/test/azure/legacy/requirements.txt b/packages/autorest.python/test/azure/legacy/requirements.txt index fb8badd6985..eb41329e84a 100644 --- a/packages/autorest.python/test/azure/legacy/requirements.txt +++ b/packages/autorest.python/test/azure/legacy/requirements.txt @@ -4,7 +4,7 @@ pytest pytest-cov pytest-asyncio==0.14.0;python_full_version>="3.5.2" async_generator;python_full_version>="3.5.2" -azure-core==1.29.5 +-e git+https://github.com/Azure/azure-sdk-for-python.git@main#egg=azure-core&subdirectory=sdk/core/azure-core azure-mgmt-core==1.3.2 msrest==0.7.1 -e ./Expected/AcceptanceTests/AzureBodyDuration diff --git a/packages/autorest.python/test/azure/version-tolerant/requirements.txt b/packages/autorest.python/test/azure/version-tolerant/requirements.txt index ee65d9df4d6..2e12f1530f9 100644 --- a/packages/autorest.python/test/azure/version-tolerant/requirements.txt +++ b/packages/autorest.python/test/azure/version-tolerant/requirements.txt @@ -4,7 +4,7 @@ pytest pytest-cov pytest-asyncio==0.14.0;python_full_version>="3.5.2" async_generator;python_full_version>="3.5.2" -azure-core==1.29.5 +-e git+https://github.com/Azure/azure-sdk-for-python.git@main#egg=azure-core&subdirectory=sdk/core/azure-core azure-mgmt-core==1.3.2 -e ./Expected/AcceptanceTests/AzureBodyDurationVersionTolerant -e ./Expected/AcceptanceTests/AzureParameterGroupingVersionTolerant diff --git a/packages/autorest.python/test/dpg/version-tolerant/requirements.txt b/packages/autorest.python/test/dpg/version-tolerant/requirements.txt index bfbad5b2a7e..f1844319c07 100644 --- a/packages/autorest.python/test/dpg/version-tolerant/requirements.txt +++ b/packages/autorest.python/test/dpg/version-tolerant/requirements.txt @@ -4,7 +4,7 @@ pytest pytest-cov pytest-asyncio==0.14.0;python_full_version>="3.5.2" async_generator;python_full_version>="3.5.2" -azure-core==1.29.5 +-e git+https://github.com/Azure/azure-sdk-for-python.git@main#egg=azure-core&subdirectory=sdk/core/azure-core -e ./Expected/AcceptanceTests/DPGServiceDrivenInitialVersionTolerant/ -e ./Expected/AcceptanceTests/DPGServiceDrivenUpdateOneVersionTolerant/ -e ./Expected/AcceptanceTests/DPGCustomizationInitialVersionTolerant/ diff --git a/packages/autorest.python/test/multiapi/requirements.txt b/packages/autorest.python/test/multiapi/requirements.txt index 00b27f0d7ef..35aa5746c36 100644 --- a/packages/autorest.python/test/multiapi/requirements.txt +++ b/packages/autorest.python/test/multiapi/requirements.txt @@ -1,7 +1,7 @@ aiohttp; python_full_version >= '3.5.2' azure-common msrest==0.7.1 -azure-core==1.29.5 +-e git+https://github.com/Azure/azure-sdk-for-python.git@main#egg=azure-core&subdirectory=sdk/core/azure-core azure-mgmt-core==1.3.2 pytest pytest-cov diff --git a/packages/autorest.python/test/unittests/requirements.txt b/packages/autorest.python/test/unittests/requirements.txt index 36f98819cc3..f6662abcfe9 100644 --- a/packages/autorest.python/test/unittests/requirements.txt +++ b/packages/autorest.python/test/unittests/requirements.txt @@ -2,5 +2,5 @@ isodate<1.0.0,>=0.6.1 requests==2.28.2 pytest pytest-cov -azure-core==1.29.5 +-e git+https://github.com/Azure/azure-sdk-for-python.git@main#egg=azure-core&subdirectory=sdk/core/azure-core -e ../../. diff --git a/packages/autorest.python/test/vanilla/legacy/requirements.txt b/packages/autorest.python/test/vanilla/legacy/requirements.txt index fca5ef4d174..816206a872b 100644 --- a/packages/autorest.python/test/vanilla/legacy/requirements.txt +++ b/packages/autorest.python/test/vanilla/legacy/requirements.txt @@ -5,7 +5,7 @@ pytest-cov pytest-asyncio==0.14.0;python_full_version>="3.5.2" async_generator;python_full_version>="3.5.2" msrest==0.7.1 -azure-core==1.29.5 +-e git+https://github.com/Azure/azure-sdk-for-python.git@main#egg=azure-core&subdirectory=sdk/core/azure-core -e ./Expected/AcceptanceTests/AdditionalProperties -e ./Expected/AcceptanceTests/Anything -e ./Expected/AcceptanceTests/BodyArray diff --git a/packages/autorest.python/test/vanilla/version-tolerant/requirements.txt b/packages/autorest.python/test/vanilla/version-tolerant/requirements.txt index 047bc25fd1c..cd808ee2dd5 100644 --- a/packages/autorest.python/test/vanilla/version-tolerant/requirements.txt +++ b/packages/autorest.python/test/vanilla/version-tolerant/requirements.txt @@ -4,7 +4,7 @@ pytest pytest-cov pytest-asyncio==0.14.0;python_full_version>="3.5.2" async_generator;python_full_version>="3.5.2" -azure-core==1.29.5 +-e git+https://github.com/Azure/azure-sdk-for-python.git@main#egg=azure-core&subdirectory=sdk/core/azure-core -e ./Expected/AcceptanceTests/AdditionalPropertiesVersionTolerant -e ./Expected/AcceptanceTests/AnythingVersionTolerant -e ./Expected/AcceptanceTests/BodyArrayVersionTolerant diff --git a/packages/typespec-python/test/azure/requirements.txt b/packages/typespec-python/test/azure/requirements.txt index f01619e4bb7..b566f7e5d44 100644 --- a/packages/typespec-python/test/azure/requirements.txt +++ b/packages/typespec-python/test/azure/requirements.txt @@ -2,7 +2,7 @@ aiohttp;python_full_version>="3.5.2" requests==2.31.0 pytest pytest-asyncio==0.14.0;python_full_version>="3.5.2" -azure-core==1.29.5 +-e git+https://github.com/Azure/azure-sdk-for-python.git@main#egg=azure-core&subdirectory=sdk/core/azure-core # only for azure -e ./generated/azure-mgmt-spheredpg -e ./generated/azure-mgmt-spheremsrest diff --git a/packages/typespec-python/test/unbranded/requirements.txt b/packages/typespec-python/test/unbranded/requirements.txt index 4b68ea6550a..b34aba5b5c8 100644 --- a/packages/typespec-python/test/unbranded/requirements.txt +++ b/packages/typespec-python/test/unbranded/requirements.txt @@ -2,7 +2,7 @@ aiohttp;python_full_version>="3.5.2" requests==2.28.2 pytest pytest-asyncio==0.14.0;python_full_version>="3.5.2" -corehttp==1.0.0b2 +-e git+https://github.com/Azure/azure-sdk-for-python.git@main#egg=corehttp&subdirectory=sdk/core/corehttp # common test case -e ./generated/authentication-api-key From 1d977fdc439629f5cc633744ba61a9df62a79a51 Mon Sep 17 00:00:00 2001 From: iscai-msft Date: Thu, 1 Feb 2024 15:17:44 -0500 Subject: [PATCH 28/45] import email.utils --- .../autorest/codegen/templates/model_base.py.jinja2 | 2 +- .../authentication-api-key/authentication/apikey/_model_base.py | 2 +- .../authentication/http/custom/_model_base.py | 2 +- .../authentication-oauth2/authentication/oauth2/_model_base.py | 2 +- .../authentication-union/authentication/union/_model_base.py | 2 +- .../specs/azure/clientgenerator/core/access/_model_base.py | 2 +- .../specs/azure/clientgenerator/core/usage/_model_base.py | 2 +- .../azure-core-basic/specs/azure/core/basic/_model_base.py | 2 +- .../specs/azure/core/lro/standard/_model_base.py | 2 +- .../azure-core-traits/specs/azure/core/traits/_model_base.py | 2 +- .../azure-mgmt-spheredpg/azure/mgmt/spheredpg/_model_base.py | 2 +- .../azurecore-lro-rpc/azurecore/lro/rpc/_model_base.py | 2 +- .../azurecore/lro/rpclegacy/_model_base.py | 2 +- .../client/structure/service/_model_base.py | 2 +- .../client/structure/multiclient/_model_base.py | 2 +- .../client/structure/renamedoperation/_model_base.py | 2 +- .../client/structure/twooperationgroup/_model_base.py | 2 +- .../azure/generated/encode-bytes/encode/bytes/_model_base.py | 2 +- .../generated/encode-datetime/encode/datetime/_model_base.py | 2 +- .../generated/encode-duration/encode/duration/_model_base.py | 2 +- .../headasbooleanfalse/headasbooleanfalse/_model_base.py | 2 +- .../headasbooleantrue/headasbooleantrue/_model_base.py | 2 +- .../parameters/bodyoptionality/_model_base.py | 2 +- .../parameters/collectionformat/_model_base.py | 2 +- .../parameters-spread/parameters/spread/_model_base.py | 2 +- .../payload/contentnegotiation/_model_base.py | 2 +- .../payload-media-type/payload/mediatype/_model_base.py | 2 +- .../payload-multipart/payload/multipart/_model_base.py | 2 +- .../generated/payload-pageable/payload/pageable/_model_base.py | 2 +- .../projection/projectedname/_model_base.py | 2 +- .../resiliency/srv/driven1/_model_base.py | 2 +- .../resiliency/srv/driven2/_model_base.py | 2 +- .../server-path-multiple/server/path/multiple/_model_base.py | 2 +- .../server-path-single/server/path/single/_model_base.py | 2 +- .../server/versions/notversioned/_model_base.py | 2 +- .../server/versions/versioned/_model_base.py | 2 +- .../specialheaders/clientrequestid/_model_base.py | 2 +- .../specialheaders/conditionalrequest/_model_base.py | 2 +- .../specialheaders/repeatability/_model_base.py | 2 +- .../azure/generated/special-words/specialwords/_model_base.py | 2 +- .../generated/typetest-array/typetest/array/_model_base.py | 2 +- .../typetest-dictionary/typetest/dictionary/_model_base.py | 2 +- .../typetest/enum/extensible/_model_base.py | 2 +- .../typetest-enum-fixed/typetest/enum/fixed/_model_base.py | 2 +- .../typetest-model-empty/typetest/model/empty/_model_base.py | 2 +- .../typetest/model/enumdiscriminator/_model_base.py | 2 +- .../typetest/model/nesteddiscriminator/_model_base.py | 2 +- .../typetest/model/notdiscriminated/_model_base.py | 2 +- .../typetest/model/recursive/_model_base.py | 2 +- .../typetest/model/singlediscriminator/_model_base.py | 2 +- .../typetest-model-usage/typetest/model/usage/_model_base.py | 2 +- .../typetest/model/visibility/_model_base.py | 2 +- .../typetest/property/additionalproperties/_model_base.py | 2 +- .../typetest/property/nullable/_model_base.py | 2 +- .../typetest/property/optional/_model_base.py | 2 +- .../typetest/property/valuetypes/_model_base.py | 2 +- .../generated/typetest-scalar/typetest/scalar/_model_base.py | 2 +- .../generated/typetest-union/typetest/union/_model_base.py | 2 +- .../authentication-api-key/authentication/apikey/_model_base.py | 2 +- .../authentication/http/custom/_model_base.py | 2 +- .../authentication-oauth2/authentication/oauth2/_model_base.py | 2 +- .../authentication-union/authentication/union/_model_base.py | 2 +- .../client/structure/service/_model_base.py | 2 +- .../client/structure/multiclient/_model_base.py | 2 +- .../client/structure/renamedoperation/_model_base.py | 2 +- .../client/structure/twooperationgroup/_model_base.py | 2 +- .../generated/encode-bytes/encode/bytes/_model_base.py | 2 +- .../generated/encode-datetime/encode/datetime/_model_base.py | 2 +- .../generated/encode-duration/encode/duration/_model_base.py | 2 +- .../headasbooleanfalse/headasbooleanfalse/_model_base.py | 2 +- .../headasbooleantrue/headasbooleantrue/_model_base.py | 2 +- .../parameters/bodyoptionality/_model_base.py | 2 +- .../parameters/collectionformat/_model_base.py | 2 +- .../parameters-spread/parameters/spread/_model_base.py | 2 +- .../payload/contentnegotiation/_model_base.py | 2 +- .../payload-media-type/payload/mediatype/_model_base.py | 2 +- .../payload-multipart/payload/multipart/_model_base.py | 2 +- .../generated/payload-pageable/payload/pageable/_model_base.py | 2 +- .../projection/projectedname/_model_base.py | 2 +- .../resiliency/srv/driven1/_model_base.py | 2 +- .../resiliency/srv/driven2/_model_base.py | 2 +- .../server-path-multiple/server/path/multiple/_model_base.py | 2 +- .../server-path-single/server/path/single/_model_base.py | 2 +- .../server/versions/notversioned/_model_base.py | 2 +- .../server/versions/versioned/_model_base.py | 2 +- .../specialheaders/conditionalrequest/_model_base.py | 2 +- .../specialheaders/repeatability/_model_base.py | 2 +- .../generated/special-words/specialwords/_model_base.py | 2 +- .../generated/typetest-array/typetest/array/_model_base.py | 2 +- .../typetest-dictionary/typetest/dictionary/_model_base.py | 2 +- .../typetest/enum/extensible/_model_base.py | 2 +- .../typetest-enum-fixed/typetest/enum/fixed/_model_base.py | 2 +- .../typetest-model-empty/typetest/model/empty/_model_base.py | 2 +- .../typetest/model/enumdiscriminator/_model_base.py | 2 +- .../typetest/model/nesteddiscriminator/_model_base.py | 2 +- .../typetest/model/notdiscriminated/_model_base.py | 2 +- .../typetest/model/recursive/_model_base.py | 2 +- .../typetest/model/singlediscriminator/_model_base.py | 2 +- .../typetest-model-usage/typetest/model/usage/_model_base.py | 2 +- .../typetest/model/visibility/_model_base.py | 2 +- .../typetest/property/additionalproperties/_model_base.py | 2 +- .../typetest/property/nullable/_model_base.py | 2 +- .../typetest/property/optional/_model_base.py | 2 +- .../typetest/property/valuetypes/_model_base.py | 2 +- .../generated/typetest-scalar/typetest/scalar/_model_base.py | 2 +- .../generated/typetest-union/typetest/union/_model_base.py | 2 +- 106 files changed, 106 insertions(+), 106 deletions(-) diff --git a/packages/autorest.python/autorest/codegen/templates/model_base.py.jinja2 b/packages/autorest.python/autorest/codegen/templates/model_base.py.jinja2 index 28d6b5741ae..bf0f114d447 100644 --- a/packages/autorest.python/autorest/codegen/templates/model_base.py.jinja2 +++ b/packages/autorest.python/autorest/codegen/templates/model_base.py.jinja2 @@ -16,7 +16,7 @@ import base64 import re import copy import typing -import email +import email.utils from datetime import datetime, date, time, timedelta, timezone from json import JSONEncoder import isodate diff --git a/packages/typespec-python/test/azure/generated/authentication-api-key/authentication/apikey/_model_base.py b/packages/typespec-python/test/azure/generated/authentication-api-key/authentication/apikey/_model_base.py index 247049f44d9..bd51cdeb446 100644 --- a/packages/typespec-python/test/azure/generated/authentication-api-key/authentication/apikey/_model_base.py +++ b/packages/typespec-python/test/azure/generated/authentication-api-key/authentication/apikey/_model_base.py @@ -16,7 +16,7 @@ import re import copy import typing -import email +import email.utils from datetime import datetime, date, time, timedelta, timezone from json import JSONEncoder import isodate diff --git a/packages/typespec-python/test/azure/generated/authentication-http-custom/authentication/http/custom/_model_base.py b/packages/typespec-python/test/azure/generated/authentication-http-custom/authentication/http/custom/_model_base.py index 247049f44d9..bd51cdeb446 100644 --- a/packages/typespec-python/test/azure/generated/authentication-http-custom/authentication/http/custom/_model_base.py +++ b/packages/typespec-python/test/azure/generated/authentication-http-custom/authentication/http/custom/_model_base.py @@ -16,7 +16,7 @@ import re import copy import typing -import email +import email.utils from datetime import datetime, date, time, timedelta, timezone from json import JSONEncoder import isodate diff --git a/packages/typespec-python/test/azure/generated/authentication-oauth2/authentication/oauth2/_model_base.py b/packages/typespec-python/test/azure/generated/authentication-oauth2/authentication/oauth2/_model_base.py index 247049f44d9..bd51cdeb446 100644 --- a/packages/typespec-python/test/azure/generated/authentication-oauth2/authentication/oauth2/_model_base.py +++ b/packages/typespec-python/test/azure/generated/authentication-oauth2/authentication/oauth2/_model_base.py @@ -16,7 +16,7 @@ import re import copy import typing -import email +import email.utils from datetime import datetime, date, time, timedelta, timezone from json import JSONEncoder import isodate diff --git a/packages/typespec-python/test/azure/generated/authentication-union/authentication/union/_model_base.py b/packages/typespec-python/test/azure/generated/authentication-union/authentication/union/_model_base.py index 247049f44d9..bd51cdeb446 100644 --- a/packages/typespec-python/test/azure/generated/authentication-union/authentication/union/_model_base.py +++ b/packages/typespec-python/test/azure/generated/authentication-union/authentication/union/_model_base.py @@ -16,7 +16,7 @@ import re import copy import typing -import email +import email.utils from datetime import datetime, date, time, timedelta, timezone from json import JSONEncoder import isodate diff --git a/packages/typespec-python/test/azure/generated/azure-client-generator-core-access/specs/azure/clientgenerator/core/access/_model_base.py b/packages/typespec-python/test/azure/generated/azure-client-generator-core-access/specs/azure/clientgenerator/core/access/_model_base.py index 247049f44d9..bd51cdeb446 100644 --- a/packages/typespec-python/test/azure/generated/azure-client-generator-core-access/specs/azure/clientgenerator/core/access/_model_base.py +++ b/packages/typespec-python/test/azure/generated/azure-client-generator-core-access/specs/azure/clientgenerator/core/access/_model_base.py @@ -16,7 +16,7 @@ import re import copy import typing -import email +import email.utils from datetime import datetime, date, time, timedelta, timezone from json import JSONEncoder import isodate diff --git a/packages/typespec-python/test/azure/generated/azure-client-generator-core-usage/specs/azure/clientgenerator/core/usage/_model_base.py b/packages/typespec-python/test/azure/generated/azure-client-generator-core-usage/specs/azure/clientgenerator/core/usage/_model_base.py index 247049f44d9..bd51cdeb446 100644 --- a/packages/typespec-python/test/azure/generated/azure-client-generator-core-usage/specs/azure/clientgenerator/core/usage/_model_base.py +++ b/packages/typespec-python/test/azure/generated/azure-client-generator-core-usage/specs/azure/clientgenerator/core/usage/_model_base.py @@ -16,7 +16,7 @@ import re import copy import typing -import email +import email.utils from datetime import datetime, date, time, timedelta, timezone from json import JSONEncoder import isodate diff --git a/packages/typespec-python/test/azure/generated/azure-core-basic/specs/azure/core/basic/_model_base.py b/packages/typespec-python/test/azure/generated/azure-core-basic/specs/azure/core/basic/_model_base.py index 247049f44d9..bd51cdeb446 100644 --- a/packages/typespec-python/test/azure/generated/azure-core-basic/specs/azure/core/basic/_model_base.py +++ b/packages/typespec-python/test/azure/generated/azure-core-basic/specs/azure/core/basic/_model_base.py @@ -16,7 +16,7 @@ import re import copy import typing -import email +import email.utils from datetime import datetime, date, time, timedelta, timezone from json import JSONEncoder import isodate diff --git a/packages/typespec-python/test/azure/generated/azure-core-lro-standard/specs/azure/core/lro/standard/_model_base.py b/packages/typespec-python/test/azure/generated/azure-core-lro-standard/specs/azure/core/lro/standard/_model_base.py index 247049f44d9..bd51cdeb446 100644 --- a/packages/typespec-python/test/azure/generated/azure-core-lro-standard/specs/azure/core/lro/standard/_model_base.py +++ b/packages/typespec-python/test/azure/generated/azure-core-lro-standard/specs/azure/core/lro/standard/_model_base.py @@ -16,7 +16,7 @@ import re import copy import typing -import email +import email.utils from datetime import datetime, date, time, timedelta, timezone from json import JSONEncoder import isodate diff --git a/packages/typespec-python/test/azure/generated/azure-core-traits/specs/azure/core/traits/_model_base.py b/packages/typespec-python/test/azure/generated/azure-core-traits/specs/azure/core/traits/_model_base.py index 247049f44d9..bd51cdeb446 100644 --- a/packages/typespec-python/test/azure/generated/azure-core-traits/specs/azure/core/traits/_model_base.py +++ b/packages/typespec-python/test/azure/generated/azure-core-traits/specs/azure/core/traits/_model_base.py @@ -16,7 +16,7 @@ import re import copy import typing -import email +import email.utils from datetime import datetime, date, time, timedelta, timezone from json import JSONEncoder import isodate diff --git a/packages/typespec-python/test/azure/generated/azure-mgmt-spheredpg/azure/mgmt/spheredpg/_model_base.py b/packages/typespec-python/test/azure/generated/azure-mgmt-spheredpg/azure/mgmt/spheredpg/_model_base.py index 247049f44d9..bd51cdeb446 100644 --- a/packages/typespec-python/test/azure/generated/azure-mgmt-spheredpg/azure/mgmt/spheredpg/_model_base.py +++ b/packages/typespec-python/test/azure/generated/azure-mgmt-spheredpg/azure/mgmt/spheredpg/_model_base.py @@ -16,7 +16,7 @@ import re import copy import typing -import email +import email.utils from datetime import datetime, date, time, timedelta, timezone from json import JSONEncoder import isodate diff --git a/packages/typespec-python/test/azure/generated/azurecore-lro-rpc/azurecore/lro/rpc/_model_base.py b/packages/typespec-python/test/azure/generated/azurecore-lro-rpc/azurecore/lro/rpc/_model_base.py index 247049f44d9..bd51cdeb446 100644 --- a/packages/typespec-python/test/azure/generated/azurecore-lro-rpc/azurecore/lro/rpc/_model_base.py +++ b/packages/typespec-python/test/azure/generated/azurecore-lro-rpc/azurecore/lro/rpc/_model_base.py @@ -16,7 +16,7 @@ import re import copy import typing -import email +import email.utils from datetime import datetime, date, time, timedelta, timezone from json import JSONEncoder import isodate diff --git a/packages/typespec-python/test/azure/generated/azurecore-lro-rpclegacy/azurecore/lro/rpclegacy/_model_base.py b/packages/typespec-python/test/azure/generated/azurecore-lro-rpclegacy/azurecore/lro/rpclegacy/_model_base.py index 247049f44d9..bd51cdeb446 100644 --- a/packages/typespec-python/test/azure/generated/azurecore-lro-rpclegacy/azurecore/lro/rpclegacy/_model_base.py +++ b/packages/typespec-python/test/azure/generated/azurecore-lro-rpclegacy/azurecore/lro/rpclegacy/_model_base.py @@ -16,7 +16,7 @@ import re import copy import typing -import email +import email.utils from datetime import datetime, date, time, timedelta, timezone from json import JSONEncoder import isodate diff --git a/packages/typespec-python/test/azure/generated/client-structure-default/client/structure/service/_model_base.py b/packages/typespec-python/test/azure/generated/client-structure-default/client/structure/service/_model_base.py index 247049f44d9..bd51cdeb446 100644 --- a/packages/typespec-python/test/azure/generated/client-structure-default/client/structure/service/_model_base.py +++ b/packages/typespec-python/test/azure/generated/client-structure-default/client/structure/service/_model_base.py @@ -16,7 +16,7 @@ import re import copy import typing -import email +import email.utils from datetime import datetime, date, time, timedelta, timezone from json import JSONEncoder import isodate diff --git a/packages/typespec-python/test/azure/generated/client-structure-multiclient/client/structure/multiclient/_model_base.py b/packages/typespec-python/test/azure/generated/client-structure-multiclient/client/structure/multiclient/_model_base.py index 247049f44d9..bd51cdeb446 100644 --- a/packages/typespec-python/test/azure/generated/client-structure-multiclient/client/structure/multiclient/_model_base.py +++ b/packages/typespec-python/test/azure/generated/client-structure-multiclient/client/structure/multiclient/_model_base.py @@ -16,7 +16,7 @@ import re import copy import typing -import email +import email.utils from datetime import datetime, date, time, timedelta, timezone from json import JSONEncoder import isodate diff --git a/packages/typespec-python/test/azure/generated/client-structure-renamedoperation/client/structure/renamedoperation/_model_base.py b/packages/typespec-python/test/azure/generated/client-structure-renamedoperation/client/structure/renamedoperation/_model_base.py index 247049f44d9..bd51cdeb446 100644 --- a/packages/typespec-python/test/azure/generated/client-structure-renamedoperation/client/structure/renamedoperation/_model_base.py +++ b/packages/typespec-python/test/azure/generated/client-structure-renamedoperation/client/structure/renamedoperation/_model_base.py @@ -16,7 +16,7 @@ import re import copy import typing -import email +import email.utils from datetime import datetime, date, time, timedelta, timezone from json import JSONEncoder import isodate diff --git a/packages/typespec-python/test/azure/generated/client-structure-twooperationgroup/client/structure/twooperationgroup/_model_base.py b/packages/typespec-python/test/azure/generated/client-structure-twooperationgroup/client/structure/twooperationgroup/_model_base.py index 247049f44d9..bd51cdeb446 100644 --- a/packages/typespec-python/test/azure/generated/client-structure-twooperationgroup/client/structure/twooperationgroup/_model_base.py +++ b/packages/typespec-python/test/azure/generated/client-structure-twooperationgroup/client/structure/twooperationgroup/_model_base.py @@ -16,7 +16,7 @@ import re import copy import typing -import email +import email.utils from datetime import datetime, date, time, timedelta, timezone from json import JSONEncoder import isodate diff --git a/packages/typespec-python/test/azure/generated/encode-bytes/encode/bytes/_model_base.py b/packages/typespec-python/test/azure/generated/encode-bytes/encode/bytes/_model_base.py index 247049f44d9..bd51cdeb446 100644 --- a/packages/typespec-python/test/azure/generated/encode-bytes/encode/bytes/_model_base.py +++ b/packages/typespec-python/test/azure/generated/encode-bytes/encode/bytes/_model_base.py @@ -16,7 +16,7 @@ import re import copy import typing -import email +import email.utils from datetime import datetime, date, time, timedelta, timezone from json import JSONEncoder import isodate diff --git a/packages/typespec-python/test/azure/generated/encode-datetime/encode/datetime/_model_base.py b/packages/typespec-python/test/azure/generated/encode-datetime/encode/datetime/_model_base.py index 247049f44d9..bd51cdeb446 100644 --- a/packages/typespec-python/test/azure/generated/encode-datetime/encode/datetime/_model_base.py +++ b/packages/typespec-python/test/azure/generated/encode-datetime/encode/datetime/_model_base.py @@ -16,7 +16,7 @@ import re import copy import typing -import email +import email.utils from datetime import datetime, date, time, timedelta, timezone from json import JSONEncoder import isodate diff --git a/packages/typespec-python/test/azure/generated/encode-duration/encode/duration/_model_base.py b/packages/typespec-python/test/azure/generated/encode-duration/encode/duration/_model_base.py index 247049f44d9..bd51cdeb446 100644 --- a/packages/typespec-python/test/azure/generated/encode-duration/encode/duration/_model_base.py +++ b/packages/typespec-python/test/azure/generated/encode-duration/encode/duration/_model_base.py @@ -16,7 +16,7 @@ import re import copy import typing -import email +import email.utils from datetime import datetime, date, time, timedelta, timezone from json import JSONEncoder import isodate diff --git a/packages/typespec-python/test/azure/generated/headasbooleanfalse/headasbooleanfalse/_model_base.py b/packages/typespec-python/test/azure/generated/headasbooleanfalse/headasbooleanfalse/_model_base.py index 247049f44d9..bd51cdeb446 100644 --- a/packages/typespec-python/test/azure/generated/headasbooleanfalse/headasbooleanfalse/_model_base.py +++ b/packages/typespec-python/test/azure/generated/headasbooleanfalse/headasbooleanfalse/_model_base.py @@ -16,7 +16,7 @@ import re import copy import typing -import email +import email.utils from datetime import datetime, date, time, timedelta, timezone from json import JSONEncoder import isodate diff --git a/packages/typespec-python/test/azure/generated/headasbooleantrue/headasbooleantrue/_model_base.py b/packages/typespec-python/test/azure/generated/headasbooleantrue/headasbooleantrue/_model_base.py index 247049f44d9..bd51cdeb446 100644 --- a/packages/typespec-python/test/azure/generated/headasbooleantrue/headasbooleantrue/_model_base.py +++ b/packages/typespec-python/test/azure/generated/headasbooleantrue/headasbooleantrue/_model_base.py @@ -16,7 +16,7 @@ import re import copy import typing -import email +import email.utils from datetime import datetime, date, time, timedelta, timezone from json import JSONEncoder import isodate diff --git a/packages/typespec-python/test/azure/generated/parameters-body-optionality/parameters/bodyoptionality/_model_base.py b/packages/typespec-python/test/azure/generated/parameters-body-optionality/parameters/bodyoptionality/_model_base.py index 247049f44d9..bd51cdeb446 100644 --- a/packages/typespec-python/test/azure/generated/parameters-body-optionality/parameters/bodyoptionality/_model_base.py +++ b/packages/typespec-python/test/azure/generated/parameters-body-optionality/parameters/bodyoptionality/_model_base.py @@ -16,7 +16,7 @@ import re import copy import typing -import email +import email.utils from datetime import datetime, date, time, timedelta, timezone from json import JSONEncoder import isodate diff --git a/packages/typespec-python/test/azure/generated/parameters-collection-format/parameters/collectionformat/_model_base.py b/packages/typespec-python/test/azure/generated/parameters-collection-format/parameters/collectionformat/_model_base.py index 247049f44d9..bd51cdeb446 100644 --- a/packages/typespec-python/test/azure/generated/parameters-collection-format/parameters/collectionformat/_model_base.py +++ b/packages/typespec-python/test/azure/generated/parameters-collection-format/parameters/collectionformat/_model_base.py @@ -16,7 +16,7 @@ import re import copy import typing -import email +import email.utils from datetime import datetime, date, time, timedelta, timezone from json import JSONEncoder import isodate diff --git a/packages/typespec-python/test/azure/generated/parameters-spread/parameters/spread/_model_base.py b/packages/typespec-python/test/azure/generated/parameters-spread/parameters/spread/_model_base.py index 247049f44d9..bd51cdeb446 100644 --- a/packages/typespec-python/test/azure/generated/parameters-spread/parameters/spread/_model_base.py +++ b/packages/typespec-python/test/azure/generated/parameters-spread/parameters/spread/_model_base.py @@ -16,7 +16,7 @@ import re import copy import typing -import email +import email.utils from datetime import datetime, date, time, timedelta, timezone from json import JSONEncoder import isodate diff --git a/packages/typespec-python/test/azure/generated/payload-content-negotiation/payload/contentnegotiation/_model_base.py b/packages/typespec-python/test/azure/generated/payload-content-negotiation/payload/contentnegotiation/_model_base.py index 247049f44d9..bd51cdeb446 100644 --- a/packages/typespec-python/test/azure/generated/payload-content-negotiation/payload/contentnegotiation/_model_base.py +++ b/packages/typespec-python/test/azure/generated/payload-content-negotiation/payload/contentnegotiation/_model_base.py @@ -16,7 +16,7 @@ import re import copy import typing -import email +import email.utils from datetime import datetime, date, time, timedelta, timezone from json import JSONEncoder import isodate diff --git a/packages/typespec-python/test/azure/generated/payload-media-type/payload/mediatype/_model_base.py b/packages/typespec-python/test/azure/generated/payload-media-type/payload/mediatype/_model_base.py index 247049f44d9..bd51cdeb446 100644 --- a/packages/typespec-python/test/azure/generated/payload-media-type/payload/mediatype/_model_base.py +++ b/packages/typespec-python/test/azure/generated/payload-media-type/payload/mediatype/_model_base.py @@ -16,7 +16,7 @@ import re import copy import typing -import email +import email.utils from datetime import datetime, date, time, timedelta, timezone from json import JSONEncoder import isodate diff --git a/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/_model_base.py b/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/_model_base.py index 247049f44d9..bd51cdeb446 100644 --- a/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/_model_base.py +++ b/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/_model_base.py @@ -16,7 +16,7 @@ import re import copy import typing -import email +import email.utils from datetime import datetime, date, time, timedelta, timezone from json import JSONEncoder import isodate diff --git a/packages/typespec-python/test/azure/generated/payload-pageable/payload/pageable/_model_base.py b/packages/typespec-python/test/azure/generated/payload-pageable/payload/pageable/_model_base.py index 247049f44d9..bd51cdeb446 100644 --- a/packages/typespec-python/test/azure/generated/payload-pageable/payload/pageable/_model_base.py +++ b/packages/typespec-python/test/azure/generated/payload-pageable/payload/pageable/_model_base.py @@ -16,7 +16,7 @@ import re import copy import typing -import email +import email.utils from datetime import datetime, date, time, timedelta, timezone from json import JSONEncoder import isodate diff --git a/packages/typespec-python/test/azure/generated/projection-projected-name/projection/projectedname/_model_base.py b/packages/typespec-python/test/azure/generated/projection-projected-name/projection/projectedname/_model_base.py index 247049f44d9..bd51cdeb446 100644 --- a/packages/typespec-python/test/azure/generated/projection-projected-name/projection/projectedname/_model_base.py +++ b/packages/typespec-python/test/azure/generated/projection-projected-name/projection/projectedname/_model_base.py @@ -16,7 +16,7 @@ import re import copy import typing -import email +import email.utils from datetime import datetime, date, time, timedelta, timezone from json import JSONEncoder import isodate diff --git a/packages/typespec-python/test/azure/generated/resiliency-srv-driven1/resiliency/srv/driven1/_model_base.py b/packages/typespec-python/test/azure/generated/resiliency-srv-driven1/resiliency/srv/driven1/_model_base.py index 247049f44d9..bd51cdeb446 100644 --- a/packages/typespec-python/test/azure/generated/resiliency-srv-driven1/resiliency/srv/driven1/_model_base.py +++ b/packages/typespec-python/test/azure/generated/resiliency-srv-driven1/resiliency/srv/driven1/_model_base.py @@ -16,7 +16,7 @@ import re import copy import typing -import email +import email.utils from datetime import datetime, date, time, timedelta, timezone from json import JSONEncoder import isodate diff --git a/packages/typespec-python/test/azure/generated/resiliency-srv-driven2/resiliency/srv/driven2/_model_base.py b/packages/typespec-python/test/azure/generated/resiliency-srv-driven2/resiliency/srv/driven2/_model_base.py index 247049f44d9..bd51cdeb446 100644 --- a/packages/typespec-python/test/azure/generated/resiliency-srv-driven2/resiliency/srv/driven2/_model_base.py +++ b/packages/typespec-python/test/azure/generated/resiliency-srv-driven2/resiliency/srv/driven2/_model_base.py @@ -16,7 +16,7 @@ import re import copy import typing -import email +import email.utils from datetime import datetime, date, time, timedelta, timezone from json import JSONEncoder import isodate diff --git a/packages/typespec-python/test/azure/generated/server-path-multiple/server/path/multiple/_model_base.py b/packages/typespec-python/test/azure/generated/server-path-multiple/server/path/multiple/_model_base.py index 247049f44d9..bd51cdeb446 100644 --- a/packages/typespec-python/test/azure/generated/server-path-multiple/server/path/multiple/_model_base.py +++ b/packages/typespec-python/test/azure/generated/server-path-multiple/server/path/multiple/_model_base.py @@ -16,7 +16,7 @@ import re import copy import typing -import email +import email.utils from datetime import datetime, date, time, timedelta, timezone from json import JSONEncoder import isodate diff --git a/packages/typespec-python/test/azure/generated/server-path-single/server/path/single/_model_base.py b/packages/typespec-python/test/azure/generated/server-path-single/server/path/single/_model_base.py index 247049f44d9..bd51cdeb446 100644 --- a/packages/typespec-python/test/azure/generated/server-path-single/server/path/single/_model_base.py +++ b/packages/typespec-python/test/azure/generated/server-path-single/server/path/single/_model_base.py @@ -16,7 +16,7 @@ import re import copy import typing -import email +import email.utils from datetime import datetime, date, time, timedelta, timezone from json import JSONEncoder import isodate diff --git a/packages/typespec-python/test/azure/generated/server-versions-not-versioned/server/versions/notversioned/_model_base.py b/packages/typespec-python/test/azure/generated/server-versions-not-versioned/server/versions/notversioned/_model_base.py index 247049f44d9..bd51cdeb446 100644 --- a/packages/typespec-python/test/azure/generated/server-versions-not-versioned/server/versions/notversioned/_model_base.py +++ b/packages/typespec-python/test/azure/generated/server-versions-not-versioned/server/versions/notversioned/_model_base.py @@ -16,7 +16,7 @@ import re import copy import typing -import email +import email.utils from datetime import datetime, date, time, timedelta, timezone from json import JSONEncoder import isodate diff --git a/packages/typespec-python/test/azure/generated/server-versions-versioned/server/versions/versioned/_model_base.py b/packages/typespec-python/test/azure/generated/server-versions-versioned/server/versions/versioned/_model_base.py index 247049f44d9..bd51cdeb446 100644 --- a/packages/typespec-python/test/azure/generated/server-versions-versioned/server/versions/versioned/_model_base.py +++ b/packages/typespec-python/test/azure/generated/server-versions-versioned/server/versions/versioned/_model_base.py @@ -16,7 +16,7 @@ import re import copy import typing -import email +import email.utils from datetime import datetime, date, time, timedelta, timezone from json import JSONEncoder import isodate diff --git a/packages/typespec-python/test/azure/generated/special-headers-client-request-id/specialheaders/clientrequestid/_model_base.py b/packages/typespec-python/test/azure/generated/special-headers-client-request-id/specialheaders/clientrequestid/_model_base.py index 247049f44d9..bd51cdeb446 100644 --- a/packages/typespec-python/test/azure/generated/special-headers-client-request-id/specialheaders/clientrequestid/_model_base.py +++ b/packages/typespec-python/test/azure/generated/special-headers-client-request-id/specialheaders/clientrequestid/_model_base.py @@ -16,7 +16,7 @@ import re import copy import typing -import email +import email.utils from datetime import datetime, date, time, timedelta, timezone from json import JSONEncoder import isodate diff --git a/packages/typespec-python/test/azure/generated/special-headers-conditional-request/specialheaders/conditionalrequest/_model_base.py b/packages/typespec-python/test/azure/generated/special-headers-conditional-request/specialheaders/conditionalrequest/_model_base.py index 247049f44d9..bd51cdeb446 100644 --- a/packages/typespec-python/test/azure/generated/special-headers-conditional-request/specialheaders/conditionalrequest/_model_base.py +++ b/packages/typespec-python/test/azure/generated/special-headers-conditional-request/specialheaders/conditionalrequest/_model_base.py @@ -16,7 +16,7 @@ import re import copy import typing -import email +import email.utils from datetime import datetime, date, time, timedelta, timezone from json import JSONEncoder import isodate diff --git a/packages/typespec-python/test/azure/generated/special-headers-repeatability/specialheaders/repeatability/_model_base.py b/packages/typespec-python/test/azure/generated/special-headers-repeatability/specialheaders/repeatability/_model_base.py index 247049f44d9..bd51cdeb446 100644 --- a/packages/typespec-python/test/azure/generated/special-headers-repeatability/specialheaders/repeatability/_model_base.py +++ b/packages/typespec-python/test/azure/generated/special-headers-repeatability/specialheaders/repeatability/_model_base.py @@ -16,7 +16,7 @@ import re import copy import typing -import email +import email.utils from datetime import datetime, date, time, timedelta, timezone from json import JSONEncoder import isodate diff --git a/packages/typespec-python/test/azure/generated/special-words/specialwords/_model_base.py b/packages/typespec-python/test/azure/generated/special-words/specialwords/_model_base.py index 247049f44d9..bd51cdeb446 100644 --- a/packages/typespec-python/test/azure/generated/special-words/specialwords/_model_base.py +++ b/packages/typespec-python/test/azure/generated/special-words/specialwords/_model_base.py @@ -16,7 +16,7 @@ import re import copy import typing -import email +import email.utils from datetime import datetime, date, time, timedelta, timezone from json import JSONEncoder import isodate diff --git a/packages/typespec-python/test/azure/generated/typetest-array/typetest/array/_model_base.py b/packages/typespec-python/test/azure/generated/typetest-array/typetest/array/_model_base.py index 247049f44d9..bd51cdeb446 100644 --- a/packages/typespec-python/test/azure/generated/typetest-array/typetest/array/_model_base.py +++ b/packages/typespec-python/test/azure/generated/typetest-array/typetest/array/_model_base.py @@ -16,7 +16,7 @@ import re import copy import typing -import email +import email.utils from datetime import datetime, date, time, timedelta, timezone from json import JSONEncoder import isodate diff --git a/packages/typespec-python/test/azure/generated/typetest-dictionary/typetest/dictionary/_model_base.py b/packages/typespec-python/test/azure/generated/typetest-dictionary/typetest/dictionary/_model_base.py index 247049f44d9..bd51cdeb446 100644 --- a/packages/typespec-python/test/azure/generated/typetest-dictionary/typetest/dictionary/_model_base.py +++ b/packages/typespec-python/test/azure/generated/typetest-dictionary/typetest/dictionary/_model_base.py @@ -16,7 +16,7 @@ import re import copy import typing -import email +import email.utils from datetime import datetime, date, time, timedelta, timezone from json import JSONEncoder import isodate diff --git a/packages/typespec-python/test/azure/generated/typetest-enum-extensible/typetest/enum/extensible/_model_base.py b/packages/typespec-python/test/azure/generated/typetest-enum-extensible/typetest/enum/extensible/_model_base.py index 247049f44d9..bd51cdeb446 100644 --- a/packages/typespec-python/test/azure/generated/typetest-enum-extensible/typetest/enum/extensible/_model_base.py +++ b/packages/typespec-python/test/azure/generated/typetest-enum-extensible/typetest/enum/extensible/_model_base.py @@ -16,7 +16,7 @@ import re import copy import typing -import email +import email.utils from datetime import datetime, date, time, timedelta, timezone from json import JSONEncoder import isodate diff --git a/packages/typespec-python/test/azure/generated/typetest-enum-fixed/typetest/enum/fixed/_model_base.py b/packages/typespec-python/test/azure/generated/typetest-enum-fixed/typetest/enum/fixed/_model_base.py index 247049f44d9..bd51cdeb446 100644 --- a/packages/typespec-python/test/azure/generated/typetest-enum-fixed/typetest/enum/fixed/_model_base.py +++ b/packages/typespec-python/test/azure/generated/typetest-enum-fixed/typetest/enum/fixed/_model_base.py @@ -16,7 +16,7 @@ import re import copy import typing -import email +import email.utils from datetime import datetime, date, time, timedelta, timezone from json import JSONEncoder import isodate diff --git a/packages/typespec-python/test/azure/generated/typetest-model-empty/typetest/model/empty/_model_base.py b/packages/typespec-python/test/azure/generated/typetest-model-empty/typetest/model/empty/_model_base.py index 247049f44d9..bd51cdeb446 100644 --- a/packages/typespec-python/test/azure/generated/typetest-model-empty/typetest/model/empty/_model_base.py +++ b/packages/typespec-python/test/azure/generated/typetest-model-empty/typetest/model/empty/_model_base.py @@ -16,7 +16,7 @@ import re import copy import typing -import email +import email.utils from datetime import datetime, date, time, timedelta, timezone from json import JSONEncoder import isodate diff --git a/packages/typespec-python/test/azure/generated/typetest-model-enumdiscriminator/typetest/model/enumdiscriminator/_model_base.py b/packages/typespec-python/test/azure/generated/typetest-model-enumdiscriminator/typetest/model/enumdiscriminator/_model_base.py index 247049f44d9..bd51cdeb446 100644 --- a/packages/typespec-python/test/azure/generated/typetest-model-enumdiscriminator/typetest/model/enumdiscriminator/_model_base.py +++ b/packages/typespec-python/test/azure/generated/typetest-model-enumdiscriminator/typetest/model/enumdiscriminator/_model_base.py @@ -16,7 +16,7 @@ import re import copy import typing -import email +import email.utils from datetime import datetime, date, time, timedelta, timezone from json import JSONEncoder import isodate diff --git a/packages/typespec-python/test/azure/generated/typetest-model-nesteddiscriminator/typetest/model/nesteddiscriminator/_model_base.py b/packages/typespec-python/test/azure/generated/typetest-model-nesteddiscriminator/typetest/model/nesteddiscriminator/_model_base.py index 247049f44d9..bd51cdeb446 100644 --- a/packages/typespec-python/test/azure/generated/typetest-model-nesteddiscriminator/typetest/model/nesteddiscriminator/_model_base.py +++ b/packages/typespec-python/test/azure/generated/typetest-model-nesteddiscriminator/typetest/model/nesteddiscriminator/_model_base.py @@ -16,7 +16,7 @@ import re import copy import typing -import email +import email.utils from datetime import datetime, date, time, timedelta, timezone from json import JSONEncoder import isodate diff --git a/packages/typespec-python/test/azure/generated/typetest-model-notdiscriminated/typetest/model/notdiscriminated/_model_base.py b/packages/typespec-python/test/azure/generated/typetest-model-notdiscriminated/typetest/model/notdiscriminated/_model_base.py index 247049f44d9..bd51cdeb446 100644 --- a/packages/typespec-python/test/azure/generated/typetest-model-notdiscriminated/typetest/model/notdiscriminated/_model_base.py +++ b/packages/typespec-python/test/azure/generated/typetest-model-notdiscriminated/typetest/model/notdiscriminated/_model_base.py @@ -16,7 +16,7 @@ import re import copy import typing -import email +import email.utils from datetime import datetime, date, time, timedelta, timezone from json import JSONEncoder import isodate diff --git a/packages/typespec-python/test/azure/generated/typetest-model-recursive/typetest/model/recursive/_model_base.py b/packages/typespec-python/test/azure/generated/typetest-model-recursive/typetest/model/recursive/_model_base.py index 247049f44d9..bd51cdeb446 100644 --- a/packages/typespec-python/test/azure/generated/typetest-model-recursive/typetest/model/recursive/_model_base.py +++ b/packages/typespec-python/test/azure/generated/typetest-model-recursive/typetest/model/recursive/_model_base.py @@ -16,7 +16,7 @@ import re import copy import typing -import email +import email.utils from datetime import datetime, date, time, timedelta, timezone from json import JSONEncoder import isodate diff --git a/packages/typespec-python/test/azure/generated/typetest-model-singlediscriminator/typetest/model/singlediscriminator/_model_base.py b/packages/typespec-python/test/azure/generated/typetest-model-singlediscriminator/typetest/model/singlediscriminator/_model_base.py index 247049f44d9..bd51cdeb446 100644 --- a/packages/typespec-python/test/azure/generated/typetest-model-singlediscriminator/typetest/model/singlediscriminator/_model_base.py +++ b/packages/typespec-python/test/azure/generated/typetest-model-singlediscriminator/typetest/model/singlediscriminator/_model_base.py @@ -16,7 +16,7 @@ import re import copy import typing -import email +import email.utils from datetime import datetime, date, time, timedelta, timezone from json import JSONEncoder import isodate diff --git a/packages/typespec-python/test/azure/generated/typetest-model-usage/typetest/model/usage/_model_base.py b/packages/typespec-python/test/azure/generated/typetest-model-usage/typetest/model/usage/_model_base.py index 247049f44d9..bd51cdeb446 100644 --- a/packages/typespec-python/test/azure/generated/typetest-model-usage/typetest/model/usage/_model_base.py +++ b/packages/typespec-python/test/azure/generated/typetest-model-usage/typetest/model/usage/_model_base.py @@ -16,7 +16,7 @@ import re import copy import typing -import email +import email.utils from datetime import datetime, date, time, timedelta, timezone from json import JSONEncoder import isodate diff --git a/packages/typespec-python/test/azure/generated/typetest-model-visibility/typetest/model/visibility/_model_base.py b/packages/typespec-python/test/azure/generated/typetest-model-visibility/typetest/model/visibility/_model_base.py index 247049f44d9..bd51cdeb446 100644 --- a/packages/typespec-python/test/azure/generated/typetest-model-visibility/typetest/model/visibility/_model_base.py +++ b/packages/typespec-python/test/azure/generated/typetest-model-visibility/typetest/model/visibility/_model_base.py @@ -16,7 +16,7 @@ import re import copy import typing -import email +import email.utils from datetime import datetime, date, time, timedelta, timezone from json import JSONEncoder import isodate diff --git a/packages/typespec-python/test/azure/generated/typetest-property-additionalproperties/typetest/property/additionalproperties/_model_base.py b/packages/typespec-python/test/azure/generated/typetest-property-additionalproperties/typetest/property/additionalproperties/_model_base.py index 247049f44d9..bd51cdeb446 100644 --- a/packages/typespec-python/test/azure/generated/typetest-property-additionalproperties/typetest/property/additionalproperties/_model_base.py +++ b/packages/typespec-python/test/azure/generated/typetest-property-additionalproperties/typetest/property/additionalproperties/_model_base.py @@ -16,7 +16,7 @@ import re import copy import typing -import email +import email.utils from datetime import datetime, date, time, timedelta, timezone from json import JSONEncoder import isodate diff --git a/packages/typespec-python/test/azure/generated/typetest-property-nullable/typetest/property/nullable/_model_base.py b/packages/typespec-python/test/azure/generated/typetest-property-nullable/typetest/property/nullable/_model_base.py index 247049f44d9..bd51cdeb446 100644 --- a/packages/typespec-python/test/azure/generated/typetest-property-nullable/typetest/property/nullable/_model_base.py +++ b/packages/typespec-python/test/azure/generated/typetest-property-nullable/typetest/property/nullable/_model_base.py @@ -16,7 +16,7 @@ import re import copy import typing -import email +import email.utils from datetime import datetime, date, time, timedelta, timezone from json import JSONEncoder import isodate diff --git a/packages/typespec-python/test/azure/generated/typetest-property-optional/typetest/property/optional/_model_base.py b/packages/typespec-python/test/azure/generated/typetest-property-optional/typetest/property/optional/_model_base.py index 247049f44d9..bd51cdeb446 100644 --- a/packages/typespec-python/test/azure/generated/typetest-property-optional/typetest/property/optional/_model_base.py +++ b/packages/typespec-python/test/azure/generated/typetest-property-optional/typetest/property/optional/_model_base.py @@ -16,7 +16,7 @@ import re import copy import typing -import email +import email.utils from datetime import datetime, date, time, timedelta, timezone from json import JSONEncoder import isodate diff --git a/packages/typespec-python/test/azure/generated/typetest-property-valuetypes/typetest/property/valuetypes/_model_base.py b/packages/typespec-python/test/azure/generated/typetest-property-valuetypes/typetest/property/valuetypes/_model_base.py index 247049f44d9..bd51cdeb446 100644 --- a/packages/typespec-python/test/azure/generated/typetest-property-valuetypes/typetest/property/valuetypes/_model_base.py +++ b/packages/typespec-python/test/azure/generated/typetest-property-valuetypes/typetest/property/valuetypes/_model_base.py @@ -16,7 +16,7 @@ import re import copy import typing -import email +import email.utils from datetime import datetime, date, time, timedelta, timezone from json import JSONEncoder import isodate diff --git a/packages/typespec-python/test/azure/generated/typetest-scalar/typetest/scalar/_model_base.py b/packages/typespec-python/test/azure/generated/typetest-scalar/typetest/scalar/_model_base.py index 247049f44d9..bd51cdeb446 100644 --- a/packages/typespec-python/test/azure/generated/typetest-scalar/typetest/scalar/_model_base.py +++ b/packages/typespec-python/test/azure/generated/typetest-scalar/typetest/scalar/_model_base.py @@ -16,7 +16,7 @@ import re import copy import typing -import email +import email.utils from datetime import datetime, date, time, timedelta, timezone from json import JSONEncoder import isodate diff --git a/packages/typespec-python/test/azure/generated/typetest-union/typetest/union/_model_base.py b/packages/typespec-python/test/azure/generated/typetest-union/typetest/union/_model_base.py index 247049f44d9..bd51cdeb446 100644 --- a/packages/typespec-python/test/azure/generated/typetest-union/typetest/union/_model_base.py +++ b/packages/typespec-python/test/azure/generated/typetest-union/typetest/union/_model_base.py @@ -16,7 +16,7 @@ import re import copy import typing -import email +import email.utils from datetime import datetime, date, time, timedelta, timezone from json import JSONEncoder import isodate diff --git a/packages/typespec-python/test/unbranded/generated/authentication-api-key/authentication/apikey/_model_base.py b/packages/typespec-python/test/unbranded/generated/authentication-api-key/authentication/apikey/_model_base.py index 849db7e8e49..f96ccdcd65d 100644 --- a/packages/typespec-python/test/unbranded/generated/authentication-api-key/authentication/apikey/_model_base.py +++ b/packages/typespec-python/test/unbranded/generated/authentication-api-key/authentication/apikey/_model_base.py @@ -16,7 +16,7 @@ import re import copy import typing -import email +import email.utils from datetime import datetime, date, time, timedelta, timezone from json import JSONEncoder import isodate diff --git a/packages/typespec-python/test/unbranded/generated/authentication-http-custom/authentication/http/custom/_model_base.py b/packages/typespec-python/test/unbranded/generated/authentication-http-custom/authentication/http/custom/_model_base.py index 849db7e8e49..f96ccdcd65d 100644 --- a/packages/typespec-python/test/unbranded/generated/authentication-http-custom/authentication/http/custom/_model_base.py +++ b/packages/typespec-python/test/unbranded/generated/authentication-http-custom/authentication/http/custom/_model_base.py @@ -16,7 +16,7 @@ import re import copy import typing -import email +import email.utils from datetime import datetime, date, time, timedelta, timezone from json import JSONEncoder import isodate diff --git a/packages/typespec-python/test/unbranded/generated/authentication-oauth2/authentication/oauth2/_model_base.py b/packages/typespec-python/test/unbranded/generated/authentication-oauth2/authentication/oauth2/_model_base.py index 849db7e8e49..f96ccdcd65d 100644 --- a/packages/typespec-python/test/unbranded/generated/authentication-oauth2/authentication/oauth2/_model_base.py +++ b/packages/typespec-python/test/unbranded/generated/authentication-oauth2/authentication/oauth2/_model_base.py @@ -16,7 +16,7 @@ import re import copy import typing -import email +import email.utils from datetime import datetime, date, time, timedelta, timezone from json import JSONEncoder import isodate diff --git a/packages/typespec-python/test/unbranded/generated/authentication-union/authentication/union/_model_base.py b/packages/typespec-python/test/unbranded/generated/authentication-union/authentication/union/_model_base.py index 849db7e8e49..f96ccdcd65d 100644 --- a/packages/typespec-python/test/unbranded/generated/authentication-union/authentication/union/_model_base.py +++ b/packages/typespec-python/test/unbranded/generated/authentication-union/authentication/union/_model_base.py @@ -16,7 +16,7 @@ import re import copy import typing -import email +import email.utils from datetime import datetime, date, time, timedelta, timezone from json import JSONEncoder import isodate diff --git a/packages/typespec-python/test/unbranded/generated/client-structure-default/client/structure/service/_model_base.py b/packages/typespec-python/test/unbranded/generated/client-structure-default/client/structure/service/_model_base.py index 849db7e8e49..f96ccdcd65d 100644 --- a/packages/typespec-python/test/unbranded/generated/client-structure-default/client/structure/service/_model_base.py +++ b/packages/typespec-python/test/unbranded/generated/client-structure-default/client/structure/service/_model_base.py @@ -16,7 +16,7 @@ import re import copy import typing -import email +import email.utils from datetime import datetime, date, time, timedelta, timezone from json import JSONEncoder import isodate diff --git a/packages/typespec-python/test/unbranded/generated/client-structure-multiclient/client/structure/multiclient/_model_base.py b/packages/typespec-python/test/unbranded/generated/client-structure-multiclient/client/structure/multiclient/_model_base.py index 849db7e8e49..f96ccdcd65d 100644 --- a/packages/typespec-python/test/unbranded/generated/client-structure-multiclient/client/structure/multiclient/_model_base.py +++ b/packages/typespec-python/test/unbranded/generated/client-structure-multiclient/client/structure/multiclient/_model_base.py @@ -16,7 +16,7 @@ import re import copy import typing -import email +import email.utils from datetime import datetime, date, time, timedelta, timezone from json import JSONEncoder import isodate diff --git a/packages/typespec-python/test/unbranded/generated/client-structure-renamedoperation/client/structure/renamedoperation/_model_base.py b/packages/typespec-python/test/unbranded/generated/client-structure-renamedoperation/client/structure/renamedoperation/_model_base.py index 849db7e8e49..f96ccdcd65d 100644 --- a/packages/typespec-python/test/unbranded/generated/client-structure-renamedoperation/client/structure/renamedoperation/_model_base.py +++ b/packages/typespec-python/test/unbranded/generated/client-structure-renamedoperation/client/structure/renamedoperation/_model_base.py @@ -16,7 +16,7 @@ import re import copy import typing -import email +import email.utils from datetime import datetime, date, time, timedelta, timezone from json import JSONEncoder import isodate diff --git a/packages/typespec-python/test/unbranded/generated/client-structure-twooperationgroup/client/structure/twooperationgroup/_model_base.py b/packages/typespec-python/test/unbranded/generated/client-structure-twooperationgroup/client/structure/twooperationgroup/_model_base.py index 849db7e8e49..f96ccdcd65d 100644 --- a/packages/typespec-python/test/unbranded/generated/client-structure-twooperationgroup/client/structure/twooperationgroup/_model_base.py +++ b/packages/typespec-python/test/unbranded/generated/client-structure-twooperationgroup/client/structure/twooperationgroup/_model_base.py @@ -16,7 +16,7 @@ import re import copy import typing -import email +import email.utils from datetime import datetime, date, time, timedelta, timezone from json import JSONEncoder import isodate diff --git a/packages/typespec-python/test/unbranded/generated/encode-bytes/encode/bytes/_model_base.py b/packages/typespec-python/test/unbranded/generated/encode-bytes/encode/bytes/_model_base.py index 849db7e8e49..f96ccdcd65d 100644 --- a/packages/typespec-python/test/unbranded/generated/encode-bytes/encode/bytes/_model_base.py +++ b/packages/typespec-python/test/unbranded/generated/encode-bytes/encode/bytes/_model_base.py @@ -16,7 +16,7 @@ import re import copy import typing -import email +import email.utils from datetime import datetime, date, time, timedelta, timezone from json import JSONEncoder import isodate diff --git a/packages/typespec-python/test/unbranded/generated/encode-datetime/encode/datetime/_model_base.py b/packages/typespec-python/test/unbranded/generated/encode-datetime/encode/datetime/_model_base.py index 849db7e8e49..f96ccdcd65d 100644 --- a/packages/typespec-python/test/unbranded/generated/encode-datetime/encode/datetime/_model_base.py +++ b/packages/typespec-python/test/unbranded/generated/encode-datetime/encode/datetime/_model_base.py @@ -16,7 +16,7 @@ import re import copy import typing -import email +import email.utils from datetime import datetime, date, time, timedelta, timezone from json import JSONEncoder import isodate diff --git a/packages/typespec-python/test/unbranded/generated/encode-duration/encode/duration/_model_base.py b/packages/typespec-python/test/unbranded/generated/encode-duration/encode/duration/_model_base.py index 849db7e8e49..f96ccdcd65d 100644 --- a/packages/typespec-python/test/unbranded/generated/encode-duration/encode/duration/_model_base.py +++ b/packages/typespec-python/test/unbranded/generated/encode-duration/encode/duration/_model_base.py @@ -16,7 +16,7 @@ import re import copy import typing -import email +import email.utils from datetime import datetime, date, time, timedelta, timezone from json import JSONEncoder import isodate diff --git a/packages/typespec-python/test/unbranded/generated/headasbooleanfalse/headasbooleanfalse/_model_base.py b/packages/typespec-python/test/unbranded/generated/headasbooleanfalse/headasbooleanfalse/_model_base.py index 849db7e8e49..f96ccdcd65d 100644 --- a/packages/typespec-python/test/unbranded/generated/headasbooleanfalse/headasbooleanfalse/_model_base.py +++ b/packages/typespec-python/test/unbranded/generated/headasbooleanfalse/headasbooleanfalse/_model_base.py @@ -16,7 +16,7 @@ import re import copy import typing -import email +import email.utils from datetime import datetime, date, time, timedelta, timezone from json import JSONEncoder import isodate diff --git a/packages/typespec-python/test/unbranded/generated/headasbooleantrue/headasbooleantrue/_model_base.py b/packages/typespec-python/test/unbranded/generated/headasbooleantrue/headasbooleantrue/_model_base.py index 849db7e8e49..f96ccdcd65d 100644 --- a/packages/typespec-python/test/unbranded/generated/headasbooleantrue/headasbooleantrue/_model_base.py +++ b/packages/typespec-python/test/unbranded/generated/headasbooleantrue/headasbooleantrue/_model_base.py @@ -16,7 +16,7 @@ import re import copy import typing -import email +import email.utils from datetime import datetime, date, time, timedelta, timezone from json import JSONEncoder import isodate diff --git a/packages/typespec-python/test/unbranded/generated/parameters-body-optionality/parameters/bodyoptionality/_model_base.py b/packages/typespec-python/test/unbranded/generated/parameters-body-optionality/parameters/bodyoptionality/_model_base.py index 849db7e8e49..f96ccdcd65d 100644 --- a/packages/typespec-python/test/unbranded/generated/parameters-body-optionality/parameters/bodyoptionality/_model_base.py +++ b/packages/typespec-python/test/unbranded/generated/parameters-body-optionality/parameters/bodyoptionality/_model_base.py @@ -16,7 +16,7 @@ import re import copy import typing -import email +import email.utils from datetime import datetime, date, time, timedelta, timezone from json import JSONEncoder import isodate diff --git a/packages/typespec-python/test/unbranded/generated/parameters-collection-format/parameters/collectionformat/_model_base.py b/packages/typespec-python/test/unbranded/generated/parameters-collection-format/parameters/collectionformat/_model_base.py index 849db7e8e49..f96ccdcd65d 100644 --- a/packages/typespec-python/test/unbranded/generated/parameters-collection-format/parameters/collectionformat/_model_base.py +++ b/packages/typespec-python/test/unbranded/generated/parameters-collection-format/parameters/collectionformat/_model_base.py @@ -16,7 +16,7 @@ import re import copy import typing -import email +import email.utils from datetime import datetime, date, time, timedelta, timezone from json import JSONEncoder import isodate diff --git a/packages/typespec-python/test/unbranded/generated/parameters-spread/parameters/spread/_model_base.py b/packages/typespec-python/test/unbranded/generated/parameters-spread/parameters/spread/_model_base.py index 849db7e8e49..f96ccdcd65d 100644 --- a/packages/typespec-python/test/unbranded/generated/parameters-spread/parameters/spread/_model_base.py +++ b/packages/typespec-python/test/unbranded/generated/parameters-spread/parameters/spread/_model_base.py @@ -16,7 +16,7 @@ import re import copy import typing -import email +import email.utils from datetime import datetime, date, time, timedelta, timezone from json import JSONEncoder import isodate diff --git a/packages/typespec-python/test/unbranded/generated/payload-content-negotiation/payload/contentnegotiation/_model_base.py b/packages/typespec-python/test/unbranded/generated/payload-content-negotiation/payload/contentnegotiation/_model_base.py index 849db7e8e49..f96ccdcd65d 100644 --- a/packages/typespec-python/test/unbranded/generated/payload-content-negotiation/payload/contentnegotiation/_model_base.py +++ b/packages/typespec-python/test/unbranded/generated/payload-content-negotiation/payload/contentnegotiation/_model_base.py @@ -16,7 +16,7 @@ import re import copy import typing -import email +import email.utils from datetime import datetime, date, time, timedelta, timezone from json import JSONEncoder import isodate diff --git a/packages/typespec-python/test/unbranded/generated/payload-media-type/payload/mediatype/_model_base.py b/packages/typespec-python/test/unbranded/generated/payload-media-type/payload/mediatype/_model_base.py index 849db7e8e49..f96ccdcd65d 100644 --- a/packages/typespec-python/test/unbranded/generated/payload-media-type/payload/mediatype/_model_base.py +++ b/packages/typespec-python/test/unbranded/generated/payload-media-type/payload/mediatype/_model_base.py @@ -16,7 +16,7 @@ import re import copy import typing -import email +import email.utils from datetime import datetime, date, time, timedelta, timezone from json import JSONEncoder import isodate diff --git a/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/_model_base.py b/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/_model_base.py index 849db7e8e49..f96ccdcd65d 100644 --- a/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/_model_base.py +++ b/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/_model_base.py @@ -16,7 +16,7 @@ import re import copy import typing -import email +import email.utils from datetime import datetime, date, time, timedelta, timezone from json import JSONEncoder import isodate diff --git a/packages/typespec-python/test/unbranded/generated/payload-pageable/payload/pageable/_model_base.py b/packages/typespec-python/test/unbranded/generated/payload-pageable/payload/pageable/_model_base.py index 849db7e8e49..f96ccdcd65d 100644 --- a/packages/typespec-python/test/unbranded/generated/payload-pageable/payload/pageable/_model_base.py +++ b/packages/typespec-python/test/unbranded/generated/payload-pageable/payload/pageable/_model_base.py @@ -16,7 +16,7 @@ import re import copy import typing -import email +import email.utils from datetime import datetime, date, time, timedelta, timezone from json import JSONEncoder import isodate diff --git a/packages/typespec-python/test/unbranded/generated/projection-projected-name/projection/projectedname/_model_base.py b/packages/typespec-python/test/unbranded/generated/projection-projected-name/projection/projectedname/_model_base.py index 849db7e8e49..f96ccdcd65d 100644 --- a/packages/typespec-python/test/unbranded/generated/projection-projected-name/projection/projectedname/_model_base.py +++ b/packages/typespec-python/test/unbranded/generated/projection-projected-name/projection/projectedname/_model_base.py @@ -16,7 +16,7 @@ import re import copy import typing -import email +import email.utils from datetime import datetime, date, time, timedelta, timezone from json import JSONEncoder import isodate diff --git a/packages/typespec-python/test/unbranded/generated/resiliency-srv-driven1/resiliency/srv/driven1/_model_base.py b/packages/typespec-python/test/unbranded/generated/resiliency-srv-driven1/resiliency/srv/driven1/_model_base.py index 849db7e8e49..f96ccdcd65d 100644 --- a/packages/typespec-python/test/unbranded/generated/resiliency-srv-driven1/resiliency/srv/driven1/_model_base.py +++ b/packages/typespec-python/test/unbranded/generated/resiliency-srv-driven1/resiliency/srv/driven1/_model_base.py @@ -16,7 +16,7 @@ import re import copy import typing -import email +import email.utils from datetime import datetime, date, time, timedelta, timezone from json import JSONEncoder import isodate diff --git a/packages/typespec-python/test/unbranded/generated/resiliency-srv-driven2/resiliency/srv/driven2/_model_base.py b/packages/typespec-python/test/unbranded/generated/resiliency-srv-driven2/resiliency/srv/driven2/_model_base.py index 849db7e8e49..f96ccdcd65d 100644 --- a/packages/typespec-python/test/unbranded/generated/resiliency-srv-driven2/resiliency/srv/driven2/_model_base.py +++ b/packages/typespec-python/test/unbranded/generated/resiliency-srv-driven2/resiliency/srv/driven2/_model_base.py @@ -16,7 +16,7 @@ import re import copy import typing -import email +import email.utils from datetime import datetime, date, time, timedelta, timezone from json import JSONEncoder import isodate diff --git a/packages/typespec-python/test/unbranded/generated/server-path-multiple/server/path/multiple/_model_base.py b/packages/typespec-python/test/unbranded/generated/server-path-multiple/server/path/multiple/_model_base.py index 849db7e8e49..f96ccdcd65d 100644 --- a/packages/typespec-python/test/unbranded/generated/server-path-multiple/server/path/multiple/_model_base.py +++ b/packages/typespec-python/test/unbranded/generated/server-path-multiple/server/path/multiple/_model_base.py @@ -16,7 +16,7 @@ import re import copy import typing -import email +import email.utils from datetime import datetime, date, time, timedelta, timezone from json import JSONEncoder import isodate diff --git a/packages/typespec-python/test/unbranded/generated/server-path-single/server/path/single/_model_base.py b/packages/typespec-python/test/unbranded/generated/server-path-single/server/path/single/_model_base.py index 849db7e8e49..f96ccdcd65d 100644 --- a/packages/typespec-python/test/unbranded/generated/server-path-single/server/path/single/_model_base.py +++ b/packages/typespec-python/test/unbranded/generated/server-path-single/server/path/single/_model_base.py @@ -16,7 +16,7 @@ import re import copy import typing -import email +import email.utils from datetime import datetime, date, time, timedelta, timezone from json import JSONEncoder import isodate diff --git a/packages/typespec-python/test/unbranded/generated/server-versions-not-versioned/server/versions/notversioned/_model_base.py b/packages/typespec-python/test/unbranded/generated/server-versions-not-versioned/server/versions/notversioned/_model_base.py index 849db7e8e49..f96ccdcd65d 100644 --- a/packages/typespec-python/test/unbranded/generated/server-versions-not-versioned/server/versions/notversioned/_model_base.py +++ b/packages/typespec-python/test/unbranded/generated/server-versions-not-versioned/server/versions/notversioned/_model_base.py @@ -16,7 +16,7 @@ import re import copy import typing -import email +import email.utils from datetime import datetime, date, time, timedelta, timezone from json import JSONEncoder import isodate diff --git a/packages/typespec-python/test/unbranded/generated/server-versions-versioned/server/versions/versioned/_model_base.py b/packages/typespec-python/test/unbranded/generated/server-versions-versioned/server/versions/versioned/_model_base.py index 849db7e8e49..f96ccdcd65d 100644 --- a/packages/typespec-python/test/unbranded/generated/server-versions-versioned/server/versions/versioned/_model_base.py +++ b/packages/typespec-python/test/unbranded/generated/server-versions-versioned/server/versions/versioned/_model_base.py @@ -16,7 +16,7 @@ import re import copy import typing -import email +import email.utils from datetime import datetime, date, time, timedelta, timezone from json import JSONEncoder import isodate diff --git a/packages/typespec-python/test/unbranded/generated/special-headers-conditional-request/specialheaders/conditionalrequest/_model_base.py b/packages/typespec-python/test/unbranded/generated/special-headers-conditional-request/specialheaders/conditionalrequest/_model_base.py index 849db7e8e49..f96ccdcd65d 100644 --- a/packages/typespec-python/test/unbranded/generated/special-headers-conditional-request/specialheaders/conditionalrequest/_model_base.py +++ b/packages/typespec-python/test/unbranded/generated/special-headers-conditional-request/specialheaders/conditionalrequest/_model_base.py @@ -16,7 +16,7 @@ import re import copy import typing -import email +import email.utils from datetime import datetime, date, time, timedelta, timezone from json import JSONEncoder import isodate diff --git a/packages/typespec-python/test/unbranded/generated/special-headers-repeatability/specialheaders/repeatability/_model_base.py b/packages/typespec-python/test/unbranded/generated/special-headers-repeatability/specialheaders/repeatability/_model_base.py index 849db7e8e49..f96ccdcd65d 100644 --- a/packages/typespec-python/test/unbranded/generated/special-headers-repeatability/specialheaders/repeatability/_model_base.py +++ b/packages/typespec-python/test/unbranded/generated/special-headers-repeatability/specialheaders/repeatability/_model_base.py @@ -16,7 +16,7 @@ import re import copy import typing -import email +import email.utils from datetime import datetime, date, time, timedelta, timezone from json import JSONEncoder import isodate diff --git a/packages/typespec-python/test/unbranded/generated/special-words/specialwords/_model_base.py b/packages/typespec-python/test/unbranded/generated/special-words/specialwords/_model_base.py index 849db7e8e49..f96ccdcd65d 100644 --- a/packages/typespec-python/test/unbranded/generated/special-words/specialwords/_model_base.py +++ b/packages/typespec-python/test/unbranded/generated/special-words/specialwords/_model_base.py @@ -16,7 +16,7 @@ import re import copy import typing -import email +import email.utils from datetime import datetime, date, time, timedelta, timezone from json import JSONEncoder import isodate diff --git a/packages/typespec-python/test/unbranded/generated/typetest-array/typetest/array/_model_base.py b/packages/typespec-python/test/unbranded/generated/typetest-array/typetest/array/_model_base.py index 849db7e8e49..f96ccdcd65d 100644 --- a/packages/typespec-python/test/unbranded/generated/typetest-array/typetest/array/_model_base.py +++ b/packages/typespec-python/test/unbranded/generated/typetest-array/typetest/array/_model_base.py @@ -16,7 +16,7 @@ import re import copy import typing -import email +import email.utils from datetime import datetime, date, time, timedelta, timezone from json import JSONEncoder import isodate diff --git a/packages/typespec-python/test/unbranded/generated/typetest-dictionary/typetest/dictionary/_model_base.py b/packages/typespec-python/test/unbranded/generated/typetest-dictionary/typetest/dictionary/_model_base.py index 849db7e8e49..f96ccdcd65d 100644 --- a/packages/typespec-python/test/unbranded/generated/typetest-dictionary/typetest/dictionary/_model_base.py +++ b/packages/typespec-python/test/unbranded/generated/typetest-dictionary/typetest/dictionary/_model_base.py @@ -16,7 +16,7 @@ import re import copy import typing -import email +import email.utils from datetime import datetime, date, time, timedelta, timezone from json import JSONEncoder import isodate diff --git a/packages/typespec-python/test/unbranded/generated/typetest-enum-extensible/typetest/enum/extensible/_model_base.py b/packages/typespec-python/test/unbranded/generated/typetest-enum-extensible/typetest/enum/extensible/_model_base.py index 849db7e8e49..f96ccdcd65d 100644 --- a/packages/typespec-python/test/unbranded/generated/typetest-enum-extensible/typetest/enum/extensible/_model_base.py +++ b/packages/typespec-python/test/unbranded/generated/typetest-enum-extensible/typetest/enum/extensible/_model_base.py @@ -16,7 +16,7 @@ import re import copy import typing -import email +import email.utils from datetime import datetime, date, time, timedelta, timezone from json import JSONEncoder import isodate diff --git a/packages/typespec-python/test/unbranded/generated/typetest-enum-fixed/typetest/enum/fixed/_model_base.py b/packages/typespec-python/test/unbranded/generated/typetest-enum-fixed/typetest/enum/fixed/_model_base.py index 849db7e8e49..f96ccdcd65d 100644 --- a/packages/typespec-python/test/unbranded/generated/typetest-enum-fixed/typetest/enum/fixed/_model_base.py +++ b/packages/typespec-python/test/unbranded/generated/typetest-enum-fixed/typetest/enum/fixed/_model_base.py @@ -16,7 +16,7 @@ import re import copy import typing -import email +import email.utils from datetime import datetime, date, time, timedelta, timezone from json import JSONEncoder import isodate diff --git a/packages/typespec-python/test/unbranded/generated/typetest-model-empty/typetest/model/empty/_model_base.py b/packages/typespec-python/test/unbranded/generated/typetest-model-empty/typetest/model/empty/_model_base.py index 849db7e8e49..f96ccdcd65d 100644 --- a/packages/typespec-python/test/unbranded/generated/typetest-model-empty/typetest/model/empty/_model_base.py +++ b/packages/typespec-python/test/unbranded/generated/typetest-model-empty/typetest/model/empty/_model_base.py @@ -16,7 +16,7 @@ import re import copy import typing -import email +import email.utils from datetime import datetime, date, time, timedelta, timezone from json import JSONEncoder import isodate diff --git a/packages/typespec-python/test/unbranded/generated/typetest-model-enumdiscriminator/typetest/model/enumdiscriminator/_model_base.py b/packages/typespec-python/test/unbranded/generated/typetest-model-enumdiscriminator/typetest/model/enumdiscriminator/_model_base.py index 849db7e8e49..f96ccdcd65d 100644 --- a/packages/typespec-python/test/unbranded/generated/typetest-model-enumdiscriminator/typetest/model/enumdiscriminator/_model_base.py +++ b/packages/typespec-python/test/unbranded/generated/typetest-model-enumdiscriminator/typetest/model/enumdiscriminator/_model_base.py @@ -16,7 +16,7 @@ import re import copy import typing -import email +import email.utils from datetime import datetime, date, time, timedelta, timezone from json import JSONEncoder import isodate diff --git a/packages/typespec-python/test/unbranded/generated/typetest-model-nesteddiscriminator/typetest/model/nesteddiscriminator/_model_base.py b/packages/typespec-python/test/unbranded/generated/typetest-model-nesteddiscriminator/typetest/model/nesteddiscriminator/_model_base.py index 849db7e8e49..f96ccdcd65d 100644 --- a/packages/typespec-python/test/unbranded/generated/typetest-model-nesteddiscriminator/typetest/model/nesteddiscriminator/_model_base.py +++ b/packages/typespec-python/test/unbranded/generated/typetest-model-nesteddiscriminator/typetest/model/nesteddiscriminator/_model_base.py @@ -16,7 +16,7 @@ import re import copy import typing -import email +import email.utils from datetime import datetime, date, time, timedelta, timezone from json import JSONEncoder import isodate diff --git a/packages/typespec-python/test/unbranded/generated/typetest-model-notdiscriminated/typetest/model/notdiscriminated/_model_base.py b/packages/typespec-python/test/unbranded/generated/typetest-model-notdiscriminated/typetest/model/notdiscriminated/_model_base.py index 849db7e8e49..f96ccdcd65d 100644 --- a/packages/typespec-python/test/unbranded/generated/typetest-model-notdiscriminated/typetest/model/notdiscriminated/_model_base.py +++ b/packages/typespec-python/test/unbranded/generated/typetest-model-notdiscriminated/typetest/model/notdiscriminated/_model_base.py @@ -16,7 +16,7 @@ import re import copy import typing -import email +import email.utils from datetime import datetime, date, time, timedelta, timezone from json import JSONEncoder import isodate diff --git a/packages/typespec-python/test/unbranded/generated/typetest-model-recursive/typetest/model/recursive/_model_base.py b/packages/typespec-python/test/unbranded/generated/typetest-model-recursive/typetest/model/recursive/_model_base.py index 849db7e8e49..f96ccdcd65d 100644 --- a/packages/typespec-python/test/unbranded/generated/typetest-model-recursive/typetest/model/recursive/_model_base.py +++ b/packages/typespec-python/test/unbranded/generated/typetest-model-recursive/typetest/model/recursive/_model_base.py @@ -16,7 +16,7 @@ import re import copy import typing -import email +import email.utils from datetime import datetime, date, time, timedelta, timezone from json import JSONEncoder import isodate diff --git a/packages/typespec-python/test/unbranded/generated/typetest-model-singlediscriminator/typetest/model/singlediscriminator/_model_base.py b/packages/typespec-python/test/unbranded/generated/typetest-model-singlediscriminator/typetest/model/singlediscriminator/_model_base.py index 849db7e8e49..f96ccdcd65d 100644 --- a/packages/typespec-python/test/unbranded/generated/typetest-model-singlediscriminator/typetest/model/singlediscriminator/_model_base.py +++ b/packages/typespec-python/test/unbranded/generated/typetest-model-singlediscriminator/typetest/model/singlediscriminator/_model_base.py @@ -16,7 +16,7 @@ import re import copy import typing -import email +import email.utils from datetime import datetime, date, time, timedelta, timezone from json import JSONEncoder import isodate diff --git a/packages/typespec-python/test/unbranded/generated/typetest-model-usage/typetest/model/usage/_model_base.py b/packages/typespec-python/test/unbranded/generated/typetest-model-usage/typetest/model/usage/_model_base.py index 849db7e8e49..f96ccdcd65d 100644 --- a/packages/typespec-python/test/unbranded/generated/typetest-model-usage/typetest/model/usage/_model_base.py +++ b/packages/typespec-python/test/unbranded/generated/typetest-model-usage/typetest/model/usage/_model_base.py @@ -16,7 +16,7 @@ import re import copy import typing -import email +import email.utils from datetime import datetime, date, time, timedelta, timezone from json import JSONEncoder import isodate diff --git a/packages/typespec-python/test/unbranded/generated/typetest-model-visibility/typetest/model/visibility/_model_base.py b/packages/typespec-python/test/unbranded/generated/typetest-model-visibility/typetest/model/visibility/_model_base.py index 849db7e8e49..f96ccdcd65d 100644 --- a/packages/typespec-python/test/unbranded/generated/typetest-model-visibility/typetest/model/visibility/_model_base.py +++ b/packages/typespec-python/test/unbranded/generated/typetest-model-visibility/typetest/model/visibility/_model_base.py @@ -16,7 +16,7 @@ import re import copy import typing -import email +import email.utils from datetime import datetime, date, time, timedelta, timezone from json import JSONEncoder import isodate diff --git a/packages/typespec-python/test/unbranded/generated/typetest-property-additionalproperties/typetest/property/additionalproperties/_model_base.py b/packages/typespec-python/test/unbranded/generated/typetest-property-additionalproperties/typetest/property/additionalproperties/_model_base.py index 849db7e8e49..f96ccdcd65d 100644 --- a/packages/typespec-python/test/unbranded/generated/typetest-property-additionalproperties/typetest/property/additionalproperties/_model_base.py +++ b/packages/typespec-python/test/unbranded/generated/typetest-property-additionalproperties/typetest/property/additionalproperties/_model_base.py @@ -16,7 +16,7 @@ import re import copy import typing -import email +import email.utils from datetime import datetime, date, time, timedelta, timezone from json import JSONEncoder import isodate diff --git a/packages/typespec-python/test/unbranded/generated/typetest-property-nullable/typetest/property/nullable/_model_base.py b/packages/typespec-python/test/unbranded/generated/typetest-property-nullable/typetest/property/nullable/_model_base.py index 849db7e8e49..f96ccdcd65d 100644 --- a/packages/typespec-python/test/unbranded/generated/typetest-property-nullable/typetest/property/nullable/_model_base.py +++ b/packages/typespec-python/test/unbranded/generated/typetest-property-nullable/typetest/property/nullable/_model_base.py @@ -16,7 +16,7 @@ import re import copy import typing -import email +import email.utils from datetime import datetime, date, time, timedelta, timezone from json import JSONEncoder import isodate diff --git a/packages/typespec-python/test/unbranded/generated/typetest-property-optional/typetest/property/optional/_model_base.py b/packages/typespec-python/test/unbranded/generated/typetest-property-optional/typetest/property/optional/_model_base.py index 849db7e8e49..f96ccdcd65d 100644 --- a/packages/typespec-python/test/unbranded/generated/typetest-property-optional/typetest/property/optional/_model_base.py +++ b/packages/typespec-python/test/unbranded/generated/typetest-property-optional/typetest/property/optional/_model_base.py @@ -16,7 +16,7 @@ import re import copy import typing -import email +import email.utils from datetime import datetime, date, time, timedelta, timezone from json import JSONEncoder import isodate diff --git a/packages/typespec-python/test/unbranded/generated/typetest-property-valuetypes/typetest/property/valuetypes/_model_base.py b/packages/typespec-python/test/unbranded/generated/typetest-property-valuetypes/typetest/property/valuetypes/_model_base.py index 849db7e8e49..f96ccdcd65d 100644 --- a/packages/typespec-python/test/unbranded/generated/typetest-property-valuetypes/typetest/property/valuetypes/_model_base.py +++ b/packages/typespec-python/test/unbranded/generated/typetest-property-valuetypes/typetest/property/valuetypes/_model_base.py @@ -16,7 +16,7 @@ import re import copy import typing -import email +import email.utils from datetime import datetime, date, time, timedelta, timezone from json import JSONEncoder import isodate diff --git a/packages/typespec-python/test/unbranded/generated/typetest-scalar/typetest/scalar/_model_base.py b/packages/typespec-python/test/unbranded/generated/typetest-scalar/typetest/scalar/_model_base.py index 849db7e8e49..f96ccdcd65d 100644 --- a/packages/typespec-python/test/unbranded/generated/typetest-scalar/typetest/scalar/_model_base.py +++ b/packages/typespec-python/test/unbranded/generated/typetest-scalar/typetest/scalar/_model_base.py @@ -16,7 +16,7 @@ import re import copy import typing -import email +import email.utils from datetime import datetime, date, time, timedelta, timezone from json import JSONEncoder import isodate diff --git a/packages/typespec-python/test/unbranded/generated/typetest-union/typetest/union/_model_base.py b/packages/typespec-python/test/unbranded/generated/typetest-union/typetest/union/_model_base.py index 849db7e8e49..f96ccdcd65d 100644 --- a/packages/typespec-python/test/unbranded/generated/typetest-union/typetest/union/_model_base.py +++ b/packages/typespec-python/test/unbranded/generated/typetest-union/typetest/union/_model_base.py @@ -16,7 +16,7 @@ import re import copy import typing -import email +import email.utils from datetime import datetime, date, time, timedelta, timezone from json import JSONEncoder import isodate From 8f53d036d354339b909de909c00baacf76464154 Mon Sep 17 00:00:00 2001 From: iscai-msft Date: Thu, 1 Feb 2024 16:14:16 -0500 Subject: [PATCH 29/45] generate with optional filetype --- .../autorest/codegen/models/property.py | 11 ++++++----- .../payload/multipart/models/_models.py | 4 ++-- .../payload/multipart/models/_models.py | 4 ++-- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/packages/autorest.python/autorest/codegen/models/property.py b/packages/autorest.python/autorest/codegen/models/property.py index 62142a19316..e4dc44e78e3 100644 --- a/packages/autorest.python/autorest/codegen/models/property.py +++ b/packages/autorest.python/autorest/codegen/models/property.py @@ -97,17 +97,18 @@ def is_enum_discriminator(self) -> bool: return self.is_discriminator and self.type.type == "enum" def type_annotation(self, *, is_operation_file: bool = False) -> str: + types_type_annotation = self.type.type_annotation( + is_operation_file=is_operation_file + ) if self.is_multipart_file_input: # we only support FileType or list of FileType - if self.type.type == "list": - return "List[FileType]" - return "FileType" + types_type_annotation = types_type_annotation.replace("bytes", "FileType") if self.is_enum_discriminator: # here we are the enum discriminator property on the base model return "Literal[None]" if self.optional and self.client_default_value is None: - return f"Optional[{self.type.type_annotation(is_operation_file=is_operation_file)}]" - return self.type.type_annotation(is_operation_file=is_operation_file) + return f"Optional[{types_type_annotation}]" + return types_type_annotation def get_declaration(self, value: Any = None) -> Any: if self.is_enum_discriminator: diff --git a/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/models/_models.py b/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/models/_models.py index 759895ff114..f16ff0f0dc3 100644 --- a/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/models/_models.py +++ b/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/models/_models.py @@ -221,14 +221,14 @@ class MultiBinaryPartsRequest(_model_base.Model): profile_image: FileType = rest_field(name="profileImage", is_multipart_file_input=True) """Required.""" - picture: FileType = rest_field(is_multipart_file_input=True) + picture: Optional[FileType] = rest_field(is_multipart_file_input=True) @overload def __init__( self, *, profile_image: FileType, - picture: FileType = None, + picture: Optional[FileType] = None, ): ... diff --git a/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/models/_models.py b/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/models/_models.py index c058265a799..c4905916692 100644 --- a/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/models/_models.py +++ b/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/models/_models.py @@ -221,14 +221,14 @@ class MultiBinaryPartsRequest(_model_base.Model): profile_image: FileType = rest_field(name="profileImage", is_multipart_file_input=True) """Required.""" - picture: FileType = rest_field(is_multipart_file_input=True) + picture: Optional[FileType] = rest_field(is_multipart_file_input=True) @overload def __init__( self, *, profile_image: FileType, - picture: FileType = None, + picture: Optional[FileType] = None, ): ... From 0da11ba2a826b89e3c952cfd2aba499387e9eea2 Mon Sep 17 00:00:00 2001 From: iscai-msft Date: Thu, 1 Feb 2024 16:48:52 -0500 Subject: [PATCH 30/45] give typehint to _data --- .../autorest/codegen/models/property.py | 2 ++ .../codegen/serializers/builder_serializer.py | 2 +- .../payload/multipart/aio/operations/_operations.py | 12 ++++++------ .../payload/multipart/models/_models.py | 2 +- .../payload/multipart/operations/_operations.py | 12 ++++++------ .../payload/multipart/aio/operations/_operations.py | 12 ++++++------ .../payload/multipart/models/_models.py | 2 +- .../payload/multipart/operations/_operations.py | 12 ++++++------ 8 files changed, 29 insertions(+), 27 deletions(-) diff --git a/packages/autorest.python/autorest/codegen/models/property.py b/packages/autorest.python/autorest/codegen/models/property.py index e4dc44e78e3..b55fb93ef87 100644 --- a/packages/autorest.python/autorest/codegen/models/property.py +++ b/packages/autorest.python/autorest/codegen/models/property.py @@ -174,6 +174,8 @@ def imports(self, **kwargs) -> FileImport: ) if self.is_multipart_file_input: file_import.add_submodule_import(".._vendor", "FileType", ImportType.LOCAL) + file_import.add_submodule_import("typing", "Dict", ImportType.STDLIB) + file_import.add_submodule_import("typing", "Any", ImportType.STDLIB) return file_import @classmethod diff --git a/packages/autorest.python/autorest/codegen/serializers/builder_serializer.py b/packages/autorest.python/autorest/codegen/serializers/builder_serializer.py index bf69d02f4cb..d1733be2810 100644 --- a/packages/autorest.python/autorest/codegen/serializers/builder_serializer.py +++ b/packages/autorest.python/autorest/codegen/serializers/builder_serializer.py @@ -762,7 +762,7 @@ def _serialize_body_parameter(self, builder: OperationType) -> List[str]: f" {body_param.client_name}", ")", "_files = []", - "_data = {}", + "_data: Dict[str, Any] = {}", ] ) model_type = ( diff --git a/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/aio/operations/_operations.py b/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/aio/operations/_operations.py index 65c01f73a5a..28ae3396b2a 100644 --- a/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/aio/operations/_operations.py +++ b/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/aio/operations/_operations.py @@ -128,7 +128,7 @@ async def basic( # pylint: disable=inconsistent-return-statements _body = body.as_dict() if isinstance(body, _model_base.Model) else body _files = [] - _data = {} + _data: Dict[str, Any] = {} if _body.get("id") is not None: _data["id"] = _body["id"] if _body.get("profileImage") is not None: @@ -245,7 +245,7 @@ async def complex( # pylint: disable=inconsistent-return-statements _body = body.as_dict() if isinstance(body, _model_base.Model) else body _files = [] - _data = {} + _data: Dict[str, Any] = {} if _body.get("id") is not None: _data["id"] = _body["id"] if _body.get("address") is not None: @@ -356,7 +356,7 @@ async def json_part( # pylint: disable=inconsistent-return-statements _body = body.as_dict() if isinstance(body, _model_base.Model) else body _files = [] - _data = {} + _data: Dict[str, Any] = {} if _body.get("address") is not None: _data["address"] = json.dumps(_body["address"], cls=SdkJSONEncoder, exclude_readonly=True) if _body.get("profileImage") is not None: @@ -457,7 +457,7 @@ async def binary_array_parts( # pylint: disable=inconsistent-return-statements _body = body.as_dict() if isinstance(body, _model_base.Model) else body _files = [] - _data = {} + _data: Dict[str, Any] = {} if _body.get("id") is not None: _data["id"] = _body["id"] if _body.get("pictures") is not None: @@ -566,7 +566,7 @@ async def json_array_parts( # pylint: disable=inconsistent-return-statements _body = body.as_dict() if isinstance(body, _model_base.Model) else body _files = [] - _data = {} + _data: Dict[str, Any] = {} if _body.get("profileImage") is not None: _files.append(("profileImage", _body["profileImage"])) if _body.get("previousAddresses") is not None: @@ -669,7 +669,7 @@ async def multi_binary_parts( # pylint: disable=inconsistent-return-statements _body = body.as_dict() if isinstance(body, _model_base.Model) else body _files = [] - _data = {} + _data: Dict[str, Any] = {} if _body.get("profileImage") is not None: _files.append(("profileImage", _body["profileImage"])) if _body.get("picture") is not None: diff --git a/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/models/_models.py b/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/models/_models.py index f16ff0f0dc3..437a383e388 100644 --- a/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/models/_models.py +++ b/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/models/_models.py @@ -7,7 +7,7 @@ # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from typing import Any, List, Mapping, Optional, TYPE_CHECKING, overload +from typing import Any, Dict, List, Mapping, Optional, TYPE_CHECKING, overload from .. import _model_base from .._model_base import rest_field diff --git a/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/operations/_operations.py b/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/operations/_operations.py index f394cfffc5f..402aa68440d 100644 --- a/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/operations/_operations.py +++ b/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/operations/_operations.py @@ -179,7 +179,7 @@ def basic( # pylint: disable=inconsistent-return-statements _body = body.as_dict() if isinstance(body, _model_base.Model) else body _files = [] - _data = {} + _data: Dict[str, Any] = {} if _body.get("id") is not None: _data["id"] = _body["id"] if _body.get("profileImage") is not None: @@ -296,7 +296,7 @@ def complex( # pylint: disable=inconsistent-return-statements _body = body.as_dict() if isinstance(body, _model_base.Model) else body _files = [] - _data = {} + _data: Dict[str, Any] = {} if _body.get("id") is not None: _data["id"] = _body["id"] if _body.get("address") is not None: @@ -407,7 +407,7 @@ def json_part( # pylint: disable=inconsistent-return-statements _body = body.as_dict() if isinstance(body, _model_base.Model) else body _files = [] - _data = {} + _data: Dict[str, Any] = {} if _body.get("address") is not None: _data["address"] = json.dumps(_body["address"], cls=SdkJSONEncoder, exclude_readonly=True) if _body.get("profileImage") is not None: @@ -506,7 +506,7 @@ def binary_array_parts( # pylint: disable=inconsistent-return-statements _body = body.as_dict() if isinstance(body, _model_base.Model) else body _files = [] - _data = {} + _data: Dict[str, Any] = {} if _body.get("id") is not None: _data["id"] = _body["id"] if _body.get("pictures") is not None: @@ -613,7 +613,7 @@ def json_array_parts( # pylint: disable=inconsistent-return-statements _body = body.as_dict() if isinstance(body, _model_base.Model) else body _files = [] - _data = {} + _data: Dict[str, Any] = {} if _body.get("profileImage") is not None: _files.append(("profileImage", _body["profileImage"])) if _body.get("previousAddresses") is not None: @@ -714,7 +714,7 @@ def multi_binary_parts( # pylint: disable=inconsistent-return-statements _body = body.as_dict() if isinstance(body, _model_base.Model) else body _files = [] - _data = {} + _data: Dict[str, Any] = {} if _body.get("profileImage") is not None: _files.append(("profileImage", _body["profileImage"])) if _body.get("picture") is not None: diff --git a/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/aio/operations/_operations.py b/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/aio/operations/_operations.py index 261ed6b7d8b..3691c1740bf 100644 --- a/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/aio/operations/_operations.py +++ b/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/aio/operations/_operations.py @@ -126,7 +126,7 @@ async def basic( # pylint: disable=inconsistent-return-statements _body = body.as_dict() if isinstance(body, _model_base.Model) else body _files = [] - _data = {} + _data: Dict[str, Any] = {} if _body.get("id") is not None: _data["id"] = _body["id"] if _body.get("profileImage") is not None: @@ -242,7 +242,7 @@ async def complex( # pylint: disable=inconsistent-return-statements _body = body.as_dict() if isinstance(body, _model_base.Model) else body _files = [] - _data = {} + _data: Dict[str, Any] = {} if _body.get("id") is not None: _data["id"] = _body["id"] if _body.get("address") is not None: @@ -352,7 +352,7 @@ async def json_part( # pylint: disable=inconsistent-return-statements _body = body.as_dict() if isinstance(body, _model_base.Model) else body _files = [] - _data = {} + _data: Dict[str, Any] = {} if _body.get("address") is not None: _data["address"] = json.dumps(_body["address"], cls=SdkJSONEncoder, exclude_readonly=True) if _body.get("profileImage") is not None: @@ -452,7 +452,7 @@ async def binary_array_parts( # pylint: disable=inconsistent-return-statements _body = body.as_dict() if isinstance(body, _model_base.Model) else body _files = [] - _data = {} + _data: Dict[str, Any] = {} if _body.get("id") is not None: _data["id"] = _body["id"] if _body.get("pictures") is not None: @@ -560,7 +560,7 @@ async def json_array_parts( # pylint: disable=inconsistent-return-statements _body = body.as_dict() if isinstance(body, _model_base.Model) else body _files = [] - _data = {} + _data: Dict[str, Any] = {} if _body.get("profileImage") is not None: _files.append(("profileImage", _body["profileImage"])) if _body.get("previousAddresses") is not None: @@ -662,7 +662,7 @@ async def multi_binary_parts( # pylint: disable=inconsistent-return-statements _body = body.as_dict() if isinstance(body, _model_base.Model) else body _files = [] - _data = {} + _data: Dict[str, Any] = {} if _body.get("profileImage") is not None: _files.append(("profileImage", _body["profileImage"])) if _body.get("picture") is not None: diff --git a/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/models/_models.py b/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/models/_models.py index c4905916692..654bab5f877 100644 --- a/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/models/_models.py +++ b/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/models/_models.py @@ -7,7 +7,7 @@ # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from typing import Any, List, Mapping, Optional, TYPE_CHECKING, overload +from typing import Any, Dict, List, Mapping, Optional, TYPE_CHECKING, overload from .. import _model_base from .._model_base import rest_field diff --git a/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/operations/_operations.py b/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/operations/_operations.py index 58ffb6b9193..e4cdfb3ba79 100644 --- a/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/operations/_operations.py +++ b/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/operations/_operations.py @@ -177,7 +177,7 @@ def basic( # pylint: disable=inconsistent-return-statements _body = body.as_dict() if isinstance(body, _model_base.Model) else body _files = [] - _data = {} + _data: Dict[str, Any] = {} if _body.get("id") is not None: _data["id"] = _body["id"] if _body.get("profileImage") is not None: @@ -293,7 +293,7 @@ def complex( # pylint: disable=inconsistent-return-statements _body = body.as_dict() if isinstance(body, _model_base.Model) else body _files = [] - _data = {} + _data: Dict[str, Any] = {} if _body.get("id") is not None: _data["id"] = _body["id"] if _body.get("address") is not None: @@ -403,7 +403,7 @@ def json_part( # pylint: disable=inconsistent-return-statements _body = body.as_dict() if isinstance(body, _model_base.Model) else body _files = [] - _data = {} + _data: Dict[str, Any] = {} if _body.get("address") is not None: _data["address"] = json.dumps(_body["address"], cls=SdkJSONEncoder, exclude_readonly=True) if _body.get("profileImage") is not None: @@ -501,7 +501,7 @@ def binary_array_parts( # pylint: disable=inconsistent-return-statements _body = body.as_dict() if isinstance(body, _model_base.Model) else body _files = [] - _data = {} + _data: Dict[str, Any] = {} if _body.get("id") is not None: _data["id"] = _body["id"] if _body.get("pictures") is not None: @@ -607,7 +607,7 @@ def json_array_parts( # pylint: disable=inconsistent-return-statements _body = body.as_dict() if isinstance(body, _model_base.Model) else body _files = [] - _data = {} + _data: Dict[str, Any] = {} if _body.get("profileImage") is not None: _files.append(("profileImage", _body["profileImage"])) if _body.get("previousAddresses") is not None: @@ -707,7 +707,7 @@ def multi_binary_parts( # pylint: disable=inconsistent-return-statements _body = body.as_dict() if isinstance(body, _model_base.Model) else body _files = [] - _data = {} + _data: Dict[str, Any] = {} if _body.get("profileImage") is not None: _files.append(("profileImage", _body["profileImage"])) if _body.get("picture") is not None: From 7bfd08fc5a1637d0666de27f4ea5e12cc6a12504 Mon Sep 17 00:00:00 2001 From: iscai-msft Date: Thu, 1 Feb 2024 18:29:30 -0500 Subject: [PATCH 31/45] fix typing for files --- packages/autorest.python/ChangeLog.md | 17 +++++++++++++++++ .../autorest/codegen/models/property.py | 1 + .../codegen/serializers/builder_serializer.py | 2 +- .../packaging_templates/setup.py.jinja2 | 2 +- .../test/azure/legacy/requirements.txt | 2 +- .../azure/version-tolerant/requirements.txt | 2 +- .../test/dpg/version-tolerant/requirements.txt | 2 +- .../test/multiapi/requirements.txt | 2 +- .../test/unittests/requirements.txt | 2 +- .../test/vanilla/legacy/requirements.txt | 2 +- .../vanilla/version-tolerant/requirements.txt | 2 +- .../typespec-python/test/azure/requirements.txt | 2 +- .../test/unbranded/requirements.txt | 2 +- 13 files changed, 29 insertions(+), 11 deletions(-) diff --git a/packages/autorest.python/ChangeLog.md b/packages/autorest.python/ChangeLog.md index d4216c21037..411653dc18c 100644 --- a/packages/autorest.python/ChangeLog.md +++ b/packages/autorest.python/ChangeLog.md @@ -1,5 +1,22 @@ # Release +## 2024-02-01 - 6.12.4 + +| Library | Min Version | +| ----------------------------------------------------------------------- | ----------- | +| `@autorest/core` | `3.9.2` | +| `@autorest/modelerfour` | `4.24.3` | +| `azure-core` dep of generated code | `1.30.0` | +| `isodate` dep of generated code | `0.6.1` | +| `msrest` dep of generated code (If generating legacy code) | `0.7.1` | +| `azure-mgmt-core` dep of generated code (If generating mgmt plane code) | `1.3.2` | +| `typing-extensions` dep of generated code (If generating with constants)| `4.0.1` | + +**Other Changes** + +- Add support for multipart generation from typespec #2380 +- Bump minimum dependency of `azure-core` to 1.30.0 + ## 2023-01-19 - 6.12.3 | Library | Min Version | diff --git a/packages/autorest.python/autorest/codegen/models/property.py b/packages/autorest.python/autorest/codegen/models/property.py index b55fb93ef87..64fa2b9b6a4 100644 --- a/packages/autorest.python/autorest/codegen/models/property.py +++ b/packages/autorest.python/autorest/codegen/models/property.py @@ -174,6 +174,7 @@ def imports(self, **kwargs) -> FileImport: ) if self.is_multipart_file_input: file_import.add_submodule_import(".._vendor", "FileType", ImportType.LOCAL) + file_import.add_submodule_import(".._vendor", "FilesType", ImportType.LOCAL) file_import.add_submodule_import("typing", "Dict", ImportType.STDLIB) file_import.add_submodule_import("typing", "Any", ImportType.STDLIB) return file_import diff --git a/packages/autorest.python/autorest/codegen/serializers/builder_serializer.py b/packages/autorest.python/autorest/codegen/serializers/builder_serializer.py index d1733be2810..863465e3a11 100644 --- a/packages/autorest.python/autorest/codegen/serializers/builder_serializer.py +++ b/packages/autorest.python/autorest/codegen/serializers/builder_serializer.py @@ -761,7 +761,7 @@ def _serialize_body_parameter(self, builder: OperationType) -> List[str]: f" if isinstance({body_param.client_name}, _model_base.Model) else", f" {body_param.client_name}", ")", - "_files = []", + "_files: FilesType = []", "_data: Dict[str, Any] = {}", ] ) diff --git a/packages/autorest.python/autorest/codegen/templates/packaging_templates/setup.py.jinja2 b/packages/autorest.python/autorest/codegen/templates/packaging_templates/setup.py.jinja2 index 4d17b5bfc4f..ad77a49061c 100644 --- a/packages/autorest.python/autorest/codegen/templates/packaging_templates/setup.py.jinja2 +++ b/packages/autorest.python/autorest/codegen/templates/packaging_templates/setup.py.jinja2 @@ -94,7 +94,7 @@ setup( {% elif azure_arm %} "azure-mgmt-core<2.0.0,>=1.3.2", {% else %} - "azure-core<2.0.0,>=1.29.5", + "azure-core<2.0.0,>=1.30.0", {% endif %} ], {% if package_mode %} diff --git a/packages/autorest.python/test/azure/legacy/requirements.txt b/packages/autorest.python/test/azure/legacy/requirements.txt index eb41329e84a..dc985574506 100644 --- a/packages/autorest.python/test/azure/legacy/requirements.txt +++ b/packages/autorest.python/test/azure/legacy/requirements.txt @@ -4,7 +4,7 @@ pytest pytest-cov pytest-asyncio==0.14.0;python_full_version>="3.5.2" async_generator;python_full_version>="3.5.2" --e git+https://github.com/Azure/azure-sdk-for-python.git@main#egg=azure-core&subdirectory=sdk/core/azure-core +azure-core==1.30.0 azure-mgmt-core==1.3.2 msrest==0.7.1 -e ./Expected/AcceptanceTests/AzureBodyDuration diff --git a/packages/autorest.python/test/azure/version-tolerant/requirements.txt b/packages/autorest.python/test/azure/version-tolerant/requirements.txt index 2e12f1530f9..8844c55b4d4 100644 --- a/packages/autorest.python/test/azure/version-tolerant/requirements.txt +++ b/packages/autorest.python/test/azure/version-tolerant/requirements.txt @@ -4,7 +4,7 @@ pytest pytest-cov pytest-asyncio==0.14.0;python_full_version>="3.5.2" async_generator;python_full_version>="3.5.2" --e git+https://github.com/Azure/azure-sdk-for-python.git@main#egg=azure-core&subdirectory=sdk/core/azure-core +azure-core==1.30.0 azure-mgmt-core==1.3.2 -e ./Expected/AcceptanceTests/AzureBodyDurationVersionTolerant -e ./Expected/AcceptanceTests/AzureParameterGroupingVersionTolerant diff --git a/packages/autorest.python/test/dpg/version-tolerant/requirements.txt b/packages/autorest.python/test/dpg/version-tolerant/requirements.txt index f1844319c07..5fd5309227b 100644 --- a/packages/autorest.python/test/dpg/version-tolerant/requirements.txt +++ b/packages/autorest.python/test/dpg/version-tolerant/requirements.txt @@ -4,7 +4,7 @@ pytest pytest-cov pytest-asyncio==0.14.0;python_full_version>="3.5.2" async_generator;python_full_version>="3.5.2" --e git+https://github.com/Azure/azure-sdk-for-python.git@main#egg=azure-core&subdirectory=sdk/core/azure-core +azure-core==1.30.0 -e ./Expected/AcceptanceTests/DPGServiceDrivenInitialVersionTolerant/ -e ./Expected/AcceptanceTests/DPGServiceDrivenUpdateOneVersionTolerant/ -e ./Expected/AcceptanceTests/DPGCustomizationInitialVersionTolerant/ diff --git a/packages/autorest.python/test/multiapi/requirements.txt b/packages/autorest.python/test/multiapi/requirements.txt index 35aa5746c36..8ef66ee1792 100644 --- a/packages/autorest.python/test/multiapi/requirements.txt +++ b/packages/autorest.python/test/multiapi/requirements.txt @@ -1,7 +1,7 @@ aiohttp; python_full_version >= '3.5.2' azure-common msrest==0.7.1 --e git+https://github.com/Azure/azure-sdk-for-python.git@main#egg=azure-core&subdirectory=sdk/core/azure-core +azure-core==1.30.0 azure-mgmt-core==1.3.2 pytest pytest-cov diff --git a/packages/autorest.python/test/unittests/requirements.txt b/packages/autorest.python/test/unittests/requirements.txt index f6662abcfe9..fc34585a0cb 100644 --- a/packages/autorest.python/test/unittests/requirements.txt +++ b/packages/autorest.python/test/unittests/requirements.txt @@ -2,5 +2,5 @@ isodate<1.0.0,>=0.6.1 requests==2.28.2 pytest pytest-cov --e git+https://github.com/Azure/azure-sdk-for-python.git@main#egg=azure-core&subdirectory=sdk/core/azure-core +azure-core==1.30.0 -e ../../. diff --git a/packages/autorest.python/test/vanilla/legacy/requirements.txt b/packages/autorest.python/test/vanilla/legacy/requirements.txt index 816206a872b..f6488477613 100644 --- a/packages/autorest.python/test/vanilla/legacy/requirements.txt +++ b/packages/autorest.python/test/vanilla/legacy/requirements.txt @@ -5,7 +5,7 @@ pytest-cov pytest-asyncio==0.14.0;python_full_version>="3.5.2" async_generator;python_full_version>="3.5.2" msrest==0.7.1 --e git+https://github.com/Azure/azure-sdk-for-python.git@main#egg=azure-core&subdirectory=sdk/core/azure-core +azure-core==1.30.0 -e ./Expected/AcceptanceTests/AdditionalProperties -e ./Expected/AcceptanceTests/Anything -e ./Expected/AcceptanceTests/BodyArray diff --git a/packages/autorest.python/test/vanilla/version-tolerant/requirements.txt b/packages/autorest.python/test/vanilla/version-tolerant/requirements.txt index cd808ee2dd5..8e84507cb0f 100644 --- a/packages/autorest.python/test/vanilla/version-tolerant/requirements.txt +++ b/packages/autorest.python/test/vanilla/version-tolerant/requirements.txt @@ -4,7 +4,7 @@ pytest pytest-cov pytest-asyncio==0.14.0;python_full_version>="3.5.2" async_generator;python_full_version>="3.5.2" --e git+https://github.com/Azure/azure-sdk-for-python.git@main#egg=azure-core&subdirectory=sdk/core/azure-core +azure-core==1.30.0 -e ./Expected/AcceptanceTests/AdditionalPropertiesVersionTolerant -e ./Expected/AcceptanceTests/AnythingVersionTolerant -e ./Expected/AcceptanceTests/BodyArrayVersionTolerant diff --git a/packages/typespec-python/test/azure/requirements.txt b/packages/typespec-python/test/azure/requirements.txt index b566f7e5d44..75d4b1d5bda 100644 --- a/packages/typespec-python/test/azure/requirements.txt +++ b/packages/typespec-python/test/azure/requirements.txt @@ -2,7 +2,7 @@ aiohttp;python_full_version>="3.5.2" requests==2.31.0 pytest pytest-asyncio==0.14.0;python_full_version>="3.5.2" --e git+https://github.com/Azure/azure-sdk-for-python.git@main#egg=azure-core&subdirectory=sdk/core/azure-core +azure-core==1.30.0 # only for azure -e ./generated/azure-mgmt-spheredpg -e ./generated/azure-mgmt-spheremsrest diff --git a/packages/typespec-python/test/unbranded/requirements.txt b/packages/typespec-python/test/unbranded/requirements.txt index b34aba5b5c8..e66322134e1 100644 --- a/packages/typespec-python/test/unbranded/requirements.txt +++ b/packages/typespec-python/test/unbranded/requirements.txt @@ -2,7 +2,7 @@ aiohttp;python_full_version>="3.5.2" requests==2.28.2 pytest pytest-asyncio==0.14.0;python_full_version>="3.5.2" --e git+https://github.com/Azure/azure-sdk-for-python.git@main#egg=corehttp&subdirectory=sdk/core/corehttp +corehttp==1.0.0b3 # common test case -e ./generated/authentication-api-key From 6704313161cae8000b91433e08e79514fa2359ad Mon Sep 17 00:00:00 2001 From: iscai-msft Date: Thu, 1 Feb 2024 18:36:03 -0500 Subject: [PATCH 32/45] bump azure-core versions --- .../autorest/codegen/models/parameter.py | 9 +++++++++ .../autorest/codegen/models/property.py | 3 --- .../azure/generated/authentication-api-key/setup.py | 2 +- .../generated/authentication-http-custom/setup.py | 2 +- .../azure/generated/authentication-oauth2/setup.py | 2 +- .../azure/generated/authentication-union/setup.py | 2 +- .../azure-client-generator-core-access/setup.py | 2 +- .../azure-client-generator-core-usage/setup.py | 2 +- .../test/azure/generated/azure-core-basic/setup.py | 2 +- .../azure/generated/azure-core-lro-standard/setup.py | 2 +- .../test/azure/generated/azure-core-traits/setup.py | 2 +- .../test/azure/generated/azurecore-lro-rpc/setup.py | 2 +- .../azure/generated/azurecore-lro-rpclegacy/setup.py | 2 +- .../generated/client-structure-default/setup.py | 2 +- .../generated/client-structure-multiclient/setup.py | 2 +- .../client-structure-renamedoperation/setup.py | 2 +- .../client-structure-twooperationgroup/setup.py | 2 +- .../test/azure/generated/encode-bytes/setup.py | 2 +- .../test/azure/generated/encode-datetime/setup.py | 2 +- .../test/azure/generated/encode-duration/setup.py | 2 +- .../test/azure/generated/headasbooleanfalse/setup.py | 2 +- .../test/azure/generated/headasbooleantrue/setup.py | 2 +- .../generated/parameters-body-optionality/setup.py | 2 +- .../generated/parameters-collection-format/setup.py | 2 +- .../test/azure/generated/parameters-spread/setup.py | 2 +- .../generated/payload-content-negotiation/setup.py | 2 +- .../test/azure/generated/payload-media-type/setup.py | 2 +- .../payload/multipart/aio/operations/_operations.py | 12 ++++++------ .../payload/multipart/models/_models.py | 2 +- .../payload/multipart/operations/_operations.py | 12 ++++++------ .../test/azure/generated/payload-multipart/setup.py | 2 +- .../test/azure/generated/payload-pageable/setup.py | 2 +- .../generated/projection-projected-name/setup.py | 2 +- .../azure/generated/resiliency-srv-driven1/setup.py | 2 +- .../azure/generated/resiliency-srv-driven2/setup.py | 2 +- .../azure/generated/server-path-multiple/setup.py | 2 +- .../test/azure/generated/server-path-single/setup.py | 2 +- .../generated/server-versions-not-versioned/setup.py | 2 +- .../generated/server-versions-versioned/setup.py | 2 +- .../special-headers-client-request-id/setup.py | 2 +- .../special-headers-conditional-request/setup.py | 2 +- .../generated/special-headers-repeatability/setup.py | 2 +- .../test/azure/generated/special-words/setup.py | 2 +- .../test/azure/generated/typetest-array/setup.py | 2 +- .../azure/generated/typetest-dictionary/setup.py | 2 +- .../generated/typetest-enum-extensible/setup.py | 2 +- .../azure/generated/typetest-enum-fixed/setup.py | 2 +- .../azure/generated/typetest-model-empty/setup.py | 2 +- .../typetest-model-enumdiscriminator/setup.py | 2 +- .../typetest-model-nesteddiscriminator/setup.py | 2 +- .../typetest-model-notdiscriminated/setup.py | 2 +- .../generated/typetest-model-recursive/setup.py | 2 +- .../typetest-model-singlediscriminator/setup.py | 2 +- .../azure/generated/typetest-model-usage/setup.py | 2 +- .../generated/typetest-model-visibility/setup.py | 2 +- .../typetest-property-additionalproperties/setup.py | 2 +- .../generated/typetest-property-nullable/setup.py | 2 +- .../generated/typetest-property-optional/setup.py | 2 +- .../generated/typetest-property-valuetypes/setup.py | 2 +- .../test/azure/generated/typetest-scalar/setup.py | 2 +- .../test/azure/generated/typetest-union/setup.py | 2 +- .../payload/multipart/aio/operations/_operations.py | 12 ++++++------ .../payload/multipart/models/_models.py | 2 +- .../payload/multipart/operations/_operations.py | 12 ++++++------ 64 files changed, 91 insertions(+), 85 deletions(-) diff --git a/packages/autorest.python/autorest/codegen/models/parameter.py b/packages/autorest.python/autorest/codegen/models/parameter.py index 49fa21c2a54..5b2e65daf04 100644 --- a/packages/autorest.python/autorest/codegen/models/parameter.py +++ b/packages/autorest.python/autorest/codegen/models/parameter.py @@ -16,6 +16,8 @@ Union, ) +from .imports import FileImport + from .imports import FileImport, ImportType, TypingSection from .base import BaseModel from .base import BaseType @@ -289,6 +291,13 @@ def has_json_model_type(self) -> bool: if isinstance(self.type, CombinedType): return self.type.target_model_subtype((JSONModelType,)) is not None return isinstance(self.type, JSONModelType) + + def imports(self, async_mode: bool, **kwargs: Any) -> FileImport: + file_import = super().imports(async_mode, **kwargs) + if self.is_form_data: + file_import.add_submodule_import(".._vendor", "FilesType", ImportType.LOCAL) + file_import.add_submodule_import("typing", "Dict", ImportType.STDLIB) + file_import.add_submodule_import("typing", "Any", ImportType.STDLIB) @classmethod def from_yaml( diff --git a/packages/autorest.python/autorest/codegen/models/property.py b/packages/autorest.python/autorest/codegen/models/property.py index 64fa2b9b6a4..e4dc44e78e3 100644 --- a/packages/autorest.python/autorest/codegen/models/property.py +++ b/packages/autorest.python/autorest/codegen/models/property.py @@ -174,9 +174,6 @@ def imports(self, **kwargs) -> FileImport: ) if self.is_multipart_file_input: file_import.add_submodule_import(".._vendor", "FileType", ImportType.LOCAL) - file_import.add_submodule_import(".._vendor", "FilesType", ImportType.LOCAL) - file_import.add_submodule_import("typing", "Dict", ImportType.STDLIB) - file_import.add_submodule_import("typing", "Any", ImportType.STDLIB) return file_import @classmethod diff --git a/packages/typespec-python/test/azure/generated/authentication-api-key/setup.py b/packages/typespec-python/test/azure/generated/authentication-api-key/setup.py index 8d77586880d..1be623c0332 100644 --- a/packages/typespec-python/test/azure/generated/authentication-api-key/setup.py +++ b/packages/typespec-python/test/azure/generated/authentication-api-key/setup.py @@ -63,7 +63,7 @@ }, install_requires=[ "isodate<1.0.0,>=0.6.1", - "azure-core<2.0.0,>=1.29.5", + "azure-core<2.0.0,>=1.30.0", ], python_requires=">=3.8", ) diff --git a/packages/typespec-python/test/azure/generated/authentication-http-custom/setup.py b/packages/typespec-python/test/azure/generated/authentication-http-custom/setup.py index 37d1782630f..2a19ef4bd97 100644 --- a/packages/typespec-python/test/azure/generated/authentication-http-custom/setup.py +++ b/packages/typespec-python/test/azure/generated/authentication-http-custom/setup.py @@ -64,7 +64,7 @@ }, install_requires=[ "isodate<1.0.0,>=0.6.1", - "azure-core<2.0.0,>=1.29.5", + "azure-core<2.0.0,>=1.30.0", ], python_requires=">=3.8", ) diff --git a/packages/typespec-python/test/azure/generated/authentication-oauth2/setup.py b/packages/typespec-python/test/azure/generated/authentication-oauth2/setup.py index d08ece9514a..a57903c5cda 100644 --- a/packages/typespec-python/test/azure/generated/authentication-oauth2/setup.py +++ b/packages/typespec-python/test/azure/generated/authentication-oauth2/setup.py @@ -63,7 +63,7 @@ }, install_requires=[ "isodate<1.0.0,>=0.6.1", - "azure-core<2.0.0,>=1.29.5", + "azure-core<2.0.0,>=1.30.0", ], python_requires=">=3.8", ) diff --git a/packages/typespec-python/test/azure/generated/authentication-union/setup.py b/packages/typespec-python/test/azure/generated/authentication-union/setup.py index d913a45f8cc..265f321f334 100644 --- a/packages/typespec-python/test/azure/generated/authentication-union/setup.py +++ b/packages/typespec-python/test/azure/generated/authentication-union/setup.py @@ -63,7 +63,7 @@ }, install_requires=[ "isodate<1.0.0,>=0.6.1", - "azure-core<2.0.0,>=1.29.5", + "azure-core<2.0.0,>=1.30.0", ], python_requires=">=3.8", ) diff --git a/packages/typespec-python/test/azure/generated/azure-client-generator-core-access/setup.py b/packages/typespec-python/test/azure/generated/azure-client-generator-core-access/setup.py index 532997bb727..77c7d110517 100644 --- a/packages/typespec-python/test/azure/generated/azure-client-generator-core-access/setup.py +++ b/packages/typespec-python/test/azure/generated/azure-client-generator-core-access/setup.py @@ -66,7 +66,7 @@ }, install_requires=[ "isodate<1.0.0,>=0.6.1", - "azure-core<2.0.0,>=1.29.5", + "azure-core<2.0.0,>=1.30.0", ], python_requires=">=3.8", ) diff --git a/packages/typespec-python/test/azure/generated/azure-client-generator-core-usage/setup.py b/packages/typespec-python/test/azure/generated/azure-client-generator-core-usage/setup.py index 8969b9a2ef4..c9b7b928b53 100644 --- a/packages/typespec-python/test/azure/generated/azure-client-generator-core-usage/setup.py +++ b/packages/typespec-python/test/azure/generated/azure-client-generator-core-usage/setup.py @@ -66,7 +66,7 @@ }, install_requires=[ "isodate<1.0.0,>=0.6.1", - "azure-core<2.0.0,>=1.29.5", + "azure-core<2.0.0,>=1.30.0", ], python_requires=">=3.8", ) diff --git a/packages/typespec-python/test/azure/generated/azure-core-basic/setup.py b/packages/typespec-python/test/azure/generated/azure-core-basic/setup.py index af54d4e9e2e..0ea74def475 100644 --- a/packages/typespec-python/test/azure/generated/azure-core-basic/setup.py +++ b/packages/typespec-python/test/azure/generated/azure-core-basic/setup.py @@ -65,7 +65,7 @@ }, install_requires=[ "isodate<1.0.0,>=0.6.1", - "azure-core<2.0.0,>=1.29.5", + "azure-core<2.0.0,>=1.30.0", ], python_requires=">=3.8", ) diff --git a/packages/typespec-python/test/azure/generated/azure-core-lro-standard/setup.py b/packages/typespec-python/test/azure/generated/azure-core-lro-standard/setup.py index 72c0f8768ee..ca595381c4e 100644 --- a/packages/typespec-python/test/azure/generated/azure-core-lro-standard/setup.py +++ b/packages/typespec-python/test/azure/generated/azure-core-lro-standard/setup.py @@ -66,7 +66,7 @@ }, install_requires=[ "isodate<1.0.0,>=0.6.1", - "azure-core<2.0.0,>=1.29.5", + "azure-core<2.0.0,>=1.30.0", ], python_requires=">=3.8", ) diff --git a/packages/typespec-python/test/azure/generated/azure-core-traits/setup.py b/packages/typespec-python/test/azure/generated/azure-core-traits/setup.py index 36516a5e75e..72f25c8e247 100644 --- a/packages/typespec-python/test/azure/generated/azure-core-traits/setup.py +++ b/packages/typespec-python/test/azure/generated/azure-core-traits/setup.py @@ -65,7 +65,7 @@ }, install_requires=[ "isodate<1.0.0,>=0.6.1", - "azure-core<2.0.0,>=1.29.5", + "azure-core<2.0.0,>=1.30.0", ], python_requires=">=3.8", ) diff --git a/packages/typespec-python/test/azure/generated/azurecore-lro-rpc/setup.py b/packages/typespec-python/test/azure/generated/azurecore-lro-rpc/setup.py index 618d98f514a..848ed53a344 100644 --- a/packages/typespec-python/test/azure/generated/azurecore-lro-rpc/setup.py +++ b/packages/typespec-python/test/azure/generated/azurecore-lro-rpc/setup.py @@ -64,7 +64,7 @@ }, install_requires=[ "isodate<1.0.0,>=0.6.1", - "azure-core<2.0.0,>=1.29.5", + "azure-core<2.0.0,>=1.30.0", ], python_requires=">=3.8", ) diff --git a/packages/typespec-python/test/azure/generated/azurecore-lro-rpclegacy/setup.py b/packages/typespec-python/test/azure/generated/azurecore-lro-rpclegacy/setup.py index 5db70d718e0..50706867a26 100644 --- a/packages/typespec-python/test/azure/generated/azurecore-lro-rpclegacy/setup.py +++ b/packages/typespec-python/test/azure/generated/azurecore-lro-rpclegacy/setup.py @@ -64,7 +64,7 @@ }, install_requires=[ "isodate<1.0.0,>=0.6.1", - "azure-core<2.0.0,>=1.29.5", + "azure-core<2.0.0,>=1.30.0", ], python_requires=">=3.8", ) diff --git a/packages/typespec-python/test/azure/generated/client-structure-default/setup.py b/packages/typespec-python/test/azure/generated/client-structure-default/setup.py index 6ad145f94a0..0eb27d1158d 100644 --- a/packages/typespec-python/test/azure/generated/client-structure-default/setup.py +++ b/packages/typespec-python/test/azure/generated/client-structure-default/setup.py @@ -64,7 +64,7 @@ }, install_requires=[ "isodate<1.0.0,>=0.6.1", - "azure-core<2.0.0,>=1.29.5", + "azure-core<2.0.0,>=1.30.0", ], python_requires=">=3.8", ) diff --git a/packages/typespec-python/test/azure/generated/client-structure-multiclient/setup.py b/packages/typespec-python/test/azure/generated/client-structure-multiclient/setup.py index d032cf557da..5ba5f48249d 100644 --- a/packages/typespec-python/test/azure/generated/client-structure-multiclient/setup.py +++ b/packages/typespec-python/test/azure/generated/client-structure-multiclient/setup.py @@ -64,7 +64,7 @@ }, install_requires=[ "isodate<1.0.0,>=0.6.1", - "azure-core<2.0.0,>=1.29.5", + "azure-core<2.0.0,>=1.30.0", ], python_requires=">=3.8", ) diff --git a/packages/typespec-python/test/azure/generated/client-structure-renamedoperation/setup.py b/packages/typespec-python/test/azure/generated/client-structure-renamedoperation/setup.py index b275962ba91..6662a8387fc 100644 --- a/packages/typespec-python/test/azure/generated/client-structure-renamedoperation/setup.py +++ b/packages/typespec-python/test/azure/generated/client-structure-renamedoperation/setup.py @@ -64,7 +64,7 @@ }, install_requires=[ "isodate<1.0.0,>=0.6.1", - "azure-core<2.0.0,>=1.29.5", + "azure-core<2.0.0,>=1.30.0", ], python_requires=">=3.8", ) diff --git a/packages/typespec-python/test/azure/generated/client-structure-twooperationgroup/setup.py b/packages/typespec-python/test/azure/generated/client-structure-twooperationgroup/setup.py index 5bb46edd89e..a0c38355067 100644 --- a/packages/typespec-python/test/azure/generated/client-structure-twooperationgroup/setup.py +++ b/packages/typespec-python/test/azure/generated/client-structure-twooperationgroup/setup.py @@ -64,7 +64,7 @@ }, install_requires=[ "isodate<1.0.0,>=0.6.1", - "azure-core<2.0.0,>=1.29.5", + "azure-core<2.0.0,>=1.30.0", ], python_requires=">=3.8", ) diff --git a/packages/typespec-python/test/azure/generated/encode-bytes/setup.py b/packages/typespec-python/test/azure/generated/encode-bytes/setup.py index 21482e79018..d3387a26081 100644 --- a/packages/typespec-python/test/azure/generated/encode-bytes/setup.py +++ b/packages/typespec-python/test/azure/generated/encode-bytes/setup.py @@ -63,7 +63,7 @@ }, install_requires=[ "isodate<1.0.0,>=0.6.1", - "azure-core<2.0.0,>=1.29.5", + "azure-core<2.0.0,>=1.30.0", ], python_requires=">=3.8", ) diff --git a/packages/typespec-python/test/azure/generated/encode-datetime/setup.py b/packages/typespec-python/test/azure/generated/encode-datetime/setup.py index 0c3405d8397..ebbb26a5fb7 100644 --- a/packages/typespec-python/test/azure/generated/encode-datetime/setup.py +++ b/packages/typespec-python/test/azure/generated/encode-datetime/setup.py @@ -63,7 +63,7 @@ }, install_requires=[ "isodate<1.0.0,>=0.6.1", - "azure-core<2.0.0,>=1.29.5", + "azure-core<2.0.0,>=1.30.0", ], python_requires=">=3.8", ) diff --git a/packages/typespec-python/test/azure/generated/encode-duration/setup.py b/packages/typespec-python/test/azure/generated/encode-duration/setup.py index 66edf4eb5a5..68b19496894 100644 --- a/packages/typespec-python/test/azure/generated/encode-duration/setup.py +++ b/packages/typespec-python/test/azure/generated/encode-duration/setup.py @@ -63,7 +63,7 @@ }, install_requires=[ "isodate<1.0.0,>=0.6.1", - "azure-core<2.0.0,>=1.29.5", + "azure-core<2.0.0,>=1.30.0", ], python_requires=">=3.8", ) diff --git a/packages/typespec-python/test/azure/generated/headasbooleanfalse/setup.py b/packages/typespec-python/test/azure/generated/headasbooleanfalse/setup.py index 39f9962d472..6b886fa8dfe 100644 --- a/packages/typespec-python/test/azure/generated/headasbooleanfalse/setup.py +++ b/packages/typespec-python/test/azure/generated/headasbooleanfalse/setup.py @@ -61,7 +61,7 @@ }, install_requires=[ "isodate<1.0.0,>=0.6.1", - "azure-core<2.0.0,>=1.29.5", + "azure-core<2.0.0,>=1.30.0", ], python_requires=">=3.8", ) diff --git a/packages/typespec-python/test/azure/generated/headasbooleantrue/setup.py b/packages/typespec-python/test/azure/generated/headasbooleantrue/setup.py index 79c166c8b8b..5b8a292dd68 100644 --- a/packages/typespec-python/test/azure/generated/headasbooleantrue/setup.py +++ b/packages/typespec-python/test/azure/generated/headasbooleantrue/setup.py @@ -61,7 +61,7 @@ }, install_requires=[ "isodate<1.0.0,>=0.6.1", - "azure-core<2.0.0,>=1.29.5", + "azure-core<2.0.0,>=1.30.0", ], python_requires=">=3.8", ) diff --git a/packages/typespec-python/test/azure/generated/parameters-body-optionality/setup.py b/packages/typespec-python/test/azure/generated/parameters-body-optionality/setup.py index 7ed2eba9f1a..8679e405ee1 100644 --- a/packages/typespec-python/test/azure/generated/parameters-body-optionality/setup.py +++ b/packages/typespec-python/test/azure/generated/parameters-body-optionality/setup.py @@ -63,7 +63,7 @@ }, install_requires=[ "isodate<1.0.0,>=0.6.1", - "azure-core<2.0.0,>=1.29.5", + "azure-core<2.0.0,>=1.30.0", ], python_requires=">=3.8", ) diff --git a/packages/typespec-python/test/azure/generated/parameters-collection-format/setup.py b/packages/typespec-python/test/azure/generated/parameters-collection-format/setup.py index 331bf3ac941..fef679b4594 100644 --- a/packages/typespec-python/test/azure/generated/parameters-collection-format/setup.py +++ b/packages/typespec-python/test/azure/generated/parameters-collection-format/setup.py @@ -63,7 +63,7 @@ }, install_requires=[ "isodate<1.0.0,>=0.6.1", - "azure-core<2.0.0,>=1.29.5", + "azure-core<2.0.0,>=1.30.0", ], python_requires=">=3.8", ) diff --git a/packages/typespec-python/test/azure/generated/parameters-spread/setup.py b/packages/typespec-python/test/azure/generated/parameters-spread/setup.py index 99c93332785..08543bb6a42 100644 --- a/packages/typespec-python/test/azure/generated/parameters-spread/setup.py +++ b/packages/typespec-python/test/azure/generated/parameters-spread/setup.py @@ -63,7 +63,7 @@ }, install_requires=[ "isodate<1.0.0,>=0.6.1", - "azure-core<2.0.0,>=1.29.5", + "azure-core<2.0.0,>=1.30.0", ], python_requires=">=3.8", ) diff --git a/packages/typespec-python/test/azure/generated/payload-content-negotiation/setup.py b/packages/typespec-python/test/azure/generated/payload-content-negotiation/setup.py index 6aff6116aa8..03d7b7ec69c 100644 --- a/packages/typespec-python/test/azure/generated/payload-content-negotiation/setup.py +++ b/packages/typespec-python/test/azure/generated/payload-content-negotiation/setup.py @@ -63,7 +63,7 @@ }, install_requires=[ "isodate<1.0.0,>=0.6.1", - "azure-core<2.0.0,>=1.29.5", + "azure-core<2.0.0,>=1.30.0", ], python_requires=">=3.8", ) diff --git a/packages/typespec-python/test/azure/generated/payload-media-type/setup.py b/packages/typespec-python/test/azure/generated/payload-media-type/setup.py index 3e95dcd86c7..ac061f57316 100644 --- a/packages/typespec-python/test/azure/generated/payload-media-type/setup.py +++ b/packages/typespec-python/test/azure/generated/payload-media-type/setup.py @@ -63,7 +63,7 @@ }, install_requires=[ "isodate<1.0.0,>=0.6.1", - "azure-core<2.0.0,>=1.29.5", + "azure-core<2.0.0,>=1.30.0", ], python_requires=">=3.8", ) diff --git a/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/aio/operations/_operations.py b/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/aio/operations/_operations.py index 28ae3396b2a..8c2d7bdd60c 100644 --- a/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/aio/operations/_operations.py +++ b/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/aio/operations/_operations.py @@ -127,7 +127,7 @@ async def basic( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) _body = body.as_dict() if isinstance(body, _model_base.Model) else body - _files = [] + _files: FilesType = [] _data: Dict[str, Any] = {} if _body.get("id") is not None: _data["id"] = _body["id"] @@ -244,7 +244,7 @@ async def complex( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) _body = body.as_dict() if isinstance(body, _model_base.Model) else body - _files = [] + _files: FilesType = [] _data: Dict[str, Any] = {} if _body.get("id") is not None: _data["id"] = _body["id"] @@ -355,7 +355,7 @@ async def json_part( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) _body = body.as_dict() if isinstance(body, _model_base.Model) else body - _files = [] + _files: FilesType = [] _data: Dict[str, Any] = {} if _body.get("address") is not None: _data["address"] = json.dumps(_body["address"], cls=SdkJSONEncoder, exclude_readonly=True) @@ -456,7 +456,7 @@ async def binary_array_parts( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) _body = body.as_dict() if isinstance(body, _model_base.Model) else body - _files = [] + _files: FilesType = [] _data: Dict[str, Any] = {} if _body.get("id") is not None: _data["id"] = _body["id"] @@ -565,7 +565,7 @@ async def json_array_parts( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) _body = body.as_dict() if isinstance(body, _model_base.Model) else body - _files = [] + _files: FilesType = [] _data: Dict[str, Any] = {} if _body.get("profileImage") is not None: _files.append(("profileImage", _body["profileImage"])) @@ -668,7 +668,7 @@ async def multi_binary_parts( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) _body = body.as_dict() if isinstance(body, _model_base.Model) else body - _files = [] + _files: FilesType = [] _data: Dict[str, Any] = {} if _body.get("profileImage") is not None: _files.append(("profileImage", _body["profileImage"])) diff --git a/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/models/_models.py b/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/models/_models.py index 437a383e388..8707ee48d4f 100644 --- a/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/models/_models.py +++ b/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/models/_models.py @@ -11,7 +11,7 @@ from .. import _model_base from .._model_base import rest_field -from .._vendor import FileType +from .._vendor import FileType, FilesType if TYPE_CHECKING: # pylint: disable=unused-import,ungrouped-imports diff --git a/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/operations/_operations.py b/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/operations/_operations.py index 402aa68440d..ef2bc37e9c7 100644 --- a/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/operations/_operations.py +++ b/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/operations/_operations.py @@ -178,7 +178,7 @@ def basic( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) _body = body.as_dict() if isinstance(body, _model_base.Model) else body - _files = [] + _files: FilesType = [] _data: Dict[str, Any] = {} if _body.get("id") is not None: _data["id"] = _body["id"] @@ -295,7 +295,7 @@ def complex( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) _body = body.as_dict() if isinstance(body, _model_base.Model) else body - _files = [] + _files: FilesType = [] _data: Dict[str, Any] = {} if _body.get("id") is not None: _data["id"] = _body["id"] @@ -406,7 +406,7 @@ def json_part( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) _body = body.as_dict() if isinstance(body, _model_base.Model) else body - _files = [] + _files: FilesType = [] _data: Dict[str, Any] = {} if _body.get("address") is not None: _data["address"] = json.dumps(_body["address"], cls=SdkJSONEncoder, exclude_readonly=True) @@ -505,7 +505,7 @@ def binary_array_parts( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) _body = body.as_dict() if isinstance(body, _model_base.Model) else body - _files = [] + _files: FilesType = [] _data: Dict[str, Any] = {} if _body.get("id") is not None: _data["id"] = _body["id"] @@ -612,7 +612,7 @@ def json_array_parts( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) _body = body.as_dict() if isinstance(body, _model_base.Model) else body - _files = [] + _files: FilesType = [] _data: Dict[str, Any] = {} if _body.get("profileImage") is not None: _files.append(("profileImage", _body["profileImage"])) @@ -713,7 +713,7 @@ def multi_binary_parts( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) _body = body.as_dict() if isinstance(body, _model_base.Model) else body - _files = [] + _files: FilesType = [] _data: Dict[str, Any] = {} if _body.get("profileImage") is not None: _files.append(("profileImage", _body["profileImage"])) diff --git a/packages/typespec-python/test/azure/generated/payload-multipart/setup.py b/packages/typespec-python/test/azure/generated/payload-multipart/setup.py index 6b3cbd072bd..2f6828c491a 100644 --- a/packages/typespec-python/test/azure/generated/payload-multipart/setup.py +++ b/packages/typespec-python/test/azure/generated/payload-multipart/setup.py @@ -63,7 +63,7 @@ }, install_requires=[ "isodate<1.0.0,>=0.6.1", - "azure-core<2.0.0,>=1.29.5", + "azure-core<2.0.0,>=1.30.0", ], python_requires=">=3.8", ) diff --git a/packages/typespec-python/test/azure/generated/payload-pageable/setup.py b/packages/typespec-python/test/azure/generated/payload-pageable/setup.py index 545f0c99ae9..eade00d89a9 100644 --- a/packages/typespec-python/test/azure/generated/payload-pageable/setup.py +++ b/packages/typespec-python/test/azure/generated/payload-pageable/setup.py @@ -63,7 +63,7 @@ }, install_requires=[ "isodate<1.0.0,>=0.6.1", - "azure-core<2.0.0,>=1.29.5", + "azure-core<2.0.0,>=1.30.0", ], python_requires=">=3.8", ) diff --git a/packages/typespec-python/test/azure/generated/projection-projected-name/setup.py b/packages/typespec-python/test/azure/generated/projection-projected-name/setup.py index 7df6c327b10..ebb4e44a4b4 100644 --- a/packages/typespec-python/test/azure/generated/projection-projected-name/setup.py +++ b/packages/typespec-python/test/azure/generated/projection-projected-name/setup.py @@ -63,7 +63,7 @@ }, install_requires=[ "isodate<1.0.0,>=0.6.1", - "azure-core<2.0.0,>=1.29.5", + "azure-core<2.0.0,>=1.30.0", ], python_requires=">=3.8", ) diff --git a/packages/typespec-python/test/azure/generated/resiliency-srv-driven1/setup.py b/packages/typespec-python/test/azure/generated/resiliency-srv-driven1/setup.py index 0819bfb7f6d..314b86dc676 100644 --- a/packages/typespec-python/test/azure/generated/resiliency-srv-driven1/setup.py +++ b/packages/typespec-python/test/azure/generated/resiliency-srv-driven1/setup.py @@ -64,7 +64,7 @@ }, install_requires=[ "isodate<1.0.0,>=0.6.1", - "azure-core<2.0.0,>=1.29.5", + "azure-core<2.0.0,>=1.30.0", ], python_requires=">=3.8", ) diff --git a/packages/typespec-python/test/azure/generated/resiliency-srv-driven2/setup.py b/packages/typespec-python/test/azure/generated/resiliency-srv-driven2/setup.py index f8249006218..609d6faa364 100644 --- a/packages/typespec-python/test/azure/generated/resiliency-srv-driven2/setup.py +++ b/packages/typespec-python/test/azure/generated/resiliency-srv-driven2/setup.py @@ -64,7 +64,7 @@ }, install_requires=[ "isodate<1.0.0,>=0.6.1", - "azure-core<2.0.0,>=1.29.5", + "azure-core<2.0.0,>=1.30.0", ], python_requires=">=3.8", ) diff --git a/packages/typespec-python/test/azure/generated/server-path-multiple/setup.py b/packages/typespec-python/test/azure/generated/server-path-multiple/setup.py index d7e58647e61..cde7f27d961 100644 --- a/packages/typespec-python/test/azure/generated/server-path-multiple/setup.py +++ b/packages/typespec-python/test/azure/generated/server-path-multiple/setup.py @@ -64,7 +64,7 @@ }, install_requires=[ "isodate<1.0.0,>=0.6.1", - "azure-core<2.0.0,>=1.29.5", + "azure-core<2.0.0,>=1.30.0", ], python_requires=">=3.8", ) diff --git a/packages/typespec-python/test/azure/generated/server-path-single/setup.py b/packages/typespec-python/test/azure/generated/server-path-single/setup.py index 981e70b3b64..3531b6c96cb 100644 --- a/packages/typespec-python/test/azure/generated/server-path-single/setup.py +++ b/packages/typespec-python/test/azure/generated/server-path-single/setup.py @@ -64,7 +64,7 @@ }, install_requires=[ "isodate<1.0.0,>=0.6.1", - "azure-core<2.0.0,>=1.29.5", + "azure-core<2.0.0,>=1.30.0", ], python_requires=">=3.8", ) diff --git a/packages/typespec-python/test/azure/generated/server-versions-not-versioned/setup.py b/packages/typespec-python/test/azure/generated/server-versions-not-versioned/setup.py index 7d8bde17250..9817e288df5 100644 --- a/packages/typespec-python/test/azure/generated/server-versions-not-versioned/setup.py +++ b/packages/typespec-python/test/azure/generated/server-versions-not-versioned/setup.py @@ -64,7 +64,7 @@ }, install_requires=[ "isodate<1.0.0,>=0.6.1", - "azure-core<2.0.0,>=1.29.5", + "azure-core<2.0.0,>=1.30.0", ], python_requires=">=3.8", ) diff --git a/packages/typespec-python/test/azure/generated/server-versions-versioned/setup.py b/packages/typespec-python/test/azure/generated/server-versions-versioned/setup.py index 053bd8b2605..5be66734f2b 100644 --- a/packages/typespec-python/test/azure/generated/server-versions-versioned/setup.py +++ b/packages/typespec-python/test/azure/generated/server-versions-versioned/setup.py @@ -64,7 +64,7 @@ }, install_requires=[ "isodate<1.0.0,>=0.6.1", - "azure-core<2.0.0,>=1.29.5", + "azure-core<2.0.0,>=1.30.0", ], python_requires=">=3.8", ) diff --git a/packages/typespec-python/test/azure/generated/special-headers-client-request-id/setup.py b/packages/typespec-python/test/azure/generated/special-headers-client-request-id/setup.py index ab9923ee488..57f1d24fc76 100644 --- a/packages/typespec-python/test/azure/generated/special-headers-client-request-id/setup.py +++ b/packages/typespec-python/test/azure/generated/special-headers-client-request-id/setup.py @@ -63,7 +63,7 @@ }, install_requires=[ "isodate<1.0.0,>=0.6.1", - "azure-core<2.0.0,>=1.29.5", + "azure-core<2.0.0,>=1.30.0", ], python_requires=">=3.8", ) diff --git a/packages/typespec-python/test/azure/generated/special-headers-conditional-request/setup.py b/packages/typespec-python/test/azure/generated/special-headers-conditional-request/setup.py index 79f09117e75..59e14f4d15d 100644 --- a/packages/typespec-python/test/azure/generated/special-headers-conditional-request/setup.py +++ b/packages/typespec-python/test/azure/generated/special-headers-conditional-request/setup.py @@ -63,7 +63,7 @@ }, install_requires=[ "isodate<1.0.0,>=0.6.1", - "azure-core<2.0.0,>=1.29.5", + "azure-core<2.0.0,>=1.30.0", ], python_requires=">=3.8", ) diff --git a/packages/typespec-python/test/azure/generated/special-headers-repeatability/setup.py b/packages/typespec-python/test/azure/generated/special-headers-repeatability/setup.py index d6bdb08ff49..21f080a458e 100644 --- a/packages/typespec-python/test/azure/generated/special-headers-repeatability/setup.py +++ b/packages/typespec-python/test/azure/generated/special-headers-repeatability/setup.py @@ -63,7 +63,7 @@ }, install_requires=[ "isodate<1.0.0,>=0.6.1", - "azure-core<2.0.0,>=1.29.5", + "azure-core<2.0.0,>=1.30.0", ], python_requires=">=3.8", ) diff --git a/packages/typespec-python/test/azure/generated/special-words/setup.py b/packages/typespec-python/test/azure/generated/special-words/setup.py index a8944dd822f..39b87a884b2 100644 --- a/packages/typespec-python/test/azure/generated/special-words/setup.py +++ b/packages/typespec-python/test/azure/generated/special-words/setup.py @@ -61,7 +61,7 @@ }, install_requires=[ "isodate<1.0.0,>=0.6.1", - "azure-core<2.0.0,>=1.29.5", + "azure-core<2.0.0,>=1.30.0", ], python_requires=">=3.8", ) diff --git a/packages/typespec-python/test/azure/generated/typetest-array/setup.py b/packages/typespec-python/test/azure/generated/typetest-array/setup.py index 95fccf20e29..c6e6c7ff526 100644 --- a/packages/typespec-python/test/azure/generated/typetest-array/setup.py +++ b/packages/typespec-python/test/azure/generated/typetest-array/setup.py @@ -63,7 +63,7 @@ }, install_requires=[ "isodate<1.0.0,>=0.6.1", - "azure-core<2.0.0,>=1.29.5", + "azure-core<2.0.0,>=1.30.0", ], python_requires=">=3.8", ) diff --git a/packages/typespec-python/test/azure/generated/typetest-dictionary/setup.py b/packages/typespec-python/test/azure/generated/typetest-dictionary/setup.py index 53396f2f1f4..d70ad2d89ac 100644 --- a/packages/typespec-python/test/azure/generated/typetest-dictionary/setup.py +++ b/packages/typespec-python/test/azure/generated/typetest-dictionary/setup.py @@ -63,7 +63,7 @@ }, install_requires=[ "isodate<1.0.0,>=0.6.1", - "azure-core<2.0.0,>=1.29.5", + "azure-core<2.0.0,>=1.30.0", ], python_requires=">=3.8", ) diff --git a/packages/typespec-python/test/azure/generated/typetest-enum-extensible/setup.py b/packages/typespec-python/test/azure/generated/typetest-enum-extensible/setup.py index 02adf996bd5..88eb1ebe918 100644 --- a/packages/typespec-python/test/azure/generated/typetest-enum-extensible/setup.py +++ b/packages/typespec-python/test/azure/generated/typetest-enum-extensible/setup.py @@ -64,7 +64,7 @@ }, install_requires=[ "isodate<1.0.0,>=0.6.1", - "azure-core<2.0.0,>=1.29.5", + "azure-core<2.0.0,>=1.30.0", ], python_requires=">=3.8", ) diff --git a/packages/typespec-python/test/azure/generated/typetest-enum-fixed/setup.py b/packages/typespec-python/test/azure/generated/typetest-enum-fixed/setup.py index dd85a459de7..c906bbe645d 100644 --- a/packages/typespec-python/test/azure/generated/typetest-enum-fixed/setup.py +++ b/packages/typespec-python/test/azure/generated/typetest-enum-fixed/setup.py @@ -64,7 +64,7 @@ }, install_requires=[ "isodate<1.0.0,>=0.6.1", - "azure-core<2.0.0,>=1.29.5", + "azure-core<2.0.0,>=1.30.0", ], python_requires=">=3.8", ) diff --git a/packages/typespec-python/test/azure/generated/typetest-model-empty/setup.py b/packages/typespec-python/test/azure/generated/typetest-model-empty/setup.py index e459b574f29..37eac81a8d1 100644 --- a/packages/typespec-python/test/azure/generated/typetest-model-empty/setup.py +++ b/packages/typespec-python/test/azure/generated/typetest-model-empty/setup.py @@ -64,7 +64,7 @@ }, install_requires=[ "isodate<1.0.0,>=0.6.1", - "azure-core<2.0.0,>=1.29.5", + "azure-core<2.0.0,>=1.30.0", ], python_requires=">=3.8", ) diff --git a/packages/typespec-python/test/azure/generated/typetest-model-enumdiscriminator/setup.py b/packages/typespec-python/test/azure/generated/typetest-model-enumdiscriminator/setup.py index c1282da1de3..91110fc5b55 100644 --- a/packages/typespec-python/test/azure/generated/typetest-model-enumdiscriminator/setup.py +++ b/packages/typespec-python/test/azure/generated/typetest-model-enumdiscriminator/setup.py @@ -64,7 +64,7 @@ }, install_requires=[ "isodate<1.0.0,>=0.6.1", - "azure-core<2.0.0,>=1.29.5", + "azure-core<2.0.0,>=1.30.0", ], python_requires=">=3.8", ) diff --git a/packages/typespec-python/test/azure/generated/typetest-model-nesteddiscriminator/setup.py b/packages/typespec-python/test/azure/generated/typetest-model-nesteddiscriminator/setup.py index 62278a71a88..c21df6ba47d 100644 --- a/packages/typespec-python/test/azure/generated/typetest-model-nesteddiscriminator/setup.py +++ b/packages/typespec-python/test/azure/generated/typetest-model-nesteddiscriminator/setup.py @@ -64,7 +64,7 @@ }, install_requires=[ "isodate<1.0.0,>=0.6.1", - "azure-core<2.0.0,>=1.29.5", + "azure-core<2.0.0,>=1.30.0", ], python_requires=">=3.8", ) diff --git a/packages/typespec-python/test/azure/generated/typetest-model-notdiscriminated/setup.py b/packages/typespec-python/test/azure/generated/typetest-model-notdiscriminated/setup.py index cb79832d561..0296ecf83ef 100644 --- a/packages/typespec-python/test/azure/generated/typetest-model-notdiscriminated/setup.py +++ b/packages/typespec-python/test/azure/generated/typetest-model-notdiscriminated/setup.py @@ -64,7 +64,7 @@ }, install_requires=[ "isodate<1.0.0,>=0.6.1", - "azure-core<2.0.0,>=1.29.5", + "azure-core<2.0.0,>=1.30.0", ], python_requires=">=3.8", ) diff --git a/packages/typespec-python/test/azure/generated/typetest-model-recursive/setup.py b/packages/typespec-python/test/azure/generated/typetest-model-recursive/setup.py index 5b458cce9b3..de1198d7ec1 100644 --- a/packages/typespec-python/test/azure/generated/typetest-model-recursive/setup.py +++ b/packages/typespec-python/test/azure/generated/typetest-model-recursive/setup.py @@ -64,7 +64,7 @@ }, install_requires=[ "isodate<1.0.0,>=0.6.1", - "azure-core<2.0.0,>=1.29.5", + "azure-core<2.0.0,>=1.30.0", ], python_requires=">=3.8", ) diff --git a/packages/typespec-python/test/azure/generated/typetest-model-singlediscriminator/setup.py b/packages/typespec-python/test/azure/generated/typetest-model-singlediscriminator/setup.py index 016eb410207..ee31d1827d7 100644 --- a/packages/typespec-python/test/azure/generated/typetest-model-singlediscriminator/setup.py +++ b/packages/typespec-python/test/azure/generated/typetest-model-singlediscriminator/setup.py @@ -64,7 +64,7 @@ }, install_requires=[ "isodate<1.0.0,>=0.6.1", - "azure-core<2.0.0,>=1.29.5", + "azure-core<2.0.0,>=1.30.0", ], python_requires=">=3.8", ) diff --git a/packages/typespec-python/test/azure/generated/typetest-model-usage/setup.py b/packages/typespec-python/test/azure/generated/typetest-model-usage/setup.py index dd6b3d14746..69d8d0b4c91 100644 --- a/packages/typespec-python/test/azure/generated/typetest-model-usage/setup.py +++ b/packages/typespec-python/test/azure/generated/typetest-model-usage/setup.py @@ -64,7 +64,7 @@ }, install_requires=[ "isodate<1.0.0,>=0.6.1", - "azure-core<2.0.0,>=1.29.5", + "azure-core<2.0.0,>=1.30.0", ], python_requires=">=3.8", ) diff --git a/packages/typespec-python/test/azure/generated/typetest-model-visibility/setup.py b/packages/typespec-python/test/azure/generated/typetest-model-visibility/setup.py index ad9a2eef67a..8d09f4bd0eb 100644 --- a/packages/typespec-python/test/azure/generated/typetest-model-visibility/setup.py +++ b/packages/typespec-python/test/azure/generated/typetest-model-visibility/setup.py @@ -64,7 +64,7 @@ }, install_requires=[ "isodate<1.0.0,>=0.6.1", - "azure-core<2.0.0,>=1.29.5", + "azure-core<2.0.0,>=1.30.0", ], python_requires=">=3.8", ) diff --git a/packages/typespec-python/test/azure/generated/typetest-property-additionalproperties/setup.py b/packages/typespec-python/test/azure/generated/typetest-property-additionalproperties/setup.py index 303f5dd6495..685202676dd 100644 --- a/packages/typespec-python/test/azure/generated/typetest-property-additionalproperties/setup.py +++ b/packages/typespec-python/test/azure/generated/typetest-property-additionalproperties/setup.py @@ -64,7 +64,7 @@ }, install_requires=[ "isodate<1.0.0,>=0.6.1", - "azure-core<2.0.0,>=1.29.5", + "azure-core<2.0.0,>=1.30.0", ], python_requires=">=3.8", ) diff --git a/packages/typespec-python/test/azure/generated/typetest-property-nullable/setup.py b/packages/typespec-python/test/azure/generated/typetest-property-nullable/setup.py index 58dd427c3d6..4ebf3d3c344 100644 --- a/packages/typespec-python/test/azure/generated/typetest-property-nullable/setup.py +++ b/packages/typespec-python/test/azure/generated/typetest-property-nullable/setup.py @@ -64,7 +64,7 @@ }, install_requires=[ "isodate<1.0.0,>=0.6.1", - "azure-core<2.0.0,>=1.29.5", + "azure-core<2.0.0,>=1.30.0", ], python_requires=">=3.8", ) diff --git a/packages/typespec-python/test/azure/generated/typetest-property-optional/setup.py b/packages/typespec-python/test/azure/generated/typetest-property-optional/setup.py index 1465c82a81e..42d716b4775 100644 --- a/packages/typespec-python/test/azure/generated/typetest-property-optional/setup.py +++ b/packages/typespec-python/test/azure/generated/typetest-property-optional/setup.py @@ -64,7 +64,7 @@ }, install_requires=[ "isodate<1.0.0,>=0.6.1", - "azure-core<2.0.0,>=1.29.5", + "azure-core<2.0.0,>=1.30.0", ], python_requires=">=3.8", ) diff --git a/packages/typespec-python/test/azure/generated/typetest-property-valuetypes/setup.py b/packages/typespec-python/test/azure/generated/typetest-property-valuetypes/setup.py index e450e6e6996..f402834f778 100644 --- a/packages/typespec-python/test/azure/generated/typetest-property-valuetypes/setup.py +++ b/packages/typespec-python/test/azure/generated/typetest-property-valuetypes/setup.py @@ -64,7 +64,7 @@ }, install_requires=[ "isodate<1.0.0,>=0.6.1", - "azure-core<2.0.0,>=1.29.5", + "azure-core<2.0.0,>=1.30.0", ], python_requires=">=3.8", ) diff --git a/packages/typespec-python/test/azure/generated/typetest-scalar/setup.py b/packages/typespec-python/test/azure/generated/typetest-scalar/setup.py index 3db8977e442..cc8c4c31ece 100644 --- a/packages/typespec-python/test/azure/generated/typetest-scalar/setup.py +++ b/packages/typespec-python/test/azure/generated/typetest-scalar/setup.py @@ -63,7 +63,7 @@ }, install_requires=[ "isodate<1.0.0,>=0.6.1", - "azure-core<2.0.0,>=1.29.5", + "azure-core<2.0.0,>=1.30.0", ], python_requires=">=3.8", ) diff --git a/packages/typespec-python/test/azure/generated/typetest-union/setup.py b/packages/typespec-python/test/azure/generated/typetest-union/setup.py index 44d0c7e043c..12515936ecb 100644 --- a/packages/typespec-python/test/azure/generated/typetest-union/setup.py +++ b/packages/typespec-python/test/azure/generated/typetest-union/setup.py @@ -63,7 +63,7 @@ }, install_requires=[ "isodate<1.0.0,>=0.6.1", - "azure-core<2.0.0,>=1.29.5", + "azure-core<2.0.0,>=1.30.0", ], python_requires=">=3.8", ) diff --git a/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/aio/operations/_operations.py b/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/aio/operations/_operations.py index 3691c1740bf..a7ea122b624 100644 --- a/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/aio/operations/_operations.py +++ b/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/aio/operations/_operations.py @@ -125,7 +125,7 @@ async def basic( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) _body = body.as_dict() if isinstance(body, _model_base.Model) else body - _files = [] + _files: FilesType = [] _data: Dict[str, Any] = {} if _body.get("id") is not None: _data["id"] = _body["id"] @@ -241,7 +241,7 @@ async def complex( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) _body = body.as_dict() if isinstance(body, _model_base.Model) else body - _files = [] + _files: FilesType = [] _data: Dict[str, Any] = {} if _body.get("id") is not None: _data["id"] = _body["id"] @@ -351,7 +351,7 @@ async def json_part( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) _body = body.as_dict() if isinstance(body, _model_base.Model) else body - _files = [] + _files: FilesType = [] _data: Dict[str, Any] = {} if _body.get("address") is not None: _data["address"] = json.dumps(_body["address"], cls=SdkJSONEncoder, exclude_readonly=True) @@ -451,7 +451,7 @@ async def binary_array_parts( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) _body = body.as_dict() if isinstance(body, _model_base.Model) else body - _files = [] + _files: FilesType = [] _data: Dict[str, Any] = {} if _body.get("id") is not None: _data["id"] = _body["id"] @@ -559,7 +559,7 @@ async def json_array_parts( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) _body = body.as_dict() if isinstance(body, _model_base.Model) else body - _files = [] + _files: FilesType = [] _data: Dict[str, Any] = {} if _body.get("profileImage") is not None: _files.append(("profileImage", _body["profileImage"])) @@ -661,7 +661,7 @@ async def multi_binary_parts( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) _body = body.as_dict() if isinstance(body, _model_base.Model) else body - _files = [] + _files: FilesType = [] _data: Dict[str, Any] = {} if _body.get("profileImage") is not None: _files.append(("profileImage", _body["profileImage"])) diff --git a/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/models/_models.py b/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/models/_models.py index 654bab5f877..c41ac172c6f 100644 --- a/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/models/_models.py +++ b/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/models/_models.py @@ -11,7 +11,7 @@ from .. import _model_base from .._model_base import rest_field -from .._vendor import FileType +from .._vendor import FileType, FilesType if TYPE_CHECKING: # pylint: disable=unused-import,ungrouped-imports diff --git a/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/operations/_operations.py b/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/operations/_operations.py index e4cdfb3ba79..d3b2ce30615 100644 --- a/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/operations/_operations.py +++ b/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/operations/_operations.py @@ -176,7 +176,7 @@ def basic( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) _body = body.as_dict() if isinstance(body, _model_base.Model) else body - _files = [] + _files: FilesType = [] _data: Dict[str, Any] = {} if _body.get("id") is not None: _data["id"] = _body["id"] @@ -292,7 +292,7 @@ def complex( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) _body = body.as_dict() if isinstance(body, _model_base.Model) else body - _files = [] + _files: FilesType = [] _data: Dict[str, Any] = {} if _body.get("id") is not None: _data["id"] = _body["id"] @@ -402,7 +402,7 @@ def json_part( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) _body = body.as_dict() if isinstance(body, _model_base.Model) else body - _files = [] + _files: FilesType = [] _data: Dict[str, Any] = {} if _body.get("address") is not None: _data["address"] = json.dumps(_body["address"], cls=SdkJSONEncoder, exclude_readonly=True) @@ -500,7 +500,7 @@ def binary_array_parts( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) _body = body.as_dict() if isinstance(body, _model_base.Model) else body - _files = [] + _files: FilesType = [] _data: Dict[str, Any] = {} if _body.get("id") is not None: _data["id"] = _body["id"] @@ -606,7 +606,7 @@ def json_array_parts( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) _body = body.as_dict() if isinstance(body, _model_base.Model) else body - _files = [] + _files: FilesType = [] _data: Dict[str, Any] = {} if _body.get("profileImage") is not None: _files.append(("profileImage", _body["profileImage"])) @@ -706,7 +706,7 @@ def multi_binary_parts( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) _body = body.as_dict() if isinstance(body, _model_base.Model) else body - _files = [] + _files: FilesType = [] _data: Dict[str, Any] = {} if _body.get("profileImage") is not None: _files.append(("profileImage", _body["profileImage"])) From dcf59fa6a774544aa666a39647b13404721cb1e5 Mon Sep 17 00:00:00 2001 From: iscai-msft Date: Thu, 1 Feb 2024 18:39:08 -0500 Subject: [PATCH 33/45] regen with fixed files typing --- packages/autorest.python/autorest/codegen/models/parameter.py | 4 +++- .../codegen/templates/packaging_templates/setup.py.jinja2 | 2 +- .../specification/azure_key_credential/generated/setup.py | 2 +- .../samples/specification/basic/generated/setup.py | 2 +- .../samples/specification/directives/generated/setup.py | 2 +- .../Expected/AcceptanceTests/AzureBodyDuration/setup.py | 2 +- .../Expected/AcceptanceTests/AzureParameterGrouping/setup.py | 2 +- .../legacy/Expected/AcceptanceTests/AzureReport/setup.py | 2 +- .../legacy/Expected/AcceptanceTests/CustomBaseUri/setup.py | 2 +- .../legacy/Expected/AcceptanceTests/CustomUrlPaging/setup.py | 2 +- .../AcceptanceTests/LroWithParameterizedEndpoints/setup.py | 2 +- .../legacy/Expected/AcceptanceTests/MixedApiVersion/setup.py | 2 +- .../azure/legacy/Expected/AcceptanceTests/Paging/setup.py | 2 +- .../AcceptanceTests/AzureBodyDurationVersionTolerant/setup.py | 2 +- .../AzureParameterGroupingVersionTolerant/setup.py | 2 +- .../AcceptanceTests/AzureReportVersionTolerant/setup.py | 2 +- .../AcceptanceTests/CustomBaseUriVersionTolerant/setup.py | 2 +- .../AcceptanceTests/CustomUrlPagingVersionTolerant/setup.py | 2 +- .../AcceptanceTests/LroPagingVersionTolerant/setup.py | 2 +- .../LroWithParameterizedEndpointsVersionTolerant/setup.py | 2 +- .../Expected/AcceptanceTests/PagingVersionTolerant/setup.py | 2 +- .../DPGCustomizationCustomizedVersionTolerant/setup.py | 2 +- .../DPGCustomizationInitialVersionTolerant/setup.py | 2 +- .../DPGServiceDrivenInitialVersionTolerant/setup.py | 2 +- .../DPGServiceDrivenUpdateOneVersionTolerant/setup.py | 2 +- .../AcceptanceTests/DPGTestModelsVersionTolerant/setup.py | 2 +- .../Expected/AcceptanceTests/AdditionalProperties/setup.py | 2 +- .../vanilla/legacy/Expected/AcceptanceTests/Anything/setup.py | 2 +- .../legacy/Expected/AcceptanceTests/BodyArray/setup.py | 2 +- .../AcceptanceTests/BodyArrayWithNamespaceFolders/setup.py | 2 +- .../legacy/Expected/AcceptanceTests/BodyBinary/setup.py | 2 +- .../legacy/Expected/AcceptanceTests/BodyBoolean/setup.py | 2 +- .../vanilla/legacy/Expected/AcceptanceTests/BodyByte/setup.py | 2 +- .../Expected/AcceptanceTests/BodyByteWithPackageName/setup.py | 2 +- .../legacy/Expected/AcceptanceTests/BodyComplex/setup.py | 2 +- .../vanilla/legacy/Expected/AcceptanceTests/BodyDate/setup.py | 2 +- .../legacy/Expected/AcceptanceTests/BodyDateTime/setup.py | 2 +- .../Expected/AcceptanceTests/BodyDateTimeRfc1123/setup.py | 2 +- .../legacy/Expected/AcceptanceTests/BodyDictionary/setup.py | 2 +- .../legacy/Expected/AcceptanceTests/BodyDuration/setup.py | 2 +- .../vanilla/legacy/Expected/AcceptanceTests/BodyFile/setup.py | 2 +- .../legacy/Expected/AcceptanceTests/BodyFormData/setup.py | 2 +- .../Expected/AcceptanceTests/BodyFormUrlEncodedData/setup.py | 2 +- .../legacy/Expected/AcceptanceTests/BodyInteger/setup.py | 2 +- .../legacy/Expected/AcceptanceTests/BodyNumber/setup.py | 2 +- .../legacy/Expected/AcceptanceTests/BodyString/setup.py | 2 +- .../vanilla/legacy/Expected/AcceptanceTests/BodyTime/setup.py | 2 +- .../legacy/Expected/AcceptanceTests/ClientEnum/setup.py | 2 +- .../legacy/Expected/AcceptanceTests/Constants/setup.py | 2 +- .../legacy/Expected/AcceptanceTests/CustomBaseUri/setup.py | 2 +- .../AcceptanceTests/CustomBaseUriMoreOptions/setup.py | 2 +- .../legacy/Expected/AcceptanceTests/ErrorWithSecrets/setup.py | 2 +- .../legacy/Expected/AcceptanceTests/ExtensibleEnums/setup.py | 2 +- .../vanilla/legacy/Expected/AcceptanceTests/Header/setup.py | 2 +- .../vanilla/legacy/Expected/AcceptanceTests/Http/setup.py | 2 +- .../Expected/AcceptanceTests/IncorrectErrorResponse/setup.py | 2 +- .../Expected/AcceptanceTests/InternalOperation/setup.py | 2 +- .../legacy/Expected/AcceptanceTests/MediaTypes/setup.py | 2 +- .../legacy/Expected/AcceptanceTests/MergePatchJson/setup.py | 2 +- .../legacy/Expected/AcceptanceTests/ModelFlattening/setup.py | 2 +- .../Expected/AcceptanceTests/MultipleInheritance/setup.py | 2 +- .../legacy/Expected/AcceptanceTests/NoOperations/setup.py | 2 +- .../legacy/Expected/AcceptanceTests/NonStringEnums/setup.py | 2 +- .../legacy/Expected/AcceptanceTests/ObjectType/setup.py | 2 +- .../Expected/AcceptanceTests/PackageModeDataPlane/setup.py | 2 +- .../Expected/AcceptanceTests/ParameterFlattening/setup.py | 2 +- .../Expected/AcceptanceTests/ParameterizedEndpoint/setup.py | 2 +- .../vanilla/legacy/Expected/AcceptanceTests/Report/setup.py | 2 +- .../legacy/Expected/AcceptanceTests/RequiredOptional/setup.py | 2 +- .../legacy/Expected/AcceptanceTests/ReservedWords/setup.py | 2 +- .../Expected/AcceptanceTests/SecurityAadSwagger/setup.py | 2 +- .../AcceptanceTests/SecurityAadSwaggerCredentialFlag/setup.py | 2 +- .../Expected/AcceptanceTests/SecurityKeySwagger/setup.py | 2 +- .../AcceptanceTests/SecurityKeySwaggerCredentialFlag/setup.py | 2 +- .../test/vanilla/legacy/Expected/AcceptanceTests/Url/setup.py | 2 +- .../AcceptanceTests/UrlMultiCollectionFormat/setup.py | 2 +- .../legacy/Expected/AcceptanceTests/Validation/setup.py | 2 +- .../test/vanilla/legacy/Expected/AcceptanceTests/Xml/setup.py | 2 +- .../legacy/Expected/AcceptanceTests/XmsErrorResponse/setup.py | 2 +- .../AdditionalPropertiesVersionTolerant/setup.py | 2 +- .../Expected/AcceptanceTests/AnythingVersionTolerant/setup.py | 2 +- .../AcceptanceTests/BodyArrayVersionTolerant/setup.py | 2 +- .../AcceptanceTests/BodyBinaryVersionTolerant/setup.py | 2 +- .../AcceptanceTests/BodyBooleanVersionTolerant/setup.py | 2 +- .../Expected/AcceptanceTests/BodyByteVersionTolerant/setup.py | 2 +- .../AcceptanceTests/BodyComplexVersionTolerant/setup.py | 2 +- .../BodyDateTimeRfc1123VersionTolerant/setup.py | 2 +- .../AcceptanceTests/BodyDateTimeVersionTolerant/setup.py | 2 +- .../Expected/AcceptanceTests/BodyDateVersionTolerant/setup.py | 2 +- .../AcceptanceTests/BodyDictionaryVersionTolerant/setup.py | 2 +- .../AcceptanceTests/BodyDurationVersionTolerant/setup.py | 2 +- .../Expected/AcceptanceTests/BodyFileVersionTolerant/setup.py | 2 +- .../AcceptanceTests/BodyFormDataVersionTolerant/setup.py | 2 +- .../BodyFormUrlEncodedDataVersionTolerant/setup.py | 2 +- .../AcceptanceTests/BodyIntegerVersionTolerant/setup.py | 2 +- .../AcceptanceTests/BodyNumberVersionTolerant/setup.py | 2 +- .../AcceptanceTests/BodyStringVersionTolerant/setup.py | 2 +- .../Expected/AcceptanceTests/BodyTimeVersionTolerant/setup.py | 2 +- .../AcceptanceTests/ClientEnumVersionTolerant/setup.py | 2 +- .../AcceptanceTests/ConstantsVersionTolerant/setup.py | 2 +- .../CustomBaseUriMoreOptionsVersionTolerant/setup.py | 2 +- .../AcceptanceTests/CustomBaseUriVersionTolerant/setup.py | 2 +- .../AcceptanceTests/ErrorWithSecretsVersionTolerant/setup.py | 2 +- .../AcceptanceTests/ExtensibleEnumsVersionTolerant/setup.py | 2 +- .../Expected/AcceptanceTests/HeaderVersionTolerant/setup.py | 2 +- .../Expected/AcceptanceTests/HttpVersionTolerant/setup.py | 2 +- .../IncorrectErrorResponseVersionTolerant/setup.py | 2 +- .../AcceptanceTests/MediaTypesVersionTolerant/setup.py | 2 +- .../AcceptanceTests/MergePatchJsonVersionTolerant/setup.py | 2 +- .../AcceptanceTests/ModelFlatteningVersionTolerant/setup.py | 2 +- .../MultipleInheritanceVersionTolerant/setup.py | 2 +- .../AcceptanceTests/NoNamespaceFlagVersionTolerant/setup.py | 2 +- .../AcceptanceTests/NoOperationsVersionTolerant/setup.py | 2 +- .../AcceptanceTests/NonStringEnumsVersionTolerant/setup.py | 2 +- .../AcceptanceTests/ObjectTypeVersionTolerant/setup.py | 2 +- .../ParameterFlatteningVersionTolerant/setup.py | 2 +- .../ParameterizedEndpointVersionTolerant/setup.py | 2 +- .../Expected/AcceptanceTests/ReportVersionTolerant/setup.py | 2 +- .../AcceptanceTests/RequiredOptionalVersionTolerant/setup.py | 2 +- .../AcceptanceTests/ReservedWordsVersionTolerant/setup.py | 2 +- .../SecurityAadSwaggerVersionTolerant/setup.py | 2 +- .../SecurityKeySwaggerVersionTolerant/setup.py | 2 +- .../UrlMultiCollectionFormatVersionTolerant/setup.py | 2 +- .../Expected/AcceptanceTests/UrlVersionTolerant/setup.py | 2 +- .../AcceptanceTests/ValidationVersionTolerant/setup.py | 2 +- .../Expected/AcceptanceTests/XmlVersionTolerant/setup.py | 2 +- .../AcceptanceTests/XmsErrorResponseVersionTolerant/setup.py | 2 +- .../payload/multipart/aio/operations/_operations.py | 1 + .../payload-multipart/payload/multipart/models/_models.py | 4 ++-- .../payload/multipart/operations/_operations.py | 1 + .../test/unbranded/generated/authentication-api-key/setup.py | 2 +- .../unbranded/generated/authentication-http-custom/setup.py | 2 +- .../test/unbranded/generated/authentication-oauth2/setup.py | 2 +- .../test/unbranded/generated/authentication-union/setup.py | 2 +- .../unbranded/generated/client-structure-default/setup.py | 2 +- .../unbranded/generated/client-structure-multiclient/setup.py | 2 +- .../generated/client-structure-renamedoperation/setup.py | 2 +- .../generated/client-structure-twooperationgroup/setup.py | 2 +- .../test/unbranded/generated/encode-bytes/setup.py | 2 +- .../test/unbranded/generated/encode-datetime/setup.py | 2 +- .../test/unbranded/generated/encode-duration/setup.py | 2 +- .../test/unbranded/generated/headasbooleanfalse/setup.py | 2 +- .../test/unbranded/generated/headasbooleantrue/setup.py | 2 +- .../unbranded/generated/parameters-body-optionality/setup.py | 2 +- .../unbranded/generated/parameters-collection-format/setup.py | 2 +- .../test/unbranded/generated/parameters-spread/setup.py | 2 +- .../unbranded/generated/payload-content-negotiation/setup.py | 2 +- .../test/unbranded/generated/payload-media-type/setup.py | 2 +- .../payload/multipart/aio/operations/_operations.py | 1 + .../payload-multipart/payload/multipart/models/_models.py | 4 ++-- .../payload/multipart/operations/_operations.py | 1 + .../test/unbranded/generated/payload-multipart/setup.py | 2 +- .../test/unbranded/generated/payload-pageable/setup.py | 2 +- .../unbranded/generated/projection-projected-name/setup.py | 2 +- .../test/unbranded/generated/resiliency-srv-driven1/setup.py | 2 +- .../test/unbranded/generated/resiliency-srv-driven2/setup.py | 2 +- .../test/unbranded/generated/server-path-multiple/setup.py | 2 +- .../test/unbranded/generated/server-path-single/setup.py | 2 +- .../generated/server-versions-not-versioned/setup.py | 2 +- .../unbranded/generated/server-versions-versioned/setup.py | 2 +- .../generated/special-headers-conditional-request/setup.py | 2 +- .../generated/special-headers-repeatability/setup.py | 2 +- .../test/unbranded/generated/special-words/setup.py | 2 +- .../test/unbranded/generated/typetest-array/setup.py | 2 +- .../test/unbranded/generated/typetest-dictionary/setup.py | 2 +- .../unbranded/generated/typetest-enum-extensible/setup.py | 2 +- .../test/unbranded/generated/typetest-enum-fixed/setup.py | 2 +- .../test/unbranded/generated/typetest-model-empty/setup.py | 2 +- .../generated/typetest-model-enumdiscriminator/setup.py | 2 +- .../generated/typetest-model-nesteddiscriminator/setup.py | 2 +- .../generated/typetest-model-notdiscriminated/setup.py | 2 +- .../unbranded/generated/typetest-model-recursive/setup.py | 2 +- .../generated/typetest-model-singlediscriminator/setup.py | 2 +- .../test/unbranded/generated/typetest-model-usage/setup.py | 2 +- .../unbranded/generated/typetest-model-visibility/setup.py | 2 +- .../generated/typetest-property-additionalproperties/setup.py | 2 +- .../unbranded/generated/typetest-property-nullable/setup.py | 2 +- .../unbranded/generated/typetest-property-optional/setup.py | 2 +- .../unbranded/generated/typetest-property-valuetypes/setup.py | 2 +- .../test/unbranded/generated/typetest-scalar/setup.py | 2 +- .../test/unbranded/generated/typetest-union/setup.py | 2 +- 181 files changed, 185 insertions(+), 179 deletions(-) diff --git a/packages/autorest.python/autorest/codegen/models/parameter.py b/packages/autorest.python/autorest/codegen/models/parameter.py index 5b2e65daf04..c49b92ac34e 100644 --- a/packages/autorest.python/autorest/codegen/models/parameter.py +++ b/packages/autorest.python/autorest/codegen/models/parameter.py @@ -295,9 +295,11 @@ def has_json_model_type(self) -> bool: def imports(self, async_mode: bool, **kwargs: Any) -> FileImport: file_import = super().imports(async_mode, **kwargs) if self.is_form_data: - file_import.add_submodule_import(".._vendor", "FilesType", ImportType.LOCAL) + relative_path = "..." if async_mode else ".." + file_import.add_submodule_import(f"{relative_path}_vendor", "FilesType", ImportType.LOCAL) file_import.add_submodule_import("typing", "Dict", ImportType.STDLIB) file_import.add_submodule_import("typing", "Any", ImportType.STDLIB) + return file_import @classmethod def from_yaml( diff --git a/packages/autorest.python/autorest/codegen/templates/packaging_templates/setup.py.jinja2 b/packages/autorest.python/autorest/codegen/templates/packaging_templates/setup.py.jinja2 index ad77a49061c..50004ed896f 100644 --- a/packages/autorest.python/autorest/codegen/templates/packaging_templates/setup.py.jinja2 +++ b/packages/autorest.python/autorest/codegen/templates/packaging_templates/setup.py.jinja2 @@ -90,7 +90,7 @@ setup( "isodate<1.0.0,>=0.6.1", {% endif %} {% if unbranded %} - "corehttp[requests]", + "corehttp[requests]<1.0.0,>=1.0.0b3", {% elif azure_arm %} "azure-mgmt-core<2.0.0,>=1.3.2", {% else %} diff --git a/packages/autorest.python/samples/specification/azure_key_credential/generated/setup.py b/packages/autorest.python/samples/specification/azure_key_credential/generated/setup.py index fc2cded5fe8..047183871d3 100644 --- a/packages/autorest.python/samples/specification/azure_key_credential/generated/setup.py +++ b/packages/autorest.python/samples/specification/azure_key_credential/generated/setup.py @@ -22,7 +22,7 @@ include_package_data=True, install_requires=[ "isodate<1.0.0,>=0.6.1", - "azure-core<2.0.0,>=1.29.5", + "azure-core<2.0.0,>=1.30.0", ], long_description="""\ Test Infrastructure for AutoRest. diff --git a/packages/autorest.python/samples/specification/basic/generated/setup.py b/packages/autorest.python/samples/specification/basic/generated/setup.py index 19bc9ec2874..1f4752aebed 100644 --- a/packages/autorest.python/samples/specification/basic/generated/setup.py +++ b/packages/autorest.python/samples/specification/basic/generated/setup.py @@ -22,7 +22,7 @@ include_package_data=True, install_requires=[ "isodate<1.0.0,>=0.6.1", - "azure-core<2.0.0,>=1.29.5", + "azure-core<2.0.0,>=1.30.0", ], long_description="""\ Test Infrastructure for AutoRest. diff --git a/packages/autorest.python/samples/specification/directives/generated/setup.py b/packages/autorest.python/samples/specification/directives/generated/setup.py index 9e3bd2fee99..3916d9ad689 100644 --- a/packages/autorest.python/samples/specification/directives/generated/setup.py +++ b/packages/autorest.python/samples/specification/directives/generated/setup.py @@ -22,7 +22,7 @@ include_package_data=True, install_requires=[ "isodate<1.0.0,>=0.6.1", - "azure-core<2.0.0,>=1.29.5", + "azure-core<2.0.0,>=1.30.0", ], long_description="""\ Show polling and paging generation. diff --git a/packages/autorest.python/test/azure/legacy/Expected/AcceptanceTests/AzureBodyDuration/setup.py b/packages/autorest.python/test/azure/legacy/Expected/AcceptanceTests/AzureBodyDuration/setup.py index fc80105c68c..66bf7c6a5e5 100644 --- a/packages/autorest.python/test/azure/legacy/Expected/AcceptanceTests/AzureBodyDuration/setup.py +++ b/packages/autorest.python/test/azure/legacy/Expected/AcceptanceTests/AzureBodyDuration/setup.py @@ -22,7 +22,7 @@ include_package_data=True, install_requires=[ "msrest>=0.7.1", - "azure-core<2.0.0,>=1.29.5", + "azure-core<2.0.0,>=1.30.0", ], long_description="""\ Test Infrastructure for AutoRest. diff --git a/packages/autorest.python/test/azure/legacy/Expected/AcceptanceTests/AzureParameterGrouping/setup.py b/packages/autorest.python/test/azure/legacy/Expected/AcceptanceTests/AzureParameterGrouping/setup.py index 29bfe82adfb..e4f2d15a4da 100644 --- a/packages/autorest.python/test/azure/legacy/Expected/AcceptanceTests/AzureParameterGrouping/setup.py +++ b/packages/autorest.python/test/azure/legacy/Expected/AcceptanceTests/AzureParameterGrouping/setup.py @@ -22,7 +22,7 @@ include_package_data=True, install_requires=[ "msrest>=0.7.1", - "azure-core<2.0.0,>=1.29.5", + "azure-core<2.0.0,>=1.30.0", ], long_description="""\ Test Infrastructure for AutoRest. diff --git a/packages/autorest.python/test/azure/legacy/Expected/AcceptanceTests/AzureReport/setup.py b/packages/autorest.python/test/azure/legacy/Expected/AcceptanceTests/AzureReport/setup.py index 4ec0e75d203..bbce89d8f46 100644 --- a/packages/autorest.python/test/azure/legacy/Expected/AcceptanceTests/AzureReport/setup.py +++ b/packages/autorest.python/test/azure/legacy/Expected/AcceptanceTests/AzureReport/setup.py @@ -22,7 +22,7 @@ include_package_data=True, install_requires=[ "msrest>=0.7.1", - "azure-core<2.0.0,>=1.29.5", + "azure-core<2.0.0,>=1.30.0", ], long_description="""\ Test Infrastructure for AutoRest. diff --git a/packages/autorest.python/test/azure/legacy/Expected/AcceptanceTests/CustomBaseUri/setup.py b/packages/autorest.python/test/azure/legacy/Expected/AcceptanceTests/CustomBaseUri/setup.py index 82d4cc4982d..3379514f62b 100644 --- a/packages/autorest.python/test/azure/legacy/Expected/AcceptanceTests/CustomBaseUri/setup.py +++ b/packages/autorest.python/test/azure/legacy/Expected/AcceptanceTests/CustomBaseUri/setup.py @@ -22,7 +22,7 @@ include_package_data=True, install_requires=[ "msrest>=0.7.1", - "azure-core<2.0.0,>=1.29.5", + "azure-core<2.0.0,>=1.30.0", ], long_description="""\ Test Infrastructure for AutoRest. diff --git a/packages/autorest.python/test/azure/legacy/Expected/AcceptanceTests/CustomUrlPaging/setup.py b/packages/autorest.python/test/azure/legacy/Expected/AcceptanceTests/CustomUrlPaging/setup.py index d8ffef325dc..16bd3bc8d0e 100644 --- a/packages/autorest.python/test/azure/legacy/Expected/AcceptanceTests/CustomUrlPaging/setup.py +++ b/packages/autorest.python/test/azure/legacy/Expected/AcceptanceTests/CustomUrlPaging/setup.py @@ -22,7 +22,7 @@ include_package_data=True, install_requires=[ "msrest>=0.7.1", - "azure-core<2.0.0,>=1.29.5", + "azure-core<2.0.0,>=1.30.0", ], long_description="""\ Test Infrastructure for AutoRest. diff --git a/packages/autorest.python/test/azure/legacy/Expected/AcceptanceTests/LroWithParameterizedEndpoints/setup.py b/packages/autorest.python/test/azure/legacy/Expected/AcceptanceTests/LroWithParameterizedEndpoints/setup.py index 1ff251753a0..2eb626c3483 100644 --- a/packages/autorest.python/test/azure/legacy/Expected/AcceptanceTests/LroWithParameterizedEndpoints/setup.py +++ b/packages/autorest.python/test/azure/legacy/Expected/AcceptanceTests/LroWithParameterizedEndpoints/setup.py @@ -22,7 +22,7 @@ include_package_data=True, install_requires=[ "msrest>=0.7.1", - "azure-core<2.0.0,>=1.29.5", + "azure-core<2.0.0,>=1.30.0", ], long_description="""\ Test Infrastructure for AutoRest. diff --git a/packages/autorest.python/test/azure/legacy/Expected/AcceptanceTests/MixedApiVersion/setup.py b/packages/autorest.python/test/azure/legacy/Expected/AcceptanceTests/MixedApiVersion/setup.py index cc82b26a037..b905086f368 100644 --- a/packages/autorest.python/test/azure/legacy/Expected/AcceptanceTests/MixedApiVersion/setup.py +++ b/packages/autorest.python/test/azure/legacy/Expected/AcceptanceTests/MixedApiVersion/setup.py @@ -22,7 +22,7 @@ include_package_data=True, install_requires=[ "msrest>=0.7.1", - "azure-core<2.0.0,>=1.29.5", + "azure-core<2.0.0,>=1.30.0", ], long_description="""\ Test Infrastructure for AutoRest. diff --git a/packages/autorest.python/test/azure/legacy/Expected/AcceptanceTests/Paging/setup.py b/packages/autorest.python/test/azure/legacy/Expected/AcceptanceTests/Paging/setup.py index 3da5b3f692f..ccc76c3359d 100644 --- a/packages/autorest.python/test/azure/legacy/Expected/AcceptanceTests/Paging/setup.py +++ b/packages/autorest.python/test/azure/legacy/Expected/AcceptanceTests/Paging/setup.py @@ -22,7 +22,7 @@ include_package_data=True, install_requires=[ "msrest>=0.7.1", - "azure-core<2.0.0,>=1.29.5", + "azure-core<2.0.0,>=1.30.0", ], long_description="""\ Long-running Operation for AutoRest. diff --git a/packages/autorest.python/test/azure/version-tolerant/Expected/AcceptanceTests/AzureBodyDurationVersionTolerant/setup.py b/packages/autorest.python/test/azure/version-tolerant/Expected/AcceptanceTests/AzureBodyDurationVersionTolerant/setup.py index 7b248bcf505..8e07e8b6f89 100644 --- a/packages/autorest.python/test/azure/version-tolerant/Expected/AcceptanceTests/AzureBodyDurationVersionTolerant/setup.py +++ b/packages/autorest.python/test/azure/version-tolerant/Expected/AcceptanceTests/AzureBodyDurationVersionTolerant/setup.py @@ -22,7 +22,7 @@ include_package_data=True, install_requires=[ "isodate<1.0.0,>=0.6.1", - "azure-core<2.0.0,>=1.29.5", + "azure-core<2.0.0,>=1.30.0", ], long_description="""\ Test Infrastructure for AutoRest. diff --git a/packages/autorest.python/test/azure/version-tolerant/Expected/AcceptanceTests/AzureParameterGroupingVersionTolerant/setup.py b/packages/autorest.python/test/azure/version-tolerant/Expected/AcceptanceTests/AzureParameterGroupingVersionTolerant/setup.py index eff907aad85..011c85abf82 100644 --- a/packages/autorest.python/test/azure/version-tolerant/Expected/AcceptanceTests/AzureParameterGroupingVersionTolerant/setup.py +++ b/packages/autorest.python/test/azure/version-tolerant/Expected/AcceptanceTests/AzureParameterGroupingVersionTolerant/setup.py @@ -22,7 +22,7 @@ include_package_data=True, install_requires=[ "isodate<1.0.0,>=0.6.1", - "azure-core<2.0.0,>=1.29.5", + "azure-core<2.0.0,>=1.30.0", ], long_description="""\ Test Infrastructure for AutoRest. diff --git a/packages/autorest.python/test/azure/version-tolerant/Expected/AcceptanceTests/AzureReportVersionTolerant/setup.py b/packages/autorest.python/test/azure/version-tolerant/Expected/AcceptanceTests/AzureReportVersionTolerant/setup.py index cd5071d08c2..0afd0425843 100644 --- a/packages/autorest.python/test/azure/version-tolerant/Expected/AcceptanceTests/AzureReportVersionTolerant/setup.py +++ b/packages/autorest.python/test/azure/version-tolerant/Expected/AcceptanceTests/AzureReportVersionTolerant/setup.py @@ -22,7 +22,7 @@ include_package_data=True, install_requires=[ "isodate<1.0.0,>=0.6.1", - "azure-core<2.0.0,>=1.29.5", + "azure-core<2.0.0,>=1.30.0", ], long_description="""\ Test Infrastructure for AutoRest. diff --git a/packages/autorest.python/test/azure/version-tolerant/Expected/AcceptanceTests/CustomBaseUriVersionTolerant/setup.py b/packages/autorest.python/test/azure/version-tolerant/Expected/AcceptanceTests/CustomBaseUriVersionTolerant/setup.py index 434b61fb4f3..7a2aed8d1bb 100644 --- a/packages/autorest.python/test/azure/version-tolerant/Expected/AcceptanceTests/CustomBaseUriVersionTolerant/setup.py +++ b/packages/autorest.python/test/azure/version-tolerant/Expected/AcceptanceTests/CustomBaseUriVersionTolerant/setup.py @@ -22,7 +22,7 @@ include_package_data=True, install_requires=[ "isodate<1.0.0,>=0.6.1", - "azure-core<2.0.0,>=1.29.5", + "azure-core<2.0.0,>=1.30.0", ], long_description="""\ Test Infrastructure for AutoRest. diff --git a/packages/autorest.python/test/azure/version-tolerant/Expected/AcceptanceTests/CustomUrlPagingVersionTolerant/setup.py b/packages/autorest.python/test/azure/version-tolerant/Expected/AcceptanceTests/CustomUrlPagingVersionTolerant/setup.py index 152b8d4c466..ed5c37e7af5 100644 --- a/packages/autorest.python/test/azure/version-tolerant/Expected/AcceptanceTests/CustomUrlPagingVersionTolerant/setup.py +++ b/packages/autorest.python/test/azure/version-tolerant/Expected/AcceptanceTests/CustomUrlPagingVersionTolerant/setup.py @@ -22,7 +22,7 @@ include_package_data=True, install_requires=[ "isodate<1.0.0,>=0.6.1", - "azure-core<2.0.0,>=1.29.5", + "azure-core<2.0.0,>=1.30.0", ], long_description="""\ Test Infrastructure for AutoRest. diff --git a/packages/autorest.python/test/azure/version-tolerant/Expected/AcceptanceTests/LroPagingVersionTolerant/setup.py b/packages/autorest.python/test/azure/version-tolerant/Expected/AcceptanceTests/LroPagingVersionTolerant/setup.py index ddbad7e4a0f..56f44a4e670 100644 --- a/packages/autorest.python/test/azure/version-tolerant/Expected/AcceptanceTests/LroPagingVersionTolerant/setup.py +++ b/packages/autorest.python/test/azure/version-tolerant/Expected/AcceptanceTests/LroPagingVersionTolerant/setup.py @@ -22,7 +22,7 @@ include_package_data=True, install_requires=[ "isodate<1.0.0,>=0.6.1", - "azure-core<2.0.0,>=1.29.5", + "azure-core<2.0.0,>=1.30.0", ], long_description="""\ The language service API is a suite of natural language processing (NLP) skills built with best-in-class Microsoft machine learning algorithms. diff --git a/packages/autorest.python/test/azure/version-tolerant/Expected/AcceptanceTests/LroWithParameterizedEndpointsVersionTolerant/setup.py b/packages/autorest.python/test/azure/version-tolerant/Expected/AcceptanceTests/LroWithParameterizedEndpointsVersionTolerant/setup.py index 21c3b1e79d6..6ab77ce6429 100644 --- a/packages/autorest.python/test/azure/version-tolerant/Expected/AcceptanceTests/LroWithParameterizedEndpointsVersionTolerant/setup.py +++ b/packages/autorest.python/test/azure/version-tolerant/Expected/AcceptanceTests/LroWithParameterizedEndpointsVersionTolerant/setup.py @@ -22,7 +22,7 @@ include_package_data=True, install_requires=[ "isodate<1.0.0,>=0.6.1", - "azure-core<2.0.0,>=1.29.5", + "azure-core<2.0.0,>=1.30.0", ], long_description="""\ Test Infrastructure for AutoRest. diff --git a/packages/autorest.python/test/azure/version-tolerant/Expected/AcceptanceTests/PagingVersionTolerant/setup.py b/packages/autorest.python/test/azure/version-tolerant/Expected/AcceptanceTests/PagingVersionTolerant/setup.py index 0a698a1127a..b5af252721d 100644 --- a/packages/autorest.python/test/azure/version-tolerant/Expected/AcceptanceTests/PagingVersionTolerant/setup.py +++ b/packages/autorest.python/test/azure/version-tolerant/Expected/AcceptanceTests/PagingVersionTolerant/setup.py @@ -22,7 +22,7 @@ include_package_data=True, install_requires=[ "isodate<1.0.0,>=0.6.1", - "azure-core<2.0.0,>=1.29.5", + "azure-core<2.0.0,>=1.30.0", ], long_description="""\ Long-running Operation for AutoRest. diff --git a/packages/autorest.python/test/dpg/version-tolerant/Expected/AcceptanceTests/DPGCustomizationCustomizedVersionTolerant/setup.py b/packages/autorest.python/test/dpg/version-tolerant/Expected/AcceptanceTests/DPGCustomizationCustomizedVersionTolerant/setup.py index 4db50e34cb9..7c95ba160d0 100644 --- a/packages/autorest.python/test/dpg/version-tolerant/Expected/AcceptanceTests/DPGCustomizationCustomizedVersionTolerant/setup.py +++ b/packages/autorest.python/test/dpg/version-tolerant/Expected/AcceptanceTests/DPGCustomizationCustomizedVersionTolerant/setup.py @@ -22,7 +22,7 @@ include_package_data=True, install_requires=[ "isodate<1.0.0,>=0.6.1", - "azure-core<2.0.0,>=1.29.5", + "azure-core<2.0.0,>=1.30.0", ], long_description="""\ DPG Swagger that tests our ability to grow up. diff --git a/packages/autorest.python/test/dpg/version-tolerant/Expected/AcceptanceTests/DPGCustomizationInitialVersionTolerant/setup.py b/packages/autorest.python/test/dpg/version-tolerant/Expected/AcceptanceTests/DPGCustomizationInitialVersionTolerant/setup.py index 27b100a68dd..a7dc25cb624 100644 --- a/packages/autorest.python/test/dpg/version-tolerant/Expected/AcceptanceTests/DPGCustomizationInitialVersionTolerant/setup.py +++ b/packages/autorest.python/test/dpg/version-tolerant/Expected/AcceptanceTests/DPGCustomizationInitialVersionTolerant/setup.py @@ -22,7 +22,7 @@ include_package_data=True, install_requires=[ "isodate<1.0.0,>=0.6.1", - "azure-core<2.0.0,>=1.29.5", + "azure-core<2.0.0,>=1.30.0", ], long_description="""\ DPG Swagger that tests our ability to grow up. diff --git a/packages/autorest.python/test/dpg/version-tolerant/Expected/AcceptanceTests/DPGServiceDrivenInitialVersionTolerant/setup.py b/packages/autorest.python/test/dpg/version-tolerant/Expected/AcceptanceTests/DPGServiceDrivenInitialVersionTolerant/setup.py index 8a87a9d4b35..bc80fcc2088 100644 --- a/packages/autorest.python/test/dpg/version-tolerant/Expected/AcceptanceTests/DPGServiceDrivenInitialVersionTolerant/setup.py +++ b/packages/autorest.python/test/dpg/version-tolerant/Expected/AcceptanceTests/DPGServiceDrivenInitialVersionTolerant/setup.py @@ -22,7 +22,7 @@ include_package_data=True, install_requires=[ "isodate<1.0.0,>=0.6.1", - "azure-core<2.0.0,>=1.29.5", + "azure-core<2.0.0,>=1.30.0", ], long_description="""\ DPG Swagger, this is the initial swagger a service could do. diff --git a/packages/autorest.python/test/dpg/version-tolerant/Expected/AcceptanceTests/DPGServiceDrivenUpdateOneVersionTolerant/setup.py b/packages/autorest.python/test/dpg/version-tolerant/Expected/AcceptanceTests/DPGServiceDrivenUpdateOneVersionTolerant/setup.py index 26497a4744a..2dcf6dd34e6 100644 --- a/packages/autorest.python/test/dpg/version-tolerant/Expected/AcceptanceTests/DPGServiceDrivenUpdateOneVersionTolerant/setup.py +++ b/packages/autorest.python/test/dpg/version-tolerant/Expected/AcceptanceTests/DPGServiceDrivenUpdateOneVersionTolerant/setup.py @@ -22,7 +22,7 @@ include_package_data=True, install_requires=[ "isodate<1.0.0,>=0.6.1", - "azure-core<2.0.0,>=1.29.5", + "azure-core<2.0.0,>=1.30.0", ], long_description="""\ DPG Swagger, this is the initial swagger a service could do. diff --git a/packages/autorest.python/test/dpg/version-tolerant/Expected/AcceptanceTests/DPGTestModelsVersionTolerant/setup.py b/packages/autorest.python/test/dpg/version-tolerant/Expected/AcceptanceTests/DPGTestModelsVersionTolerant/setup.py index 138f0ae9898..a8d842c3eb1 100644 --- a/packages/autorest.python/test/dpg/version-tolerant/Expected/AcceptanceTests/DPGTestModelsVersionTolerant/setup.py +++ b/packages/autorest.python/test/dpg/version-tolerant/Expected/AcceptanceTests/DPGTestModelsVersionTolerant/setup.py @@ -22,7 +22,7 @@ include_package_data=True, install_requires=[ "isodate<1.0.0,>=0.6.1", - "azure-core<2.0.0,>=1.29.5", + "azure-core<2.0.0,>=1.30.0", ], long_description="""\ DPG Swagger that tests our ability to grow up. diff --git a/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/AdditionalProperties/setup.py b/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/AdditionalProperties/setup.py index a41c4a4109e..57f9c8630d7 100644 --- a/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/AdditionalProperties/setup.py +++ b/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/AdditionalProperties/setup.py @@ -22,7 +22,7 @@ include_package_data=True, install_requires=[ "msrest>=0.7.1", - "azure-core<2.0.0,>=1.29.5", + "azure-core<2.0.0,>=1.30.0", ], long_description="""\ Test Infrastructure for AutoRest. diff --git a/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/Anything/setup.py b/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/Anything/setup.py index f8533bb20aa..1fb1a1f9b56 100644 --- a/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/Anything/setup.py +++ b/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/Anything/setup.py @@ -22,7 +22,7 @@ include_package_data=True, install_requires=[ "msrest>=0.7.1", - "azure-core<2.0.0,>=1.29.5", + "azure-core<2.0.0,>=1.30.0", ], long_description="""\ Service client for testing basic anything types. Those schemas without types can be anything: primitive, object, array. diff --git a/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/BodyArray/setup.py b/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/BodyArray/setup.py index b7a685dd2b9..bae0c9a3e66 100644 --- a/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/BodyArray/setup.py +++ b/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/BodyArray/setup.py @@ -22,7 +22,7 @@ include_package_data=True, install_requires=[ "msrest>=0.7.1", - "azure-core<2.0.0,>=1.29.5", + "azure-core<2.0.0,>=1.30.0", ], long_description="""\ Test Infrastructure for AutoRest Swagger BAT. diff --git a/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/BodyArrayWithNamespaceFolders/setup.py b/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/BodyArrayWithNamespaceFolders/setup.py index b7a685dd2b9..bae0c9a3e66 100644 --- a/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/BodyArrayWithNamespaceFolders/setup.py +++ b/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/BodyArrayWithNamespaceFolders/setup.py @@ -22,7 +22,7 @@ include_package_data=True, install_requires=[ "msrest>=0.7.1", - "azure-core<2.0.0,>=1.29.5", + "azure-core<2.0.0,>=1.30.0", ], long_description="""\ Test Infrastructure for AutoRest Swagger BAT. diff --git a/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/BodyBinary/setup.py b/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/BodyBinary/setup.py index 93e31d4bd7b..c958026c249 100644 --- a/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/BodyBinary/setup.py +++ b/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/BodyBinary/setup.py @@ -22,7 +22,7 @@ include_package_data=True, install_requires=[ "msrest>=0.7.1", - "azure-core<2.0.0,>=1.29.5", + "azure-core<2.0.0,>=1.30.0", ], long_description="""\ Sample for file with json and binary content type. diff --git a/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/BodyBoolean/setup.py b/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/BodyBoolean/setup.py index da866acb5b9..30a07fd5172 100644 --- a/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/BodyBoolean/setup.py +++ b/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/BodyBoolean/setup.py @@ -22,7 +22,7 @@ include_package_data=True, install_requires=[ "msrest>=0.7.1", - "azure-core<2.0.0,>=1.29.5", + "azure-core<2.0.0,>=1.30.0", ], long_description="""\ Test Infrastructure for AutoRest. diff --git a/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/BodyByte/setup.py b/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/BodyByte/setup.py index bd59221daff..0a88057621a 100644 --- a/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/BodyByte/setup.py +++ b/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/BodyByte/setup.py @@ -22,7 +22,7 @@ include_package_data=True, install_requires=[ "msrest>=0.7.1", - "azure-core<2.0.0,>=1.29.5", + "azure-core<2.0.0,>=1.30.0", ], long_description="""\ Test Infrastructure for AutoRest Swagger BAT. diff --git a/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/BodyByteWithPackageName/setup.py b/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/BodyByteWithPackageName/setup.py index 61f4f730912..e259f41d1ad 100644 --- a/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/BodyByteWithPackageName/setup.py +++ b/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/BodyByteWithPackageName/setup.py @@ -22,7 +22,7 @@ include_package_data=True, install_requires=[ "msrest>=0.7.1", - "azure-core<2.0.0,>=1.29.5", + "azure-core<2.0.0,>=1.30.0", ], long_description="""\ Test Infrastructure for AutoRest Swagger BAT. diff --git a/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/BodyComplex/setup.py b/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/BodyComplex/setup.py index b399df5edee..742af7da9fd 100644 --- a/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/BodyComplex/setup.py +++ b/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/BodyComplex/setup.py @@ -22,7 +22,7 @@ include_package_data=True, install_requires=[ "msrest>=0.7.1", - "azure-core<2.0.0,>=1.29.5", + "azure-core<2.0.0,>=1.30.0", ], long_description="""\ Test Infrastructure for AutoRest. diff --git a/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/BodyDate/setup.py b/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/BodyDate/setup.py index a0815f35552..553c93eeaac 100644 --- a/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/BodyDate/setup.py +++ b/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/BodyDate/setup.py @@ -22,7 +22,7 @@ include_package_data=True, install_requires=[ "msrest>=0.7.1", - "azure-core<2.0.0,>=1.29.5", + "azure-core<2.0.0,>=1.30.0", ], long_description="""\ Test Infrastructure for AutoRest. diff --git a/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/BodyDateTime/setup.py b/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/BodyDateTime/setup.py index f3cb43258a3..0d233a0c11b 100644 --- a/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/BodyDateTime/setup.py +++ b/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/BodyDateTime/setup.py @@ -22,7 +22,7 @@ include_package_data=True, install_requires=[ "msrest>=0.7.1", - "azure-core<2.0.0,>=1.29.5", + "azure-core<2.0.0,>=1.30.0", ], long_description="""\ Test Infrastructure for AutoRest. diff --git a/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/BodyDateTimeRfc1123/setup.py b/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/BodyDateTimeRfc1123/setup.py index 58bd4a5a550..72d8c1d2f26 100644 --- a/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/BodyDateTimeRfc1123/setup.py +++ b/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/BodyDateTimeRfc1123/setup.py @@ -22,7 +22,7 @@ include_package_data=True, install_requires=[ "msrest>=0.7.1", - "azure-core<2.0.0,>=1.29.5", + "azure-core<2.0.0,>=1.30.0", ], long_description="""\ Test Infrastructure for AutoRest. diff --git a/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/BodyDictionary/setup.py b/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/BodyDictionary/setup.py index 46e8569aca1..544e910ce6f 100644 --- a/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/BodyDictionary/setup.py +++ b/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/BodyDictionary/setup.py @@ -22,7 +22,7 @@ include_package_data=True, install_requires=[ "msrest>=0.7.1", - "azure-core<2.0.0,>=1.29.5", + "azure-core<2.0.0,>=1.30.0", ], long_description="""\ Test Infrastructure for AutoRest Swagger BAT. diff --git a/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/BodyDuration/setup.py b/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/BodyDuration/setup.py index fc80105c68c..66bf7c6a5e5 100644 --- a/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/BodyDuration/setup.py +++ b/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/BodyDuration/setup.py @@ -22,7 +22,7 @@ include_package_data=True, install_requires=[ "msrest>=0.7.1", - "azure-core<2.0.0,>=1.29.5", + "azure-core<2.0.0,>=1.30.0", ], long_description="""\ Test Infrastructure for AutoRest. diff --git a/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/BodyFile/setup.py b/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/BodyFile/setup.py index 4afaa4559ea..41c4cdec7c9 100644 --- a/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/BodyFile/setup.py +++ b/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/BodyFile/setup.py @@ -22,7 +22,7 @@ include_package_data=True, install_requires=[ "msrest>=0.7.1", - "azure-core<2.0.0,>=1.29.5", + "azure-core<2.0.0,>=1.30.0", ], long_description="""\ Test Infrastructure for AutoRest Swagger BAT. diff --git a/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/BodyFormData/setup.py b/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/BodyFormData/setup.py index 599a0fc24f4..3a4dd958399 100644 --- a/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/BodyFormData/setup.py +++ b/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/BodyFormData/setup.py @@ -22,7 +22,7 @@ include_package_data=True, install_requires=[ "msrest>=0.7.1", - "azure-core<2.0.0,>=1.29.5", + "azure-core<2.0.0,>=1.30.0", ], long_description="""\ Test Infrastructure for AutoRest Swagger BAT. diff --git a/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/BodyFormUrlEncodedData/setup.py b/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/BodyFormUrlEncodedData/setup.py index 3fd0f4b9ca4..cf6261e3fb0 100644 --- a/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/BodyFormUrlEncodedData/setup.py +++ b/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/BodyFormUrlEncodedData/setup.py @@ -22,7 +22,7 @@ include_package_data=True, install_requires=[ "msrest>=0.7.1", - "azure-core<2.0.0,>=1.29.5", + "azure-core<2.0.0,>=1.30.0", ], long_description="""\ Test Infrastructure for AutoRest Swagger BAT. diff --git a/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/BodyInteger/setup.py b/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/BodyInteger/setup.py index 6dfe24fd549..1ca770dad35 100644 --- a/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/BodyInteger/setup.py +++ b/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/BodyInteger/setup.py @@ -22,7 +22,7 @@ include_package_data=True, install_requires=[ "msrest>=0.7.1", - "azure-core<2.0.0,>=1.29.5", + "azure-core<2.0.0,>=1.30.0", ], long_description="""\ Test Infrastructure for AutoRest. diff --git a/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/BodyNumber/setup.py b/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/BodyNumber/setup.py index c226f425c50..322f94ac5c1 100644 --- a/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/BodyNumber/setup.py +++ b/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/BodyNumber/setup.py @@ -22,7 +22,7 @@ include_package_data=True, install_requires=[ "msrest>=0.7.1", - "azure-core<2.0.0,>=1.29.5", + "azure-core<2.0.0,>=1.30.0", ], long_description="""\ Test Infrastructure for AutoRest. diff --git a/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/BodyString/setup.py b/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/BodyString/setup.py index 00a958ba8f4..63401063a23 100644 --- a/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/BodyString/setup.py +++ b/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/BodyString/setup.py @@ -22,7 +22,7 @@ include_package_data=True, install_requires=[ "msrest>=0.7.1", - "azure-core<2.0.0,>=1.29.5", + "azure-core<2.0.0,>=1.30.0", ], long_description="""\ Test Infrastructure for AutoRest Swagger BAT. diff --git a/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/BodyTime/setup.py b/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/BodyTime/setup.py index fc2658ddc7a..43c2ac57337 100644 --- a/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/BodyTime/setup.py +++ b/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/BodyTime/setup.py @@ -22,7 +22,7 @@ include_package_data=True, install_requires=[ "msrest>=0.7.1", - "azure-core<2.0.0,>=1.29.5", + "azure-core<2.0.0,>=1.30.0", ], long_description="""\ Test Infrastructure for AutoRest. diff --git a/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/ClientEnum/setup.py b/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/ClientEnum/setup.py index eeeafeea816..7ae2d03fbdc 100644 --- a/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/ClientEnum/setup.py +++ b/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/ClientEnum/setup.py @@ -22,7 +22,7 @@ include_package_data=True, install_requires=[ "msrest>=0.7.1", - "azure-core<2.0.0,>=1.29.5", + "azure-core<2.0.0,>=1.30.0", ], long_description="""\ Test client with enum variable. diff --git a/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/Constants/setup.py b/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/Constants/setup.py index 737a5cf4eb7..254041a6b2e 100644 --- a/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/Constants/setup.py +++ b/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/Constants/setup.py @@ -22,7 +22,7 @@ include_package_data=True, install_requires=[ "msrest>=0.7.1", - "azure-core<2.0.0,>=1.29.5", + "azure-core<2.0.0,>=1.30.0", ], long_description="""\ Test Infrastructure for AutoRest Swagger Constant. diff --git a/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/CustomBaseUri/setup.py b/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/CustomBaseUri/setup.py index 82d4cc4982d..3379514f62b 100644 --- a/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/CustomBaseUri/setup.py +++ b/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/CustomBaseUri/setup.py @@ -22,7 +22,7 @@ include_package_data=True, install_requires=[ "msrest>=0.7.1", - "azure-core<2.0.0,>=1.29.5", + "azure-core<2.0.0,>=1.30.0", ], long_description="""\ Test Infrastructure for AutoRest. diff --git a/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/CustomBaseUriMoreOptions/setup.py b/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/CustomBaseUriMoreOptions/setup.py index 7aab3238a2e..679aa3ab52a 100644 --- a/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/CustomBaseUriMoreOptions/setup.py +++ b/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/CustomBaseUriMoreOptions/setup.py @@ -22,7 +22,7 @@ include_package_data=True, install_requires=[ "msrest>=0.7.1", - "azure-core<2.0.0,>=1.29.5", + "azure-core<2.0.0,>=1.30.0", ], long_description="""\ Test Infrastructure for AutoRest. diff --git a/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/ErrorWithSecrets/setup.py b/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/ErrorWithSecrets/setup.py index c101053dff2..053bc3eaf24 100644 --- a/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/ErrorWithSecrets/setup.py +++ b/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/ErrorWithSecrets/setup.py @@ -22,7 +22,7 @@ include_package_data=True, install_requires=[ "msrest>=0.7.1", - "azure-core<2.0.0,>=1.29.5", + "azure-core<2.0.0,>=1.30.0", ], long_description="""\ Tests whether loggers/tracers redact secrets and PII within error responses. diff --git a/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/ExtensibleEnums/setup.py b/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/ExtensibleEnums/setup.py index 20b07b6b539..15b986b2b5b 100644 --- a/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/ExtensibleEnums/setup.py +++ b/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/ExtensibleEnums/setup.py @@ -22,7 +22,7 @@ include_package_data=True, install_requires=[ "msrest>=0.7.1", - "azure-core<2.0.0,>=1.29.5", + "azure-core<2.0.0,>=1.30.0", ], long_description="""\ PetStore. diff --git a/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/Header/setup.py b/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/Header/setup.py index e91ecc5ca53..dd7b8698ca3 100644 --- a/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/Header/setup.py +++ b/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/Header/setup.py @@ -22,7 +22,7 @@ include_package_data=True, install_requires=[ "msrest>=0.7.1", - "azure-core<2.0.0,>=1.29.5", + "azure-core<2.0.0,>=1.30.0", ], long_description="""\ Test Infrastructure for AutoRest. diff --git a/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/Http/setup.py b/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/Http/setup.py index 73a5f2bb432..d4ddd1a6708 100644 --- a/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/Http/setup.py +++ b/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/Http/setup.py @@ -22,7 +22,7 @@ include_package_data=True, install_requires=[ "msrest>=0.7.1", - "azure-core<2.0.0,>=1.29.5", + "azure-core<2.0.0,>=1.30.0", ], long_description="""\ Test Infrastructure for AutoRest. diff --git a/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/IncorrectErrorResponse/setup.py b/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/IncorrectErrorResponse/setup.py index 9d50d684d92..a9dc067d8a6 100644 --- a/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/IncorrectErrorResponse/setup.py +++ b/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/IncorrectErrorResponse/setup.py @@ -22,7 +22,7 @@ include_package_data=True, install_requires=[ "msrest>=0.7.1", - "azure-core<2.0.0,>=1.29.5", + "azure-core<2.0.0,>=1.30.0", ], long_description="""\ Test to see when throwing an HttpResponseError whether we swallow error model deserialization errors. diff --git a/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/InternalOperation/setup.py b/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/InternalOperation/setup.py index b9e42e19ccc..2e26e20f0a6 100644 --- a/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/InternalOperation/setup.py +++ b/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/InternalOperation/setup.py @@ -61,7 +61,7 @@ }, install_requires=[ "msrest>=0.7.1", - "azure-core<2.0.0,>=1.29.5", + "azure-core<2.0.0,>=1.30.0", ], python_requires=">=3.8", ) diff --git a/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/MediaTypes/setup.py b/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/MediaTypes/setup.py index 0120a19da2c..fd2e454e7bf 100644 --- a/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/MediaTypes/setup.py +++ b/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/MediaTypes/setup.py @@ -22,7 +22,7 @@ include_package_data=True, install_requires=[ "msrest>=0.7.1", - "azure-core<2.0.0,>=1.29.5", + "azure-core<2.0.0,>=1.30.0", ], long_description="""\ Play with produces/consumes and media-types in general. diff --git a/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/MergePatchJson/setup.py b/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/MergePatchJson/setup.py index f759f5208e0..78c3c1c5c50 100644 --- a/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/MergePatchJson/setup.py +++ b/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/MergePatchJson/setup.py @@ -22,7 +22,7 @@ include_package_data=True, install_requires=[ "msrest>=0.7.1", - "azure-core<2.0.0,>=1.29.5", + "azure-core<2.0.0,>=1.30.0", ], long_description="""\ Service client for testing merge patch json. diff --git a/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/ModelFlattening/setup.py b/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/ModelFlattening/setup.py index 334a553cddf..d5ddcb2c067 100644 --- a/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/ModelFlattening/setup.py +++ b/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/ModelFlattening/setup.py @@ -22,7 +22,7 @@ include_package_data=True, install_requires=[ "msrest>=0.7.1", - "azure-core<2.0.0,>=1.29.5", + "azure-core<2.0.0,>=1.30.0", ], long_description="""\ Resource Flattening for AutoRest. diff --git a/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/MultipleInheritance/setup.py b/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/MultipleInheritance/setup.py index 9c517f9ccb2..a1d80e4a2a6 100644 --- a/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/MultipleInheritance/setup.py +++ b/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/MultipleInheritance/setup.py @@ -22,7 +22,7 @@ include_package_data=True, install_requires=[ "msrest>=0.7.1", - "azure-core<2.0.0,>=1.29.5", + "azure-core<2.0.0,>=1.30.0", ], long_description="""\ Service client for multiinheritance client testing. diff --git a/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/NoOperations/setup.py b/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/NoOperations/setup.py index b9e66a039fd..8a9a5c74fbf 100644 --- a/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/NoOperations/setup.py +++ b/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/NoOperations/setup.py @@ -22,7 +22,7 @@ include_package_data=True, install_requires=[ "msrest>=0.7.1", - "azure-core<2.0.0,>=1.29.5", + "azure-core<2.0.0,>=1.30.0", ], long_description="""\ Service client with no operations. diff --git a/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/NonStringEnums/setup.py b/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/NonStringEnums/setup.py index 806fc69b538..2ead8848e9e 100644 --- a/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/NonStringEnums/setup.py +++ b/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/NonStringEnums/setup.py @@ -22,7 +22,7 @@ include_package_data=True, install_requires=[ "msrest>=0.7.1", - "azure-core<2.0.0,>=1.29.5", + "azure-core<2.0.0,>=1.30.0", ], long_description="""\ Testing non-string enums. diff --git a/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/ObjectType/setup.py b/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/ObjectType/setup.py index cc098047670..9db876b5dd3 100644 --- a/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/ObjectType/setup.py +++ b/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/ObjectType/setup.py @@ -22,7 +22,7 @@ include_package_data=True, install_requires=[ "msrest>=0.7.1", - "azure-core<2.0.0,>=1.29.5", + "azure-core<2.0.0,>=1.30.0", ], long_description="""\ Service client for testing basic type: object swaggers. diff --git a/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/PackageModeDataPlane/setup.py b/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/PackageModeDataPlane/setup.py index becff6caab9..d55246aabe6 100644 --- a/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/PackageModeDataPlane/setup.py +++ b/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/PackageModeDataPlane/setup.py @@ -61,7 +61,7 @@ }, install_requires=[ "msrest>=0.7.1", - "azure-core<2.0.0,>=1.29.5", + "azure-core<2.0.0,>=1.30.0", ], python_requires=">=3.8", ) diff --git a/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/ParameterFlattening/setup.py b/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/ParameterFlattening/setup.py index f9b025130c6..7bc328ce34f 100644 --- a/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/ParameterFlattening/setup.py +++ b/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/ParameterFlattening/setup.py @@ -22,7 +22,7 @@ include_package_data=True, install_requires=[ "msrest>=0.7.1", - "azure-core<2.0.0,>=1.29.5", + "azure-core<2.0.0,>=1.30.0", ], long_description="""\ Resource Flattening for AutoRest. diff --git a/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/ParameterizedEndpoint/setup.py b/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/ParameterizedEndpoint/setup.py index aa7a3bca685..695cb5bb948 100644 --- a/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/ParameterizedEndpoint/setup.py +++ b/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/ParameterizedEndpoint/setup.py @@ -22,7 +22,7 @@ include_package_data=True, install_requires=[ "msrest>=0.7.1", - "azure-core<2.0.0,>=1.29.5", + "azure-core<2.0.0,>=1.30.0", ], long_description="""\ Service client for testing parameterized hosts with the name 'endpoint'. diff --git a/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/Report/setup.py b/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/Report/setup.py index 7a85c2895fe..b5efbe30560 100644 --- a/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/Report/setup.py +++ b/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/Report/setup.py @@ -22,7 +22,7 @@ include_package_data=True, install_requires=[ "msrest>=0.7.1", - "azure-core<2.0.0,>=1.29.5", + "azure-core<2.0.0,>=1.30.0", ], long_description="""\ Test Infrastructure for AutoRest. diff --git a/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/RequiredOptional/setup.py b/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/RequiredOptional/setup.py index c7bcdef0bc5..4abde23ebb0 100644 --- a/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/RequiredOptional/setup.py +++ b/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/RequiredOptional/setup.py @@ -22,7 +22,7 @@ include_package_data=True, install_requires=[ "msrest>=0.7.1", - "azure-core<2.0.0,>=1.29.5", + "azure-core<2.0.0,>=1.30.0", ], long_description="""\ Test Infrastructure for AutoRest. diff --git a/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/ReservedWords/setup.py b/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/ReservedWords/setup.py index a51581fdb8e..c20752ea129 100644 --- a/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/ReservedWords/setup.py +++ b/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/ReservedWords/setup.py @@ -22,7 +22,7 @@ include_package_data=True, install_requires=[ "msrest>=0.7.1", - "azure-core<2.0.0,>=1.29.5", + "azure-core<2.0.0,>=1.30.0", ], long_description="""\ Swagger that has operation groups etc. with reserved words. diff --git a/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/SecurityAadSwagger/setup.py b/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/SecurityAadSwagger/setup.py index 41408073774..e7b987a0586 100644 --- a/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/SecurityAadSwagger/setup.py +++ b/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/SecurityAadSwagger/setup.py @@ -22,7 +22,7 @@ include_package_data=True, install_requires=[ "msrest>=0.7.1", - "azure-core<2.0.0,>=1.29.5", + "azure-core<2.0.0,>=1.30.0", ], long_description="""\ Autorest Security Aad REST APIs. diff --git a/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/SecurityAadSwaggerCredentialFlag/setup.py b/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/SecurityAadSwaggerCredentialFlag/setup.py index df441ff6088..02b97949e73 100644 --- a/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/SecurityAadSwaggerCredentialFlag/setup.py +++ b/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/SecurityAadSwaggerCredentialFlag/setup.py @@ -22,7 +22,7 @@ include_package_data=True, install_requires=[ "msrest>=0.7.1", - "azure-core<2.0.0,>=1.29.5", + "azure-core<2.0.0,>=1.30.0", ], long_description="""\ Autorest Security Aad REST APIs. diff --git a/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/SecurityKeySwagger/setup.py b/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/SecurityKeySwagger/setup.py index f164fe542e3..590a992509a 100644 --- a/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/SecurityKeySwagger/setup.py +++ b/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/SecurityKeySwagger/setup.py @@ -22,7 +22,7 @@ include_package_data=True, install_requires=[ "msrest>=0.7.1", - "azure-core<2.0.0,>=1.29.5", + "azure-core<2.0.0,>=1.30.0", ], long_description="""\ Autorest Security Key REST APIs. diff --git a/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/SecurityKeySwaggerCredentialFlag/setup.py b/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/SecurityKeySwaggerCredentialFlag/setup.py index 78924a40995..5df61c2a157 100644 --- a/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/SecurityKeySwaggerCredentialFlag/setup.py +++ b/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/SecurityKeySwaggerCredentialFlag/setup.py @@ -22,7 +22,7 @@ include_package_data=True, install_requires=[ "msrest>=0.7.1", - "azure-core<2.0.0,>=1.29.5", + "azure-core<2.0.0,>=1.30.0", ], long_description="""\ Autorest Security Key REST APIs. diff --git a/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/Url/setup.py b/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/Url/setup.py index c617f5ce9bf..d131dc1557e 100644 --- a/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/Url/setup.py +++ b/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/Url/setup.py @@ -22,7 +22,7 @@ include_package_data=True, install_requires=[ "msrest>=0.7.1", - "azure-core<2.0.0,>=1.29.5", + "azure-core<2.0.0,>=1.30.0", ], long_description="""\ Test Infrastructure for AutoRest. diff --git a/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/UrlMultiCollectionFormat/setup.py b/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/UrlMultiCollectionFormat/setup.py index 57483dd12cd..0f9473614cc 100644 --- a/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/UrlMultiCollectionFormat/setup.py +++ b/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/UrlMultiCollectionFormat/setup.py @@ -22,7 +22,7 @@ include_package_data=True, install_requires=[ "msrest>=0.7.1", - "azure-core<2.0.0,>=1.29.5", + "azure-core<2.0.0,>=1.30.0", ], long_description="""\ Test Infrastructure for AutoRest. diff --git a/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/Validation/setup.py b/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/Validation/setup.py index 54145acf059..4869cb99904 100644 --- a/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/Validation/setup.py +++ b/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/Validation/setup.py @@ -22,7 +22,7 @@ include_package_data=True, install_requires=[ "msrest>=0.7.1", - "azure-core<2.0.0,>=1.29.5", + "azure-core<2.0.0,>=1.30.0", ], long_description="""\ Test Infrastructure for AutoRest. No server backend exists for these tests. diff --git a/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/Xml/setup.py b/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/Xml/setup.py index ff1b19dbdd8..9a00c864d19 100644 --- a/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/Xml/setup.py +++ b/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/Xml/setup.py @@ -22,7 +22,7 @@ include_package_data=True, install_requires=[ "msrest>=0.7.1", - "azure-core<2.0.0,>=1.29.5", + "azure-core<2.0.0,>=1.30.0", ], long_description="""\ Test Infrastructure for AutoRest Swagger BAT. diff --git a/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/XmsErrorResponse/setup.py b/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/XmsErrorResponse/setup.py index de4b31df8d1..1c215a9f33c 100644 --- a/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/XmsErrorResponse/setup.py +++ b/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/XmsErrorResponse/setup.py @@ -22,7 +22,7 @@ include_package_data=True, install_requires=[ "msrest>=0.7.1", - "azure-core<2.0.0,>=1.29.5", + "azure-core<2.0.0,>=1.30.0", ], long_description="""\ XMS Error Response Extensions. diff --git a/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/AdditionalPropertiesVersionTolerant/setup.py b/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/AdditionalPropertiesVersionTolerant/setup.py index a5eb1027088..101e3b7367f 100644 --- a/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/AdditionalPropertiesVersionTolerant/setup.py +++ b/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/AdditionalPropertiesVersionTolerant/setup.py @@ -22,7 +22,7 @@ include_package_data=True, install_requires=[ "isodate<1.0.0,>=0.6.1", - "azure-core<2.0.0,>=1.29.5", + "azure-core<2.0.0,>=1.30.0", ], long_description="""\ Test Infrastructure for AutoRest. diff --git a/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/AnythingVersionTolerant/setup.py b/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/AnythingVersionTolerant/setup.py index beedb5a462d..dce65dc6dfb 100644 --- a/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/AnythingVersionTolerant/setup.py +++ b/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/AnythingVersionTolerant/setup.py @@ -22,7 +22,7 @@ include_package_data=True, install_requires=[ "isodate<1.0.0,>=0.6.1", - "azure-core<2.0.0,>=1.29.5", + "azure-core<2.0.0,>=1.30.0", ], long_description="""\ Service client for testing basic anything types. Those schemas without types can be anything: primitive, object, array. diff --git a/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/BodyArrayVersionTolerant/setup.py b/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/BodyArrayVersionTolerant/setup.py index 315368006de..f336cd3fe38 100644 --- a/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/BodyArrayVersionTolerant/setup.py +++ b/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/BodyArrayVersionTolerant/setup.py @@ -22,7 +22,7 @@ include_package_data=True, install_requires=[ "isodate<1.0.0,>=0.6.1", - "azure-core<2.0.0,>=1.29.5", + "azure-core<2.0.0,>=1.30.0", ], long_description="""\ Test Infrastructure for AutoRest Swagger BAT. diff --git a/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/BodyBinaryVersionTolerant/setup.py b/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/BodyBinaryVersionTolerant/setup.py index 4e1ff60383e..d61df69f99d 100644 --- a/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/BodyBinaryVersionTolerant/setup.py +++ b/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/BodyBinaryVersionTolerant/setup.py @@ -22,7 +22,7 @@ include_package_data=True, install_requires=[ "isodate<1.0.0,>=0.6.1", - "azure-core<2.0.0,>=1.29.5", + "azure-core<2.0.0,>=1.30.0", ], long_description="""\ Sample for file with json and binary content type. diff --git a/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/BodyBooleanVersionTolerant/setup.py b/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/BodyBooleanVersionTolerant/setup.py index d111f1b082f..88d402e13f0 100644 --- a/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/BodyBooleanVersionTolerant/setup.py +++ b/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/BodyBooleanVersionTolerant/setup.py @@ -22,7 +22,7 @@ include_package_data=True, install_requires=[ "isodate<1.0.0,>=0.6.1", - "azure-core<2.0.0,>=1.29.5", + "azure-core<2.0.0,>=1.30.0", ], long_description="""\ Test Infrastructure for AutoRest. diff --git a/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/BodyByteVersionTolerant/setup.py b/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/BodyByteVersionTolerant/setup.py index 28e8ce29449..f80801c0a2a 100644 --- a/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/BodyByteVersionTolerant/setup.py +++ b/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/BodyByteVersionTolerant/setup.py @@ -22,7 +22,7 @@ include_package_data=True, install_requires=[ "isodate<1.0.0,>=0.6.1", - "azure-core<2.0.0,>=1.29.5", + "azure-core<2.0.0,>=1.30.0", ], long_description="""\ Test Infrastructure for AutoRest Swagger BAT. diff --git a/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/BodyComplexVersionTolerant/setup.py b/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/BodyComplexVersionTolerant/setup.py index 422907b9eeb..801519ad27f 100644 --- a/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/BodyComplexVersionTolerant/setup.py +++ b/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/BodyComplexVersionTolerant/setup.py @@ -22,7 +22,7 @@ include_package_data=True, install_requires=[ "isodate<1.0.0,>=0.6.1", - "azure-core<2.0.0,>=1.29.5", + "azure-core<2.0.0,>=1.30.0", ], long_description="""\ Test Infrastructure for AutoRest. diff --git a/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/BodyDateTimeRfc1123VersionTolerant/setup.py b/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/BodyDateTimeRfc1123VersionTolerant/setup.py index dc65c0eda03..504e9ab2fff 100644 --- a/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/BodyDateTimeRfc1123VersionTolerant/setup.py +++ b/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/BodyDateTimeRfc1123VersionTolerant/setup.py @@ -22,7 +22,7 @@ include_package_data=True, install_requires=[ "isodate<1.0.0,>=0.6.1", - "azure-core<2.0.0,>=1.29.5", + "azure-core<2.0.0,>=1.30.0", ], long_description="""\ Test Infrastructure for AutoRest. diff --git a/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/BodyDateTimeVersionTolerant/setup.py b/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/BodyDateTimeVersionTolerant/setup.py index fcae179ac16..6445f2e9b41 100644 --- a/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/BodyDateTimeVersionTolerant/setup.py +++ b/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/BodyDateTimeVersionTolerant/setup.py @@ -22,7 +22,7 @@ include_package_data=True, install_requires=[ "isodate<1.0.0,>=0.6.1", - "azure-core<2.0.0,>=1.29.5", + "azure-core<2.0.0,>=1.30.0", ], long_description="""\ Test Infrastructure for AutoRest. diff --git a/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/BodyDateVersionTolerant/setup.py b/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/BodyDateVersionTolerant/setup.py index f1ac4d17a14..7343fac7774 100644 --- a/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/BodyDateVersionTolerant/setup.py +++ b/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/BodyDateVersionTolerant/setup.py @@ -22,7 +22,7 @@ include_package_data=True, install_requires=[ "isodate<1.0.0,>=0.6.1", - "azure-core<2.0.0,>=1.29.5", + "azure-core<2.0.0,>=1.30.0", ], long_description="""\ Test Infrastructure for AutoRest. diff --git a/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/BodyDictionaryVersionTolerant/setup.py b/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/BodyDictionaryVersionTolerant/setup.py index b9ae3e07c49..07c609bca35 100644 --- a/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/BodyDictionaryVersionTolerant/setup.py +++ b/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/BodyDictionaryVersionTolerant/setup.py @@ -22,7 +22,7 @@ include_package_data=True, install_requires=[ "isodate<1.0.0,>=0.6.1", - "azure-core<2.0.0,>=1.29.5", + "azure-core<2.0.0,>=1.30.0", ], long_description="""\ Test Infrastructure for AutoRest Swagger BAT. diff --git a/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/BodyDurationVersionTolerant/setup.py b/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/BodyDurationVersionTolerant/setup.py index 7b248bcf505..8e07e8b6f89 100644 --- a/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/BodyDurationVersionTolerant/setup.py +++ b/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/BodyDurationVersionTolerant/setup.py @@ -22,7 +22,7 @@ include_package_data=True, install_requires=[ "isodate<1.0.0,>=0.6.1", - "azure-core<2.0.0,>=1.29.5", + "azure-core<2.0.0,>=1.30.0", ], long_description="""\ Test Infrastructure for AutoRest. diff --git a/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/BodyFileVersionTolerant/setup.py b/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/BodyFileVersionTolerant/setup.py index dcfc709d9e6..f7073846fe3 100644 --- a/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/BodyFileVersionTolerant/setup.py +++ b/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/BodyFileVersionTolerant/setup.py @@ -22,7 +22,7 @@ include_package_data=True, install_requires=[ "isodate<1.0.0,>=0.6.1", - "azure-core<2.0.0,>=1.29.5", + "azure-core<2.0.0,>=1.30.0", ], long_description="""\ Test Infrastructure for AutoRest Swagger BAT. diff --git a/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/BodyFormDataVersionTolerant/setup.py b/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/BodyFormDataVersionTolerant/setup.py index c48e418e684..84923c12df5 100644 --- a/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/BodyFormDataVersionTolerant/setup.py +++ b/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/BodyFormDataVersionTolerant/setup.py @@ -22,7 +22,7 @@ include_package_data=True, install_requires=[ "isodate<1.0.0,>=0.6.1", - "azure-core<2.0.0,>=1.29.5", + "azure-core<2.0.0,>=1.30.0", ], long_description="""\ Test Infrastructure for AutoRest Swagger BAT. diff --git a/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/BodyFormUrlEncodedDataVersionTolerant/setup.py b/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/BodyFormUrlEncodedDataVersionTolerant/setup.py index 8106092863d..29d92ee727e 100644 --- a/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/BodyFormUrlEncodedDataVersionTolerant/setup.py +++ b/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/BodyFormUrlEncodedDataVersionTolerant/setup.py @@ -22,7 +22,7 @@ include_package_data=True, install_requires=[ "isodate<1.0.0,>=0.6.1", - "azure-core<2.0.0,>=1.29.5", + "azure-core<2.0.0,>=1.30.0", ], long_description="""\ Test Infrastructure for AutoRest Swagger BAT. diff --git a/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/BodyIntegerVersionTolerant/setup.py b/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/BodyIntegerVersionTolerant/setup.py index 6bcd4757f95..4c05228dec6 100644 --- a/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/BodyIntegerVersionTolerant/setup.py +++ b/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/BodyIntegerVersionTolerant/setup.py @@ -22,7 +22,7 @@ include_package_data=True, install_requires=[ "isodate<1.0.0,>=0.6.1", - "azure-core<2.0.0,>=1.29.5", + "azure-core<2.0.0,>=1.30.0", ], long_description="""\ Test Infrastructure for AutoRest. diff --git a/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/BodyNumberVersionTolerant/setup.py b/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/BodyNumberVersionTolerant/setup.py index 64561030d8a..26cd40c3250 100644 --- a/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/BodyNumberVersionTolerant/setup.py +++ b/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/BodyNumberVersionTolerant/setup.py @@ -22,7 +22,7 @@ include_package_data=True, install_requires=[ "isodate<1.0.0,>=0.6.1", - "azure-core<2.0.0,>=1.29.5", + "azure-core<2.0.0,>=1.30.0", ], long_description="""\ Test Infrastructure for AutoRest. diff --git a/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/BodyStringVersionTolerant/setup.py b/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/BodyStringVersionTolerant/setup.py index 74478187cfd..71d0690f8d9 100644 --- a/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/BodyStringVersionTolerant/setup.py +++ b/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/BodyStringVersionTolerant/setup.py @@ -22,7 +22,7 @@ include_package_data=True, install_requires=[ "isodate<1.0.0,>=0.6.1", - "azure-core<2.0.0,>=1.29.5", + "azure-core<2.0.0,>=1.30.0", ], long_description="""\ Test Infrastructure for AutoRest Swagger BAT. diff --git a/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/BodyTimeVersionTolerant/setup.py b/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/BodyTimeVersionTolerant/setup.py index b2e85e95279..b58483da2f9 100644 --- a/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/BodyTimeVersionTolerant/setup.py +++ b/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/BodyTimeVersionTolerant/setup.py @@ -22,7 +22,7 @@ include_package_data=True, install_requires=[ "isodate<1.0.0,>=0.6.1", - "azure-core<2.0.0,>=1.29.5", + "azure-core<2.0.0,>=1.30.0", ], long_description="""\ Test Infrastructure for AutoRest. diff --git a/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/ClientEnumVersionTolerant/setup.py b/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/ClientEnumVersionTolerant/setup.py index b9ff7912323..f266208fccf 100644 --- a/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/ClientEnumVersionTolerant/setup.py +++ b/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/ClientEnumVersionTolerant/setup.py @@ -22,7 +22,7 @@ include_package_data=True, install_requires=[ "isodate<1.0.0,>=0.6.1", - "azure-core<2.0.0,>=1.29.5", + "azure-core<2.0.0,>=1.30.0", ], long_description="""\ Test client with enum variable. diff --git a/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/ConstantsVersionTolerant/setup.py b/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/ConstantsVersionTolerant/setup.py index 41dbf202ca8..85cdebd6bd2 100644 --- a/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/ConstantsVersionTolerant/setup.py +++ b/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/ConstantsVersionTolerant/setup.py @@ -22,7 +22,7 @@ include_package_data=True, install_requires=[ "isodate<1.0.0,>=0.6.1", - "azure-core<2.0.0,>=1.29.5", + "azure-core<2.0.0,>=1.30.0", ], long_description="""\ Test Infrastructure for AutoRest Swagger Constant. diff --git a/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/CustomBaseUriMoreOptionsVersionTolerant/setup.py b/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/CustomBaseUriMoreOptionsVersionTolerant/setup.py index 6e80816a985..19e0beffee7 100644 --- a/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/CustomBaseUriMoreOptionsVersionTolerant/setup.py +++ b/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/CustomBaseUriMoreOptionsVersionTolerant/setup.py @@ -22,7 +22,7 @@ include_package_data=True, install_requires=[ "isodate<1.0.0,>=0.6.1", - "azure-core<2.0.0,>=1.29.5", + "azure-core<2.0.0,>=1.30.0", ], long_description="""\ Test Infrastructure for AutoRest. diff --git a/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/CustomBaseUriVersionTolerant/setup.py b/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/CustomBaseUriVersionTolerant/setup.py index 434b61fb4f3..7a2aed8d1bb 100644 --- a/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/CustomBaseUriVersionTolerant/setup.py +++ b/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/CustomBaseUriVersionTolerant/setup.py @@ -22,7 +22,7 @@ include_package_data=True, install_requires=[ "isodate<1.0.0,>=0.6.1", - "azure-core<2.0.0,>=1.29.5", + "azure-core<2.0.0,>=1.30.0", ], long_description="""\ Test Infrastructure for AutoRest. diff --git a/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/ErrorWithSecretsVersionTolerant/setup.py b/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/ErrorWithSecretsVersionTolerant/setup.py index ff022c907d0..4310d51c208 100644 --- a/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/ErrorWithSecretsVersionTolerant/setup.py +++ b/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/ErrorWithSecretsVersionTolerant/setup.py @@ -22,7 +22,7 @@ include_package_data=True, install_requires=[ "isodate<1.0.0,>=0.6.1", - "azure-core<2.0.0,>=1.29.5", + "azure-core<2.0.0,>=1.30.0", ], long_description="""\ Tests whether loggers/tracers redact secrets and PII within error responses. diff --git a/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/ExtensibleEnumsVersionTolerant/setup.py b/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/ExtensibleEnumsVersionTolerant/setup.py index 8d5918da555..bd129dce429 100644 --- a/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/ExtensibleEnumsVersionTolerant/setup.py +++ b/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/ExtensibleEnumsVersionTolerant/setup.py @@ -22,7 +22,7 @@ include_package_data=True, install_requires=[ "isodate<1.0.0,>=0.6.1", - "azure-core<2.0.0,>=1.29.5", + "azure-core<2.0.0,>=1.30.0", ], long_description="""\ PetStore. diff --git a/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/HeaderVersionTolerant/setup.py b/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/HeaderVersionTolerant/setup.py index d2153a07e7e..f17dc4e9852 100644 --- a/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/HeaderVersionTolerant/setup.py +++ b/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/HeaderVersionTolerant/setup.py @@ -22,7 +22,7 @@ include_package_data=True, install_requires=[ "isodate<1.0.0,>=0.6.1", - "azure-core<2.0.0,>=1.29.5", + "azure-core<2.0.0,>=1.30.0", ], long_description="""\ Test Infrastructure for AutoRest. diff --git a/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/HttpVersionTolerant/setup.py b/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/HttpVersionTolerant/setup.py index 25a49df7a05..3bc74c75740 100644 --- a/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/HttpVersionTolerant/setup.py +++ b/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/HttpVersionTolerant/setup.py @@ -22,7 +22,7 @@ include_package_data=True, install_requires=[ "isodate<1.0.0,>=0.6.1", - "azure-core<2.0.0,>=1.29.5", + "azure-core<2.0.0,>=1.30.0", ], long_description="""\ Test Infrastructure for AutoRest. diff --git a/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/IncorrectErrorResponseVersionTolerant/setup.py b/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/IncorrectErrorResponseVersionTolerant/setup.py index 79cdcb99c7c..63cc8cf2a9c 100644 --- a/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/IncorrectErrorResponseVersionTolerant/setup.py +++ b/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/IncorrectErrorResponseVersionTolerant/setup.py @@ -22,7 +22,7 @@ include_package_data=True, install_requires=[ "isodate<1.0.0,>=0.6.1", - "azure-core<2.0.0,>=1.29.5", + "azure-core<2.0.0,>=1.30.0", ], long_description="""\ Test to see when throwing an HttpResponseError whether we swallow error model deserialization errors. diff --git a/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/MediaTypesVersionTolerant/setup.py b/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/MediaTypesVersionTolerant/setup.py index f2526daaea9..84edd82c368 100644 --- a/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/MediaTypesVersionTolerant/setup.py +++ b/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/MediaTypesVersionTolerant/setup.py @@ -22,7 +22,7 @@ include_package_data=True, install_requires=[ "isodate<1.0.0,>=0.6.1", - "azure-core<2.0.0,>=1.29.5", + "azure-core<2.0.0,>=1.30.0", ], long_description="""\ Play with produces/consumes and media-types in general. diff --git a/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/MergePatchJsonVersionTolerant/setup.py b/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/MergePatchJsonVersionTolerant/setup.py index 775b090c087..a5848f66bf7 100644 --- a/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/MergePatchJsonVersionTolerant/setup.py +++ b/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/MergePatchJsonVersionTolerant/setup.py @@ -22,7 +22,7 @@ include_package_data=True, install_requires=[ "isodate<1.0.0,>=0.6.1", - "azure-core<2.0.0,>=1.29.5", + "azure-core<2.0.0,>=1.30.0", ], long_description="""\ Service client for testing merge patch json. diff --git a/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/ModelFlatteningVersionTolerant/setup.py b/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/ModelFlatteningVersionTolerant/setup.py index fd563351129..6713d0bcfc2 100644 --- a/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/ModelFlatteningVersionTolerant/setup.py +++ b/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/ModelFlatteningVersionTolerant/setup.py @@ -22,7 +22,7 @@ include_package_data=True, install_requires=[ "isodate<1.0.0,>=0.6.1", - "azure-core<2.0.0,>=1.29.5", + "azure-core<2.0.0,>=1.30.0", ], long_description="""\ Resource Flattening for AutoRest. diff --git a/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/MultipleInheritanceVersionTolerant/setup.py b/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/MultipleInheritanceVersionTolerant/setup.py index 728a0b3caf3..e7e456a65dc 100644 --- a/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/MultipleInheritanceVersionTolerant/setup.py +++ b/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/MultipleInheritanceVersionTolerant/setup.py @@ -22,7 +22,7 @@ include_package_data=True, install_requires=[ "isodate<1.0.0,>=0.6.1", - "azure-core<2.0.0,>=1.29.5", + "azure-core<2.0.0,>=1.30.0", ], long_description="""\ Service client for multiinheritance client testing. diff --git a/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/NoNamespaceFlagVersionTolerant/setup.py b/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/NoNamespaceFlagVersionTolerant/setup.py index 038be4b34b5..e7ca43d7778 100644 --- a/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/NoNamespaceFlagVersionTolerant/setup.py +++ b/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/NoNamespaceFlagVersionTolerant/setup.py @@ -22,7 +22,7 @@ include_package_data=True, install_requires=[ "isodate<1.0.0,>=0.6.1", - "azure-core<2.0.0,>=1.29.5", + "azure-core<2.0.0,>=1.30.0", ], long_description="""\ Service client for testing basic anything types. Those schemas without types can be anything: primitive, object, array. diff --git a/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/NoOperationsVersionTolerant/setup.py b/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/NoOperationsVersionTolerant/setup.py index bb52c0ec1a4..dc0f666b4c3 100644 --- a/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/NoOperationsVersionTolerant/setup.py +++ b/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/NoOperationsVersionTolerant/setup.py @@ -22,7 +22,7 @@ include_package_data=True, install_requires=[ "isodate<1.0.0,>=0.6.1", - "azure-core<2.0.0,>=1.29.5", + "azure-core<2.0.0,>=1.30.0", ], long_description="""\ Service client with no operations. diff --git a/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/NonStringEnumsVersionTolerant/setup.py b/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/NonStringEnumsVersionTolerant/setup.py index 784797c7ec4..9ef2174b840 100644 --- a/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/NonStringEnumsVersionTolerant/setup.py +++ b/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/NonStringEnumsVersionTolerant/setup.py @@ -22,7 +22,7 @@ include_package_data=True, install_requires=[ "isodate<1.0.0,>=0.6.1", - "azure-core<2.0.0,>=1.29.5", + "azure-core<2.0.0,>=1.30.0", ], long_description="""\ Testing non-string enums. diff --git a/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/ObjectTypeVersionTolerant/setup.py b/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/ObjectTypeVersionTolerant/setup.py index 80cfada62da..686d0949d38 100644 --- a/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/ObjectTypeVersionTolerant/setup.py +++ b/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/ObjectTypeVersionTolerant/setup.py @@ -22,7 +22,7 @@ include_package_data=True, install_requires=[ "isodate<1.0.0,>=0.6.1", - "azure-core<2.0.0,>=1.29.5", + "azure-core<2.0.0,>=1.30.0", ], long_description="""\ Service client for testing basic type: object swaggers. diff --git a/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/ParameterFlatteningVersionTolerant/setup.py b/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/ParameterFlatteningVersionTolerant/setup.py index 0e6e7873a48..16b702d513c 100644 --- a/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/ParameterFlatteningVersionTolerant/setup.py +++ b/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/ParameterFlatteningVersionTolerant/setup.py @@ -22,7 +22,7 @@ include_package_data=True, install_requires=[ "isodate<1.0.0,>=0.6.1", - "azure-core<2.0.0,>=1.29.5", + "azure-core<2.0.0,>=1.30.0", ], long_description="""\ Resource Flattening for AutoRest. diff --git a/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/ParameterizedEndpointVersionTolerant/setup.py b/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/ParameterizedEndpointVersionTolerant/setup.py index bae3d7e0da1..c81470bc16a 100644 --- a/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/ParameterizedEndpointVersionTolerant/setup.py +++ b/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/ParameterizedEndpointVersionTolerant/setup.py @@ -22,7 +22,7 @@ include_package_data=True, install_requires=[ "isodate<1.0.0,>=0.6.1", - "azure-core<2.0.0,>=1.29.5", + "azure-core<2.0.0,>=1.30.0", ], long_description="""\ Service client for testing parameterized hosts with the name 'endpoint'. diff --git a/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/ReportVersionTolerant/setup.py b/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/ReportVersionTolerant/setup.py index 1fc99018e70..656d64f54fe 100644 --- a/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/ReportVersionTolerant/setup.py +++ b/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/ReportVersionTolerant/setup.py @@ -22,7 +22,7 @@ include_package_data=True, install_requires=[ "isodate<1.0.0,>=0.6.1", - "azure-core<2.0.0,>=1.29.5", + "azure-core<2.0.0,>=1.30.0", ], long_description="""\ Test Infrastructure for AutoRest. diff --git a/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/RequiredOptionalVersionTolerant/setup.py b/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/RequiredOptionalVersionTolerant/setup.py index ef55a6372a6..be08bd5a9d5 100644 --- a/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/RequiredOptionalVersionTolerant/setup.py +++ b/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/RequiredOptionalVersionTolerant/setup.py @@ -22,7 +22,7 @@ include_package_data=True, install_requires=[ "isodate<1.0.0,>=0.6.1", - "azure-core<2.0.0,>=1.29.5", + "azure-core<2.0.0,>=1.30.0", ], long_description="""\ Test Infrastructure for AutoRest. diff --git a/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/ReservedWordsVersionTolerant/setup.py b/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/ReservedWordsVersionTolerant/setup.py index 6fbe015e4d8..23aa82878c5 100644 --- a/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/ReservedWordsVersionTolerant/setup.py +++ b/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/ReservedWordsVersionTolerant/setup.py @@ -22,7 +22,7 @@ include_package_data=True, install_requires=[ "isodate<1.0.0,>=0.6.1", - "azure-core<2.0.0,>=1.29.5", + "azure-core<2.0.0,>=1.30.0", ], long_description="""\ Swagger that has operation groups etc. with reserved words. diff --git a/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/SecurityAadSwaggerVersionTolerant/setup.py b/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/SecurityAadSwaggerVersionTolerant/setup.py index 350540b587a..59f7066ae2f 100644 --- a/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/SecurityAadSwaggerVersionTolerant/setup.py +++ b/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/SecurityAadSwaggerVersionTolerant/setup.py @@ -22,7 +22,7 @@ include_package_data=True, install_requires=[ "isodate<1.0.0,>=0.6.1", - "azure-core<2.0.0,>=1.29.5", + "azure-core<2.0.0,>=1.30.0", ], long_description="""\ Autorest Security Aad REST APIs. diff --git a/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/SecurityKeySwaggerVersionTolerant/setup.py b/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/SecurityKeySwaggerVersionTolerant/setup.py index bd1b2e7efc2..6783233302a 100644 --- a/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/SecurityKeySwaggerVersionTolerant/setup.py +++ b/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/SecurityKeySwaggerVersionTolerant/setup.py @@ -22,7 +22,7 @@ include_package_data=True, install_requires=[ "isodate<1.0.0,>=0.6.1", - "azure-core<2.0.0,>=1.29.5", + "azure-core<2.0.0,>=1.30.0", ], long_description="""\ Autorest Security Key REST APIs. diff --git a/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/UrlMultiCollectionFormatVersionTolerant/setup.py b/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/UrlMultiCollectionFormatVersionTolerant/setup.py index 5a22e5e79a1..ece1eeeb748 100644 --- a/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/UrlMultiCollectionFormatVersionTolerant/setup.py +++ b/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/UrlMultiCollectionFormatVersionTolerant/setup.py @@ -22,7 +22,7 @@ include_package_data=True, install_requires=[ "isodate<1.0.0,>=0.6.1", - "azure-core<2.0.0,>=1.29.5", + "azure-core<2.0.0,>=1.30.0", ], long_description="""\ Test Infrastructure for AutoRest. diff --git a/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/UrlVersionTolerant/setup.py b/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/UrlVersionTolerant/setup.py index fdff4a2ecfc..e590c843ad6 100644 --- a/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/UrlVersionTolerant/setup.py +++ b/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/UrlVersionTolerant/setup.py @@ -22,7 +22,7 @@ include_package_data=True, install_requires=[ "isodate<1.0.0,>=0.6.1", - "azure-core<2.0.0,>=1.29.5", + "azure-core<2.0.0,>=1.30.0", ], long_description="""\ Test Infrastructure for AutoRest. diff --git a/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/ValidationVersionTolerant/setup.py b/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/ValidationVersionTolerant/setup.py index 8e268089f38..6a615eadb67 100644 --- a/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/ValidationVersionTolerant/setup.py +++ b/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/ValidationVersionTolerant/setup.py @@ -22,7 +22,7 @@ include_package_data=True, install_requires=[ "isodate<1.0.0,>=0.6.1", - "azure-core<2.0.0,>=1.29.5", + "azure-core<2.0.0,>=1.30.0", ], long_description="""\ Test Infrastructure for AutoRest. No server backend exists for these tests. diff --git a/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/XmlVersionTolerant/setup.py b/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/XmlVersionTolerant/setup.py index 75e53b25e68..63b2722bfe2 100644 --- a/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/XmlVersionTolerant/setup.py +++ b/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/XmlVersionTolerant/setup.py @@ -22,7 +22,7 @@ include_package_data=True, install_requires=[ "isodate<1.0.0,>=0.6.1", - "azure-core<2.0.0,>=1.29.5", + "azure-core<2.0.0,>=1.30.0", ], long_description="""\ Test Infrastructure for AutoRest Swagger BAT. diff --git a/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/XmsErrorResponseVersionTolerant/setup.py b/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/XmsErrorResponseVersionTolerant/setup.py index 2a7cd088688..b8df4b8efae 100644 --- a/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/XmsErrorResponseVersionTolerant/setup.py +++ b/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/XmsErrorResponseVersionTolerant/setup.py @@ -22,7 +22,7 @@ include_package_data=True, install_requires=[ "isodate<1.0.0,>=0.6.1", - "azure-core<2.0.0,>=1.29.5", + "azure-core<2.0.0,>=1.30.0", ], long_description="""\ XMS Error Response Extensions. diff --git a/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/aio/operations/_operations.py b/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/aio/operations/_operations.py index 8c2d7bdd60c..43034324490 100644 --- a/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/aio/operations/_operations.py +++ b/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/aio/operations/_operations.py @@ -24,6 +24,7 @@ from ... import _model_base, models as _models from ..._model_base import SdkJSONEncoder +from ..._vendor import FilesType from ...operations._operations import ( build_form_data_basic_request, build_form_data_binary_array_parts_request, diff --git a/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/models/_models.py b/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/models/_models.py index 8707ee48d4f..f16ff0f0dc3 100644 --- a/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/models/_models.py +++ b/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/models/_models.py @@ -7,11 +7,11 @@ # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from typing import Any, Dict, List, Mapping, Optional, TYPE_CHECKING, overload +from typing import Any, List, Mapping, Optional, TYPE_CHECKING, overload from .. import _model_base from .._model_base import rest_field -from .._vendor import FileType, FilesType +from .._vendor import FileType if TYPE_CHECKING: # pylint: disable=unused-import,ungrouped-imports diff --git a/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/operations/_operations.py b/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/operations/_operations.py index ef2bc37e9c7..cb2dc7df0a0 100644 --- a/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/operations/_operations.py +++ b/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/operations/_operations.py @@ -26,6 +26,7 @@ from .. import _model_base, models as _models from .._model_base import SdkJSONEncoder from .._serialization import Serializer +from .._vendor import FilesType if sys.version_info >= (3, 9): from collections.abc import MutableMapping diff --git a/packages/typespec-python/test/unbranded/generated/authentication-api-key/setup.py b/packages/typespec-python/test/unbranded/generated/authentication-api-key/setup.py index 8dbab9e89fd..dea99122204 100644 --- a/packages/typespec-python/test/unbranded/generated/authentication-api-key/setup.py +++ b/packages/typespec-python/test/unbranded/generated/authentication-api-key/setup.py @@ -60,7 +60,7 @@ }, install_requires=[ "isodate<1.0.0,>=0.6.1", - "corehttp[requests]", + "corehttp[requests]<1.0.0,>=1.0.0b3", ], python_requires=">=3.8", ) diff --git a/packages/typespec-python/test/unbranded/generated/authentication-http-custom/setup.py b/packages/typespec-python/test/unbranded/generated/authentication-http-custom/setup.py index cc335efcf91..53ad28dc0c6 100644 --- a/packages/typespec-python/test/unbranded/generated/authentication-http-custom/setup.py +++ b/packages/typespec-python/test/unbranded/generated/authentication-http-custom/setup.py @@ -61,7 +61,7 @@ }, install_requires=[ "isodate<1.0.0,>=0.6.1", - "corehttp[requests]", + "corehttp[requests]<1.0.0,>=1.0.0b3", ], python_requires=">=3.8", ) diff --git a/packages/typespec-python/test/unbranded/generated/authentication-oauth2/setup.py b/packages/typespec-python/test/unbranded/generated/authentication-oauth2/setup.py index dfc2f2272b2..8a90119cd9a 100644 --- a/packages/typespec-python/test/unbranded/generated/authentication-oauth2/setup.py +++ b/packages/typespec-python/test/unbranded/generated/authentication-oauth2/setup.py @@ -60,7 +60,7 @@ }, install_requires=[ "isodate<1.0.0,>=0.6.1", - "corehttp[requests]", + "corehttp[requests]<1.0.0,>=1.0.0b3", ], python_requires=">=3.8", ) diff --git a/packages/typespec-python/test/unbranded/generated/authentication-union/setup.py b/packages/typespec-python/test/unbranded/generated/authentication-union/setup.py index a88192e728d..427b4826109 100644 --- a/packages/typespec-python/test/unbranded/generated/authentication-union/setup.py +++ b/packages/typespec-python/test/unbranded/generated/authentication-union/setup.py @@ -60,7 +60,7 @@ }, install_requires=[ "isodate<1.0.0,>=0.6.1", - "corehttp[requests]", + "corehttp[requests]<1.0.0,>=1.0.0b3", ], python_requires=">=3.8", ) diff --git a/packages/typespec-python/test/unbranded/generated/client-structure-default/setup.py b/packages/typespec-python/test/unbranded/generated/client-structure-default/setup.py index 4d890ce9445..7b525350b2d 100644 --- a/packages/typespec-python/test/unbranded/generated/client-structure-default/setup.py +++ b/packages/typespec-python/test/unbranded/generated/client-structure-default/setup.py @@ -61,7 +61,7 @@ }, install_requires=[ "isodate<1.0.0,>=0.6.1", - "corehttp[requests]", + "corehttp[requests]<1.0.0,>=1.0.0b3", ], python_requires=">=3.8", ) diff --git a/packages/typespec-python/test/unbranded/generated/client-structure-multiclient/setup.py b/packages/typespec-python/test/unbranded/generated/client-structure-multiclient/setup.py index c626dcd1c68..d22f1ae8e70 100644 --- a/packages/typespec-python/test/unbranded/generated/client-structure-multiclient/setup.py +++ b/packages/typespec-python/test/unbranded/generated/client-structure-multiclient/setup.py @@ -61,7 +61,7 @@ }, install_requires=[ "isodate<1.0.0,>=0.6.1", - "corehttp[requests]", + "corehttp[requests]<1.0.0,>=1.0.0b3", ], python_requires=">=3.8", ) diff --git a/packages/typespec-python/test/unbranded/generated/client-structure-renamedoperation/setup.py b/packages/typespec-python/test/unbranded/generated/client-structure-renamedoperation/setup.py index 3e9710db217..9d21c8eafe8 100644 --- a/packages/typespec-python/test/unbranded/generated/client-structure-renamedoperation/setup.py +++ b/packages/typespec-python/test/unbranded/generated/client-structure-renamedoperation/setup.py @@ -61,7 +61,7 @@ }, install_requires=[ "isodate<1.0.0,>=0.6.1", - "corehttp[requests]", + "corehttp[requests]<1.0.0,>=1.0.0b3", ], python_requires=">=3.8", ) diff --git a/packages/typespec-python/test/unbranded/generated/client-structure-twooperationgroup/setup.py b/packages/typespec-python/test/unbranded/generated/client-structure-twooperationgroup/setup.py index 597e8e5efaa..0e2c3977554 100644 --- a/packages/typespec-python/test/unbranded/generated/client-structure-twooperationgroup/setup.py +++ b/packages/typespec-python/test/unbranded/generated/client-structure-twooperationgroup/setup.py @@ -61,7 +61,7 @@ }, install_requires=[ "isodate<1.0.0,>=0.6.1", - "corehttp[requests]", + "corehttp[requests]<1.0.0,>=1.0.0b3", ], python_requires=">=3.8", ) diff --git a/packages/typespec-python/test/unbranded/generated/encode-bytes/setup.py b/packages/typespec-python/test/unbranded/generated/encode-bytes/setup.py index 929487021cf..51f3ef1db93 100644 --- a/packages/typespec-python/test/unbranded/generated/encode-bytes/setup.py +++ b/packages/typespec-python/test/unbranded/generated/encode-bytes/setup.py @@ -60,7 +60,7 @@ }, install_requires=[ "isodate<1.0.0,>=0.6.1", - "corehttp[requests]", + "corehttp[requests]<1.0.0,>=1.0.0b3", ], python_requires=">=3.8", ) diff --git a/packages/typespec-python/test/unbranded/generated/encode-datetime/setup.py b/packages/typespec-python/test/unbranded/generated/encode-datetime/setup.py index b5f6759532e..14752f34fd8 100644 --- a/packages/typespec-python/test/unbranded/generated/encode-datetime/setup.py +++ b/packages/typespec-python/test/unbranded/generated/encode-datetime/setup.py @@ -60,7 +60,7 @@ }, install_requires=[ "isodate<1.0.0,>=0.6.1", - "corehttp[requests]", + "corehttp[requests]<1.0.0,>=1.0.0b3", ], python_requires=">=3.8", ) diff --git a/packages/typespec-python/test/unbranded/generated/encode-duration/setup.py b/packages/typespec-python/test/unbranded/generated/encode-duration/setup.py index 441362b764f..20518838101 100644 --- a/packages/typespec-python/test/unbranded/generated/encode-duration/setup.py +++ b/packages/typespec-python/test/unbranded/generated/encode-duration/setup.py @@ -60,7 +60,7 @@ }, install_requires=[ "isodate<1.0.0,>=0.6.1", - "corehttp[requests]", + "corehttp[requests]<1.0.0,>=1.0.0b3", ], python_requires=">=3.8", ) diff --git a/packages/typespec-python/test/unbranded/generated/headasbooleanfalse/setup.py b/packages/typespec-python/test/unbranded/generated/headasbooleanfalse/setup.py index 2d1a7c89b62..f9110ee1081 100644 --- a/packages/typespec-python/test/unbranded/generated/headasbooleanfalse/setup.py +++ b/packages/typespec-python/test/unbranded/generated/headasbooleanfalse/setup.py @@ -58,7 +58,7 @@ }, install_requires=[ "isodate<1.0.0,>=0.6.1", - "corehttp[requests]", + "corehttp[requests]<1.0.0,>=1.0.0b3", ], python_requires=">=3.8", ) diff --git a/packages/typespec-python/test/unbranded/generated/headasbooleantrue/setup.py b/packages/typespec-python/test/unbranded/generated/headasbooleantrue/setup.py index 7a73bc974c2..0bce3894eeb 100644 --- a/packages/typespec-python/test/unbranded/generated/headasbooleantrue/setup.py +++ b/packages/typespec-python/test/unbranded/generated/headasbooleantrue/setup.py @@ -58,7 +58,7 @@ }, install_requires=[ "isodate<1.0.0,>=0.6.1", - "corehttp[requests]", + "corehttp[requests]<1.0.0,>=1.0.0b3", ], python_requires=">=3.8", ) diff --git a/packages/typespec-python/test/unbranded/generated/parameters-body-optionality/setup.py b/packages/typespec-python/test/unbranded/generated/parameters-body-optionality/setup.py index abc50cb38aa..38f71534246 100644 --- a/packages/typespec-python/test/unbranded/generated/parameters-body-optionality/setup.py +++ b/packages/typespec-python/test/unbranded/generated/parameters-body-optionality/setup.py @@ -60,7 +60,7 @@ }, install_requires=[ "isodate<1.0.0,>=0.6.1", - "corehttp[requests]", + "corehttp[requests]<1.0.0,>=1.0.0b3", ], python_requires=">=3.8", ) diff --git a/packages/typespec-python/test/unbranded/generated/parameters-collection-format/setup.py b/packages/typespec-python/test/unbranded/generated/parameters-collection-format/setup.py index 8cdfb5631d5..0bc1f3d8567 100644 --- a/packages/typespec-python/test/unbranded/generated/parameters-collection-format/setup.py +++ b/packages/typespec-python/test/unbranded/generated/parameters-collection-format/setup.py @@ -60,7 +60,7 @@ }, install_requires=[ "isodate<1.0.0,>=0.6.1", - "corehttp[requests]", + "corehttp[requests]<1.0.0,>=1.0.0b3", ], python_requires=">=3.8", ) diff --git a/packages/typespec-python/test/unbranded/generated/parameters-spread/setup.py b/packages/typespec-python/test/unbranded/generated/parameters-spread/setup.py index a1122ac0ef6..2da454bc524 100644 --- a/packages/typespec-python/test/unbranded/generated/parameters-spread/setup.py +++ b/packages/typespec-python/test/unbranded/generated/parameters-spread/setup.py @@ -60,7 +60,7 @@ }, install_requires=[ "isodate<1.0.0,>=0.6.1", - "corehttp[requests]", + "corehttp[requests]<1.0.0,>=1.0.0b3", ], python_requires=">=3.8", ) diff --git a/packages/typespec-python/test/unbranded/generated/payload-content-negotiation/setup.py b/packages/typespec-python/test/unbranded/generated/payload-content-negotiation/setup.py index f46d666aa8d..630f0e84398 100644 --- a/packages/typespec-python/test/unbranded/generated/payload-content-negotiation/setup.py +++ b/packages/typespec-python/test/unbranded/generated/payload-content-negotiation/setup.py @@ -60,7 +60,7 @@ }, install_requires=[ "isodate<1.0.0,>=0.6.1", - "corehttp[requests]", + "corehttp[requests]<1.0.0,>=1.0.0b3", ], python_requires=">=3.8", ) diff --git a/packages/typespec-python/test/unbranded/generated/payload-media-type/setup.py b/packages/typespec-python/test/unbranded/generated/payload-media-type/setup.py index 0613c20dbde..716a8886323 100644 --- a/packages/typespec-python/test/unbranded/generated/payload-media-type/setup.py +++ b/packages/typespec-python/test/unbranded/generated/payload-media-type/setup.py @@ -60,7 +60,7 @@ }, install_requires=[ "isodate<1.0.0,>=0.6.1", - "corehttp[requests]", + "corehttp[requests]<1.0.0,>=1.0.0b3", ], python_requires=">=3.8", ) diff --git a/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/aio/operations/_operations.py b/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/aio/operations/_operations.py index a7ea122b624..f084d1ef3bd 100644 --- a/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/aio/operations/_operations.py +++ b/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/aio/operations/_operations.py @@ -23,6 +23,7 @@ from ... import _model_base, models as _models from ..._model_base import SdkJSONEncoder +from ..._vendor import FilesType from ...operations._operations import ( build_form_data_basic_request, build_form_data_binary_array_parts_request, diff --git a/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/models/_models.py b/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/models/_models.py index c41ac172c6f..c4905916692 100644 --- a/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/models/_models.py +++ b/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/models/_models.py @@ -7,11 +7,11 @@ # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from typing import Any, Dict, List, Mapping, Optional, TYPE_CHECKING, overload +from typing import Any, List, Mapping, Optional, TYPE_CHECKING, overload from .. import _model_base from .._model_base import rest_field -from .._vendor import FileType, FilesType +from .._vendor import FileType if TYPE_CHECKING: # pylint: disable=unused-import,ungrouped-imports diff --git a/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/operations/_operations.py b/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/operations/_operations.py index d3b2ce30615..6f15f51d7e6 100644 --- a/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/operations/_operations.py +++ b/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/operations/_operations.py @@ -25,6 +25,7 @@ from .. import _model_base, models as _models from .._model_base import SdkJSONEncoder from .._serialization import Serializer +from .._vendor import FilesType if sys.version_info >= (3, 9): from collections.abc import MutableMapping diff --git a/packages/typespec-python/test/unbranded/generated/payload-multipart/setup.py b/packages/typespec-python/test/unbranded/generated/payload-multipart/setup.py index 7c9f7dafa5b..7e1acccbb68 100644 --- a/packages/typespec-python/test/unbranded/generated/payload-multipart/setup.py +++ b/packages/typespec-python/test/unbranded/generated/payload-multipart/setup.py @@ -60,7 +60,7 @@ }, install_requires=[ "isodate<1.0.0,>=0.6.1", - "corehttp[requests]", + "corehttp[requests]<1.0.0,>=1.0.0b3", ], python_requires=">=3.8", ) diff --git a/packages/typespec-python/test/unbranded/generated/payload-pageable/setup.py b/packages/typespec-python/test/unbranded/generated/payload-pageable/setup.py index e35b497cc1b..a422e947da7 100644 --- a/packages/typespec-python/test/unbranded/generated/payload-pageable/setup.py +++ b/packages/typespec-python/test/unbranded/generated/payload-pageable/setup.py @@ -60,7 +60,7 @@ }, install_requires=[ "isodate<1.0.0,>=0.6.1", - "corehttp[requests]", + "corehttp[requests]<1.0.0,>=1.0.0b3", ], python_requires=">=3.8", ) diff --git a/packages/typespec-python/test/unbranded/generated/projection-projected-name/setup.py b/packages/typespec-python/test/unbranded/generated/projection-projected-name/setup.py index bd8dd1f8dda..d45bb1d679e 100644 --- a/packages/typespec-python/test/unbranded/generated/projection-projected-name/setup.py +++ b/packages/typespec-python/test/unbranded/generated/projection-projected-name/setup.py @@ -60,7 +60,7 @@ }, install_requires=[ "isodate<1.0.0,>=0.6.1", - "corehttp[requests]", + "corehttp[requests]<1.0.0,>=1.0.0b3", ], python_requires=">=3.8", ) diff --git a/packages/typespec-python/test/unbranded/generated/resiliency-srv-driven1/setup.py b/packages/typespec-python/test/unbranded/generated/resiliency-srv-driven1/setup.py index 69089130ad8..e3532e6abf6 100644 --- a/packages/typespec-python/test/unbranded/generated/resiliency-srv-driven1/setup.py +++ b/packages/typespec-python/test/unbranded/generated/resiliency-srv-driven1/setup.py @@ -61,7 +61,7 @@ }, install_requires=[ "isodate<1.0.0,>=0.6.1", - "corehttp[requests]", + "corehttp[requests]<1.0.0,>=1.0.0b3", ], python_requires=">=3.8", ) diff --git a/packages/typespec-python/test/unbranded/generated/resiliency-srv-driven2/setup.py b/packages/typespec-python/test/unbranded/generated/resiliency-srv-driven2/setup.py index 08fdea654fc..1af13c6dc22 100644 --- a/packages/typespec-python/test/unbranded/generated/resiliency-srv-driven2/setup.py +++ b/packages/typespec-python/test/unbranded/generated/resiliency-srv-driven2/setup.py @@ -61,7 +61,7 @@ }, install_requires=[ "isodate<1.0.0,>=0.6.1", - "corehttp[requests]", + "corehttp[requests]<1.0.0,>=1.0.0b3", ], python_requires=">=3.8", ) diff --git a/packages/typespec-python/test/unbranded/generated/server-path-multiple/setup.py b/packages/typespec-python/test/unbranded/generated/server-path-multiple/setup.py index ea072909c2a..fc9800d8bce 100644 --- a/packages/typespec-python/test/unbranded/generated/server-path-multiple/setup.py +++ b/packages/typespec-python/test/unbranded/generated/server-path-multiple/setup.py @@ -61,7 +61,7 @@ }, install_requires=[ "isodate<1.0.0,>=0.6.1", - "corehttp[requests]", + "corehttp[requests]<1.0.0,>=1.0.0b3", ], python_requires=">=3.8", ) diff --git a/packages/typespec-python/test/unbranded/generated/server-path-single/setup.py b/packages/typespec-python/test/unbranded/generated/server-path-single/setup.py index 335e33e9f34..04a25b63566 100644 --- a/packages/typespec-python/test/unbranded/generated/server-path-single/setup.py +++ b/packages/typespec-python/test/unbranded/generated/server-path-single/setup.py @@ -61,7 +61,7 @@ }, install_requires=[ "isodate<1.0.0,>=0.6.1", - "corehttp[requests]", + "corehttp[requests]<1.0.0,>=1.0.0b3", ], python_requires=">=3.8", ) diff --git a/packages/typespec-python/test/unbranded/generated/server-versions-not-versioned/setup.py b/packages/typespec-python/test/unbranded/generated/server-versions-not-versioned/setup.py index 207e4bb37a0..6b3320718ba 100644 --- a/packages/typespec-python/test/unbranded/generated/server-versions-not-versioned/setup.py +++ b/packages/typespec-python/test/unbranded/generated/server-versions-not-versioned/setup.py @@ -61,7 +61,7 @@ }, install_requires=[ "isodate<1.0.0,>=0.6.1", - "corehttp[requests]", + "corehttp[requests]<1.0.0,>=1.0.0b3", ], python_requires=">=3.8", ) diff --git a/packages/typespec-python/test/unbranded/generated/server-versions-versioned/setup.py b/packages/typespec-python/test/unbranded/generated/server-versions-versioned/setup.py index 4d427feb7c6..fc4dd1c881c 100644 --- a/packages/typespec-python/test/unbranded/generated/server-versions-versioned/setup.py +++ b/packages/typespec-python/test/unbranded/generated/server-versions-versioned/setup.py @@ -61,7 +61,7 @@ }, install_requires=[ "isodate<1.0.0,>=0.6.1", - "corehttp[requests]", + "corehttp[requests]<1.0.0,>=1.0.0b3", ], python_requires=">=3.8", ) diff --git a/packages/typespec-python/test/unbranded/generated/special-headers-conditional-request/setup.py b/packages/typespec-python/test/unbranded/generated/special-headers-conditional-request/setup.py index 2d5774e9445..dd7ce0c63d3 100644 --- a/packages/typespec-python/test/unbranded/generated/special-headers-conditional-request/setup.py +++ b/packages/typespec-python/test/unbranded/generated/special-headers-conditional-request/setup.py @@ -60,7 +60,7 @@ }, install_requires=[ "isodate<1.0.0,>=0.6.1", - "corehttp[requests]", + "corehttp[requests]<1.0.0,>=1.0.0b3", ], python_requires=">=3.8", ) diff --git a/packages/typespec-python/test/unbranded/generated/special-headers-repeatability/setup.py b/packages/typespec-python/test/unbranded/generated/special-headers-repeatability/setup.py index 8a293451720..fd5347e6c6d 100644 --- a/packages/typespec-python/test/unbranded/generated/special-headers-repeatability/setup.py +++ b/packages/typespec-python/test/unbranded/generated/special-headers-repeatability/setup.py @@ -60,7 +60,7 @@ }, install_requires=[ "isodate<1.0.0,>=0.6.1", - "corehttp[requests]", + "corehttp[requests]<1.0.0,>=1.0.0b3", ], python_requires=">=3.8", ) diff --git a/packages/typespec-python/test/unbranded/generated/special-words/setup.py b/packages/typespec-python/test/unbranded/generated/special-words/setup.py index 7bb5fe03bdd..cf823c7e26a 100644 --- a/packages/typespec-python/test/unbranded/generated/special-words/setup.py +++ b/packages/typespec-python/test/unbranded/generated/special-words/setup.py @@ -58,7 +58,7 @@ }, install_requires=[ "isodate<1.0.0,>=0.6.1", - "corehttp[requests]", + "corehttp[requests]<1.0.0,>=1.0.0b3", ], python_requires=">=3.8", ) diff --git a/packages/typespec-python/test/unbranded/generated/typetest-array/setup.py b/packages/typespec-python/test/unbranded/generated/typetest-array/setup.py index 028cda94082..13f8be41beb 100644 --- a/packages/typespec-python/test/unbranded/generated/typetest-array/setup.py +++ b/packages/typespec-python/test/unbranded/generated/typetest-array/setup.py @@ -60,7 +60,7 @@ }, install_requires=[ "isodate<1.0.0,>=0.6.1", - "corehttp[requests]", + "corehttp[requests]<1.0.0,>=1.0.0b3", ], python_requires=">=3.8", ) diff --git a/packages/typespec-python/test/unbranded/generated/typetest-dictionary/setup.py b/packages/typespec-python/test/unbranded/generated/typetest-dictionary/setup.py index 2bdee02151a..cad70681a5a 100644 --- a/packages/typespec-python/test/unbranded/generated/typetest-dictionary/setup.py +++ b/packages/typespec-python/test/unbranded/generated/typetest-dictionary/setup.py @@ -60,7 +60,7 @@ }, install_requires=[ "isodate<1.0.0,>=0.6.1", - "corehttp[requests]", + "corehttp[requests]<1.0.0,>=1.0.0b3", ], python_requires=">=3.8", ) diff --git a/packages/typespec-python/test/unbranded/generated/typetest-enum-extensible/setup.py b/packages/typespec-python/test/unbranded/generated/typetest-enum-extensible/setup.py index 793c0a96268..c9e4dc69dea 100644 --- a/packages/typespec-python/test/unbranded/generated/typetest-enum-extensible/setup.py +++ b/packages/typespec-python/test/unbranded/generated/typetest-enum-extensible/setup.py @@ -61,7 +61,7 @@ }, install_requires=[ "isodate<1.0.0,>=0.6.1", - "corehttp[requests]", + "corehttp[requests]<1.0.0,>=1.0.0b3", ], python_requires=">=3.8", ) diff --git a/packages/typespec-python/test/unbranded/generated/typetest-enum-fixed/setup.py b/packages/typespec-python/test/unbranded/generated/typetest-enum-fixed/setup.py index 37154b2b604..af6016ea669 100644 --- a/packages/typespec-python/test/unbranded/generated/typetest-enum-fixed/setup.py +++ b/packages/typespec-python/test/unbranded/generated/typetest-enum-fixed/setup.py @@ -61,7 +61,7 @@ }, install_requires=[ "isodate<1.0.0,>=0.6.1", - "corehttp[requests]", + "corehttp[requests]<1.0.0,>=1.0.0b3", ], python_requires=">=3.8", ) diff --git a/packages/typespec-python/test/unbranded/generated/typetest-model-empty/setup.py b/packages/typespec-python/test/unbranded/generated/typetest-model-empty/setup.py index 2f3b9f7b517..d087132ae7e 100644 --- a/packages/typespec-python/test/unbranded/generated/typetest-model-empty/setup.py +++ b/packages/typespec-python/test/unbranded/generated/typetest-model-empty/setup.py @@ -61,7 +61,7 @@ }, install_requires=[ "isodate<1.0.0,>=0.6.1", - "corehttp[requests]", + "corehttp[requests]<1.0.0,>=1.0.0b3", ], python_requires=">=3.8", ) diff --git a/packages/typespec-python/test/unbranded/generated/typetest-model-enumdiscriminator/setup.py b/packages/typespec-python/test/unbranded/generated/typetest-model-enumdiscriminator/setup.py index 94780328001..1522b3c648d 100644 --- a/packages/typespec-python/test/unbranded/generated/typetest-model-enumdiscriminator/setup.py +++ b/packages/typespec-python/test/unbranded/generated/typetest-model-enumdiscriminator/setup.py @@ -61,7 +61,7 @@ }, install_requires=[ "isodate<1.0.0,>=0.6.1", - "corehttp[requests]", + "corehttp[requests]<1.0.0,>=1.0.0b3", ], python_requires=">=3.8", ) diff --git a/packages/typespec-python/test/unbranded/generated/typetest-model-nesteddiscriminator/setup.py b/packages/typespec-python/test/unbranded/generated/typetest-model-nesteddiscriminator/setup.py index 38d60d185c1..2ce2f1422c1 100644 --- a/packages/typespec-python/test/unbranded/generated/typetest-model-nesteddiscriminator/setup.py +++ b/packages/typespec-python/test/unbranded/generated/typetest-model-nesteddiscriminator/setup.py @@ -61,7 +61,7 @@ }, install_requires=[ "isodate<1.0.0,>=0.6.1", - "corehttp[requests]", + "corehttp[requests]<1.0.0,>=1.0.0b3", ], python_requires=">=3.8", ) diff --git a/packages/typespec-python/test/unbranded/generated/typetest-model-notdiscriminated/setup.py b/packages/typespec-python/test/unbranded/generated/typetest-model-notdiscriminated/setup.py index 6afcc482b64..60f22d7b682 100644 --- a/packages/typespec-python/test/unbranded/generated/typetest-model-notdiscriminated/setup.py +++ b/packages/typespec-python/test/unbranded/generated/typetest-model-notdiscriminated/setup.py @@ -61,7 +61,7 @@ }, install_requires=[ "isodate<1.0.0,>=0.6.1", - "corehttp[requests]", + "corehttp[requests]<1.0.0,>=1.0.0b3", ], python_requires=">=3.8", ) diff --git a/packages/typespec-python/test/unbranded/generated/typetest-model-recursive/setup.py b/packages/typespec-python/test/unbranded/generated/typetest-model-recursive/setup.py index 4191c27f5ad..c383f0a6a3e 100644 --- a/packages/typespec-python/test/unbranded/generated/typetest-model-recursive/setup.py +++ b/packages/typespec-python/test/unbranded/generated/typetest-model-recursive/setup.py @@ -61,7 +61,7 @@ }, install_requires=[ "isodate<1.0.0,>=0.6.1", - "corehttp[requests]", + "corehttp[requests]<1.0.0,>=1.0.0b3", ], python_requires=">=3.8", ) diff --git a/packages/typespec-python/test/unbranded/generated/typetest-model-singlediscriminator/setup.py b/packages/typespec-python/test/unbranded/generated/typetest-model-singlediscriminator/setup.py index 6ffe6cb9a2a..21ff0830955 100644 --- a/packages/typespec-python/test/unbranded/generated/typetest-model-singlediscriminator/setup.py +++ b/packages/typespec-python/test/unbranded/generated/typetest-model-singlediscriminator/setup.py @@ -61,7 +61,7 @@ }, install_requires=[ "isodate<1.0.0,>=0.6.1", - "corehttp[requests]", + "corehttp[requests]<1.0.0,>=1.0.0b3", ], python_requires=">=3.8", ) diff --git a/packages/typespec-python/test/unbranded/generated/typetest-model-usage/setup.py b/packages/typespec-python/test/unbranded/generated/typetest-model-usage/setup.py index 92725093f4b..408c5298c66 100644 --- a/packages/typespec-python/test/unbranded/generated/typetest-model-usage/setup.py +++ b/packages/typespec-python/test/unbranded/generated/typetest-model-usage/setup.py @@ -61,7 +61,7 @@ }, install_requires=[ "isodate<1.0.0,>=0.6.1", - "corehttp[requests]", + "corehttp[requests]<1.0.0,>=1.0.0b3", ], python_requires=">=3.8", ) diff --git a/packages/typespec-python/test/unbranded/generated/typetest-model-visibility/setup.py b/packages/typespec-python/test/unbranded/generated/typetest-model-visibility/setup.py index dc3b9d2677c..c0e8d1ee62b 100644 --- a/packages/typespec-python/test/unbranded/generated/typetest-model-visibility/setup.py +++ b/packages/typespec-python/test/unbranded/generated/typetest-model-visibility/setup.py @@ -61,7 +61,7 @@ }, install_requires=[ "isodate<1.0.0,>=0.6.1", - "corehttp[requests]", + "corehttp[requests]<1.0.0,>=1.0.0b3", ], python_requires=">=3.8", ) diff --git a/packages/typespec-python/test/unbranded/generated/typetest-property-additionalproperties/setup.py b/packages/typespec-python/test/unbranded/generated/typetest-property-additionalproperties/setup.py index dd4149c9b28..86f0331d567 100644 --- a/packages/typespec-python/test/unbranded/generated/typetest-property-additionalproperties/setup.py +++ b/packages/typespec-python/test/unbranded/generated/typetest-property-additionalproperties/setup.py @@ -61,7 +61,7 @@ }, install_requires=[ "isodate<1.0.0,>=0.6.1", - "corehttp[requests]", + "corehttp[requests]<1.0.0,>=1.0.0b3", ], python_requires=">=3.8", ) diff --git a/packages/typespec-python/test/unbranded/generated/typetest-property-nullable/setup.py b/packages/typespec-python/test/unbranded/generated/typetest-property-nullable/setup.py index 746bcd0b2aa..af254d14611 100644 --- a/packages/typespec-python/test/unbranded/generated/typetest-property-nullable/setup.py +++ b/packages/typespec-python/test/unbranded/generated/typetest-property-nullable/setup.py @@ -61,7 +61,7 @@ }, install_requires=[ "isodate<1.0.0,>=0.6.1", - "corehttp[requests]", + "corehttp[requests]<1.0.0,>=1.0.0b3", ], python_requires=">=3.8", ) diff --git a/packages/typespec-python/test/unbranded/generated/typetest-property-optional/setup.py b/packages/typespec-python/test/unbranded/generated/typetest-property-optional/setup.py index 07c1ee6f709..5001269cfca 100644 --- a/packages/typespec-python/test/unbranded/generated/typetest-property-optional/setup.py +++ b/packages/typespec-python/test/unbranded/generated/typetest-property-optional/setup.py @@ -61,7 +61,7 @@ }, install_requires=[ "isodate<1.0.0,>=0.6.1", - "corehttp[requests]", + "corehttp[requests]<1.0.0,>=1.0.0b3", ], python_requires=">=3.8", ) diff --git a/packages/typespec-python/test/unbranded/generated/typetest-property-valuetypes/setup.py b/packages/typespec-python/test/unbranded/generated/typetest-property-valuetypes/setup.py index 7f826b6cddf..81b459576f2 100644 --- a/packages/typespec-python/test/unbranded/generated/typetest-property-valuetypes/setup.py +++ b/packages/typespec-python/test/unbranded/generated/typetest-property-valuetypes/setup.py @@ -61,7 +61,7 @@ }, install_requires=[ "isodate<1.0.0,>=0.6.1", - "corehttp[requests]", + "corehttp[requests]<1.0.0,>=1.0.0b3", ], python_requires=">=3.8", ) diff --git a/packages/typespec-python/test/unbranded/generated/typetest-scalar/setup.py b/packages/typespec-python/test/unbranded/generated/typetest-scalar/setup.py index c876d5bff2a..03c91cc0e13 100644 --- a/packages/typespec-python/test/unbranded/generated/typetest-scalar/setup.py +++ b/packages/typespec-python/test/unbranded/generated/typetest-scalar/setup.py @@ -60,7 +60,7 @@ }, install_requires=[ "isodate<1.0.0,>=0.6.1", - "corehttp[requests]", + "corehttp[requests]<1.0.0,>=1.0.0b3", ], python_requires=">=3.8", ) diff --git a/packages/typespec-python/test/unbranded/generated/typetest-union/setup.py b/packages/typespec-python/test/unbranded/generated/typetest-union/setup.py index efa92786ad5..44e03fc7f30 100644 --- a/packages/typespec-python/test/unbranded/generated/typetest-union/setup.py +++ b/packages/typespec-python/test/unbranded/generated/typetest-union/setup.py @@ -60,7 +60,7 @@ }, install_requires=[ "isodate<1.0.0,>=0.6.1", - "corehttp[requests]", + "corehttp[requests]<1.0.0,>=1.0.0b3", ], python_requires=">=3.8", ) From 3eb1f38e41e78fc6fba7b75528f1226c852a40c3 Mon Sep 17 00:00:00 2001 From: iscai-msft Date: Thu, 1 Feb 2024 18:50:15 -0500 Subject: [PATCH 34/45] prepare changelog and package.json --- packages/autorest.python/package.json | 2 +- packages/typespec-python/CHANGELOG.md | 25 +++++++++++++++++++++++++ packages/typespec-python/package.json | 2 +- 3 files changed, 27 insertions(+), 2 deletions(-) diff --git a/packages/autorest.python/package.json b/packages/autorest.python/package.json index b487f1bb920..56a3e5f801b 100644 --- a/packages/autorest.python/package.json +++ b/packages/autorest.python/package.json @@ -1,6 +1,6 @@ { "name": "@autorest/python", - "version": "6.12.3", + "version": "6.12.4", "description": "The Python extension for generators in AutoRest.", "scripts": { "prepare": "node run-python3.js prepare.py", diff --git a/packages/typespec-python/CHANGELOG.md b/packages/typespec-python/CHANGELOG.md index 482c6367a48..5f8164d3fdf 100644 --- a/packages/typespec-python/CHANGELOG.md +++ b/packages/typespec-python/CHANGELOG.md @@ -1,5 +1,30 @@ # Release +## 2023-02-01 - 0.19.0 + +| Library | Min Version | +| ----------------------------------------------------------------------- | ------------- | +| `@typespec/compiler` | `0.52.0` | +| `@typespec/http` | `0.52.0` | +| `@typespec/rest` | `0.52.0` | +| `@typespec/versioning` | `0.52.0` | +| `@azure-tools/typespec-azure-core` | `0.38.0` | +| `@azure-tools/typespec-client-generator-core` | `0.38.0` | +| `azure-core` dep of generated code | `1.30.0` | +| `corehttp` dep of generated code | `1.0.0b3` | +| `isodate` dep of generated code | `0.6.1` | +| `azure-mgmt-core` dep of generated code (If generating mgmt plane code) | `1.3.2` | +| `typing-extensions` dep of generated code (If generating with constants)| `4.0.1` | + +**New Features** + +- Add support for complete tuple input for file types #2380 + +**Other Changes** + +- Bump min dep of `azure-core` to `1.30.0` #2380 +- Bump min dep of `corehttp` to `1.0.0b3` #2380 + ## 2023-01-24 - 0.18.3 | Library | Min Version | diff --git a/packages/typespec-python/package.json b/packages/typespec-python/package.json index 3c0b68b5948..54c06d3ee1b 100644 --- a/packages/typespec-python/package.json +++ b/packages/typespec-python/package.json @@ -1,6 +1,6 @@ { "name": "@azure-tools/typespec-python", - "version": "0.18.3", + "version": "0.19.0", "author": "Microsoft Corporation", "description": "TypeSpec emitter for Python SDKs", "homepage": "https://github.com/Azure/autorest.python", From 2c256e67d4fa30fc825ee5758b5db5e6dd36a47f Mon Sep 17 00:00:00 2001 From: iscai-msft Date: Thu, 1 Feb 2024 18:56:43 -0500 Subject: [PATCH 35/45] black --- .../autorest.python/autorest/codegen/models/parameter.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/autorest.python/autorest/codegen/models/parameter.py b/packages/autorest.python/autorest/codegen/models/parameter.py index c49b92ac34e..5380c91d80b 100644 --- a/packages/autorest.python/autorest/codegen/models/parameter.py +++ b/packages/autorest.python/autorest/codegen/models/parameter.py @@ -16,8 +16,6 @@ Union, ) -from .imports import FileImport - from .imports import FileImport, ImportType, TypingSection from .base import BaseModel from .base import BaseType @@ -291,12 +289,14 @@ def has_json_model_type(self) -> bool: if isinstance(self.type, CombinedType): return self.type.target_model_subtype((JSONModelType,)) is not None return isinstance(self.type, JSONModelType) - + def imports(self, async_mode: bool, **kwargs: Any) -> FileImport: file_import = super().imports(async_mode, **kwargs) if self.is_form_data: relative_path = "..." if async_mode else ".." - file_import.add_submodule_import(f"{relative_path}_vendor", "FilesType", ImportType.LOCAL) + file_import.add_submodule_import( + f"{relative_path}_vendor", "FilesType", ImportType.LOCAL + ) file_import.add_submodule_import("typing", "Dict", ImportType.STDLIB) file_import.add_submodule_import("typing", "Any", ImportType.STDLIB) return file_import From 6d3da872074ce201b9db50f32dcdc2ac0a52a74b Mon Sep 17 00:00:00 2001 From: iscai-msft Date: Thu, 1 Feb 2024 19:07:43 -0500 Subject: [PATCH 36/45] fix corehttp dep in setup.py --- .../codegen/templates/packaging_templates/setup.py.jinja2 | 2 +- .../test/unbranded/generated/authentication-api-key/setup.py | 2 +- .../unbranded/generated/authentication-http-custom/setup.py | 2 +- .../test/unbranded/generated/authentication-oauth2/setup.py | 2 +- .../test/unbranded/generated/authentication-union/setup.py | 2 +- .../test/unbranded/generated/client-structure-default/setup.py | 2 +- .../unbranded/generated/client-structure-multiclient/setup.py | 2 +- .../generated/client-structure-renamedoperation/setup.py | 2 +- .../generated/client-structure-twooperationgroup/setup.py | 2 +- .../test/unbranded/generated/encode-bytes/setup.py | 2 +- .../test/unbranded/generated/encode-datetime/setup.py | 2 +- .../test/unbranded/generated/encode-duration/setup.py | 2 +- .../test/unbranded/generated/headasbooleanfalse/setup.py | 2 +- .../test/unbranded/generated/headasbooleantrue/setup.py | 2 +- .../unbranded/generated/parameters-body-optionality/setup.py | 2 +- .../unbranded/generated/parameters-collection-format/setup.py | 2 +- .../test/unbranded/generated/parameters-spread/setup.py | 2 +- .../unbranded/generated/payload-content-negotiation/setup.py | 2 +- .../test/unbranded/generated/payload-media-type/setup.py | 2 +- .../test/unbranded/generated/payload-multipart/setup.py | 2 +- .../test/unbranded/generated/payload-pageable/setup.py | 2 +- .../test/unbranded/generated/projection-projected-name/setup.py | 2 +- .../test/unbranded/generated/resiliency-srv-driven1/setup.py | 2 +- .../test/unbranded/generated/resiliency-srv-driven2/setup.py | 2 +- .../test/unbranded/generated/server-path-multiple/setup.py | 2 +- .../test/unbranded/generated/server-path-single/setup.py | 2 +- .../unbranded/generated/server-versions-not-versioned/setup.py | 2 +- .../test/unbranded/generated/server-versions-versioned/setup.py | 2 +- .../generated/special-headers-conditional-request/setup.py | 2 +- .../unbranded/generated/special-headers-repeatability/setup.py | 2 +- .../test/unbranded/generated/special-words/setup.py | 2 +- .../test/unbranded/generated/typetest-array/setup.py | 2 +- .../test/unbranded/generated/typetest-dictionary/setup.py | 2 +- .../test/unbranded/generated/typetest-enum-extensible/setup.py | 2 +- .../test/unbranded/generated/typetest-enum-fixed/setup.py | 2 +- .../test/unbranded/generated/typetest-model-empty/setup.py | 2 +- .../generated/typetest-model-enumdiscriminator/setup.py | 2 +- .../generated/typetest-model-nesteddiscriminator/setup.py | 2 +- .../generated/typetest-model-notdiscriminated/setup.py | 2 +- .../test/unbranded/generated/typetest-model-recursive/setup.py | 2 +- .../generated/typetest-model-singlediscriminator/setup.py | 2 +- .../test/unbranded/generated/typetest-model-usage/setup.py | 2 +- .../test/unbranded/generated/typetest-model-visibility/setup.py | 2 +- .../generated/typetest-property-additionalproperties/setup.py | 2 +- .../unbranded/generated/typetest-property-nullable/setup.py | 2 +- .../unbranded/generated/typetest-property-optional/setup.py | 2 +- .../unbranded/generated/typetest-property-valuetypes/setup.py | 2 +- .../test/unbranded/generated/typetest-scalar/setup.py | 2 +- .../test/unbranded/generated/typetest-union/setup.py | 2 +- 49 files changed, 49 insertions(+), 49 deletions(-) diff --git a/packages/autorest.python/autorest/codegen/templates/packaging_templates/setup.py.jinja2 b/packages/autorest.python/autorest/codegen/templates/packaging_templates/setup.py.jinja2 index 50004ed896f..ad77a49061c 100644 --- a/packages/autorest.python/autorest/codegen/templates/packaging_templates/setup.py.jinja2 +++ b/packages/autorest.python/autorest/codegen/templates/packaging_templates/setup.py.jinja2 @@ -90,7 +90,7 @@ setup( "isodate<1.0.0,>=0.6.1", {% endif %} {% if unbranded %} - "corehttp[requests]<1.0.0,>=1.0.0b3", + "corehttp[requests]", {% elif azure_arm %} "azure-mgmt-core<2.0.0,>=1.3.2", {% else %} diff --git a/packages/typespec-python/test/unbranded/generated/authentication-api-key/setup.py b/packages/typespec-python/test/unbranded/generated/authentication-api-key/setup.py index dea99122204..8dbab9e89fd 100644 --- a/packages/typespec-python/test/unbranded/generated/authentication-api-key/setup.py +++ b/packages/typespec-python/test/unbranded/generated/authentication-api-key/setup.py @@ -60,7 +60,7 @@ }, install_requires=[ "isodate<1.0.0,>=0.6.1", - "corehttp[requests]<1.0.0,>=1.0.0b3", + "corehttp[requests]", ], python_requires=">=3.8", ) diff --git a/packages/typespec-python/test/unbranded/generated/authentication-http-custom/setup.py b/packages/typespec-python/test/unbranded/generated/authentication-http-custom/setup.py index 53ad28dc0c6..cc335efcf91 100644 --- a/packages/typespec-python/test/unbranded/generated/authentication-http-custom/setup.py +++ b/packages/typespec-python/test/unbranded/generated/authentication-http-custom/setup.py @@ -61,7 +61,7 @@ }, install_requires=[ "isodate<1.0.0,>=0.6.1", - "corehttp[requests]<1.0.0,>=1.0.0b3", + "corehttp[requests]", ], python_requires=">=3.8", ) diff --git a/packages/typespec-python/test/unbranded/generated/authentication-oauth2/setup.py b/packages/typespec-python/test/unbranded/generated/authentication-oauth2/setup.py index 8a90119cd9a..dfc2f2272b2 100644 --- a/packages/typespec-python/test/unbranded/generated/authentication-oauth2/setup.py +++ b/packages/typespec-python/test/unbranded/generated/authentication-oauth2/setup.py @@ -60,7 +60,7 @@ }, install_requires=[ "isodate<1.0.0,>=0.6.1", - "corehttp[requests]<1.0.0,>=1.0.0b3", + "corehttp[requests]", ], python_requires=">=3.8", ) diff --git a/packages/typespec-python/test/unbranded/generated/authentication-union/setup.py b/packages/typespec-python/test/unbranded/generated/authentication-union/setup.py index 427b4826109..a88192e728d 100644 --- a/packages/typespec-python/test/unbranded/generated/authentication-union/setup.py +++ b/packages/typespec-python/test/unbranded/generated/authentication-union/setup.py @@ -60,7 +60,7 @@ }, install_requires=[ "isodate<1.0.0,>=0.6.1", - "corehttp[requests]<1.0.0,>=1.0.0b3", + "corehttp[requests]", ], python_requires=">=3.8", ) diff --git a/packages/typespec-python/test/unbranded/generated/client-structure-default/setup.py b/packages/typespec-python/test/unbranded/generated/client-structure-default/setup.py index 7b525350b2d..4d890ce9445 100644 --- a/packages/typespec-python/test/unbranded/generated/client-structure-default/setup.py +++ b/packages/typespec-python/test/unbranded/generated/client-structure-default/setup.py @@ -61,7 +61,7 @@ }, install_requires=[ "isodate<1.0.0,>=0.6.1", - "corehttp[requests]<1.0.0,>=1.0.0b3", + "corehttp[requests]", ], python_requires=">=3.8", ) diff --git a/packages/typespec-python/test/unbranded/generated/client-structure-multiclient/setup.py b/packages/typespec-python/test/unbranded/generated/client-structure-multiclient/setup.py index d22f1ae8e70..c626dcd1c68 100644 --- a/packages/typespec-python/test/unbranded/generated/client-structure-multiclient/setup.py +++ b/packages/typespec-python/test/unbranded/generated/client-structure-multiclient/setup.py @@ -61,7 +61,7 @@ }, install_requires=[ "isodate<1.0.0,>=0.6.1", - "corehttp[requests]<1.0.0,>=1.0.0b3", + "corehttp[requests]", ], python_requires=">=3.8", ) diff --git a/packages/typespec-python/test/unbranded/generated/client-structure-renamedoperation/setup.py b/packages/typespec-python/test/unbranded/generated/client-structure-renamedoperation/setup.py index 9d21c8eafe8..3e9710db217 100644 --- a/packages/typespec-python/test/unbranded/generated/client-structure-renamedoperation/setup.py +++ b/packages/typespec-python/test/unbranded/generated/client-structure-renamedoperation/setup.py @@ -61,7 +61,7 @@ }, install_requires=[ "isodate<1.0.0,>=0.6.1", - "corehttp[requests]<1.0.0,>=1.0.0b3", + "corehttp[requests]", ], python_requires=">=3.8", ) diff --git a/packages/typespec-python/test/unbranded/generated/client-structure-twooperationgroup/setup.py b/packages/typespec-python/test/unbranded/generated/client-structure-twooperationgroup/setup.py index 0e2c3977554..597e8e5efaa 100644 --- a/packages/typespec-python/test/unbranded/generated/client-structure-twooperationgroup/setup.py +++ b/packages/typespec-python/test/unbranded/generated/client-structure-twooperationgroup/setup.py @@ -61,7 +61,7 @@ }, install_requires=[ "isodate<1.0.0,>=0.6.1", - "corehttp[requests]<1.0.0,>=1.0.0b3", + "corehttp[requests]", ], python_requires=">=3.8", ) diff --git a/packages/typespec-python/test/unbranded/generated/encode-bytes/setup.py b/packages/typespec-python/test/unbranded/generated/encode-bytes/setup.py index 51f3ef1db93..929487021cf 100644 --- a/packages/typespec-python/test/unbranded/generated/encode-bytes/setup.py +++ b/packages/typespec-python/test/unbranded/generated/encode-bytes/setup.py @@ -60,7 +60,7 @@ }, install_requires=[ "isodate<1.0.0,>=0.6.1", - "corehttp[requests]<1.0.0,>=1.0.0b3", + "corehttp[requests]", ], python_requires=">=3.8", ) diff --git a/packages/typespec-python/test/unbranded/generated/encode-datetime/setup.py b/packages/typespec-python/test/unbranded/generated/encode-datetime/setup.py index 14752f34fd8..b5f6759532e 100644 --- a/packages/typespec-python/test/unbranded/generated/encode-datetime/setup.py +++ b/packages/typespec-python/test/unbranded/generated/encode-datetime/setup.py @@ -60,7 +60,7 @@ }, install_requires=[ "isodate<1.0.0,>=0.6.1", - "corehttp[requests]<1.0.0,>=1.0.0b3", + "corehttp[requests]", ], python_requires=">=3.8", ) diff --git a/packages/typespec-python/test/unbranded/generated/encode-duration/setup.py b/packages/typespec-python/test/unbranded/generated/encode-duration/setup.py index 20518838101..441362b764f 100644 --- a/packages/typespec-python/test/unbranded/generated/encode-duration/setup.py +++ b/packages/typespec-python/test/unbranded/generated/encode-duration/setup.py @@ -60,7 +60,7 @@ }, install_requires=[ "isodate<1.0.0,>=0.6.1", - "corehttp[requests]<1.0.0,>=1.0.0b3", + "corehttp[requests]", ], python_requires=">=3.8", ) diff --git a/packages/typespec-python/test/unbranded/generated/headasbooleanfalse/setup.py b/packages/typespec-python/test/unbranded/generated/headasbooleanfalse/setup.py index f9110ee1081..2d1a7c89b62 100644 --- a/packages/typespec-python/test/unbranded/generated/headasbooleanfalse/setup.py +++ b/packages/typespec-python/test/unbranded/generated/headasbooleanfalse/setup.py @@ -58,7 +58,7 @@ }, install_requires=[ "isodate<1.0.0,>=0.6.1", - "corehttp[requests]<1.0.0,>=1.0.0b3", + "corehttp[requests]", ], python_requires=">=3.8", ) diff --git a/packages/typespec-python/test/unbranded/generated/headasbooleantrue/setup.py b/packages/typespec-python/test/unbranded/generated/headasbooleantrue/setup.py index 0bce3894eeb..7a73bc974c2 100644 --- a/packages/typespec-python/test/unbranded/generated/headasbooleantrue/setup.py +++ b/packages/typespec-python/test/unbranded/generated/headasbooleantrue/setup.py @@ -58,7 +58,7 @@ }, install_requires=[ "isodate<1.0.0,>=0.6.1", - "corehttp[requests]<1.0.0,>=1.0.0b3", + "corehttp[requests]", ], python_requires=">=3.8", ) diff --git a/packages/typespec-python/test/unbranded/generated/parameters-body-optionality/setup.py b/packages/typespec-python/test/unbranded/generated/parameters-body-optionality/setup.py index 38f71534246..abc50cb38aa 100644 --- a/packages/typespec-python/test/unbranded/generated/parameters-body-optionality/setup.py +++ b/packages/typespec-python/test/unbranded/generated/parameters-body-optionality/setup.py @@ -60,7 +60,7 @@ }, install_requires=[ "isodate<1.0.0,>=0.6.1", - "corehttp[requests]<1.0.0,>=1.0.0b3", + "corehttp[requests]", ], python_requires=">=3.8", ) diff --git a/packages/typespec-python/test/unbranded/generated/parameters-collection-format/setup.py b/packages/typespec-python/test/unbranded/generated/parameters-collection-format/setup.py index 0bc1f3d8567..8cdfb5631d5 100644 --- a/packages/typespec-python/test/unbranded/generated/parameters-collection-format/setup.py +++ b/packages/typespec-python/test/unbranded/generated/parameters-collection-format/setup.py @@ -60,7 +60,7 @@ }, install_requires=[ "isodate<1.0.0,>=0.6.1", - "corehttp[requests]<1.0.0,>=1.0.0b3", + "corehttp[requests]", ], python_requires=">=3.8", ) diff --git a/packages/typespec-python/test/unbranded/generated/parameters-spread/setup.py b/packages/typespec-python/test/unbranded/generated/parameters-spread/setup.py index 2da454bc524..a1122ac0ef6 100644 --- a/packages/typespec-python/test/unbranded/generated/parameters-spread/setup.py +++ b/packages/typespec-python/test/unbranded/generated/parameters-spread/setup.py @@ -60,7 +60,7 @@ }, install_requires=[ "isodate<1.0.0,>=0.6.1", - "corehttp[requests]<1.0.0,>=1.0.0b3", + "corehttp[requests]", ], python_requires=">=3.8", ) diff --git a/packages/typespec-python/test/unbranded/generated/payload-content-negotiation/setup.py b/packages/typespec-python/test/unbranded/generated/payload-content-negotiation/setup.py index 630f0e84398..f46d666aa8d 100644 --- a/packages/typespec-python/test/unbranded/generated/payload-content-negotiation/setup.py +++ b/packages/typespec-python/test/unbranded/generated/payload-content-negotiation/setup.py @@ -60,7 +60,7 @@ }, install_requires=[ "isodate<1.0.0,>=0.6.1", - "corehttp[requests]<1.0.0,>=1.0.0b3", + "corehttp[requests]", ], python_requires=">=3.8", ) diff --git a/packages/typespec-python/test/unbranded/generated/payload-media-type/setup.py b/packages/typespec-python/test/unbranded/generated/payload-media-type/setup.py index 716a8886323..0613c20dbde 100644 --- a/packages/typespec-python/test/unbranded/generated/payload-media-type/setup.py +++ b/packages/typespec-python/test/unbranded/generated/payload-media-type/setup.py @@ -60,7 +60,7 @@ }, install_requires=[ "isodate<1.0.0,>=0.6.1", - "corehttp[requests]<1.0.0,>=1.0.0b3", + "corehttp[requests]", ], python_requires=">=3.8", ) diff --git a/packages/typespec-python/test/unbranded/generated/payload-multipart/setup.py b/packages/typespec-python/test/unbranded/generated/payload-multipart/setup.py index 7e1acccbb68..7c9f7dafa5b 100644 --- a/packages/typespec-python/test/unbranded/generated/payload-multipart/setup.py +++ b/packages/typespec-python/test/unbranded/generated/payload-multipart/setup.py @@ -60,7 +60,7 @@ }, install_requires=[ "isodate<1.0.0,>=0.6.1", - "corehttp[requests]<1.0.0,>=1.0.0b3", + "corehttp[requests]", ], python_requires=">=3.8", ) diff --git a/packages/typespec-python/test/unbranded/generated/payload-pageable/setup.py b/packages/typespec-python/test/unbranded/generated/payload-pageable/setup.py index a422e947da7..e35b497cc1b 100644 --- a/packages/typespec-python/test/unbranded/generated/payload-pageable/setup.py +++ b/packages/typespec-python/test/unbranded/generated/payload-pageable/setup.py @@ -60,7 +60,7 @@ }, install_requires=[ "isodate<1.0.0,>=0.6.1", - "corehttp[requests]<1.0.0,>=1.0.0b3", + "corehttp[requests]", ], python_requires=">=3.8", ) diff --git a/packages/typespec-python/test/unbranded/generated/projection-projected-name/setup.py b/packages/typespec-python/test/unbranded/generated/projection-projected-name/setup.py index d45bb1d679e..bd8dd1f8dda 100644 --- a/packages/typespec-python/test/unbranded/generated/projection-projected-name/setup.py +++ b/packages/typespec-python/test/unbranded/generated/projection-projected-name/setup.py @@ -60,7 +60,7 @@ }, install_requires=[ "isodate<1.0.0,>=0.6.1", - "corehttp[requests]<1.0.0,>=1.0.0b3", + "corehttp[requests]", ], python_requires=">=3.8", ) diff --git a/packages/typespec-python/test/unbranded/generated/resiliency-srv-driven1/setup.py b/packages/typespec-python/test/unbranded/generated/resiliency-srv-driven1/setup.py index e3532e6abf6..69089130ad8 100644 --- a/packages/typespec-python/test/unbranded/generated/resiliency-srv-driven1/setup.py +++ b/packages/typespec-python/test/unbranded/generated/resiliency-srv-driven1/setup.py @@ -61,7 +61,7 @@ }, install_requires=[ "isodate<1.0.0,>=0.6.1", - "corehttp[requests]<1.0.0,>=1.0.0b3", + "corehttp[requests]", ], python_requires=">=3.8", ) diff --git a/packages/typespec-python/test/unbranded/generated/resiliency-srv-driven2/setup.py b/packages/typespec-python/test/unbranded/generated/resiliency-srv-driven2/setup.py index 1af13c6dc22..08fdea654fc 100644 --- a/packages/typespec-python/test/unbranded/generated/resiliency-srv-driven2/setup.py +++ b/packages/typespec-python/test/unbranded/generated/resiliency-srv-driven2/setup.py @@ -61,7 +61,7 @@ }, install_requires=[ "isodate<1.0.0,>=0.6.1", - "corehttp[requests]<1.0.0,>=1.0.0b3", + "corehttp[requests]", ], python_requires=">=3.8", ) diff --git a/packages/typespec-python/test/unbranded/generated/server-path-multiple/setup.py b/packages/typespec-python/test/unbranded/generated/server-path-multiple/setup.py index fc9800d8bce..ea072909c2a 100644 --- a/packages/typespec-python/test/unbranded/generated/server-path-multiple/setup.py +++ b/packages/typespec-python/test/unbranded/generated/server-path-multiple/setup.py @@ -61,7 +61,7 @@ }, install_requires=[ "isodate<1.0.0,>=0.6.1", - "corehttp[requests]<1.0.0,>=1.0.0b3", + "corehttp[requests]", ], python_requires=">=3.8", ) diff --git a/packages/typespec-python/test/unbranded/generated/server-path-single/setup.py b/packages/typespec-python/test/unbranded/generated/server-path-single/setup.py index 04a25b63566..335e33e9f34 100644 --- a/packages/typespec-python/test/unbranded/generated/server-path-single/setup.py +++ b/packages/typespec-python/test/unbranded/generated/server-path-single/setup.py @@ -61,7 +61,7 @@ }, install_requires=[ "isodate<1.0.0,>=0.6.1", - "corehttp[requests]<1.0.0,>=1.0.0b3", + "corehttp[requests]", ], python_requires=">=3.8", ) diff --git a/packages/typespec-python/test/unbranded/generated/server-versions-not-versioned/setup.py b/packages/typespec-python/test/unbranded/generated/server-versions-not-versioned/setup.py index 6b3320718ba..207e4bb37a0 100644 --- a/packages/typespec-python/test/unbranded/generated/server-versions-not-versioned/setup.py +++ b/packages/typespec-python/test/unbranded/generated/server-versions-not-versioned/setup.py @@ -61,7 +61,7 @@ }, install_requires=[ "isodate<1.0.0,>=0.6.1", - "corehttp[requests]<1.0.0,>=1.0.0b3", + "corehttp[requests]", ], python_requires=">=3.8", ) diff --git a/packages/typespec-python/test/unbranded/generated/server-versions-versioned/setup.py b/packages/typespec-python/test/unbranded/generated/server-versions-versioned/setup.py index fc4dd1c881c..4d427feb7c6 100644 --- a/packages/typespec-python/test/unbranded/generated/server-versions-versioned/setup.py +++ b/packages/typespec-python/test/unbranded/generated/server-versions-versioned/setup.py @@ -61,7 +61,7 @@ }, install_requires=[ "isodate<1.0.0,>=0.6.1", - "corehttp[requests]<1.0.0,>=1.0.0b3", + "corehttp[requests]", ], python_requires=">=3.8", ) diff --git a/packages/typespec-python/test/unbranded/generated/special-headers-conditional-request/setup.py b/packages/typespec-python/test/unbranded/generated/special-headers-conditional-request/setup.py index dd7ce0c63d3..2d5774e9445 100644 --- a/packages/typespec-python/test/unbranded/generated/special-headers-conditional-request/setup.py +++ b/packages/typespec-python/test/unbranded/generated/special-headers-conditional-request/setup.py @@ -60,7 +60,7 @@ }, install_requires=[ "isodate<1.0.0,>=0.6.1", - "corehttp[requests]<1.0.0,>=1.0.0b3", + "corehttp[requests]", ], python_requires=">=3.8", ) diff --git a/packages/typespec-python/test/unbranded/generated/special-headers-repeatability/setup.py b/packages/typespec-python/test/unbranded/generated/special-headers-repeatability/setup.py index fd5347e6c6d..8a293451720 100644 --- a/packages/typespec-python/test/unbranded/generated/special-headers-repeatability/setup.py +++ b/packages/typespec-python/test/unbranded/generated/special-headers-repeatability/setup.py @@ -60,7 +60,7 @@ }, install_requires=[ "isodate<1.0.0,>=0.6.1", - "corehttp[requests]<1.0.0,>=1.0.0b3", + "corehttp[requests]", ], python_requires=">=3.8", ) diff --git a/packages/typespec-python/test/unbranded/generated/special-words/setup.py b/packages/typespec-python/test/unbranded/generated/special-words/setup.py index cf823c7e26a..7bb5fe03bdd 100644 --- a/packages/typespec-python/test/unbranded/generated/special-words/setup.py +++ b/packages/typespec-python/test/unbranded/generated/special-words/setup.py @@ -58,7 +58,7 @@ }, install_requires=[ "isodate<1.0.0,>=0.6.1", - "corehttp[requests]<1.0.0,>=1.0.0b3", + "corehttp[requests]", ], python_requires=">=3.8", ) diff --git a/packages/typespec-python/test/unbranded/generated/typetest-array/setup.py b/packages/typespec-python/test/unbranded/generated/typetest-array/setup.py index 13f8be41beb..028cda94082 100644 --- a/packages/typespec-python/test/unbranded/generated/typetest-array/setup.py +++ b/packages/typespec-python/test/unbranded/generated/typetest-array/setup.py @@ -60,7 +60,7 @@ }, install_requires=[ "isodate<1.0.0,>=0.6.1", - "corehttp[requests]<1.0.0,>=1.0.0b3", + "corehttp[requests]", ], python_requires=">=3.8", ) diff --git a/packages/typespec-python/test/unbranded/generated/typetest-dictionary/setup.py b/packages/typespec-python/test/unbranded/generated/typetest-dictionary/setup.py index cad70681a5a..2bdee02151a 100644 --- a/packages/typespec-python/test/unbranded/generated/typetest-dictionary/setup.py +++ b/packages/typespec-python/test/unbranded/generated/typetest-dictionary/setup.py @@ -60,7 +60,7 @@ }, install_requires=[ "isodate<1.0.0,>=0.6.1", - "corehttp[requests]<1.0.0,>=1.0.0b3", + "corehttp[requests]", ], python_requires=">=3.8", ) diff --git a/packages/typespec-python/test/unbranded/generated/typetest-enum-extensible/setup.py b/packages/typespec-python/test/unbranded/generated/typetest-enum-extensible/setup.py index c9e4dc69dea..793c0a96268 100644 --- a/packages/typespec-python/test/unbranded/generated/typetest-enum-extensible/setup.py +++ b/packages/typespec-python/test/unbranded/generated/typetest-enum-extensible/setup.py @@ -61,7 +61,7 @@ }, install_requires=[ "isodate<1.0.0,>=0.6.1", - "corehttp[requests]<1.0.0,>=1.0.0b3", + "corehttp[requests]", ], python_requires=">=3.8", ) diff --git a/packages/typespec-python/test/unbranded/generated/typetest-enum-fixed/setup.py b/packages/typespec-python/test/unbranded/generated/typetest-enum-fixed/setup.py index af6016ea669..37154b2b604 100644 --- a/packages/typespec-python/test/unbranded/generated/typetest-enum-fixed/setup.py +++ b/packages/typespec-python/test/unbranded/generated/typetest-enum-fixed/setup.py @@ -61,7 +61,7 @@ }, install_requires=[ "isodate<1.0.0,>=0.6.1", - "corehttp[requests]<1.0.0,>=1.0.0b3", + "corehttp[requests]", ], python_requires=">=3.8", ) diff --git a/packages/typespec-python/test/unbranded/generated/typetest-model-empty/setup.py b/packages/typespec-python/test/unbranded/generated/typetest-model-empty/setup.py index d087132ae7e..2f3b9f7b517 100644 --- a/packages/typespec-python/test/unbranded/generated/typetest-model-empty/setup.py +++ b/packages/typespec-python/test/unbranded/generated/typetest-model-empty/setup.py @@ -61,7 +61,7 @@ }, install_requires=[ "isodate<1.0.0,>=0.6.1", - "corehttp[requests]<1.0.0,>=1.0.0b3", + "corehttp[requests]", ], python_requires=">=3.8", ) diff --git a/packages/typespec-python/test/unbranded/generated/typetest-model-enumdiscriminator/setup.py b/packages/typespec-python/test/unbranded/generated/typetest-model-enumdiscriminator/setup.py index 1522b3c648d..94780328001 100644 --- a/packages/typespec-python/test/unbranded/generated/typetest-model-enumdiscriminator/setup.py +++ b/packages/typespec-python/test/unbranded/generated/typetest-model-enumdiscriminator/setup.py @@ -61,7 +61,7 @@ }, install_requires=[ "isodate<1.0.0,>=0.6.1", - "corehttp[requests]<1.0.0,>=1.0.0b3", + "corehttp[requests]", ], python_requires=">=3.8", ) diff --git a/packages/typespec-python/test/unbranded/generated/typetest-model-nesteddiscriminator/setup.py b/packages/typespec-python/test/unbranded/generated/typetest-model-nesteddiscriminator/setup.py index 2ce2f1422c1..38d60d185c1 100644 --- a/packages/typespec-python/test/unbranded/generated/typetest-model-nesteddiscriminator/setup.py +++ b/packages/typespec-python/test/unbranded/generated/typetest-model-nesteddiscriminator/setup.py @@ -61,7 +61,7 @@ }, install_requires=[ "isodate<1.0.0,>=0.6.1", - "corehttp[requests]<1.0.0,>=1.0.0b3", + "corehttp[requests]", ], python_requires=">=3.8", ) diff --git a/packages/typespec-python/test/unbranded/generated/typetest-model-notdiscriminated/setup.py b/packages/typespec-python/test/unbranded/generated/typetest-model-notdiscriminated/setup.py index 60f22d7b682..6afcc482b64 100644 --- a/packages/typespec-python/test/unbranded/generated/typetest-model-notdiscriminated/setup.py +++ b/packages/typespec-python/test/unbranded/generated/typetest-model-notdiscriminated/setup.py @@ -61,7 +61,7 @@ }, install_requires=[ "isodate<1.0.0,>=0.6.1", - "corehttp[requests]<1.0.0,>=1.0.0b3", + "corehttp[requests]", ], python_requires=">=3.8", ) diff --git a/packages/typespec-python/test/unbranded/generated/typetest-model-recursive/setup.py b/packages/typespec-python/test/unbranded/generated/typetest-model-recursive/setup.py index c383f0a6a3e..4191c27f5ad 100644 --- a/packages/typespec-python/test/unbranded/generated/typetest-model-recursive/setup.py +++ b/packages/typespec-python/test/unbranded/generated/typetest-model-recursive/setup.py @@ -61,7 +61,7 @@ }, install_requires=[ "isodate<1.0.0,>=0.6.1", - "corehttp[requests]<1.0.0,>=1.0.0b3", + "corehttp[requests]", ], python_requires=">=3.8", ) diff --git a/packages/typespec-python/test/unbranded/generated/typetest-model-singlediscriminator/setup.py b/packages/typespec-python/test/unbranded/generated/typetest-model-singlediscriminator/setup.py index 21ff0830955..6ffe6cb9a2a 100644 --- a/packages/typespec-python/test/unbranded/generated/typetest-model-singlediscriminator/setup.py +++ b/packages/typespec-python/test/unbranded/generated/typetest-model-singlediscriminator/setup.py @@ -61,7 +61,7 @@ }, install_requires=[ "isodate<1.0.0,>=0.6.1", - "corehttp[requests]<1.0.0,>=1.0.0b3", + "corehttp[requests]", ], python_requires=">=3.8", ) diff --git a/packages/typespec-python/test/unbranded/generated/typetest-model-usage/setup.py b/packages/typespec-python/test/unbranded/generated/typetest-model-usage/setup.py index 408c5298c66..92725093f4b 100644 --- a/packages/typespec-python/test/unbranded/generated/typetest-model-usage/setup.py +++ b/packages/typespec-python/test/unbranded/generated/typetest-model-usage/setup.py @@ -61,7 +61,7 @@ }, install_requires=[ "isodate<1.0.0,>=0.6.1", - "corehttp[requests]<1.0.0,>=1.0.0b3", + "corehttp[requests]", ], python_requires=">=3.8", ) diff --git a/packages/typespec-python/test/unbranded/generated/typetest-model-visibility/setup.py b/packages/typespec-python/test/unbranded/generated/typetest-model-visibility/setup.py index c0e8d1ee62b..dc3b9d2677c 100644 --- a/packages/typespec-python/test/unbranded/generated/typetest-model-visibility/setup.py +++ b/packages/typespec-python/test/unbranded/generated/typetest-model-visibility/setup.py @@ -61,7 +61,7 @@ }, install_requires=[ "isodate<1.0.0,>=0.6.1", - "corehttp[requests]<1.0.0,>=1.0.0b3", + "corehttp[requests]", ], python_requires=">=3.8", ) diff --git a/packages/typespec-python/test/unbranded/generated/typetest-property-additionalproperties/setup.py b/packages/typespec-python/test/unbranded/generated/typetest-property-additionalproperties/setup.py index 86f0331d567..dd4149c9b28 100644 --- a/packages/typespec-python/test/unbranded/generated/typetest-property-additionalproperties/setup.py +++ b/packages/typespec-python/test/unbranded/generated/typetest-property-additionalproperties/setup.py @@ -61,7 +61,7 @@ }, install_requires=[ "isodate<1.0.0,>=0.6.1", - "corehttp[requests]<1.0.0,>=1.0.0b3", + "corehttp[requests]", ], python_requires=">=3.8", ) diff --git a/packages/typespec-python/test/unbranded/generated/typetest-property-nullable/setup.py b/packages/typespec-python/test/unbranded/generated/typetest-property-nullable/setup.py index af254d14611..746bcd0b2aa 100644 --- a/packages/typespec-python/test/unbranded/generated/typetest-property-nullable/setup.py +++ b/packages/typespec-python/test/unbranded/generated/typetest-property-nullable/setup.py @@ -61,7 +61,7 @@ }, install_requires=[ "isodate<1.0.0,>=0.6.1", - "corehttp[requests]<1.0.0,>=1.0.0b3", + "corehttp[requests]", ], python_requires=">=3.8", ) diff --git a/packages/typespec-python/test/unbranded/generated/typetest-property-optional/setup.py b/packages/typespec-python/test/unbranded/generated/typetest-property-optional/setup.py index 5001269cfca..07c1ee6f709 100644 --- a/packages/typespec-python/test/unbranded/generated/typetest-property-optional/setup.py +++ b/packages/typespec-python/test/unbranded/generated/typetest-property-optional/setup.py @@ -61,7 +61,7 @@ }, install_requires=[ "isodate<1.0.0,>=0.6.1", - "corehttp[requests]<1.0.0,>=1.0.0b3", + "corehttp[requests]", ], python_requires=">=3.8", ) diff --git a/packages/typespec-python/test/unbranded/generated/typetest-property-valuetypes/setup.py b/packages/typespec-python/test/unbranded/generated/typetest-property-valuetypes/setup.py index 81b459576f2..7f826b6cddf 100644 --- a/packages/typespec-python/test/unbranded/generated/typetest-property-valuetypes/setup.py +++ b/packages/typespec-python/test/unbranded/generated/typetest-property-valuetypes/setup.py @@ -61,7 +61,7 @@ }, install_requires=[ "isodate<1.0.0,>=0.6.1", - "corehttp[requests]<1.0.0,>=1.0.0b3", + "corehttp[requests]", ], python_requires=">=3.8", ) diff --git a/packages/typespec-python/test/unbranded/generated/typetest-scalar/setup.py b/packages/typespec-python/test/unbranded/generated/typetest-scalar/setup.py index 03c91cc0e13..c876d5bff2a 100644 --- a/packages/typespec-python/test/unbranded/generated/typetest-scalar/setup.py +++ b/packages/typespec-python/test/unbranded/generated/typetest-scalar/setup.py @@ -60,7 +60,7 @@ }, install_requires=[ "isodate<1.0.0,>=0.6.1", - "corehttp[requests]<1.0.0,>=1.0.0b3", + "corehttp[requests]", ], python_requires=">=3.8", ) diff --git a/packages/typespec-python/test/unbranded/generated/typetest-union/setup.py b/packages/typespec-python/test/unbranded/generated/typetest-union/setup.py index 44e03fc7f30..efa92786ad5 100644 --- a/packages/typespec-python/test/unbranded/generated/typetest-union/setup.py +++ b/packages/typespec-python/test/unbranded/generated/typetest-union/setup.py @@ -60,7 +60,7 @@ }, install_requires=[ "isodate<1.0.0,>=0.6.1", - "corehttp[requests]<1.0.0,>=1.0.0b3", + "corehttp[requests]", ], python_requires=">=3.8", ) From 2533326dd2250967fdf214c88641f72ca8be7230 Mon Sep 17 00:00:00 2001 From: iscai-msft Date: Thu, 1 Feb 2024 19:51:41 -0500 Subject: [PATCH 37/45] mypy fix --- .../autorest/codegen/models/parameter.py | 1 + .../codegen/serializers/builder_serializer.py | 2 +- .../multipart/aio/operations/_operations.py | 14 +++++++------- .../payload/multipart/operations/_operations.py | 14 +++++++------- .../multipart/aio/operations/_operations.py | 14 +++++++------- .../payload/multipart/operations/_operations.py | 14 +++++++------- 6 files changed, 30 insertions(+), 29 deletions(-) diff --git a/packages/autorest.python/autorest/codegen/models/parameter.py b/packages/autorest.python/autorest/codegen/models/parameter.py index 5380c91d80b..a8d07063970 100644 --- a/packages/autorest.python/autorest/codegen/models/parameter.py +++ b/packages/autorest.python/autorest/codegen/models/parameter.py @@ -299,6 +299,7 @@ def imports(self, async_mode: bool, **kwargs: Any) -> FileImport: ) file_import.add_submodule_import("typing", "Dict", ImportType.STDLIB) file_import.add_submodule_import("typing", "Any", ImportType.STDLIB) + file_import.add_submodule_import("typing", "List", ImportType.STDLIB) return file_import @classmethod diff --git a/packages/autorest.python/autorest/codegen/serializers/builder_serializer.py b/packages/autorest.python/autorest/codegen/serializers/builder_serializer.py index 863465e3a11..850489c1bb6 100644 --- a/packages/autorest.python/autorest/codegen/serializers/builder_serializer.py +++ b/packages/autorest.python/autorest/codegen/serializers/builder_serializer.py @@ -761,7 +761,7 @@ def _serialize_body_parameter(self, builder: OperationType) -> List[str]: f" if isinstance({body_param.client_name}, _model_base.Model) else", f" {body_param.client_name}", ")", - "_files: FilesType = []", + "_files: List[FilesType] = []", "_data: Dict[str, Any] = {}", ] ) diff --git a/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/aio/operations/_operations.py b/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/aio/operations/_operations.py index 43034324490..e9f11b5d19c 100644 --- a/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/aio/operations/_operations.py +++ b/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/aio/operations/_operations.py @@ -8,7 +8,7 @@ # -------------------------------------------------------------------------- import json import sys -from typing import Any, Callable, Dict, Optional, TypeVar, Union, overload +from typing import Any, Callable, Dict, List, Optional, TypeVar, Union, overload from azure.core.exceptions import ( ClientAuthenticationError, @@ -128,7 +128,7 @@ async def basic( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) _body = body.as_dict() if isinstance(body, _model_base.Model) else body - _files: FilesType = [] + _files: List[FilesType] = [] _data: Dict[str, Any] = {} if _body.get("id") is not None: _data["id"] = _body["id"] @@ -245,7 +245,7 @@ async def complex( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) _body = body.as_dict() if isinstance(body, _model_base.Model) else body - _files: FilesType = [] + _files: List[FilesType] = [] _data: Dict[str, Any] = {} if _body.get("id") is not None: _data["id"] = _body["id"] @@ -356,7 +356,7 @@ async def json_part( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) _body = body.as_dict() if isinstance(body, _model_base.Model) else body - _files: FilesType = [] + _files: List[FilesType] = [] _data: Dict[str, Any] = {} if _body.get("address") is not None: _data["address"] = json.dumps(_body["address"], cls=SdkJSONEncoder, exclude_readonly=True) @@ -457,7 +457,7 @@ async def binary_array_parts( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) _body = body.as_dict() if isinstance(body, _model_base.Model) else body - _files: FilesType = [] + _files: List[FilesType] = [] _data: Dict[str, Any] = {} if _body.get("id") is not None: _data["id"] = _body["id"] @@ -566,7 +566,7 @@ async def json_array_parts( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) _body = body.as_dict() if isinstance(body, _model_base.Model) else body - _files: FilesType = [] + _files: List[FilesType] = [] _data: Dict[str, Any] = {} if _body.get("profileImage") is not None: _files.append(("profileImage", _body["profileImage"])) @@ -669,7 +669,7 @@ async def multi_binary_parts( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) _body = body.as_dict() if isinstance(body, _model_base.Model) else body - _files: FilesType = [] + _files: List[FilesType] = [] _data: Dict[str, Any] = {} if _body.get("profileImage") is not None: _files.append(("profileImage", _body["profileImage"])) diff --git a/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/operations/_operations.py b/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/operations/_operations.py index cb2dc7df0a0..a4ef86ebeb1 100644 --- a/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/operations/_operations.py +++ b/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/operations/_operations.py @@ -8,7 +8,7 @@ # -------------------------------------------------------------------------- import json import sys -from typing import Any, Callable, Dict, Optional, TypeVar, Union, overload +from typing import Any, Callable, Dict, List, Optional, TypeVar, Union, overload from azure.core.exceptions import ( ClientAuthenticationError, @@ -179,7 +179,7 @@ def basic( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) _body = body.as_dict() if isinstance(body, _model_base.Model) else body - _files: FilesType = [] + _files: List[FilesType] = [] _data: Dict[str, Any] = {} if _body.get("id") is not None: _data["id"] = _body["id"] @@ -296,7 +296,7 @@ def complex( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) _body = body.as_dict() if isinstance(body, _model_base.Model) else body - _files: FilesType = [] + _files: List[FilesType] = [] _data: Dict[str, Any] = {} if _body.get("id") is not None: _data["id"] = _body["id"] @@ -407,7 +407,7 @@ def json_part( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) _body = body.as_dict() if isinstance(body, _model_base.Model) else body - _files: FilesType = [] + _files: List[FilesType] = [] _data: Dict[str, Any] = {} if _body.get("address") is not None: _data["address"] = json.dumps(_body["address"], cls=SdkJSONEncoder, exclude_readonly=True) @@ -506,7 +506,7 @@ def binary_array_parts( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) _body = body.as_dict() if isinstance(body, _model_base.Model) else body - _files: FilesType = [] + _files: List[FilesType] = [] _data: Dict[str, Any] = {} if _body.get("id") is not None: _data["id"] = _body["id"] @@ -613,7 +613,7 @@ def json_array_parts( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) _body = body.as_dict() if isinstance(body, _model_base.Model) else body - _files: FilesType = [] + _files: List[FilesType] = [] _data: Dict[str, Any] = {} if _body.get("profileImage") is not None: _files.append(("profileImage", _body["profileImage"])) @@ -714,7 +714,7 @@ def multi_binary_parts( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) _body = body.as_dict() if isinstance(body, _model_base.Model) else body - _files: FilesType = [] + _files: List[FilesType] = [] _data: Dict[str, Any] = {} if _body.get("profileImage") is not None: _files.append(("profileImage", _body["profileImage"])) diff --git a/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/aio/operations/_operations.py b/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/aio/operations/_operations.py index f084d1ef3bd..1db9e201070 100644 --- a/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/aio/operations/_operations.py +++ b/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/aio/operations/_operations.py @@ -8,7 +8,7 @@ # -------------------------------------------------------------------------- import json import sys -from typing import Any, Callable, Dict, Optional, TypeVar, Union, overload +from typing import Any, Callable, Dict, List, Optional, TypeVar, Union, overload from corehttp.exceptions import ( ClientAuthenticationError, @@ -126,7 +126,7 @@ async def basic( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) _body = body.as_dict() if isinstance(body, _model_base.Model) else body - _files: FilesType = [] + _files: List[FilesType] = [] _data: Dict[str, Any] = {} if _body.get("id") is not None: _data["id"] = _body["id"] @@ -242,7 +242,7 @@ async def complex( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) _body = body.as_dict() if isinstance(body, _model_base.Model) else body - _files: FilesType = [] + _files: List[FilesType] = [] _data: Dict[str, Any] = {} if _body.get("id") is not None: _data["id"] = _body["id"] @@ -352,7 +352,7 @@ async def json_part( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) _body = body.as_dict() if isinstance(body, _model_base.Model) else body - _files: FilesType = [] + _files: List[FilesType] = [] _data: Dict[str, Any] = {} if _body.get("address") is not None: _data["address"] = json.dumps(_body["address"], cls=SdkJSONEncoder, exclude_readonly=True) @@ -452,7 +452,7 @@ async def binary_array_parts( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) _body = body.as_dict() if isinstance(body, _model_base.Model) else body - _files: FilesType = [] + _files: List[FilesType] = [] _data: Dict[str, Any] = {} if _body.get("id") is not None: _data["id"] = _body["id"] @@ -560,7 +560,7 @@ async def json_array_parts( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) _body = body.as_dict() if isinstance(body, _model_base.Model) else body - _files: FilesType = [] + _files: List[FilesType] = [] _data: Dict[str, Any] = {} if _body.get("profileImage") is not None: _files.append(("profileImage", _body["profileImage"])) @@ -662,7 +662,7 @@ async def multi_binary_parts( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) _body = body.as_dict() if isinstance(body, _model_base.Model) else body - _files: FilesType = [] + _files: List[FilesType] = [] _data: Dict[str, Any] = {} if _body.get("profileImage") is not None: _files.append(("profileImage", _body["profileImage"])) diff --git a/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/operations/_operations.py b/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/operations/_operations.py index 6f15f51d7e6..d11d9623577 100644 --- a/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/operations/_operations.py +++ b/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/operations/_operations.py @@ -8,7 +8,7 @@ # -------------------------------------------------------------------------- import json import sys -from typing import Any, Callable, Dict, Optional, TypeVar, Union, overload +from typing import Any, Callable, Dict, List, Optional, TypeVar, Union, overload from corehttp.exceptions import ( ClientAuthenticationError, @@ -177,7 +177,7 @@ def basic( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) _body = body.as_dict() if isinstance(body, _model_base.Model) else body - _files: FilesType = [] + _files: List[FilesType] = [] _data: Dict[str, Any] = {} if _body.get("id") is not None: _data["id"] = _body["id"] @@ -293,7 +293,7 @@ def complex( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) _body = body.as_dict() if isinstance(body, _model_base.Model) else body - _files: FilesType = [] + _files: List[FilesType] = [] _data: Dict[str, Any] = {} if _body.get("id") is not None: _data["id"] = _body["id"] @@ -403,7 +403,7 @@ def json_part( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) _body = body.as_dict() if isinstance(body, _model_base.Model) else body - _files: FilesType = [] + _files: List[FilesType] = [] _data: Dict[str, Any] = {} if _body.get("address") is not None: _data["address"] = json.dumps(_body["address"], cls=SdkJSONEncoder, exclude_readonly=True) @@ -501,7 +501,7 @@ def binary_array_parts( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) _body = body.as_dict() if isinstance(body, _model_base.Model) else body - _files: FilesType = [] + _files: List[FilesType] = [] _data: Dict[str, Any] = {} if _body.get("id") is not None: _data["id"] = _body["id"] @@ -607,7 +607,7 @@ def json_array_parts( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) _body = body.as_dict() if isinstance(body, _model_base.Model) else body - _files: FilesType = [] + _files: List[FilesType] = [] _data: Dict[str, Any] = {} if _body.get("profileImage") is not None: _files.append(("profileImage", _body["profileImage"])) @@ -707,7 +707,7 @@ def multi_binary_parts( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) _body = body.as_dict() if isinstance(body, _model_base.Model) else body - _files: FilesType = [] + _files: List[FilesType] = [] _data: Dict[str, Any] = {} if _body.get("profileImage") is not None: _files.append(("profileImage", _body["profileImage"])) From c15d6b4f5839cdad084319fbed82bdcafdf74706 Mon Sep 17 00:00:00 2001 From: iscai-msft Date: Fri, 2 Feb 2024 13:11:24 -0500 Subject: [PATCH 38/45] use FilesType typing for _files --- .../autorest/codegen/models/parameter.py | 1 - .../codegen/serializers/builder_serializer.py | 2 +- .../multipart/aio/operations/_operations.py | 14 +++++++------- .../payload/multipart/operations/_operations.py | 14 +++++++------- .../multipart/aio/operations/_operations.py | 14 +++++++------- .../payload/multipart/operations/_operations.py | 14 +++++++------- 6 files changed, 29 insertions(+), 30 deletions(-) diff --git a/packages/autorest.python/autorest/codegen/models/parameter.py b/packages/autorest.python/autorest/codegen/models/parameter.py index a8d07063970..5380c91d80b 100644 --- a/packages/autorest.python/autorest/codegen/models/parameter.py +++ b/packages/autorest.python/autorest/codegen/models/parameter.py @@ -299,7 +299,6 @@ def imports(self, async_mode: bool, **kwargs: Any) -> FileImport: ) file_import.add_submodule_import("typing", "Dict", ImportType.STDLIB) file_import.add_submodule_import("typing", "Any", ImportType.STDLIB) - file_import.add_submodule_import("typing", "List", ImportType.STDLIB) return file_import @classmethod diff --git a/packages/autorest.python/autorest/codegen/serializers/builder_serializer.py b/packages/autorest.python/autorest/codegen/serializers/builder_serializer.py index 850489c1bb6..863465e3a11 100644 --- a/packages/autorest.python/autorest/codegen/serializers/builder_serializer.py +++ b/packages/autorest.python/autorest/codegen/serializers/builder_serializer.py @@ -761,7 +761,7 @@ def _serialize_body_parameter(self, builder: OperationType) -> List[str]: f" if isinstance({body_param.client_name}, _model_base.Model) else", f" {body_param.client_name}", ")", - "_files: List[FilesType] = []", + "_files: FilesType = []", "_data: Dict[str, Any] = {}", ] ) diff --git a/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/aio/operations/_operations.py b/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/aio/operations/_operations.py index e9f11b5d19c..43034324490 100644 --- a/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/aio/operations/_operations.py +++ b/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/aio/operations/_operations.py @@ -8,7 +8,7 @@ # -------------------------------------------------------------------------- import json import sys -from typing import Any, Callable, Dict, List, Optional, TypeVar, Union, overload +from typing import Any, Callable, Dict, Optional, TypeVar, Union, overload from azure.core.exceptions import ( ClientAuthenticationError, @@ -128,7 +128,7 @@ async def basic( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) _body = body.as_dict() if isinstance(body, _model_base.Model) else body - _files: List[FilesType] = [] + _files: FilesType = [] _data: Dict[str, Any] = {} if _body.get("id") is not None: _data["id"] = _body["id"] @@ -245,7 +245,7 @@ async def complex( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) _body = body.as_dict() if isinstance(body, _model_base.Model) else body - _files: List[FilesType] = [] + _files: FilesType = [] _data: Dict[str, Any] = {} if _body.get("id") is not None: _data["id"] = _body["id"] @@ -356,7 +356,7 @@ async def json_part( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) _body = body.as_dict() if isinstance(body, _model_base.Model) else body - _files: List[FilesType] = [] + _files: FilesType = [] _data: Dict[str, Any] = {} if _body.get("address") is not None: _data["address"] = json.dumps(_body["address"], cls=SdkJSONEncoder, exclude_readonly=True) @@ -457,7 +457,7 @@ async def binary_array_parts( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) _body = body.as_dict() if isinstance(body, _model_base.Model) else body - _files: List[FilesType] = [] + _files: FilesType = [] _data: Dict[str, Any] = {} if _body.get("id") is not None: _data["id"] = _body["id"] @@ -566,7 +566,7 @@ async def json_array_parts( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) _body = body.as_dict() if isinstance(body, _model_base.Model) else body - _files: List[FilesType] = [] + _files: FilesType = [] _data: Dict[str, Any] = {} if _body.get("profileImage") is not None: _files.append(("profileImage", _body["profileImage"])) @@ -669,7 +669,7 @@ async def multi_binary_parts( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) _body = body.as_dict() if isinstance(body, _model_base.Model) else body - _files: List[FilesType] = [] + _files: FilesType = [] _data: Dict[str, Any] = {} if _body.get("profileImage") is not None: _files.append(("profileImage", _body["profileImage"])) diff --git a/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/operations/_operations.py b/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/operations/_operations.py index a4ef86ebeb1..cb2dc7df0a0 100644 --- a/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/operations/_operations.py +++ b/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/operations/_operations.py @@ -8,7 +8,7 @@ # -------------------------------------------------------------------------- import json import sys -from typing import Any, Callable, Dict, List, Optional, TypeVar, Union, overload +from typing import Any, Callable, Dict, Optional, TypeVar, Union, overload from azure.core.exceptions import ( ClientAuthenticationError, @@ -179,7 +179,7 @@ def basic( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) _body = body.as_dict() if isinstance(body, _model_base.Model) else body - _files: List[FilesType] = [] + _files: FilesType = [] _data: Dict[str, Any] = {} if _body.get("id") is not None: _data["id"] = _body["id"] @@ -296,7 +296,7 @@ def complex( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) _body = body.as_dict() if isinstance(body, _model_base.Model) else body - _files: List[FilesType] = [] + _files: FilesType = [] _data: Dict[str, Any] = {} if _body.get("id") is not None: _data["id"] = _body["id"] @@ -407,7 +407,7 @@ def json_part( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) _body = body.as_dict() if isinstance(body, _model_base.Model) else body - _files: List[FilesType] = [] + _files: FilesType = [] _data: Dict[str, Any] = {} if _body.get("address") is not None: _data["address"] = json.dumps(_body["address"], cls=SdkJSONEncoder, exclude_readonly=True) @@ -506,7 +506,7 @@ def binary_array_parts( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) _body = body.as_dict() if isinstance(body, _model_base.Model) else body - _files: List[FilesType] = [] + _files: FilesType = [] _data: Dict[str, Any] = {} if _body.get("id") is not None: _data["id"] = _body["id"] @@ -613,7 +613,7 @@ def json_array_parts( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) _body = body.as_dict() if isinstance(body, _model_base.Model) else body - _files: List[FilesType] = [] + _files: FilesType = [] _data: Dict[str, Any] = {} if _body.get("profileImage") is not None: _files.append(("profileImage", _body["profileImage"])) @@ -714,7 +714,7 @@ def multi_binary_parts( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) _body = body.as_dict() if isinstance(body, _model_base.Model) else body - _files: List[FilesType] = [] + _files: FilesType = [] _data: Dict[str, Any] = {} if _body.get("profileImage") is not None: _files.append(("profileImage", _body["profileImage"])) diff --git a/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/aio/operations/_operations.py b/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/aio/operations/_operations.py index 1db9e201070..f084d1ef3bd 100644 --- a/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/aio/operations/_operations.py +++ b/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/aio/operations/_operations.py @@ -8,7 +8,7 @@ # -------------------------------------------------------------------------- import json import sys -from typing import Any, Callable, Dict, List, Optional, TypeVar, Union, overload +from typing import Any, Callable, Dict, Optional, TypeVar, Union, overload from corehttp.exceptions import ( ClientAuthenticationError, @@ -126,7 +126,7 @@ async def basic( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) _body = body.as_dict() if isinstance(body, _model_base.Model) else body - _files: List[FilesType] = [] + _files: FilesType = [] _data: Dict[str, Any] = {} if _body.get("id") is not None: _data["id"] = _body["id"] @@ -242,7 +242,7 @@ async def complex( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) _body = body.as_dict() if isinstance(body, _model_base.Model) else body - _files: List[FilesType] = [] + _files: FilesType = [] _data: Dict[str, Any] = {} if _body.get("id") is not None: _data["id"] = _body["id"] @@ -352,7 +352,7 @@ async def json_part( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) _body = body.as_dict() if isinstance(body, _model_base.Model) else body - _files: List[FilesType] = [] + _files: FilesType = [] _data: Dict[str, Any] = {} if _body.get("address") is not None: _data["address"] = json.dumps(_body["address"], cls=SdkJSONEncoder, exclude_readonly=True) @@ -452,7 +452,7 @@ async def binary_array_parts( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) _body = body.as_dict() if isinstance(body, _model_base.Model) else body - _files: List[FilesType] = [] + _files: FilesType = [] _data: Dict[str, Any] = {} if _body.get("id") is not None: _data["id"] = _body["id"] @@ -560,7 +560,7 @@ async def json_array_parts( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) _body = body.as_dict() if isinstance(body, _model_base.Model) else body - _files: List[FilesType] = [] + _files: FilesType = [] _data: Dict[str, Any] = {} if _body.get("profileImage") is not None: _files.append(("profileImage", _body["profileImage"])) @@ -662,7 +662,7 @@ async def multi_binary_parts( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) _body = body.as_dict() if isinstance(body, _model_base.Model) else body - _files: List[FilesType] = [] + _files: FilesType = [] _data: Dict[str, Any] = {} if _body.get("profileImage") is not None: _files.append(("profileImage", _body["profileImage"])) diff --git a/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/operations/_operations.py b/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/operations/_operations.py index d11d9623577..6f15f51d7e6 100644 --- a/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/operations/_operations.py +++ b/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/operations/_operations.py @@ -8,7 +8,7 @@ # -------------------------------------------------------------------------- import json import sys -from typing import Any, Callable, Dict, List, Optional, TypeVar, Union, overload +from typing import Any, Callable, Dict, Optional, TypeVar, Union, overload from corehttp.exceptions import ( ClientAuthenticationError, @@ -177,7 +177,7 @@ def basic( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) _body = body.as_dict() if isinstance(body, _model_base.Model) else body - _files: List[FilesType] = [] + _files: FilesType = [] _data: Dict[str, Any] = {} if _body.get("id") is not None: _data["id"] = _body["id"] @@ -293,7 +293,7 @@ def complex( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) _body = body.as_dict() if isinstance(body, _model_base.Model) else body - _files: List[FilesType] = [] + _files: FilesType = [] _data: Dict[str, Any] = {} if _body.get("id") is not None: _data["id"] = _body["id"] @@ -403,7 +403,7 @@ def json_part( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) _body = body.as_dict() if isinstance(body, _model_base.Model) else body - _files: List[FilesType] = [] + _files: FilesType = [] _data: Dict[str, Any] = {} if _body.get("address") is not None: _data["address"] = json.dumps(_body["address"], cls=SdkJSONEncoder, exclude_readonly=True) @@ -501,7 +501,7 @@ def binary_array_parts( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) _body = body.as_dict() if isinstance(body, _model_base.Model) else body - _files: List[FilesType] = [] + _files: FilesType = [] _data: Dict[str, Any] = {} if _body.get("id") is not None: _data["id"] = _body["id"] @@ -607,7 +607,7 @@ def json_array_parts( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) _body = body.as_dict() if isinstance(body, _model_base.Model) else body - _files: List[FilesType] = [] + _files: FilesType = [] _data: Dict[str, Any] = {} if _body.get("profileImage") is not None: _files.append(("profileImage", _body["profileImage"])) @@ -707,7 +707,7 @@ def multi_binary_parts( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) _body = body.as_dict() if isinstance(body, _model_base.Model) else body - _files: List[FilesType] = [] + _files: FilesType = [] _data: Dict[str, Any] = {} if _body.get("profileImage") is not None: _files.append(("profileImage", _body["profileImage"])) From 43520d4f09c3b00a105328ef3b8e1599b89d5bb1 Mon Sep 17 00:00:00 2001 From: iscai-msft Date: Fri, 2 Feb 2024 13:25:20 -0500 Subject: [PATCH 39/45] fix mypy hopefully --- .../autorest/codegen/models/parameter.py | 5 ++--- .../codegen/serializers/builder_serializer.py | 2 +- .../multipart/aio/operations/_operations.py | 16 ++++++++-------- .../payload/multipart/operations/_operations.py | 16 ++++++++-------- .../multipart/aio/operations/_operations.py | 16 ++++++++-------- .../payload/multipart/operations/_operations.py | 16 ++++++++-------- 6 files changed, 35 insertions(+), 36 deletions(-) diff --git a/packages/autorest.python/autorest/codegen/models/parameter.py b/packages/autorest.python/autorest/codegen/models/parameter.py index 5380c91d80b..8176f25e1c3 100644 --- a/packages/autorest.python/autorest/codegen/models/parameter.py +++ b/packages/autorest.python/autorest/codegen/models/parameter.py @@ -294,11 +294,10 @@ def imports(self, async_mode: bool, **kwargs: Any) -> FileImport: file_import = super().imports(async_mode, **kwargs) if self.is_form_data: relative_path = "..." if async_mode else ".." - file_import.add_submodule_import( - f"{relative_path}_vendor", "FilesType", ImportType.LOCAL - ) + file_import.add_submodule_import(f"{relative_path}vendor", "FileType", ImportType.LOCAL) file_import.add_submodule_import("typing", "Dict", ImportType.STDLIB) file_import.add_submodule_import("typing", "Any", ImportType.STDLIB) + file_import.add_submodule_import("typing", "List", ImportType.STDLIB) return file_import @classmethod diff --git a/packages/autorest.python/autorest/codegen/serializers/builder_serializer.py b/packages/autorest.python/autorest/codegen/serializers/builder_serializer.py index 863465e3a11..694c46a7f03 100644 --- a/packages/autorest.python/autorest/codegen/serializers/builder_serializer.py +++ b/packages/autorest.python/autorest/codegen/serializers/builder_serializer.py @@ -761,7 +761,7 @@ def _serialize_body_parameter(self, builder: OperationType) -> List[str]: f" if isinstance({body_param.client_name}, _model_base.Model) else", f" {body_param.client_name}", ")", - "_files: FilesType = []", + "_files: List[FileType] = []", "_data: Dict[str, Any] = {}", ] ) diff --git a/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/aio/operations/_operations.py b/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/aio/operations/_operations.py index 43034324490..030f592384a 100644 --- a/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/aio/operations/_operations.py +++ b/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/aio/operations/_operations.py @@ -8,7 +8,7 @@ # -------------------------------------------------------------------------- import json import sys -from typing import Any, Callable, Dict, Optional, TypeVar, Union, overload +from typing import Any, Callable, Dict, List, Optional, TypeVar, Union, overload from azure.core.exceptions import ( ClientAuthenticationError, @@ -24,7 +24,6 @@ from ... import _model_base, models as _models from ..._model_base import SdkJSONEncoder -from ..._vendor import FilesType from ...operations._operations import ( build_form_data_basic_request, build_form_data_binary_array_parts_request, @@ -33,6 +32,7 @@ build_form_data_json_part_request, build_form_data_multi_binary_parts_request, ) +from ...vendor import FileType if sys.version_info >= (3, 9): from collections.abc import MutableMapping @@ -128,7 +128,7 @@ async def basic( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) _body = body.as_dict() if isinstance(body, _model_base.Model) else body - _files: FilesType = [] + _files: List[FileType] = [] _data: Dict[str, Any] = {} if _body.get("id") is not None: _data["id"] = _body["id"] @@ -245,7 +245,7 @@ async def complex( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) _body = body.as_dict() if isinstance(body, _model_base.Model) else body - _files: FilesType = [] + _files: List[FileType] = [] _data: Dict[str, Any] = {} if _body.get("id") is not None: _data["id"] = _body["id"] @@ -356,7 +356,7 @@ async def json_part( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) _body = body.as_dict() if isinstance(body, _model_base.Model) else body - _files: FilesType = [] + _files: List[FileType] = [] _data: Dict[str, Any] = {} if _body.get("address") is not None: _data["address"] = json.dumps(_body["address"], cls=SdkJSONEncoder, exclude_readonly=True) @@ -457,7 +457,7 @@ async def binary_array_parts( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) _body = body.as_dict() if isinstance(body, _model_base.Model) else body - _files: FilesType = [] + _files: List[FileType] = [] _data: Dict[str, Any] = {} if _body.get("id") is not None: _data["id"] = _body["id"] @@ -566,7 +566,7 @@ async def json_array_parts( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) _body = body.as_dict() if isinstance(body, _model_base.Model) else body - _files: FilesType = [] + _files: List[FileType] = [] _data: Dict[str, Any] = {} if _body.get("profileImage") is not None: _files.append(("profileImage", _body["profileImage"])) @@ -669,7 +669,7 @@ async def multi_binary_parts( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) _body = body.as_dict() if isinstance(body, _model_base.Model) else body - _files: FilesType = [] + _files: List[FileType] = [] _data: Dict[str, Any] = {} if _body.get("profileImage") is not None: _files.append(("profileImage", _body["profileImage"])) diff --git a/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/operations/_operations.py b/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/operations/_operations.py index cb2dc7df0a0..890c76501f0 100644 --- a/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/operations/_operations.py +++ b/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/operations/_operations.py @@ -8,7 +8,7 @@ # -------------------------------------------------------------------------- import json import sys -from typing import Any, Callable, Dict, Optional, TypeVar, Union, overload +from typing import Any, Callable, Dict, List, Optional, TypeVar, Union, overload from azure.core.exceptions import ( ClientAuthenticationError, @@ -26,7 +26,7 @@ from .. import _model_base, models as _models from .._model_base import SdkJSONEncoder from .._serialization import Serializer -from .._vendor import FilesType +from ..vendor import FileType if sys.version_info >= (3, 9): from collections.abc import MutableMapping @@ -179,7 +179,7 @@ def basic( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) _body = body.as_dict() if isinstance(body, _model_base.Model) else body - _files: FilesType = [] + _files: List[FileType] = [] _data: Dict[str, Any] = {} if _body.get("id") is not None: _data["id"] = _body["id"] @@ -296,7 +296,7 @@ def complex( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) _body = body.as_dict() if isinstance(body, _model_base.Model) else body - _files: FilesType = [] + _files: List[FileType] = [] _data: Dict[str, Any] = {} if _body.get("id") is not None: _data["id"] = _body["id"] @@ -407,7 +407,7 @@ def json_part( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) _body = body.as_dict() if isinstance(body, _model_base.Model) else body - _files: FilesType = [] + _files: List[FileType] = [] _data: Dict[str, Any] = {} if _body.get("address") is not None: _data["address"] = json.dumps(_body["address"], cls=SdkJSONEncoder, exclude_readonly=True) @@ -506,7 +506,7 @@ def binary_array_parts( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) _body = body.as_dict() if isinstance(body, _model_base.Model) else body - _files: FilesType = [] + _files: List[FileType] = [] _data: Dict[str, Any] = {} if _body.get("id") is not None: _data["id"] = _body["id"] @@ -613,7 +613,7 @@ def json_array_parts( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) _body = body.as_dict() if isinstance(body, _model_base.Model) else body - _files: FilesType = [] + _files: List[FileType] = [] _data: Dict[str, Any] = {} if _body.get("profileImage") is not None: _files.append(("profileImage", _body["profileImage"])) @@ -714,7 +714,7 @@ def multi_binary_parts( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) _body = body.as_dict() if isinstance(body, _model_base.Model) else body - _files: FilesType = [] + _files: List[FileType] = [] _data: Dict[str, Any] = {} if _body.get("profileImage") is not None: _files.append(("profileImage", _body["profileImage"])) diff --git a/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/aio/operations/_operations.py b/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/aio/operations/_operations.py index f084d1ef3bd..910a4d5bcea 100644 --- a/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/aio/operations/_operations.py +++ b/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/aio/operations/_operations.py @@ -8,7 +8,7 @@ # -------------------------------------------------------------------------- import json import sys -from typing import Any, Callable, Dict, Optional, TypeVar, Union, overload +from typing import Any, Callable, Dict, List, Optional, TypeVar, Union, overload from corehttp.exceptions import ( ClientAuthenticationError, @@ -23,7 +23,6 @@ from ... import _model_base, models as _models from ..._model_base import SdkJSONEncoder -from ..._vendor import FilesType from ...operations._operations import ( build_form_data_basic_request, build_form_data_binary_array_parts_request, @@ -32,6 +31,7 @@ build_form_data_json_part_request, build_form_data_multi_binary_parts_request, ) +from ...vendor import FileType if sys.version_info >= (3, 9): from collections.abc import MutableMapping @@ -126,7 +126,7 @@ async def basic( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) _body = body.as_dict() if isinstance(body, _model_base.Model) else body - _files: FilesType = [] + _files: List[FileType] = [] _data: Dict[str, Any] = {} if _body.get("id") is not None: _data["id"] = _body["id"] @@ -242,7 +242,7 @@ async def complex( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) _body = body.as_dict() if isinstance(body, _model_base.Model) else body - _files: FilesType = [] + _files: List[FileType] = [] _data: Dict[str, Any] = {} if _body.get("id") is not None: _data["id"] = _body["id"] @@ -352,7 +352,7 @@ async def json_part( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) _body = body.as_dict() if isinstance(body, _model_base.Model) else body - _files: FilesType = [] + _files: List[FileType] = [] _data: Dict[str, Any] = {} if _body.get("address") is not None: _data["address"] = json.dumps(_body["address"], cls=SdkJSONEncoder, exclude_readonly=True) @@ -452,7 +452,7 @@ async def binary_array_parts( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) _body = body.as_dict() if isinstance(body, _model_base.Model) else body - _files: FilesType = [] + _files: List[FileType] = [] _data: Dict[str, Any] = {} if _body.get("id") is not None: _data["id"] = _body["id"] @@ -560,7 +560,7 @@ async def json_array_parts( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) _body = body.as_dict() if isinstance(body, _model_base.Model) else body - _files: FilesType = [] + _files: List[FileType] = [] _data: Dict[str, Any] = {} if _body.get("profileImage") is not None: _files.append(("profileImage", _body["profileImage"])) @@ -662,7 +662,7 @@ async def multi_binary_parts( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) _body = body.as_dict() if isinstance(body, _model_base.Model) else body - _files: FilesType = [] + _files: List[FileType] = [] _data: Dict[str, Any] = {} if _body.get("profileImage") is not None: _files.append(("profileImage", _body["profileImage"])) diff --git a/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/operations/_operations.py b/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/operations/_operations.py index 6f15f51d7e6..d3792d7a6f7 100644 --- a/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/operations/_operations.py +++ b/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/operations/_operations.py @@ -8,7 +8,7 @@ # -------------------------------------------------------------------------- import json import sys -from typing import Any, Callable, Dict, Optional, TypeVar, Union, overload +from typing import Any, Callable, Dict, List, Optional, TypeVar, Union, overload from corehttp.exceptions import ( ClientAuthenticationError, @@ -25,7 +25,7 @@ from .. import _model_base, models as _models from .._model_base import SdkJSONEncoder from .._serialization import Serializer -from .._vendor import FilesType +from ..vendor import FileType if sys.version_info >= (3, 9): from collections.abc import MutableMapping @@ -177,7 +177,7 @@ def basic( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) _body = body.as_dict() if isinstance(body, _model_base.Model) else body - _files: FilesType = [] + _files: List[FileType] = [] _data: Dict[str, Any] = {} if _body.get("id") is not None: _data["id"] = _body["id"] @@ -293,7 +293,7 @@ def complex( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) _body = body.as_dict() if isinstance(body, _model_base.Model) else body - _files: FilesType = [] + _files: List[FileType] = [] _data: Dict[str, Any] = {} if _body.get("id") is not None: _data["id"] = _body["id"] @@ -403,7 +403,7 @@ def json_part( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) _body = body.as_dict() if isinstance(body, _model_base.Model) else body - _files: FilesType = [] + _files: List[FileType] = [] _data: Dict[str, Any] = {} if _body.get("address") is not None: _data["address"] = json.dumps(_body["address"], cls=SdkJSONEncoder, exclude_readonly=True) @@ -501,7 +501,7 @@ def binary_array_parts( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) _body = body.as_dict() if isinstance(body, _model_base.Model) else body - _files: FilesType = [] + _files: List[FileType] = [] _data: Dict[str, Any] = {} if _body.get("id") is not None: _data["id"] = _body["id"] @@ -607,7 +607,7 @@ def json_array_parts( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) _body = body.as_dict() if isinstance(body, _model_base.Model) else body - _files: FilesType = [] + _files: List[FileType] = [] _data: Dict[str, Any] = {} if _body.get("profileImage") is not None: _files.append(("profileImage", _body["profileImage"])) @@ -707,7 +707,7 @@ def multi_binary_parts( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) _body = body.as_dict() if isinstance(body, _model_base.Model) else body - _files: FilesType = [] + _files: List[FileType] = [] _data: Dict[str, Any] = {} if _body.get("profileImage") is not None: _files.append(("profileImage", _body["profileImage"])) From e8d1b7a07b809e91296623b2700b6b22cd26842b Mon Sep 17 00:00:00 2001 From: iscai-msft Date: Fri, 2 Feb 2024 13:35:16 -0500 Subject: [PATCH 40/45] regen with correct relative import of FileType --- packages/autorest.python/autorest/codegen/models/parameter.py | 2 +- .../payload/multipart/aio/operations/_operations.py | 2 +- .../payload/multipart/operations/_operations.py | 2 +- .../payload/multipart/aio/operations/_operations.py | 2 +- .../payload/multipart/operations/_operations.py | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/autorest.python/autorest/codegen/models/parameter.py b/packages/autorest.python/autorest/codegen/models/parameter.py index 8176f25e1c3..752ef935015 100644 --- a/packages/autorest.python/autorest/codegen/models/parameter.py +++ b/packages/autorest.python/autorest/codegen/models/parameter.py @@ -294,7 +294,7 @@ def imports(self, async_mode: bool, **kwargs: Any) -> FileImport: file_import = super().imports(async_mode, **kwargs) if self.is_form_data: relative_path = "..." if async_mode else ".." - file_import.add_submodule_import(f"{relative_path}vendor", "FileType", ImportType.LOCAL) + file_import.add_submodule_import(f"{relative_path}_vendor", "FileType", ImportType.LOCAL) file_import.add_submodule_import("typing", "Dict", ImportType.STDLIB) file_import.add_submodule_import("typing", "Any", ImportType.STDLIB) file_import.add_submodule_import("typing", "List", ImportType.STDLIB) diff --git a/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/aio/operations/_operations.py b/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/aio/operations/_operations.py index 030f592384a..49f350b59cc 100644 --- a/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/aio/operations/_operations.py +++ b/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/aio/operations/_operations.py @@ -24,6 +24,7 @@ from ... import _model_base, models as _models from ..._model_base import SdkJSONEncoder +from ..._vendor import FileType from ...operations._operations import ( build_form_data_basic_request, build_form_data_binary_array_parts_request, @@ -32,7 +33,6 @@ build_form_data_json_part_request, build_form_data_multi_binary_parts_request, ) -from ...vendor import FileType if sys.version_info >= (3, 9): from collections.abc import MutableMapping diff --git a/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/operations/_operations.py b/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/operations/_operations.py index 890c76501f0..0ff28439c85 100644 --- a/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/operations/_operations.py +++ b/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/operations/_operations.py @@ -26,7 +26,7 @@ from .. import _model_base, models as _models from .._model_base import SdkJSONEncoder from .._serialization import Serializer -from ..vendor import FileType +from .._vendor import FileType if sys.version_info >= (3, 9): from collections.abc import MutableMapping diff --git a/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/aio/operations/_operations.py b/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/aio/operations/_operations.py index 910a4d5bcea..7463f55148a 100644 --- a/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/aio/operations/_operations.py +++ b/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/aio/operations/_operations.py @@ -23,6 +23,7 @@ from ... import _model_base, models as _models from ..._model_base import SdkJSONEncoder +from ..._vendor import FileType from ...operations._operations import ( build_form_data_basic_request, build_form_data_binary_array_parts_request, @@ -31,7 +32,6 @@ build_form_data_json_part_request, build_form_data_multi_binary_parts_request, ) -from ...vendor import FileType if sys.version_info >= (3, 9): from collections.abc import MutableMapping diff --git a/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/operations/_operations.py b/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/operations/_operations.py index d3792d7a6f7..c0ba6c244a8 100644 --- a/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/operations/_operations.py +++ b/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/operations/_operations.py @@ -25,7 +25,7 @@ from .. import _model_base, models as _models from .._model_base import SdkJSONEncoder from .._serialization import Serializer -from ..vendor import FileType +from .._vendor import FileType if sys.version_info >= (3, 9): from collections.abc import MutableMapping From ad3174d37be66b1ed223187d5ae3db56ef3d619a Mon Sep 17 00:00:00 2001 From: iscai-msft Date: Fri, 2 Feb 2024 14:29:40 -0500 Subject: [PATCH 41/45] improve code structure --- .../autorest/codegen/models/parameter.py | 9 +-- .../codegen/serializers/builder_serializer.py | 44 +++--------- .../codegen/serializers/general_serializer.py | 14 ++++ .../codegen/templates/vendor.py.jinja2 | 24 +++++++ .../payload/multipart/_vendor.py | 31 ++++++++- .../multipart/aio/operations/_operations.py | 68 ++++++------------- .../multipart/operations/_operations.py | 68 ++++++------------- .../payload/multipart/_vendor.py | 31 ++++++++- .../multipart/aio/operations/_operations.py | 68 ++++++------------- .../multipart/operations/_operations.py | 68 ++++++------------- 10 files changed, 194 insertions(+), 231 deletions(-) diff --git a/packages/autorest.python/autorest/codegen/models/parameter.py b/packages/autorest.python/autorest/codegen/models/parameter.py index 752ef935015..fe85fb2b6b0 100644 --- a/packages/autorest.python/autorest/codegen/models/parameter.py +++ b/packages/autorest.python/autorest/codegen/models/parameter.py @@ -294,10 +294,11 @@ def imports(self, async_mode: bool, **kwargs: Any) -> FileImport: file_import = super().imports(async_mode, **kwargs) if self.is_form_data: relative_path = "..." if async_mode else ".." - file_import.add_submodule_import(f"{relative_path}_vendor", "FileType", ImportType.LOCAL) - file_import.add_submodule_import("typing", "Dict", ImportType.STDLIB) - file_import.add_submodule_import("typing", "Any", ImportType.STDLIB) - file_import.add_submodule_import("typing", "List", ImportType.STDLIB) + file_import.add_submodule_import( + f"{relative_path}_vendor", + "prepare_multipart_form_data", + ImportType.LOCAL, + ) return file_import @classmethod diff --git a/packages/autorest.python/autorest/codegen/serializers/builder_serializer.py b/packages/autorest.python/autorest/codegen/serializers/builder_serializer.py index 694c46a7f03..ba8d9c9623a 100644 --- a/packages/autorest.python/autorest/codegen/serializers/builder_serializer.py +++ b/packages/autorest.python/autorest/codegen/serializers/builder_serializer.py @@ -754,6 +754,14 @@ def _serialize_body_parameter(self, builder: OperationType) -> List[str]: retval: List[str] = [] body_param = builder.parameters.body_parameter if body_param.is_form_data: + model_type = cast( + ModelType, + ( + body_param.type.target_model_subtype((JSONModelType, DPGModelType)) + if isinstance(body_param.type, CombinedType) + else body_param.type + ), + ) retval.extend( [ "_body = (", @@ -761,41 +769,11 @@ def _serialize_body_parameter(self, builder: OperationType) -> List[str]: f" if isinstance({body_param.client_name}, _model_base.Model) else", f" {body_param.client_name}", ")", - "_files: List[FileType] = []", - "_data: Dict[str, Any] = {}", + f"_file_fields = {[p.wire_name for p in model_type.properties if p.is_multipart_file_input]}", + f"_data_fields = {[p.wire_name for p in model_type.properties if not p.is_multipart_file_input]}", + "_files, _data = prepare_multipart_form_data(_body, _file_fields, _data_fields)", ] ) - model_type = ( - body_param.type.target_model_subtype((JSONModelType, DPGModelType)) - if isinstance(body_param.type, CombinedType) - else body_param.type - ) - # we know that body param is a model type because it's a formdata - for prop in cast(ModelType, model_type).properties: - prop_access = f'_body["{prop.wire_name}"]' - retval.append(f'if _body.get("{prop.wire_name}") is not None:') - if prop.is_multipart_file_input: - if isinstance(prop.type, ListType): - retval.extend( - [ - " _files.extend([", - f' ("{prop.wire_name}", {prop.wire_name[0]})', - f" for {prop.wire_name[0]} in {prop_access}", - "])", - ] - ) - else: - # we assume that it's just a single multipart file input - retval.append( - f' _files.append(("{prop.wire_name}", {prop_access}))' - ) - else: - serialization = ( - f"json.dumps({prop_access}, cls=SdkJSONEncoder, exclude_readonly=True)" - if prop.type.type in ["list", "tuple", "dict", "model"] - else prop_access - ) - retval.append(f' _data["{prop.wire_name}"] = {serialization}') return retval body_kwarg_name = builder.request_builder.parameters.body_parameter.client_name diff --git a/packages/autorest.python/autorest/codegen/serializers/general_serializer.py b/packages/autorest.python/autorest/codegen/serializers/general_serializer.py index 06f6c1d64e7..01c65db9e32 100644 --- a/packages/autorest.python/autorest/codegen/serializers/general_serializer.py +++ b/packages/autorest.python/autorest/codegen/serializers/general_serializer.py @@ -137,6 +137,20 @@ def serialize_vendor_file(self, clients: List[Client]) -> str: file_import.add_submodule_import("typing", "Optional", ImportType.STDLIB) file_import.add_submodule_import("typing", "Mapping", ImportType.STDLIB) file_import.add_submodule_import("typing", "Sequence", ImportType.STDLIB) + file_import.add_submodule_import("typing", "Dict", ImportType.STDLIB) + file_import.add_submodule_import("typing", "Any", ImportType.STDLIB) + file_import.add_submodule_import("typing", "List", ImportType.STDLIB) + file_import.add_submodule_import( + "._model_base", + "SdkJSONEncoder", + ImportType.LOCAL, + ) + file_import.add_submodule_import( + "._model_base", + "Model", + ImportType.LOCAL, + ) + file_import.add_import("json", ImportType.STDLIB) return template.render( code_model=self.code_model, diff --git a/packages/autorest.python/autorest/codegen/templates/vendor.py.jinja2 b/packages/autorest.python/autorest/codegen/templates/vendor.py.jinja2 index b0c05724577..d9813663cae 100644 --- a/packages/autorest.python/autorest/codegen/templates/vendor.py.jinja2 +++ b/packages/autorest.python/autorest/codegen/templates/vendor.py.jinja2 @@ -79,4 +79,28 @@ FileType = Union[ ] FilesType = Union[Mapping[str, FileType], Sequence[Tuple[str, FileType]]] + +def serialize_multipart_data_entry(data_entry: Any) -> Any: + if isinstance(data_entry, (list, tuple, dict, Model)): + return json.dumps(data_entry, cls=SdkJSONEncoder, exclude_readonly=True) + return data_entry + +def prepare_multipart_form_data( + body: Dict[str, Any], multipart_fields: List[str], data_fields: List[str] +) -> Tuple[List[FileType], Dict[str, Any]]: + files: List[FileType] = [] + data: Dict[str, Any] = {} + for multipart_field in multipart_fields: + multipart_entry = body.get(multipart_field) + if isinstance(multipart_entry, list): + files.extend([(multipart_field, e) for e in multipart_entry ]) + elif multipart_entry: + files.append((multipart_field, multipart_entry)) + + for data_field in data_fields: + data_entry = body.get(data_field) + if data_entry: + data[data_field] = serialize_multipart_data_entry(data_entry) + + return files, data {% endif %} \ No newline at end of file diff --git a/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/_vendor.py b/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/_vendor.py index cb35847d99a..fa2f7aef023 100644 --- a/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/_vendor.py +++ b/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/_vendor.py @@ -5,7 +5,10 @@ # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from typing import IO, Mapping, Optional, Sequence, Tuple, Union +import json +from typing import Any, Dict, IO, List, Mapping, Optional, Sequence, Tuple, Union + +from ._model_base import Model, SdkJSONEncoder # file-like tuple could be `(filename, IO (or bytes))` or `(filename, IO (or bytes), content_type)` @@ -21,3 +24,29 @@ ] FilesType = Union[Mapping[str, FileType], Sequence[Tuple[str, FileType]]] + + +def serialize_multipart_data_entry(data_entry: Any) -> Any: + if isinstance(data_entry, (list, tuple, dict, Model)): + return json.dumps(data_entry, cls=SdkJSONEncoder, exclude_readonly=True) + return data_entry + + +def prepare_multipart_form_data( + body: Dict[str, Any], multipart_fields: List[str], data_fields: List[str] +) -> Tuple[List[FileType], Dict[str, Any]]: + files: List[FileType] = [] + data: Dict[str, Any] = {} + for multipart_field in multipart_fields: + multipart_entry = body.get(multipart_field) + if isinstance(multipart_entry, list): + files.extend([(multipart_field, e) for e in multipart_entry]) + elif multipart_entry: + files.append((multipart_field, multipart_entry)) + + for data_field in data_fields: + data_entry = body.get(data_field) + if data_entry: + data[data_field] = serialize_multipart_data_entry(data_entry) + + return files, data diff --git a/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/aio/operations/_operations.py b/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/aio/operations/_operations.py index 49f350b59cc..3dffdac2b78 100644 --- a/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/aio/operations/_operations.py +++ b/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/aio/operations/_operations.py @@ -8,7 +8,7 @@ # -------------------------------------------------------------------------- import json import sys -from typing import Any, Callable, Dict, List, Optional, TypeVar, Union, overload +from typing import Any, Callable, Dict, Optional, TypeVar, Union, overload from azure.core.exceptions import ( ClientAuthenticationError, @@ -24,7 +24,7 @@ from ... import _model_base, models as _models from ..._model_base import SdkJSONEncoder -from ..._vendor import FileType +from ..._vendor import prepare_multipart_form_data from ...operations._operations import ( build_form_data_basic_request, build_form_data_binary_array_parts_request, @@ -128,12 +128,9 @@ async def basic( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) _body = body.as_dict() if isinstance(body, _model_base.Model) else body - _files: List[FileType] = [] - _data: Dict[str, Any] = {} - if _body.get("id") is not None: - _data["id"] = _body["id"] - if _body.get("profileImage") is not None: - _files.append(("profileImage", _body["profileImage"])) + _file_fields = ["profileImage"] + _data_fields = ["id"] + _files, _data = prepare_multipart_form_data(_body, _file_fields, _data_fields) _request = build_form_data_basic_request( files=_files, @@ -245,20 +242,9 @@ async def complex( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) _body = body.as_dict() if isinstance(body, _model_base.Model) else body - _files: List[FileType] = [] - _data: Dict[str, Any] = {} - if _body.get("id") is not None: - _data["id"] = _body["id"] - if _body.get("address") is not None: - _data["address"] = json.dumps(_body["address"], cls=SdkJSONEncoder, exclude_readonly=True) - if _body.get("profileImage") is not None: - _files.append(("profileImage", _body["profileImage"])) - if _body.get("previousAddresses") is not None: - _data["previousAddresses"] = json.dumps( - _body["previousAddresses"], cls=SdkJSONEncoder, exclude_readonly=True - ) - if _body.get("pictures") is not None: - _files.extend([("pictures", p) for p in _body["pictures"]]) + _file_fields = ["profileImage", "pictures"] + _data_fields = ["id", "address", "previousAddresses"] + _files, _data = prepare_multipart_form_data(_body, _file_fields, _data_fields) _request = build_form_data_complex_request( files=_files, @@ -356,12 +342,9 @@ async def json_part( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) _body = body.as_dict() if isinstance(body, _model_base.Model) else body - _files: List[FileType] = [] - _data: Dict[str, Any] = {} - if _body.get("address") is not None: - _data["address"] = json.dumps(_body["address"], cls=SdkJSONEncoder, exclude_readonly=True) - if _body.get("profileImage") is not None: - _files.append(("profileImage", _body["profileImage"])) + _file_fields = ["profileImage"] + _data_fields = ["address"] + _files, _data = prepare_multipart_form_data(_body, _file_fields, _data_fields) _request = build_form_data_json_part_request( files=_files, @@ -457,12 +440,9 @@ async def binary_array_parts( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) _body = body.as_dict() if isinstance(body, _model_base.Model) else body - _files: List[FileType] = [] - _data: Dict[str, Any] = {} - if _body.get("id") is not None: - _data["id"] = _body["id"] - if _body.get("pictures") is not None: - _files.extend([("pictures", p) for p in _body["pictures"]]) + _file_fields = ["pictures"] + _data_fields = ["id"] + _files, _data = prepare_multipart_form_data(_body, _file_fields, _data_fields) _request = build_form_data_binary_array_parts_request( files=_files, @@ -566,14 +546,9 @@ async def json_array_parts( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) _body = body.as_dict() if isinstance(body, _model_base.Model) else body - _files: List[FileType] = [] - _data: Dict[str, Any] = {} - if _body.get("profileImage") is not None: - _files.append(("profileImage", _body["profileImage"])) - if _body.get("previousAddresses") is not None: - _data["previousAddresses"] = json.dumps( - _body["previousAddresses"], cls=SdkJSONEncoder, exclude_readonly=True - ) + _file_fields = ["profileImage"] + _data_fields = ["previousAddresses"] + _files, _data = prepare_multipart_form_data(_body, _file_fields, _data_fields) _request = build_form_data_json_array_parts_request( files=_files, @@ -669,12 +644,9 @@ async def multi_binary_parts( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) _body = body.as_dict() if isinstance(body, _model_base.Model) else body - _files: List[FileType] = [] - _data: Dict[str, Any] = {} - if _body.get("profileImage") is not None: - _files.append(("profileImage", _body["profileImage"])) - if _body.get("picture") is not None: - _files.append(("picture", _body["picture"])) + _file_fields = ["profileImage", "picture"] + _data_fields = [] + _files, _data = prepare_multipart_form_data(_body, _file_fields, _data_fields) _request = build_form_data_multi_binary_parts_request( files=_files, diff --git a/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/operations/_operations.py b/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/operations/_operations.py index 0ff28439c85..be0e68b027e 100644 --- a/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/operations/_operations.py +++ b/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/operations/_operations.py @@ -8,7 +8,7 @@ # -------------------------------------------------------------------------- import json import sys -from typing import Any, Callable, Dict, List, Optional, TypeVar, Union, overload +from typing import Any, Callable, Dict, Optional, TypeVar, Union, overload from azure.core.exceptions import ( ClientAuthenticationError, @@ -26,7 +26,7 @@ from .. import _model_base, models as _models from .._model_base import SdkJSONEncoder from .._serialization import Serializer -from .._vendor import FileType +from .._vendor import prepare_multipart_form_data if sys.version_info >= (3, 9): from collections.abc import MutableMapping @@ -179,12 +179,9 @@ def basic( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) _body = body.as_dict() if isinstance(body, _model_base.Model) else body - _files: List[FileType] = [] - _data: Dict[str, Any] = {} - if _body.get("id") is not None: - _data["id"] = _body["id"] - if _body.get("profileImage") is not None: - _files.append(("profileImage", _body["profileImage"])) + _file_fields = ["profileImage"] + _data_fields = ["id"] + _files, _data = prepare_multipart_form_data(_body, _file_fields, _data_fields) _request = build_form_data_basic_request( files=_files, @@ -296,20 +293,9 @@ def complex( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) _body = body.as_dict() if isinstance(body, _model_base.Model) else body - _files: List[FileType] = [] - _data: Dict[str, Any] = {} - if _body.get("id") is not None: - _data["id"] = _body["id"] - if _body.get("address") is not None: - _data["address"] = json.dumps(_body["address"], cls=SdkJSONEncoder, exclude_readonly=True) - if _body.get("profileImage") is not None: - _files.append(("profileImage", _body["profileImage"])) - if _body.get("previousAddresses") is not None: - _data["previousAddresses"] = json.dumps( - _body["previousAddresses"], cls=SdkJSONEncoder, exclude_readonly=True - ) - if _body.get("pictures") is not None: - _files.extend([("pictures", p) for p in _body["pictures"]]) + _file_fields = ["profileImage", "pictures"] + _data_fields = ["id", "address", "previousAddresses"] + _files, _data = prepare_multipart_form_data(_body, _file_fields, _data_fields) _request = build_form_data_complex_request( files=_files, @@ -407,12 +393,9 @@ def json_part( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) _body = body.as_dict() if isinstance(body, _model_base.Model) else body - _files: List[FileType] = [] - _data: Dict[str, Any] = {} - if _body.get("address") is not None: - _data["address"] = json.dumps(_body["address"], cls=SdkJSONEncoder, exclude_readonly=True) - if _body.get("profileImage") is not None: - _files.append(("profileImage", _body["profileImage"])) + _file_fields = ["profileImage"] + _data_fields = ["address"] + _files, _data = prepare_multipart_form_data(_body, _file_fields, _data_fields) _request = build_form_data_json_part_request( files=_files, @@ -506,12 +489,9 @@ def binary_array_parts( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) _body = body.as_dict() if isinstance(body, _model_base.Model) else body - _files: List[FileType] = [] - _data: Dict[str, Any] = {} - if _body.get("id") is not None: - _data["id"] = _body["id"] - if _body.get("pictures") is not None: - _files.extend([("pictures", p) for p in _body["pictures"]]) + _file_fields = ["pictures"] + _data_fields = ["id"] + _files, _data = prepare_multipart_form_data(_body, _file_fields, _data_fields) _request = build_form_data_binary_array_parts_request( files=_files, @@ -613,14 +593,9 @@ def json_array_parts( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) _body = body.as_dict() if isinstance(body, _model_base.Model) else body - _files: List[FileType] = [] - _data: Dict[str, Any] = {} - if _body.get("profileImage") is not None: - _files.append(("profileImage", _body["profileImage"])) - if _body.get("previousAddresses") is not None: - _data["previousAddresses"] = json.dumps( - _body["previousAddresses"], cls=SdkJSONEncoder, exclude_readonly=True - ) + _file_fields = ["profileImage"] + _data_fields = ["previousAddresses"] + _files, _data = prepare_multipart_form_data(_body, _file_fields, _data_fields) _request = build_form_data_json_array_parts_request( files=_files, @@ -714,12 +689,9 @@ def multi_binary_parts( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) _body = body.as_dict() if isinstance(body, _model_base.Model) else body - _files: List[FileType] = [] - _data: Dict[str, Any] = {} - if _body.get("profileImage") is not None: - _files.append(("profileImage", _body["profileImage"])) - if _body.get("picture") is not None: - _files.append(("picture", _body["picture"])) + _file_fields = ["profileImage", "picture"] + _data_fields = [] + _files, _data = prepare_multipart_form_data(_body, _file_fields, _data_fields) _request = build_form_data_multi_binary_parts_request( files=_files, diff --git a/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/_vendor.py b/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/_vendor.py index 3b794024c13..b0378930249 100644 --- a/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/_vendor.py +++ b/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/_vendor.py @@ -5,7 +5,10 @@ # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from typing import IO, Mapping, Optional, Sequence, Tuple, Union +import json +from typing import Any, Dict, IO, List, Mapping, Optional, Sequence, Tuple, Union + +from ._model_base import Model, SdkJSONEncoder # file-like tuple could be `(filename, IO (or bytes))` or `(filename, IO (or bytes), content_type)` @@ -21,3 +24,29 @@ ] FilesType = Union[Mapping[str, FileType], Sequence[Tuple[str, FileType]]] + + +def serialize_multipart_data_entry(data_entry: Any) -> Any: + if isinstance(data_entry, (list, tuple, dict, Model)): + return json.dumps(data_entry, cls=SdkJSONEncoder, exclude_readonly=True) + return data_entry + + +def prepare_multipart_form_data( + body: Dict[str, Any], multipart_fields: List[str], data_fields: List[str] +) -> Tuple[List[FileType], Dict[str, Any]]: + files: List[FileType] = [] + data: Dict[str, Any] = {} + for multipart_field in multipart_fields: + multipart_entry = body.get(multipart_field) + if isinstance(multipart_entry, list): + files.extend([(multipart_field, e) for e in multipart_entry]) + elif multipart_entry: + files.append((multipart_field, multipart_entry)) + + for data_field in data_fields: + data_entry = body.get(data_field) + if data_entry: + data[data_field] = serialize_multipart_data_entry(data_entry) + + return files, data diff --git a/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/aio/operations/_operations.py b/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/aio/operations/_operations.py index 7463f55148a..48c5bbbeab7 100644 --- a/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/aio/operations/_operations.py +++ b/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/aio/operations/_operations.py @@ -8,7 +8,7 @@ # -------------------------------------------------------------------------- import json import sys -from typing import Any, Callable, Dict, List, Optional, TypeVar, Union, overload +from typing import Any, Callable, Dict, Optional, TypeVar, Union, overload from corehttp.exceptions import ( ClientAuthenticationError, @@ -23,7 +23,7 @@ from ... import _model_base, models as _models from ..._model_base import SdkJSONEncoder -from ..._vendor import FileType +from ..._vendor import prepare_multipart_form_data from ...operations._operations import ( build_form_data_basic_request, build_form_data_binary_array_parts_request, @@ -126,12 +126,9 @@ async def basic( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) _body = body.as_dict() if isinstance(body, _model_base.Model) else body - _files: List[FileType] = [] - _data: Dict[str, Any] = {} - if _body.get("id") is not None: - _data["id"] = _body["id"] - if _body.get("profileImage") is not None: - _files.append(("profileImage", _body["profileImage"])) + _file_fields = ["profileImage"] + _data_fields = ["id"] + _files, _data = prepare_multipart_form_data(_body, _file_fields, _data_fields) _request = build_form_data_basic_request( files=_files, @@ -242,20 +239,9 @@ async def complex( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) _body = body.as_dict() if isinstance(body, _model_base.Model) else body - _files: List[FileType] = [] - _data: Dict[str, Any] = {} - if _body.get("id") is not None: - _data["id"] = _body["id"] - if _body.get("address") is not None: - _data["address"] = json.dumps(_body["address"], cls=SdkJSONEncoder, exclude_readonly=True) - if _body.get("profileImage") is not None: - _files.append(("profileImage", _body["profileImage"])) - if _body.get("previousAddresses") is not None: - _data["previousAddresses"] = json.dumps( - _body["previousAddresses"], cls=SdkJSONEncoder, exclude_readonly=True - ) - if _body.get("pictures") is not None: - _files.extend([("pictures", p) for p in _body["pictures"]]) + _file_fields = ["profileImage", "pictures"] + _data_fields = ["id", "address", "previousAddresses"] + _files, _data = prepare_multipart_form_data(_body, _file_fields, _data_fields) _request = build_form_data_complex_request( files=_files, @@ -352,12 +338,9 @@ async def json_part( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) _body = body.as_dict() if isinstance(body, _model_base.Model) else body - _files: List[FileType] = [] - _data: Dict[str, Any] = {} - if _body.get("address") is not None: - _data["address"] = json.dumps(_body["address"], cls=SdkJSONEncoder, exclude_readonly=True) - if _body.get("profileImage") is not None: - _files.append(("profileImage", _body["profileImage"])) + _file_fields = ["profileImage"] + _data_fields = ["address"] + _files, _data = prepare_multipart_form_data(_body, _file_fields, _data_fields) _request = build_form_data_json_part_request( files=_files, @@ -452,12 +435,9 @@ async def binary_array_parts( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) _body = body.as_dict() if isinstance(body, _model_base.Model) else body - _files: List[FileType] = [] - _data: Dict[str, Any] = {} - if _body.get("id") is not None: - _data["id"] = _body["id"] - if _body.get("pictures") is not None: - _files.extend([("pictures", p) for p in _body["pictures"]]) + _file_fields = ["pictures"] + _data_fields = ["id"] + _files, _data = prepare_multipart_form_data(_body, _file_fields, _data_fields) _request = build_form_data_binary_array_parts_request( files=_files, @@ -560,14 +540,9 @@ async def json_array_parts( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) _body = body.as_dict() if isinstance(body, _model_base.Model) else body - _files: List[FileType] = [] - _data: Dict[str, Any] = {} - if _body.get("profileImage") is not None: - _files.append(("profileImage", _body["profileImage"])) - if _body.get("previousAddresses") is not None: - _data["previousAddresses"] = json.dumps( - _body["previousAddresses"], cls=SdkJSONEncoder, exclude_readonly=True - ) + _file_fields = ["profileImage"] + _data_fields = ["previousAddresses"] + _files, _data = prepare_multipart_form_data(_body, _file_fields, _data_fields) _request = build_form_data_json_array_parts_request( files=_files, @@ -662,12 +637,9 @@ async def multi_binary_parts( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) _body = body.as_dict() if isinstance(body, _model_base.Model) else body - _files: List[FileType] = [] - _data: Dict[str, Any] = {} - if _body.get("profileImage") is not None: - _files.append(("profileImage", _body["profileImage"])) - if _body.get("picture") is not None: - _files.append(("picture", _body["picture"])) + _file_fields = ["profileImage", "picture"] + _data_fields = [] + _files, _data = prepare_multipart_form_data(_body, _file_fields, _data_fields) _request = build_form_data_multi_binary_parts_request( files=_files, diff --git a/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/operations/_operations.py b/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/operations/_operations.py index c0ba6c244a8..114a21e4031 100644 --- a/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/operations/_operations.py +++ b/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/operations/_operations.py @@ -8,7 +8,7 @@ # -------------------------------------------------------------------------- import json import sys -from typing import Any, Callable, Dict, List, Optional, TypeVar, Union, overload +from typing import Any, Callable, Dict, Optional, TypeVar, Union, overload from corehttp.exceptions import ( ClientAuthenticationError, @@ -25,7 +25,7 @@ from .. import _model_base, models as _models from .._model_base import SdkJSONEncoder from .._serialization import Serializer -from .._vendor import FileType +from .._vendor import prepare_multipart_form_data if sys.version_info >= (3, 9): from collections.abc import MutableMapping @@ -177,12 +177,9 @@ def basic( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) _body = body.as_dict() if isinstance(body, _model_base.Model) else body - _files: List[FileType] = [] - _data: Dict[str, Any] = {} - if _body.get("id") is not None: - _data["id"] = _body["id"] - if _body.get("profileImage") is not None: - _files.append(("profileImage", _body["profileImage"])) + _file_fields = ["profileImage"] + _data_fields = ["id"] + _files, _data = prepare_multipart_form_data(_body, _file_fields, _data_fields) _request = build_form_data_basic_request( files=_files, @@ -293,20 +290,9 @@ def complex( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) _body = body.as_dict() if isinstance(body, _model_base.Model) else body - _files: List[FileType] = [] - _data: Dict[str, Any] = {} - if _body.get("id") is not None: - _data["id"] = _body["id"] - if _body.get("address") is not None: - _data["address"] = json.dumps(_body["address"], cls=SdkJSONEncoder, exclude_readonly=True) - if _body.get("profileImage") is not None: - _files.append(("profileImage", _body["profileImage"])) - if _body.get("previousAddresses") is not None: - _data["previousAddresses"] = json.dumps( - _body["previousAddresses"], cls=SdkJSONEncoder, exclude_readonly=True - ) - if _body.get("pictures") is not None: - _files.extend([("pictures", p) for p in _body["pictures"]]) + _file_fields = ["profileImage", "pictures"] + _data_fields = ["id", "address", "previousAddresses"] + _files, _data = prepare_multipart_form_data(_body, _file_fields, _data_fields) _request = build_form_data_complex_request( files=_files, @@ -403,12 +389,9 @@ def json_part( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) _body = body.as_dict() if isinstance(body, _model_base.Model) else body - _files: List[FileType] = [] - _data: Dict[str, Any] = {} - if _body.get("address") is not None: - _data["address"] = json.dumps(_body["address"], cls=SdkJSONEncoder, exclude_readonly=True) - if _body.get("profileImage") is not None: - _files.append(("profileImage", _body["profileImage"])) + _file_fields = ["profileImage"] + _data_fields = ["address"] + _files, _data = prepare_multipart_form_data(_body, _file_fields, _data_fields) _request = build_form_data_json_part_request( files=_files, @@ -501,12 +484,9 @@ def binary_array_parts( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) _body = body.as_dict() if isinstance(body, _model_base.Model) else body - _files: List[FileType] = [] - _data: Dict[str, Any] = {} - if _body.get("id") is not None: - _data["id"] = _body["id"] - if _body.get("pictures") is not None: - _files.extend([("pictures", p) for p in _body["pictures"]]) + _file_fields = ["pictures"] + _data_fields = ["id"] + _files, _data = prepare_multipart_form_data(_body, _file_fields, _data_fields) _request = build_form_data_binary_array_parts_request( files=_files, @@ -607,14 +587,9 @@ def json_array_parts( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) _body = body.as_dict() if isinstance(body, _model_base.Model) else body - _files: List[FileType] = [] - _data: Dict[str, Any] = {} - if _body.get("profileImage") is not None: - _files.append(("profileImage", _body["profileImage"])) - if _body.get("previousAddresses") is not None: - _data["previousAddresses"] = json.dumps( - _body["previousAddresses"], cls=SdkJSONEncoder, exclude_readonly=True - ) + _file_fields = ["profileImage"] + _data_fields = ["previousAddresses"] + _files, _data = prepare_multipart_form_data(_body, _file_fields, _data_fields) _request = build_form_data_json_array_parts_request( files=_files, @@ -707,12 +682,9 @@ def multi_binary_parts( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) _body = body.as_dict() if isinstance(body, _model_base.Model) else body - _files: List[FileType] = [] - _data: Dict[str, Any] = {} - if _body.get("profileImage") is not None: - _files.append(("profileImage", _body["profileImage"])) - if _body.get("picture") is not None: - _files.append(("picture", _body["picture"])) + _file_fields = ["profileImage", "picture"] + _data_fields = [] + _files, _data = prepare_multipart_form_data(_body, _file_fields, _data_fields) _request = build_form_data_multi_binary_parts_request( files=_files, From 97315498c6c0af90b42cc7bbe492cee75a619a46 Mon Sep 17 00:00:00 2001 From: iscai-msft Date: Fri, 2 Feb 2024 14:41:05 -0500 Subject: [PATCH 42/45] fix generation for autorest --- .../codegen/serializers/general_serializer.py | 2 +- .../autorest/codegen/templates/vendor.py.jinja2 | 2 +- .../BodyFormData/bodyformdata/_vendor.py | 17 ----------------- .../bodyformurlencodeddata/_vendor.py | 17 ----------------- .../ReservedWords/reservedwords/_vendor.py | 17 +---------------- .../ReservedWords/reservedwords/aio/_vendor.py | 17 +---------------- .../bodyformdataversiontolerant/_vendor.py | 17 ----------------- .../bodyformdataversiontolerant/aio/_vendor.py | 17 ----------------- .../_vendor.py | 17 ----------------- .../aio/_vendor.py | 17 ----------------- .../reservedwordsversiontolerant/_vendor.py | 17 +---------------- .../reservedwordsversiontolerant/aio/_vendor.py | 17 +---------------- 12 files changed, 6 insertions(+), 168 deletions(-) diff --git a/packages/autorest.python/autorest/codegen/serializers/general_serializer.py b/packages/autorest.python/autorest/codegen/serializers/general_serializer.py index 01c65db9e32..1f2d009841f 100644 --- a/packages/autorest.python/autorest/codegen/serializers/general_serializer.py +++ b/packages/autorest.python/autorest/codegen/serializers/general_serializer.py @@ -130,7 +130,7 @@ def serialize_vendor_file(self, clients: List[Client]) -> str: "MatchConditions", ImportType.SDKCORE, ) - if self.code_model.has_form_data: + if self.code_model.has_form_data and self.code_model.options["models_mode"] == "dpg": file_import.add_submodule_import("typing", "IO", ImportType.STDLIB) file_import.add_submodule_import("typing", "Tuple", ImportType.STDLIB) file_import.add_submodule_import("typing", "Union", ImportType.STDLIB) diff --git a/packages/autorest.python/autorest/codegen/templates/vendor.py.jinja2 b/packages/autorest.python/autorest/codegen/templates/vendor.py.jinja2 index d9813663cae..79368ab466c 100644 --- a/packages/autorest.python/autorest/codegen/templates/vendor.py.jinja2 +++ b/packages/autorest.python/autorest/codegen/templates/vendor.py.jinja2 @@ -65,7 +65,7 @@ def prep_if_none_match(etag: Optional[str], match_condition: Optional[MatchCondi return "*" return None {% endif %} -{% if code_model.has_form_data %} +{% if code_model.has_form_data and code_model.options["models_mode"] == "dpg" %} # file-like tuple could be `(filename, IO (or bytes))` or `(filename, IO (or bytes), content_type)` FileContent = Union[str, bytes, IO[str], IO[bytes]] diff --git a/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/BodyFormData/bodyformdata/_vendor.py b/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/BodyFormData/bodyformdata/_vendor.py index d51e5941911..0dafe0e287f 100644 --- a/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/BodyFormData/bodyformdata/_vendor.py +++ b/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/BodyFormData/bodyformdata/_vendor.py @@ -5,8 +5,6 @@ # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from typing import IO, Mapping, Optional, Sequence, Tuple, Union - from azure.core.pipeline.transport import HttpRequest @@ -16,18 +14,3 @@ def _convert_request(request, files=None): if files: request.set_formdata_body(files) return request - - -# file-like tuple could be `(filename, IO (or bytes))` or `(filename, IO (or bytes), content_type)` -FileContent = Union[str, bytes, IO[str], IO[bytes]] - -FileType = Union[ - # file (or bytes) - FileContent, - # (filename, file (or bytes)) - Tuple[Optional[str], FileContent], - # (filename, file (or bytes), content_type) - Tuple[Optional[str], FileContent, Optional[str]], -] - -FilesType = Union[Mapping[str, FileType], Sequence[Tuple[str, FileType]]] diff --git a/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/BodyFormUrlEncodedData/bodyformurlencodeddata/_vendor.py b/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/BodyFormUrlEncodedData/bodyformurlencodeddata/_vendor.py index d51e5941911..0dafe0e287f 100644 --- a/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/BodyFormUrlEncodedData/bodyformurlencodeddata/_vendor.py +++ b/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/BodyFormUrlEncodedData/bodyformurlencodeddata/_vendor.py @@ -5,8 +5,6 @@ # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from typing import IO, Mapping, Optional, Sequence, Tuple, Union - from azure.core.pipeline.transport import HttpRequest @@ -16,18 +14,3 @@ def _convert_request(request, files=None): if files: request.set_formdata_body(files) return request - - -# file-like tuple could be `(filename, IO (or bytes))` or `(filename, IO (or bytes), content_type)` -FileContent = Union[str, bytes, IO[str], IO[bytes]] - -FileType = Union[ - # file (or bytes) - FileContent, - # (filename, file (or bytes)) - Tuple[Optional[str], FileContent], - # (filename, file (or bytes), content_type) - Tuple[Optional[str], FileContent, Optional[str]], -] - -FilesType = Union[Mapping[str, FileType], Sequence[Tuple[str, FileType]]] diff --git a/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/ReservedWords/reservedwords/_vendor.py b/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/ReservedWords/reservedwords/_vendor.py index 139a35090aa..3cde08fb119 100644 --- a/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/ReservedWords/reservedwords/_vendor.py +++ b/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/ReservedWords/reservedwords/_vendor.py @@ -6,7 +6,7 @@ # -------------------------------------------------------------------------- from abc import ABC -from typing import IO, Mapping, Optional, Sequence, TYPE_CHECKING, Tuple, Union +from typing import TYPE_CHECKING from azure.core.pipeline.transport import HttpRequest @@ -34,18 +34,3 @@ class ReservedWordsClientMixinABC(ABC): _config: ReservedWordsClientConfiguration _serialize: "Serializer" _deserialize: "Deserializer" - - -# file-like tuple could be `(filename, IO (or bytes))` or `(filename, IO (or bytes), content_type)` -FileContent = Union[str, bytes, IO[str], IO[bytes]] - -FileType = Union[ - # file (or bytes) - FileContent, - # (filename, file (or bytes)) - Tuple[Optional[str], FileContent], - # (filename, file (or bytes), content_type) - Tuple[Optional[str], FileContent, Optional[str]], -] - -FilesType = Union[Mapping[str, FileType], Sequence[Tuple[str, FileType]]] diff --git a/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/ReservedWords/reservedwords/aio/_vendor.py b/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/ReservedWords/reservedwords/aio/_vendor.py index af0c05d9373..6546cfae4fe 100644 --- a/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/ReservedWords/reservedwords/aio/_vendor.py +++ b/packages/autorest.python/test/vanilla/legacy/Expected/AcceptanceTests/ReservedWords/reservedwords/aio/_vendor.py @@ -6,7 +6,7 @@ # -------------------------------------------------------------------------- from abc import ABC -from typing import IO, Mapping, Optional, Sequence, TYPE_CHECKING, Tuple, Union +from typing import TYPE_CHECKING from azure.core.pipeline.transport import HttpRequest @@ -26,18 +26,3 @@ class ReservedWordsClientMixinABC(ABC): _config: ReservedWordsClientConfiguration _serialize: "Serializer" _deserialize: "Deserializer" - - -# file-like tuple could be `(filename, IO (or bytes))` or `(filename, IO (or bytes), content_type)` -FileContent = Union[str, bytes, IO[str], IO[bytes]] - -FileType = Union[ - # file (or bytes) - FileContent, - # (filename, file (or bytes)) - Tuple[Optional[str], FileContent], - # (filename, file (or bytes), content_type) - Tuple[Optional[str], FileContent, Optional[str]], -] - -FilesType = Union[Mapping[str, FileType], Sequence[Tuple[str, FileType]]] diff --git a/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/BodyFormDataVersionTolerant/bodyformdataversiontolerant/_vendor.py b/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/BodyFormDataVersionTolerant/bodyformdataversiontolerant/_vendor.py index 0f5eae1293e..3e21ea6effc 100644 --- a/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/BodyFormDataVersionTolerant/bodyformdataversiontolerant/_vendor.py +++ b/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/BodyFormDataVersionTolerant/bodyformdataversiontolerant/_vendor.py @@ -5,8 +5,6 @@ # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from typing import IO, Mapping, Optional, Sequence, Tuple, Union - def raise_if_not_implemented(cls, abstract_methods): not_implemented = [f for f in abstract_methods if not callable(getattr(cls, f, None))] @@ -17,18 +15,3 @@ def raise_if_not_implemented(cls, abstract_methods): cls.__name__, "', '".join(not_implemented) ) ) - - -# file-like tuple could be `(filename, IO (or bytes))` or `(filename, IO (or bytes), content_type)` -FileContent = Union[str, bytes, IO[str], IO[bytes]] - -FileType = Union[ - # file (or bytes) - FileContent, - # (filename, file (or bytes)) - Tuple[Optional[str], FileContent], - # (filename, file (or bytes), content_type) - Tuple[Optional[str], FileContent, Optional[str]], -] - -FilesType = Union[Mapping[str, FileType], Sequence[Tuple[str, FileType]]] diff --git a/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/BodyFormDataVersionTolerant/bodyformdataversiontolerant/aio/_vendor.py b/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/BodyFormDataVersionTolerant/bodyformdataversiontolerant/aio/_vendor.py index 0f5eae1293e..3e21ea6effc 100644 --- a/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/BodyFormDataVersionTolerant/bodyformdataversiontolerant/aio/_vendor.py +++ b/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/BodyFormDataVersionTolerant/bodyformdataversiontolerant/aio/_vendor.py @@ -5,8 +5,6 @@ # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from typing import IO, Mapping, Optional, Sequence, Tuple, Union - def raise_if_not_implemented(cls, abstract_methods): not_implemented = [f for f in abstract_methods if not callable(getattr(cls, f, None))] @@ -17,18 +15,3 @@ def raise_if_not_implemented(cls, abstract_methods): cls.__name__, "', '".join(not_implemented) ) ) - - -# file-like tuple could be `(filename, IO (or bytes))` or `(filename, IO (or bytes), content_type)` -FileContent = Union[str, bytes, IO[str], IO[bytes]] - -FileType = Union[ - # file (or bytes) - FileContent, - # (filename, file (or bytes)) - Tuple[Optional[str], FileContent], - # (filename, file (or bytes), content_type) - Tuple[Optional[str], FileContent, Optional[str]], -] - -FilesType = Union[Mapping[str, FileType], Sequence[Tuple[str, FileType]]] diff --git a/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/BodyFormUrlEncodedDataVersionTolerant/bodyformurlencodeddataversiontolerant/_vendor.py b/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/BodyFormUrlEncodedDataVersionTolerant/bodyformurlencodeddataversiontolerant/_vendor.py index 0f5eae1293e..3e21ea6effc 100644 --- a/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/BodyFormUrlEncodedDataVersionTolerant/bodyformurlencodeddataversiontolerant/_vendor.py +++ b/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/BodyFormUrlEncodedDataVersionTolerant/bodyformurlencodeddataversiontolerant/_vendor.py @@ -5,8 +5,6 @@ # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from typing import IO, Mapping, Optional, Sequence, Tuple, Union - def raise_if_not_implemented(cls, abstract_methods): not_implemented = [f for f in abstract_methods if not callable(getattr(cls, f, None))] @@ -17,18 +15,3 @@ def raise_if_not_implemented(cls, abstract_methods): cls.__name__, "', '".join(not_implemented) ) ) - - -# file-like tuple could be `(filename, IO (or bytes))` or `(filename, IO (or bytes), content_type)` -FileContent = Union[str, bytes, IO[str], IO[bytes]] - -FileType = Union[ - # file (or bytes) - FileContent, - # (filename, file (or bytes)) - Tuple[Optional[str], FileContent], - # (filename, file (or bytes), content_type) - Tuple[Optional[str], FileContent, Optional[str]], -] - -FilesType = Union[Mapping[str, FileType], Sequence[Tuple[str, FileType]]] diff --git a/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/BodyFormUrlEncodedDataVersionTolerant/bodyformurlencodeddataversiontolerant/aio/_vendor.py b/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/BodyFormUrlEncodedDataVersionTolerant/bodyformurlencodeddataversiontolerant/aio/_vendor.py index 0f5eae1293e..3e21ea6effc 100644 --- a/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/BodyFormUrlEncodedDataVersionTolerant/bodyformurlencodeddataversiontolerant/aio/_vendor.py +++ b/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/BodyFormUrlEncodedDataVersionTolerant/bodyformurlencodeddataversiontolerant/aio/_vendor.py @@ -5,8 +5,6 @@ # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from typing import IO, Mapping, Optional, Sequence, Tuple, Union - def raise_if_not_implemented(cls, abstract_methods): not_implemented = [f for f in abstract_methods if not callable(getattr(cls, f, None))] @@ -17,18 +15,3 @@ def raise_if_not_implemented(cls, abstract_methods): cls.__name__, "', '".join(not_implemented) ) ) - - -# file-like tuple could be `(filename, IO (or bytes))` or `(filename, IO (or bytes), content_type)` -FileContent = Union[str, bytes, IO[str], IO[bytes]] - -FileType = Union[ - # file (or bytes) - FileContent, - # (filename, file (or bytes)) - Tuple[Optional[str], FileContent], - # (filename, file (or bytes), content_type) - Tuple[Optional[str], FileContent, Optional[str]], -] - -FilesType = Union[Mapping[str, FileType], Sequence[Tuple[str, FileType]]] diff --git a/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/ReservedWordsVersionTolerant/reservedwordsversiontolerant/_vendor.py b/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/ReservedWordsVersionTolerant/reservedwordsversiontolerant/_vendor.py index aecce20a506..e74c45edd94 100644 --- a/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/ReservedWordsVersionTolerant/reservedwordsversiontolerant/_vendor.py +++ b/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/ReservedWordsVersionTolerant/reservedwordsversiontolerant/_vendor.py @@ -6,7 +6,7 @@ # -------------------------------------------------------------------------- from abc import ABC -from typing import IO, Mapping, Optional, Sequence, TYPE_CHECKING, Tuple, Union +from typing import TYPE_CHECKING from ._configuration import ReservedWordsClientConfiguration @@ -35,18 +35,3 @@ def raise_if_not_implemented(cls, abstract_methods): cls.__name__, "', '".join(not_implemented) ) ) - - -# file-like tuple could be `(filename, IO (or bytes))` or `(filename, IO (or bytes), content_type)` -FileContent = Union[str, bytes, IO[str], IO[bytes]] - -FileType = Union[ - # file (or bytes) - FileContent, - # (filename, file (or bytes)) - Tuple[Optional[str], FileContent], - # (filename, file (or bytes), content_type) - Tuple[Optional[str], FileContent, Optional[str]], -] - -FilesType = Union[Mapping[str, FileType], Sequence[Tuple[str, FileType]]] diff --git a/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/ReservedWordsVersionTolerant/reservedwordsversiontolerant/aio/_vendor.py b/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/ReservedWordsVersionTolerant/reservedwordsversiontolerant/aio/_vendor.py index 6e90d195d87..9f9d18ebb0e 100644 --- a/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/ReservedWordsVersionTolerant/reservedwordsversiontolerant/aio/_vendor.py +++ b/packages/autorest.python/test/vanilla/version-tolerant/Expected/AcceptanceTests/ReservedWordsVersionTolerant/reservedwordsversiontolerant/aio/_vendor.py @@ -6,7 +6,7 @@ # -------------------------------------------------------------------------- from abc import ABC -from typing import IO, Mapping, Optional, Sequence, TYPE_CHECKING, Tuple, Union +from typing import TYPE_CHECKING from ._configuration import ReservedWordsClientConfiguration @@ -35,18 +35,3 @@ def raise_if_not_implemented(cls, abstract_methods): cls.__name__, "', '".join(not_implemented) ) ) - - -# file-like tuple could be `(filename, IO (or bytes))` or `(filename, IO (or bytes), content_type)` -FileContent = Union[str, bytes, IO[str], IO[bytes]] - -FileType = Union[ - # file (or bytes) - FileContent, - # (filename, file (or bytes)) - Tuple[Optional[str], FileContent], - # (filename, file (or bytes), content_type) - Tuple[Optional[str], FileContent, Optional[str]], -] - -FilesType = Union[Mapping[str, FileType], Sequence[Tuple[str, FileType]]] From e49b726e8c375809df1818c5caaf9b511cecb973 Mon Sep 17 00:00:00 2001 From: iscai-msft Date: Fri, 2 Feb 2024 14:45:08 -0500 Subject: [PATCH 43/45] add complex tests --- .../test_payload_multipart_async.py | 51 +++++++--- .../test_payload_multipart.py | 94 ++++++++++++++++--- 2 files changed, 120 insertions(+), 25 deletions(-) diff --git a/packages/typespec-python/test/generic_mock_api_tests/asynctests/test_payload_multipart_async.py b/packages/typespec-python/test/generic_mock_api_tests/asynctests/test_payload_multipart_async.py index ea13afb3288..8db58967324 100644 --- a/packages/typespec-python/test/generic_mock_api_tests/asynctests/test_payload_multipart_async.py +++ b/packages/typespec-python/test/generic_mock_api_tests/asynctests/test_payload_multipart_async.py @@ -3,6 +3,7 @@ # Licensed under the MIT License. See License.txt in the project root for # license information. # -------------------------------------------------------------------------- +import uuid from typing import Dict, Any from pathlib import Path import pytest @@ -22,50 +23,74 @@ async def client(): @pytest.mark.asyncio @pytest.mark.parametrize( - "op_name,model_class,data,file", + "op_name,model_class,data,file,file_info", [ - ("basic", models.MultiPartRequest, {"id": "123"}, {"profileImage": JPG}), + ("basic", models.MultiPartRequest, {"id": "123"}, {"profileImage": JPG}, {}), ( "multi_binary_parts", models.MultiBinaryPartsRequest, {}, {"profileImage": JPG, "picture": PNG}, + {} ), ( "multi_binary_parts", models.MultiBinaryPartsRequest, {}, {"profileImage": JPG}, + {} ), ( "json_part", models.JsonPartRequest, {"address": models.Address(city="X")}, {"profileImage": JPG}, + {}, ), ( "json_array_parts", models.JsonArrayPartsRequest, {"previousAddresses": [models.Address(city="Y"), models.Address(city="Z")]}, {"profileImage": JPG}, + {}, + ), + ( + "binary_array_parts", + models.BinaryArrayPartsRequest, + {"id": "123"}, + {"pictures": [PNG, PNG]}, + {}, + ), + ( + "complex", + models.ComplexPartsRequest, + {"id": "123", "previousAddresses": [models.Address(city="Y"), models.Address(city="Z")], "address": models.Address(city="X")}, + {"pictures": [PNG, PNG], "profileImage": JPG}, + {}, ), ], ) -async def test_multi_part(client: MultiPartClient, op_name, model_class, data, file): +async def test_multi_part(client: MultiPartClient, op_name, model_class, data, file, file_info): + def add_info(file_path, is_bytes): + file_content = open(str(file_path), "rb").read() if is_bytes else open(str(file_path), "rb") + name = str(uuid.uuid4()) if file_info.get("file_name") is None else file_info.get("file_name") + content_type = "application/octet-stream" if file_info.get("content_type") is None else file_info.get("content_type") + return (name, file_content, content_type) + def convert(is_bytes=False): + files_part = {k: ([add_info(vi, is_bytes) for vi in v] if isinstance(v, list) else add_info(v, is_bytes)) for k, v in file.items()} + files_part.update(data) + return files_part op = getattr(client.form_data, op_name) - # test bytes - body = {k: open(str(v), "rb").read() for k, v in file.items()} - body.update(data) + # test bytes (raw dict) + body = convert(True) await op(body) - await op(model_class(body)) - # test io - body = {k: open(str(v), "rb") for k, v in file.items()} - body.update(data) + # test io (raw dict) + body = convert() await op(body) - body = {k: open(str(v), "rb") for k, v in file.items()} - body.update(data) + # test io (model) + body = convert() with pytest.raises(TypeError): # caused by deepcopy when DPG model init - await op(model_class(body)) + await op(model_class(body)) \ No newline at end of file diff --git a/packages/typespec-python/test/generic_mock_api_tests/test_payload_multipart.py b/packages/typespec-python/test/generic_mock_api_tests/test_payload_multipart.py index 7d4213f9f9c..4062dbb0cf5 100644 --- a/packages/typespec-python/test/generic_mock_api_tests/test_payload_multipart.py +++ b/packages/typespec-python/test/generic_mock_api_tests/test_payload_multipart.py @@ -3,6 +3,7 @@ # Licensed under the MIT License. See License.txt in the project root for # license information. # -------------------------------------------------------------------------- +import uuid from typing import Dict, Any from pathlib import Path import pytest @@ -20,50 +21,119 @@ def client(): @pytest.mark.parametrize( - "op_name,model_class,data,file", + "op_name,model_class,data,file,file_info", [ - ("basic", models.MultiPartRequest, {"id": "123"}, {"profileImage": JPG}), + ("basic", models.MultiPartRequest, {"id": "123"}, {"profileImage": JPG}, {}), ( "multi_binary_parts", models.MultiBinaryPartsRequest, {}, {"profileImage": JPG, "picture": PNG}, + {} ), ( "multi_binary_parts", models.MultiBinaryPartsRequest, {}, {"profileImage": JPG}, + {} ), ( "json_part", models.JsonPartRequest, {"address": models.Address(city="X")}, {"profileImage": JPG}, + {}, ), ( "json_array_parts", models.JsonArrayPartsRequest, {"previousAddresses": [models.Address(city="Y"), models.Address(city="Z")]}, {"profileImage": JPG}, + {}, + ), + ( + "binary_array_parts", + models.BinaryArrayPartsRequest, + {"id": "123"}, + {"pictures": [PNG, PNG]}, + {}, + ), + ( + "complex", + models.ComplexPartsRequest, + {"id": "123", "previousAddresses": [models.Address(city="Y"), models.Address(city="Z")], "address": models.Address(city="X")}, + {"pictures": [PNG, PNG], "profileImage": JPG}, + {}, ), ], ) -def test_multi_part(client: MultiPartClient, op_name, model_class, data, file): +def test_multi_part(client: MultiPartClient, op_name, model_class, data, file, file_info): + def add_info(file_path, is_bytes): + file_content = open(str(file_path), "rb").read() if is_bytes else open(str(file_path), "rb") + name = str(uuid.uuid4()) if file_info.get("file_name") is None else file_info.get("file_name") + content_type = "application/octet-stream" if file_info.get("content_type") is None else file_info.get("content_type") + return (name, file_content, content_type) + def convert(is_bytes=False): + files_part = {k: ([add_info(vi, is_bytes) for vi in v] if isinstance(v, list) else add_info(v, is_bytes)) for k, v in file.items()} + files_part.update(data) + return files_part op = getattr(client.form_data, op_name) - # test bytes - body = {k: ("blob", open(str(v), "rb").read(), "application/octet-stream") for k, v in file.items()} - body.update(data) + # test bytes (raw dict) + body = convert(True) op(body) - op(model_class(body)) - # test io - body = {k: open(str(v), "rb") for k, v in file.items()} - body.update(data) + # test io (raw dict) + body = convert() op(body) - body = {k: open(str(v), "rb") for k, v in file.items()} - body.update(data) + # test io (model) + body = convert() with pytest.raises(TypeError): # caused by deepcopy when DPG model init op(model_class(body)) + +def _test_sample_single_file(client: MultiPartClient): + # Python SDK support several kinds of file format for multipart/form-data and users can choose any of them + # 1. bytes + client.form_data.basic({"id": "123", "profileImage": open(str(PNG), "rb").read()}) + + # 2. file io + client.form_data.basic({"id": "123", "profileImage": open(str(PNG), "rb")}) + + # 3. file tuple (only set file name) + client.form_data.basic({"id": "123", "profileImage": ("my_image.jpg", open(str(JPG), "rb"))}) + # or + client.form_data.basic({"id": "123", "profileImage": ("my_image.jpg", open(str(JPG), "rb").read())}) + + # 4. file tuple (set file name and content type) + client.form_data.basic({"id": "123", "profileImage": ("my_image.jpg", open(str(JPG), "rb"), "image/jpeg")}) + # or + client.form_data.basic({"id": "123", "profileImage": ("my_image.jpg", open(str(JPG), "rb").read(), "image/jpeg")}) + +def _test_sample_array_file(client: MultiPartClient): + # If users want to upload array files for same field name, they can use list, and users can + # choose any of the above file format for each file. e.g. + + # List[bytes, io] + client.form_data.binary_array_parts({"id": "123", "pictures": [open(str(PNG), "rb").read(), open(str(PNG), "rb")]}) + + # List[bytes, tuple] + client.form_data.binary_array_parts({ + "id": "123", + "pictures": [open(str(PNG), "rb").read(), ("my_image.png", open(str(PNG), "rb"))] + }) + # or + client.form_data.binary_array_parts({ + "id": "123", + "pictures": [open(str(PNG), "rb").read(), ("my_image.png", open(str(PNG), "rb"), "image/png")] + }) + # List[io, bytes] + client.form_data.binary_array_parts({"id": "123", "pictures": [open(str(PNG), "rb"), open(str(PNG), "rb").read()]}) + + # List[tuple, tuple] + client.form_data.binary_array_parts({ + "id": "123", + "pictures": [("my_image1.png", open(str(PNG), "rb"), "image/png"), ("my_image2.png", open(str(PNG), "rb"), "image/png")] + }) + # ... \ No newline at end of file From 7ad0dbbb18acdc8991e6b3fd1f47bf8e550add2a Mon Sep 17 00:00:00 2001 From: iscai-msft Date: Fri, 2 Feb 2024 15:13:37 -0500 Subject: [PATCH 44/45] fix mypy and pyright of generated helper functions --- .../autorest/codegen/models/parameter.py | 1 + .../codegen/serializers/builder_serializer.py | 12 +++++++-- .../codegen/serializers/general_serializer.py | 5 +++- .../codegen/templates/vendor.py.jinja2 | 2 +- .../payload/multipart/_vendor.py | 2 +- .../multipart/aio/operations/_operations.py | 26 +++++++++---------- .../multipart/operations/_operations.py | 26 +++++++++---------- .../payload/multipart/_vendor.py | 2 +- .../multipart/aio/operations/_operations.py | 26 +++++++++---------- .../multipart/operations/_operations.py | 26 +++++++++---------- 10 files changed, 70 insertions(+), 58 deletions(-) diff --git a/packages/autorest.python/autorest/codegen/models/parameter.py b/packages/autorest.python/autorest/codegen/models/parameter.py index fe85fb2b6b0..9625eb717ee 100644 --- a/packages/autorest.python/autorest/codegen/models/parameter.py +++ b/packages/autorest.python/autorest/codegen/models/parameter.py @@ -299,6 +299,7 @@ def imports(self, async_mode: bool, **kwargs: Any) -> FileImport: "prepare_multipart_form_data", ImportType.LOCAL, ) + file_import.add_submodule_import("typing", "List", ImportType.STDLIB) return file_import @classmethod diff --git a/packages/autorest.python/autorest/codegen/serializers/builder_serializer.py b/packages/autorest.python/autorest/codegen/serializers/builder_serializer.py index ba8d9c9623a..46a46008c40 100644 --- a/packages/autorest.python/autorest/codegen/serializers/builder_serializer.py +++ b/packages/autorest.python/autorest/codegen/serializers/builder_serializer.py @@ -762,6 +762,14 @@ def _serialize_body_parameter(self, builder: OperationType) -> List[str]: else body_param.type ), ) + file_fields = [ + p.wire_name for p in model_type.properties if p.is_multipart_file_input + ] + data_fields = [ + p.wire_name + for p in model_type.properties + if not p.is_multipart_file_input + ] retval.extend( [ "_body = (", @@ -769,8 +777,8 @@ def _serialize_body_parameter(self, builder: OperationType) -> List[str]: f" if isinstance({body_param.client_name}, _model_base.Model) else", f" {body_param.client_name}", ")", - f"_file_fields = {[p.wire_name for p in model_type.properties if p.is_multipart_file_input]}", - f"_data_fields = {[p.wire_name for p in model_type.properties if not p.is_multipart_file_input]}", + f"_file_fields: List[str] = {file_fields}", + f"_data_fields: List[str] = {data_fields}", "_files, _data = prepare_multipart_form_data(_body, _file_fields, _data_fields)", ] ) diff --git a/packages/autorest.python/autorest/codegen/serializers/general_serializer.py b/packages/autorest.python/autorest/codegen/serializers/general_serializer.py index 1f2d009841f..13dcfa53a99 100644 --- a/packages/autorest.python/autorest/codegen/serializers/general_serializer.py +++ b/packages/autorest.python/autorest/codegen/serializers/general_serializer.py @@ -130,7 +130,10 @@ def serialize_vendor_file(self, clients: List[Client]) -> str: "MatchConditions", ImportType.SDKCORE, ) - if self.code_model.has_form_data and self.code_model.options["models_mode"] == "dpg": + if ( + self.code_model.has_form_data + and self.code_model.options["models_mode"] == "dpg" + ): file_import.add_submodule_import("typing", "IO", ImportType.STDLIB) file_import.add_submodule_import("typing", "Tuple", ImportType.STDLIB) file_import.add_submodule_import("typing", "Union", ImportType.STDLIB) diff --git a/packages/autorest.python/autorest/codegen/templates/vendor.py.jinja2 b/packages/autorest.python/autorest/codegen/templates/vendor.py.jinja2 index 79368ab466c..4d89b22193e 100644 --- a/packages/autorest.python/autorest/codegen/templates/vendor.py.jinja2 +++ b/packages/autorest.python/autorest/codegen/templates/vendor.py.jinja2 @@ -86,7 +86,7 @@ def serialize_multipart_data_entry(data_entry: Any) -> Any: return data_entry def prepare_multipart_form_data( - body: Dict[str, Any], multipart_fields: List[str], data_fields: List[str] + body: Mapping[str, Any], multipart_fields: List[str], data_fields: List[str] ) -> Tuple[List[FileType], Dict[str, Any]]: files: List[FileType] = [] data: Dict[str, Any] = {} diff --git a/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/_vendor.py b/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/_vendor.py index fa2f7aef023..ab863f3898e 100644 --- a/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/_vendor.py +++ b/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/_vendor.py @@ -33,7 +33,7 @@ def serialize_multipart_data_entry(data_entry: Any) -> Any: def prepare_multipart_form_data( - body: Dict[str, Any], multipart_fields: List[str], data_fields: List[str] + body: Mapping[str, Any], multipart_fields: List[str], data_fields: List[str] ) -> Tuple[List[FileType], Dict[str, Any]]: files: List[FileType] = [] data: Dict[str, Any] = {} diff --git a/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/aio/operations/_operations.py b/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/aio/operations/_operations.py index 3dffdac2b78..553a176f7bb 100644 --- a/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/aio/operations/_operations.py +++ b/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/aio/operations/_operations.py @@ -8,7 +8,7 @@ # -------------------------------------------------------------------------- import json import sys -from typing import Any, Callable, Dict, Optional, TypeVar, Union, overload +from typing import Any, Callable, Dict, List, Optional, TypeVar, Union, overload from azure.core.exceptions import ( ClientAuthenticationError, @@ -128,8 +128,8 @@ async def basic( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) _body = body.as_dict() if isinstance(body, _model_base.Model) else body - _file_fields = ["profileImage"] - _data_fields = ["id"] + _file_fields: List[str] = ["profileImage"] + _data_fields: List[str] = ["id"] _files, _data = prepare_multipart_form_data(_body, _file_fields, _data_fields) _request = build_form_data_basic_request( @@ -242,8 +242,8 @@ async def complex( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) _body = body.as_dict() if isinstance(body, _model_base.Model) else body - _file_fields = ["profileImage", "pictures"] - _data_fields = ["id", "address", "previousAddresses"] + _file_fields: List[str] = ["profileImage", "pictures"] + _data_fields: List[str] = ["id", "address", "previousAddresses"] _files, _data = prepare_multipart_form_data(_body, _file_fields, _data_fields) _request = build_form_data_complex_request( @@ -342,8 +342,8 @@ async def json_part( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) _body = body.as_dict() if isinstance(body, _model_base.Model) else body - _file_fields = ["profileImage"] - _data_fields = ["address"] + _file_fields: List[str] = ["profileImage"] + _data_fields: List[str] = ["address"] _files, _data = prepare_multipart_form_data(_body, _file_fields, _data_fields) _request = build_form_data_json_part_request( @@ -440,8 +440,8 @@ async def binary_array_parts( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) _body = body.as_dict() if isinstance(body, _model_base.Model) else body - _file_fields = ["pictures"] - _data_fields = ["id"] + _file_fields: List[str] = ["pictures"] + _data_fields: List[str] = ["id"] _files, _data = prepare_multipart_form_data(_body, _file_fields, _data_fields) _request = build_form_data_binary_array_parts_request( @@ -546,8 +546,8 @@ async def json_array_parts( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) _body = body.as_dict() if isinstance(body, _model_base.Model) else body - _file_fields = ["profileImage"] - _data_fields = ["previousAddresses"] + _file_fields: List[str] = ["profileImage"] + _data_fields: List[str] = ["previousAddresses"] _files, _data = prepare_multipart_form_data(_body, _file_fields, _data_fields) _request = build_form_data_json_array_parts_request( @@ -644,8 +644,8 @@ async def multi_binary_parts( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) _body = body.as_dict() if isinstance(body, _model_base.Model) else body - _file_fields = ["profileImage", "picture"] - _data_fields = [] + _file_fields: List[str] = ["profileImage", "picture"] + _data_fields: List[str] = [] _files, _data = prepare_multipart_form_data(_body, _file_fields, _data_fields) _request = build_form_data_multi_binary_parts_request( diff --git a/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/operations/_operations.py b/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/operations/_operations.py index be0e68b027e..400eaaf12a0 100644 --- a/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/operations/_operations.py +++ b/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/operations/_operations.py @@ -8,7 +8,7 @@ # -------------------------------------------------------------------------- import json import sys -from typing import Any, Callable, Dict, Optional, TypeVar, Union, overload +from typing import Any, Callable, Dict, List, Optional, TypeVar, Union, overload from azure.core.exceptions import ( ClientAuthenticationError, @@ -179,8 +179,8 @@ def basic( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) _body = body.as_dict() if isinstance(body, _model_base.Model) else body - _file_fields = ["profileImage"] - _data_fields = ["id"] + _file_fields: List[str] = ["profileImage"] + _data_fields: List[str] = ["id"] _files, _data = prepare_multipart_form_data(_body, _file_fields, _data_fields) _request = build_form_data_basic_request( @@ -293,8 +293,8 @@ def complex( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) _body = body.as_dict() if isinstance(body, _model_base.Model) else body - _file_fields = ["profileImage", "pictures"] - _data_fields = ["id", "address", "previousAddresses"] + _file_fields: List[str] = ["profileImage", "pictures"] + _data_fields: List[str] = ["id", "address", "previousAddresses"] _files, _data = prepare_multipart_form_data(_body, _file_fields, _data_fields) _request = build_form_data_complex_request( @@ -393,8 +393,8 @@ def json_part( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) _body = body.as_dict() if isinstance(body, _model_base.Model) else body - _file_fields = ["profileImage"] - _data_fields = ["address"] + _file_fields: List[str] = ["profileImage"] + _data_fields: List[str] = ["address"] _files, _data = prepare_multipart_form_data(_body, _file_fields, _data_fields) _request = build_form_data_json_part_request( @@ -489,8 +489,8 @@ def binary_array_parts( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) _body = body.as_dict() if isinstance(body, _model_base.Model) else body - _file_fields = ["pictures"] - _data_fields = ["id"] + _file_fields: List[str] = ["pictures"] + _data_fields: List[str] = ["id"] _files, _data = prepare_multipart_form_data(_body, _file_fields, _data_fields) _request = build_form_data_binary_array_parts_request( @@ -593,8 +593,8 @@ def json_array_parts( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) _body = body.as_dict() if isinstance(body, _model_base.Model) else body - _file_fields = ["profileImage"] - _data_fields = ["previousAddresses"] + _file_fields: List[str] = ["profileImage"] + _data_fields: List[str] = ["previousAddresses"] _files, _data = prepare_multipart_form_data(_body, _file_fields, _data_fields) _request = build_form_data_json_array_parts_request( @@ -689,8 +689,8 @@ def multi_binary_parts( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) _body = body.as_dict() if isinstance(body, _model_base.Model) else body - _file_fields = ["profileImage", "picture"] - _data_fields = [] + _file_fields: List[str] = ["profileImage", "picture"] + _data_fields: List[str] = [] _files, _data = prepare_multipart_form_data(_body, _file_fields, _data_fields) _request = build_form_data_multi_binary_parts_request( diff --git a/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/_vendor.py b/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/_vendor.py index b0378930249..4bd173651f5 100644 --- a/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/_vendor.py +++ b/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/_vendor.py @@ -33,7 +33,7 @@ def serialize_multipart_data_entry(data_entry: Any) -> Any: def prepare_multipart_form_data( - body: Dict[str, Any], multipart_fields: List[str], data_fields: List[str] + body: Mapping[str, Any], multipart_fields: List[str], data_fields: List[str] ) -> Tuple[List[FileType], Dict[str, Any]]: files: List[FileType] = [] data: Dict[str, Any] = {} diff --git a/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/aio/operations/_operations.py b/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/aio/operations/_operations.py index 48c5bbbeab7..13677f7313e 100644 --- a/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/aio/operations/_operations.py +++ b/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/aio/operations/_operations.py @@ -8,7 +8,7 @@ # -------------------------------------------------------------------------- import json import sys -from typing import Any, Callable, Dict, Optional, TypeVar, Union, overload +from typing import Any, Callable, Dict, List, Optional, TypeVar, Union, overload from corehttp.exceptions import ( ClientAuthenticationError, @@ -126,8 +126,8 @@ async def basic( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) _body = body.as_dict() if isinstance(body, _model_base.Model) else body - _file_fields = ["profileImage"] - _data_fields = ["id"] + _file_fields: List[str] = ["profileImage"] + _data_fields: List[str] = ["id"] _files, _data = prepare_multipart_form_data(_body, _file_fields, _data_fields) _request = build_form_data_basic_request( @@ -239,8 +239,8 @@ async def complex( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) _body = body.as_dict() if isinstance(body, _model_base.Model) else body - _file_fields = ["profileImage", "pictures"] - _data_fields = ["id", "address", "previousAddresses"] + _file_fields: List[str] = ["profileImage", "pictures"] + _data_fields: List[str] = ["id", "address", "previousAddresses"] _files, _data = prepare_multipart_form_data(_body, _file_fields, _data_fields) _request = build_form_data_complex_request( @@ -338,8 +338,8 @@ async def json_part( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) _body = body.as_dict() if isinstance(body, _model_base.Model) else body - _file_fields = ["profileImage"] - _data_fields = ["address"] + _file_fields: List[str] = ["profileImage"] + _data_fields: List[str] = ["address"] _files, _data = prepare_multipart_form_data(_body, _file_fields, _data_fields) _request = build_form_data_json_part_request( @@ -435,8 +435,8 @@ async def binary_array_parts( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) _body = body.as_dict() if isinstance(body, _model_base.Model) else body - _file_fields = ["pictures"] - _data_fields = ["id"] + _file_fields: List[str] = ["pictures"] + _data_fields: List[str] = ["id"] _files, _data = prepare_multipart_form_data(_body, _file_fields, _data_fields) _request = build_form_data_binary_array_parts_request( @@ -540,8 +540,8 @@ async def json_array_parts( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) _body = body.as_dict() if isinstance(body, _model_base.Model) else body - _file_fields = ["profileImage"] - _data_fields = ["previousAddresses"] + _file_fields: List[str] = ["profileImage"] + _data_fields: List[str] = ["previousAddresses"] _files, _data = prepare_multipart_form_data(_body, _file_fields, _data_fields) _request = build_form_data_json_array_parts_request( @@ -637,8 +637,8 @@ async def multi_binary_parts( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) _body = body.as_dict() if isinstance(body, _model_base.Model) else body - _file_fields = ["profileImage", "picture"] - _data_fields = [] + _file_fields: List[str] = ["profileImage", "picture"] + _data_fields: List[str] = [] _files, _data = prepare_multipart_form_data(_body, _file_fields, _data_fields) _request = build_form_data_multi_binary_parts_request( diff --git a/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/operations/_operations.py b/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/operations/_operations.py index 114a21e4031..1f5f0bd4d7e 100644 --- a/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/operations/_operations.py +++ b/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/operations/_operations.py @@ -8,7 +8,7 @@ # -------------------------------------------------------------------------- import json import sys -from typing import Any, Callable, Dict, Optional, TypeVar, Union, overload +from typing import Any, Callable, Dict, List, Optional, TypeVar, Union, overload from corehttp.exceptions import ( ClientAuthenticationError, @@ -177,8 +177,8 @@ def basic( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) _body = body.as_dict() if isinstance(body, _model_base.Model) else body - _file_fields = ["profileImage"] - _data_fields = ["id"] + _file_fields: List[str] = ["profileImage"] + _data_fields: List[str] = ["id"] _files, _data = prepare_multipart_form_data(_body, _file_fields, _data_fields) _request = build_form_data_basic_request( @@ -290,8 +290,8 @@ def complex( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) _body = body.as_dict() if isinstance(body, _model_base.Model) else body - _file_fields = ["profileImage", "pictures"] - _data_fields = ["id", "address", "previousAddresses"] + _file_fields: List[str] = ["profileImage", "pictures"] + _data_fields: List[str] = ["id", "address", "previousAddresses"] _files, _data = prepare_multipart_form_data(_body, _file_fields, _data_fields) _request = build_form_data_complex_request( @@ -389,8 +389,8 @@ def json_part( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) _body = body.as_dict() if isinstance(body, _model_base.Model) else body - _file_fields = ["profileImage"] - _data_fields = ["address"] + _file_fields: List[str] = ["profileImage"] + _data_fields: List[str] = ["address"] _files, _data = prepare_multipart_form_data(_body, _file_fields, _data_fields) _request = build_form_data_json_part_request( @@ -484,8 +484,8 @@ def binary_array_parts( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) _body = body.as_dict() if isinstance(body, _model_base.Model) else body - _file_fields = ["pictures"] - _data_fields = ["id"] + _file_fields: List[str] = ["pictures"] + _data_fields: List[str] = ["id"] _files, _data = prepare_multipart_form_data(_body, _file_fields, _data_fields) _request = build_form_data_binary_array_parts_request( @@ -587,8 +587,8 @@ def json_array_parts( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) _body = body.as_dict() if isinstance(body, _model_base.Model) else body - _file_fields = ["profileImage"] - _data_fields = ["previousAddresses"] + _file_fields: List[str] = ["profileImage"] + _data_fields: List[str] = ["previousAddresses"] _files, _data = prepare_multipart_form_data(_body, _file_fields, _data_fields) _request = build_form_data_json_array_parts_request( @@ -682,8 +682,8 @@ def multi_binary_parts( # pylint: disable=inconsistent-return-statements cls: ClsType[None] = kwargs.pop("cls", None) _body = body.as_dict() if isinstance(body, _model_base.Model) else body - _file_fields = ["profileImage", "picture"] - _data_fields = [] + _file_fields: List[str] = ["profileImage", "picture"] + _data_fields: List[str] = [] _files, _data = prepare_multipart_form_data(_body, _file_fields, _data_fields) _request = build_form_data_multi_binary_parts_request( From a7a41c948c061911e08bdfd0a6832d689834864d Mon Sep 17 00:00:00 2001 From: iscai-msft Date: Fri, 2 Feb 2024 15:36:16 -0500 Subject: [PATCH 45/45] remove unused imports in generated code --- .../autorest.python/autorest/codegen/models/model_type.py | 7 ------- .../payload/multipart/aio/operations/_operations.py | 2 -- .../payload/multipart/operations/_operations.py | 2 -- .../payload/multipart/aio/operations/_operations.py | 2 -- .../payload/multipart/operations/_operations.py | 2 -- 5 files changed, 15 deletions(-) diff --git a/packages/autorest.python/autorest/codegen/models/model_type.py b/packages/autorest.python/autorest/codegen/models/model_type.py index 54068689efb..4487aea6e6d 100644 --- a/packages/autorest.python/autorest/codegen/models/model_type.py +++ b/packages/autorest.python/autorest/codegen/models/model_type.py @@ -327,13 +327,6 @@ def imports(self, **kwargs: Any) -> FileImport: if kwargs.get("model_typing") else TypingSection.REGULAR, ) - if any(not p.is_multipart_file_input for p in self.properties): - file_import.add_submodule_import( - f"{relative_path}_model_base", - "SdkJSONEncoder", - ImportType.LOCAL, - ) - file_import.add_import("json", ImportType.STDLIB) return file_import diff --git a/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/aio/operations/_operations.py b/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/aio/operations/_operations.py index 553a176f7bb..ddde8227c0a 100644 --- a/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/aio/operations/_operations.py +++ b/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/aio/operations/_operations.py @@ -6,7 +6,6 @@ # Code generated by Microsoft (R) Python Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -import json import sys from typing import Any, Callable, Dict, List, Optional, TypeVar, Union, overload @@ -23,7 +22,6 @@ from azure.core.tracing.decorator_async import distributed_trace_async from ... import _model_base, models as _models -from ..._model_base import SdkJSONEncoder from ..._vendor import prepare_multipart_form_data from ...operations._operations import ( build_form_data_basic_request, diff --git a/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/operations/_operations.py b/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/operations/_operations.py index 400eaaf12a0..8df1ccfb529 100644 --- a/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/operations/_operations.py +++ b/packages/typespec-python/test/azure/generated/payload-multipart/payload/multipart/operations/_operations.py @@ -6,7 +6,6 @@ # Code generated by Microsoft (R) Python Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -import json import sys from typing import Any, Callable, Dict, List, Optional, TypeVar, Union, overload @@ -24,7 +23,6 @@ from azure.core.utils import case_insensitive_dict from .. import _model_base, models as _models -from .._model_base import SdkJSONEncoder from .._serialization import Serializer from .._vendor import prepare_multipart_form_data diff --git a/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/aio/operations/_operations.py b/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/aio/operations/_operations.py index 13677f7313e..e95b450d7fb 100644 --- a/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/aio/operations/_operations.py +++ b/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/aio/operations/_operations.py @@ -6,7 +6,6 @@ # Code generated by Unbranded (R) Python Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -import json import sys from typing import Any, Callable, Dict, List, Optional, TypeVar, Union, overload @@ -22,7 +21,6 @@ from corehttp.runtime.pipeline import PipelineResponse from ... import _model_base, models as _models -from ..._model_base import SdkJSONEncoder from ..._vendor import prepare_multipart_form_data from ...operations._operations import ( build_form_data_basic_request, diff --git a/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/operations/_operations.py b/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/operations/_operations.py index 1f5f0bd4d7e..7d64a66612a 100644 --- a/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/operations/_operations.py +++ b/packages/typespec-python/test/unbranded/generated/payload-multipart/payload/multipart/operations/_operations.py @@ -6,7 +6,6 @@ # Code generated by Unbranded (R) Python Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -import json import sys from typing import Any, Callable, Dict, List, Optional, TypeVar, Union, overload @@ -23,7 +22,6 @@ from corehttp.utils import case_insensitive_dict from .. import _model_base, models as _models -from .._model_base import SdkJSONEncoder from .._serialization import Serializer from .._vendor import prepare_multipart_form_data