From 63f176b61e3c1cb7375eae59d6bf324dd1e1d706 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 13 Jul 2026 08:26:41 +0000 Subject: [PATCH 1/8] Initial plan From fcfb415a9bf7fcbc0744e238791298524a86092f Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 13 Jul 2026 09:03:58 +0000 Subject: [PATCH 2/8] [http-client-python] Add IO overload for binary bytes body Co-authored-by: msyyc <70930885+msyyc@users.noreply.github.com> --- .../codegen/serializers/builder_serializer.py | 25 ++++- .../generator/pygen/preprocess/__init__.py | 18 +++ .../generator/pygen/utils.py | 2 + .../asynctests/test_encode_bytes_async.py | 15 +++ .../mock_api/shared/test_encode_bytes.py | 14 +++ .../tests/unit/test_bytes_body_overloads.py | 103 ++++++++++++++++++ 6 files changed, 173 insertions(+), 4 deletions(-) create mode 100644 packages/http-client-python/tests/unit/test_bytes_body_overloads.py diff --git a/packages/http-client-python/generator/pygen/codegen/serializers/builder_serializer.py b/packages/http-client-python/generator/pygen/codegen/serializers/builder_serializer.py index 2a671d7b220..05a8e7b9754 100644 --- a/packages/http-client-python/generator/pygen/codegen/serializers/builder_serializer.py +++ b/packages/http-client-python/generator/pygen/codegen/serializers/builder_serializer.py @@ -827,6 +827,27 @@ def _initialize_overloads(self, builder: OperationType, is_paging: bool = False) next((o for o in builder.overloads if isinstance(o.parameters.body_parameter.type, BinaryType))), ) binary_body_param = binary_overload.parameters.body_parameter + other_overload = cast( + OperationType, + next((o for o in builder.overloads if not isinstance(o.parameters.body_parameter.type, BinaryType))), + ) + other_body_param = other_overload.parameters.body_parameter + # When the non-binary overload also serializes to raw content (e.g. a `bytes` body + # with a binary content type), both branches assign the same value to the same + # content kwarg. Emitting the isinstance branch would be redundant and confuses + # mypy's type narrowing, so collapse it to a single assignment. + if ( + isinstance(other_body_param.type, ByteArraySchema) + and other_body_param.default_content_type != "application/json" + and binary_overload.request_builder.parameters.body_parameter.client_name + == other_overload.request_builder.parameters.body_parameter.client_name + ): + if binary_body_param.default_content_type and not same_content_type: + retval.append( + f'content_type = content_type or "{binary_body_param.default_content_type}"{check_body_suffix}' + ) + retval.extend(self._create_body_parameter(binary_overload)) + return retval retval.append(f"if {binary_body_param.type.instance_check_template.format(binary_body_param.client_name)}:") if binary_body_param.default_content_type and not same_content_type: retval.append( @@ -834,10 +855,6 @@ def _initialize_overloads(self, builder: OperationType, is_paging: bool = False) ) retval.extend(f" {l}" for l in self._create_body_parameter(binary_overload)) retval.append("else:") - other_overload = cast( - OperationType, - next((o for o in builder.overloads if not isinstance(o.parameters.body_parameter.type, BinaryType))), - ) retval.extend(f" {l}" for l in self._create_body_parameter(other_overload)) if other_overload.parameters.body_parameter.default_content_type and not same_content_type: retval.append( diff --git a/packages/http-client-python/generator/pygen/preprocess/__init__.py b/packages/http-client-python/generator/pygen/preprocess/__init__.py index 605ced4b4ed..feafd33145d 100644 --- a/packages/http-client-python/generator/pygen/preprocess/__init__.py +++ b/packages/http-client-python/generator/pygen/preprocess/__init__.py @@ -399,6 +399,24 @@ def add_body_param_type( code_model: dict[str, Any], body_parameter: dict[str, Any], ): + # For a binary `bytes` body (e.g. content type application/octet-stream or a custom + # binary media type), add an IO overload alongside the `bytes` one. This keeps backward + # compatibility for services migrating from swagger, whose binary bodies were typed as IO. + if ( + body_parameter + and body_parameter["type"]["type"] == "bytes" + and not has_json_content_type(body_parameter) + and not (self.is_tsp and has_multi_part_content_type(body_parameter)) + and self.options["models-mode"] != "typeddict" + and not any(t for t in ["flattened", "groupedBy"] if body_parameter.get(t)) + ): + body_parameter["type"] = { + "type": "combined", + "types": [body_parameter["type"], KNOWN_TYPES["binary"]], + } + code_model["types"].append(body_parameter["type"]) + return + # only add overload for special content type if ( # pylint: disable=too-many-boolean-expressions body_parameter diff --git a/packages/http-client-python/generator/pygen/utils.py b/packages/http-client-python/generator/pygen/utils.py index 15671b4f186..177b2f83c61 100644 --- a/packages/http-client-python/generator/pygen/utils.py +++ b/packages/http-client-python/generator/pygen/utils.py @@ -113,6 +113,8 @@ def get_body_type_for_description(body_parameter: dict[str, Any]) -> str: return "binary" if body_parameter["type"]["type"] == "string": return "string" + if body_parameter["type"]["type"] == "bytes": + return "byte" return "JSON" diff --git a/packages/http-client-python/tests/mock_api/shared/asynctests/test_encode_bytes_async.py b/packages/http-client-python/tests/mock_api/shared/asynctests/test_encode_bytes_async.py index 5c57cb4281c..5383f336cb2 100644 --- a/packages/http-client-python/tests/mock_api/shared/asynctests/test_encode_bytes_async.py +++ b/packages/http-client-python/tests/mock_api/shared/asynctests/test_encode_bytes_async.py @@ -3,6 +3,7 @@ # Licensed under the MIT License. See License.txt in the project root for # license information. # -------------------------------------------------------------------------- +import io import pytest import pytest_asyncio from pathlib import Path @@ -123,6 +124,20 @@ async def test_request_body(client: BytesClient, png_data: bytes): ) +@pytest.mark.asyncio +async def test_request_body_io(client: BytesClient, png_data: bytes): + # binary bodies also accept an IO input via the generated overload + await client.request_body.default( + value=io.BytesIO(png_data), + ) + await client.request_body.octet_stream( + value=io.BytesIO(png_data), + ) + await client.request_body.custom_content_type( + value=io.BytesIO(png_data), + ) + + @pytest.mark.asyncio async def test_response_body(client: BytesClient, png_data: bytes): expected = b"test" diff --git a/packages/http-client-python/tests/mock_api/shared/test_encode_bytes.py b/packages/http-client-python/tests/mock_api/shared/test_encode_bytes.py index 2ca75a22c31..edd96d13313 100644 --- a/packages/http-client-python/tests/mock_api/shared/test_encode_bytes.py +++ b/packages/http-client-python/tests/mock_api/shared/test_encode_bytes.py @@ -3,6 +3,7 @@ # Licensed under the MIT License. See License.txt in the project root for # license information. # -------------------------------------------------------------------------- +import io from pathlib import Path import pytest @@ -119,6 +120,19 @@ def test_request_body(client: BytesClient, png_data: bytes): ) +def test_request_body_io(client: BytesClient, png_data: bytes): + # binary bodies also accept an IO input via the generated overload + client.request_body.default( + value=io.BytesIO(png_data), + ) + client.request_body.octet_stream( + value=io.BytesIO(png_data), + ) + client.request_body.custom_content_type( + value=io.BytesIO(png_data), + ) + + def test_response_body(client: BytesClient, png_data: bytes): expected = b"test" assert b"".join(client.response_body.default()) == png_data diff --git a/packages/http-client-python/tests/unit/test_bytes_body_overloads.py b/packages/http-client-python/tests/unit/test_bytes_body_overloads.py new file mode 100644 index 00000000000..547964e668b --- /dev/null +++ b/packages/http-client-python/tests/unit/test_bytes_body_overloads.py @@ -0,0 +1,103 @@ +# ------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for +# license information. +# -------------------------------------------------------------------------- +"""Tests for the IO overload added to binary ``bytes`` bodies. + +TypeSpec ``bytes`` used with a binary content type (e.g. application/octet-stream +or a custom media type) is emitted as ``bytes``. To keep backward compatibility for +services migrating from swagger, whose binary bodies were typed as ``IO``, the +preprocess plugin adds an ``IO[bytes]`` overload alongside the ``bytes`` one. +""" +from pygen.preprocess import PreProcessPlugin, add_overloads_for_body_param + + +def _plugin(models_mode: str = "dpg") -> PreProcessPlugin: + return PreProcessPlugin( + output_folder="", + **{ + "version-tolerant": True, + "models-mode": models_mode, + "tsp_file": True, + "show-operations": True, + "show-send-request": True, + "builders-visibility": "public", + }, + ) + + +def _content_type_param() -> dict: + return { + "wireName": "Content-Type", + "clientName": "content_type", + "location": "header", + "optional": True, + "implementation": "Method", + "inOverload": False, + "inDocstring": True, + "type": {"type": "string"}, + } + + +def _bytes_body_operation(content_types: list) -> tuple[dict, dict]: + body_parameter = { + "wireName": "value", + "clientName": "value", + "location": "body", + "optional": False, + "implementation": "Method", + "contentTypes": content_types, + "type": {"type": "bytes"}, + } + yaml_data = { + "name": "upload", + "bodyParameter": body_parameter, + "parameters": [_content_type_param()], + "overloads": [], + "responses": [], + "exceptions": [], + } + code_model = {"types": []} + return code_model, yaml_data + + +def test_binary_bytes_body_adds_io_overload(): + """A binary ``bytes`` body gets a combined ``bytes``/``IO[bytes]`` type with two overloads.""" + plugin = _plugin() + code_model, yaml_data = _bytes_body_operation(["application/octet-stream"]) + body_parameter = yaml_data["bodyParameter"] + + plugin.add_body_param_type(code_model, body_parameter) + add_overloads_for_body_param(yaml_data) + + assert body_parameter["type"]["type"] == "combined" + member_types = [t["type"] for t in body_parameter["type"]["types"]] + assert member_types == ["bytes", "binary"] + assert len(yaml_data["overloads"]) == 2 + + +def test_json_bytes_body_stays_plain_bytes(): + """A ``bytes`` body with a JSON content type stays a plain ``bytes`` type (no IO overload).""" + plugin = _plugin() + code_model, yaml_data = _bytes_body_operation(["application/json"]) + body_parameter = yaml_data["bodyParameter"] + + plugin.add_body_param_type(code_model, body_parameter) + add_overloads_for_body_param(yaml_data) + + assert body_parameter["type"]["type"] == "bytes" + assert len(yaml_data["overloads"]) == 0 + + +def test_typeddict_mode_binary_bytes_body_stays_plain_bytes(): + """In typeddict-only mode the IO overload is skipped for binary ``bytes`` bodies.""" + plugin = _plugin("typeddict") + code_model, yaml_data = _bytes_body_operation(["application/octet-stream"]) + body_parameter = yaml_data["bodyParameter"] + + plugin.add_body_param_type(code_model, body_parameter) + add_overloads_for_body_param(yaml_data) + + assert body_parameter["type"]["type"] == "bytes" + assert len(yaml_data["overloads"]) == 0 From 32eacae27ec4380f7ecf89d9d63bfe6ca781d95b Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 14 Jul 2026 03:16:05 +0000 Subject: [PATCH 3/8] Fix too-many-boolean-expressions lint in add_body_param_type Co-authored-by: msyyc <70930885+msyyc@users.noreply.github.com> --- .../generator/pygen/preprocess/__init__.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/http-client-python/generator/pygen/preprocess/__init__.py b/packages/http-client-python/generator/pygen/preprocess/__init__.py index feafd33145d..b5149be1b47 100644 --- a/packages/http-client-python/generator/pygen/preprocess/__init__.py +++ b/packages/http-client-python/generator/pygen/preprocess/__init__.py @@ -402,11 +402,12 @@ def add_body_param_type( # For a binary `bytes` body (e.g. content type application/octet-stream or a custom # binary media type), add an IO overload alongside the `bytes` one. This keeps backward # compatibility for services migrating from swagger, whose binary bodies were typed as IO. + is_multipart = self.is_tsp and has_multi_part_content_type(body_parameter) + is_binary_body = not has_json_content_type(body_parameter) and not is_multipart if ( body_parameter and body_parameter["type"]["type"] == "bytes" - and not has_json_content_type(body_parameter) - and not (self.is_tsp and has_multi_part_content_type(body_parameter)) + and is_binary_body and self.options["models-mode"] != "typeddict" and not any(t for t in ["flattened", "groupedBy"] if body_parameter.get(t)) ): From 35473bfb2fe0fe230001c3e56d43cf2339894674 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 14 Jul 2026 03:16:44 +0000 Subject: [PATCH 4/8] Add changelog entry for bytes IO overload fix Co-authored-by: msyyc <70930885+msyyc@users.noreply.github.com> --- ...t-python_fix-bytes-body-io-overload-2026-7-14-3-14-0.md | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 .chronus/changes/http-client-python_fix-bytes-body-io-overload-2026-7-14-3-14-0.md diff --git a/.chronus/changes/http-client-python_fix-bytes-body-io-overload-2026-7-14-3-14-0.md b/.chronus/changes/http-client-python_fix-bytes-body-io-overload-2026-7-14-3-14-0.md new file mode 100644 index 00000000000..c404d49f8d4 --- /dev/null +++ b/.chronus/changes/http-client-python_fix-bytes-body-io-overload-2026-7-14-3-14-0.md @@ -0,0 +1,7 @@ +--- +changeKind: fix +packages: + - "@typespec/http-client-python" +--- + +Add an `IO[bytes]` overload alongside `bytes` for binary `bytes` bodies, keeping backward compatibility for services migrating from swagger whose binary bodies were typed as `IO`. From bf61eb3e288df1183daf80a5169afd1a48ac1581 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 14 Jul 2026 05:29:05 +0000 Subject: [PATCH 5/8] Avoid unused IOBase import for collapsed binary bytes body Co-authored-by: msyyc <70930885+msyyc@users.noreply.github.com> --- .../generator/pygen/codegen/models/operation.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/packages/http-client-python/generator/pygen/codegen/models/operation.py b/packages/http-client-python/generator/pygen/codegen/models/operation.py index b63e4205dbd..7ba964132d0 100644 --- a/packages/http-client-python/generator/pygen/codegen/models/operation.py +++ b/packages/http-client-python/generator/pygen/codegen/models/operation.py @@ -33,7 +33,7 @@ ) from .parameter_list import ParameterList from .model_type import ModelType -from .primitive_types import BinaryIteratorType, BinaryType +from .primitive_types import BinaryIteratorType, BinaryType, ByteArraySchema from .base import BaseType from .combined_type import CombinedType from .request_builder import OverloadedRequestBuilder, RequestBuilder @@ -224,7 +224,15 @@ def non_default_errors(self) -> list[Response]: @property def need_import_iobase(self) -> bool: - return self.parameters.has_body and isinstance(self.parameters.body_parameter.type, CombinedType) + if not (self.parameters.has_body and isinstance(self.parameters.body_parameter.type, CombinedType)): + return False + # For a binary `bytes` body the combined type is `bytes` + `IO[bytes]`. Both overloads + # serialize to raw content, so the body serialization collapses to a single assignment + # without an `isinstance` branch. In that case `IOBase` is never referenced, so avoid + # importing it to prevent an unused-import lint error in the generated code. + if any(isinstance(t, ByteArraySchema) for t in self.parameters.body_parameter.type.types): + return False + return True @staticmethod def has_kwargs_to_pop_with_default( From df924db89e286db5661a9202208567d693ef3732 Mon Sep 17 00:00:00 2001 From: Yuchao Yan Date: Wed, 15 Jul 2026 15:45:22 +0800 Subject: [PATCH 6/8] Skip dead _content=None for collapsed binary bytes body; describe bytes body as binary Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 082cab3e-1c55-4eb5-951a-819a9842137f --- .../codegen/serializers/builder_serializer.py | 52 ++++++++++++------- .../generator/pygen/utils.py | 2 +- 2 files changed, 35 insertions(+), 19 deletions(-) diff --git a/packages/http-client-python/generator/pygen/codegen/serializers/builder_serializer.py b/packages/http-client-python/generator/pygen/codegen/serializers/builder_serializer.py index 05a8e7b9754..df02a4c8349 100644 --- a/packages/http-client-python/generator/pygen/codegen/serializers/builder_serializer.py +++ b/packages/http-client-python/generator/pygen/codegen/serializers/builder_serializer.py @@ -817,9 +817,42 @@ def _initialize_overloads(self, builder: OperationType, is_paging: bool = False) all_dpg_model_overloads = all( _is_dpg_or_typeddict_body(o.parameters.body_parameter) for o in builder.overloads ) - if not all_dpg_model_overloads: + # A binary `bytes` body pairs a `bytes` overload (binary content type) with the added + # `IO[bytes]` overload. Both serialize to raw content on the same content kwarg, so we + # emit a single unconditional assignment instead of an `isinstance` branch (which would be + # redundant and confuse mypy's type narrowing). Since the assignment is unconditional, the + # `_ = None` pre-init below is skipped for this case as well. + collapsed_binary_bytes_overload: Optional[OperationType] = None + if builder.overloads: + binary_bytes_binary_ov = next( + (o for o in builder.overloads if isinstance(o.parameters.body_parameter.type, BinaryType)), None + ) + binary_bytes_other_ov = next( + (o for o in builder.overloads if not isinstance(o.parameters.body_parameter.type, BinaryType)), None + ) + if ( + binary_bytes_binary_ov is not None + and binary_bytes_other_ov is not None + and isinstance(binary_bytes_other_ov.parameters.body_parameter.type, ByteArraySchema) + and binary_bytes_other_ov.parameters.body_parameter.default_content_type != "application/json" + and binary_bytes_binary_ov.request_builder.parameters.body_parameter.client_name + == binary_bytes_other_ov.request_builder.parameters.body_parameter.client_name + ): + collapsed_binary_bytes_overload = cast(OperationType, binary_bytes_binary_ov) + + if not all_dpg_model_overloads and collapsed_binary_bytes_overload is None: for v in sorted(set(client_names), key=client_names.index): retval.append(f"_{v} = None") + + if collapsed_binary_bytes_overload is not None: + collapsed_body_param = collapsed_binary_bytes_overload.parameters.body_parameter + if collapsed_body_param.default_content_type and not same_content_type: + retval.append( + f'content_type = content_type or "{collapsed_body_param.default_content_type}"{check_body_suffix}' + ) + retval.extend(self._create_body_parameter(collapsed_binary_bytes_overload)) + return retval + try: # if there is a binary overload, we do a binary check first. binary_overload = cast( @@ -831,23 +864,6 @@ def _initialize_overloads(self, builder: OperationType, is_paging: bool = False) OperationType, next((o for o in builder.overloads if not isinstance(o.parameters.body_parameter.type, BinaryType))), ) - other_body_param = other_overload.parameters.body_parameter - # When the non-binary overload also serializes to raw content (e.g. a `bytes` body - # with a binary content type), both branches assign the same value to the same - # content kwarg. Emitting the isinstance branch would be redundant and confuses - # mypy's type narrowing, so collapse it to a single assignment. - if ( - isinstance(other_body_param.type, ByteArraySchema) - and other_body_param.default_content_type != "application/json" - and binary_overload.request_builder.parameters.body_parameter.client_name - == other_overload.request_builder.parameters.body_parameter.client_name - ): - if binary_body_param.default_content_type and not same_content_type: - retval.append( - f'content_type = content_type or "{binary_body_param.default_content_type}"{check_body_suffix}' - ) - retval.extend(self._create_body_parameter(binary_overload)) - return retval retval.append(f"if {binary_body_param.type.instance_check_template.format(binary_body_param.client_name)}:") if binary_body_param.default_content_type and not same_content_type: retval.append( diff --git a/packages/http-client-python/generator/pygen/utils.py b/packages/http-client-python/generator/pygen/utils.py index 177b2f83c61..e8d0581840d 100644 --- a/packages/http-client-python/generator/pygen/utils.py +++ b/packages/http-client-python/generator/pygen/utils.py @@ -114,7 +114,7 @@ def get_body_type_for_description(body_parameter: dict[str, Any]) -> str: if body_parameter["type"]["type"] == "string": return "string" if body_parameter["type"]["type"] == "bytes": - return "byte" + return "binary" return "JSON" From c8bbab80a8d9348b2384ed544aab69f7fc932d09 Mon Sep 17 00:00:00 2001 From: Yuchao Yan Date: Wed, 15 Jul 2026 15:47:37 +0800 Subject: [PATCH 7/8] Simplify get_body_type_for_description: combine binary and bytes cases Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 082cab3e-1c55-4eb5-951a-819a9842137f --- packages/http-client-python/generator/pygen/utils.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/packages/http-client-python/generator/pygen/utils.py b/packages/http-client-python/generator/pygen/utils.py index e8d0581840d..c3f27e78dad 100644 --- a/packages/http-client-python/generator/pygen/utils.py +++ b/packages/http-client-python/generator/pygen/utils.py @@ -109,12 +109,10 @@ def _get_value(value: Any) -> Any: def get_body_type_for_description(body_parameter: dict[str, Any]) -> str: - if body_parameter["type"]["type"] == "binary": + if body_parameter["type"]["type"] in ("binary", "bytes"): return "binary" if body_parameter["type"]["type"] == "string": return "string" - if body_parameter["type"]["type"] == "bytes": - return "binary" return "JSON" From c3b23aadabc8f2e4c8842fbcfea643e31dc526c1 Mon Sep 17 00:00:00 2001 From: Yuchao Yan Date: Wed, 15 Jul 2026 16:14:19 +0800 Subject: [PATCH 8/8] Extract collapsed binary bytes detection to helper to satisfy too-many-statements Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 082cab3e-1c55-4eb5-951a-819a9842137f --- .../codegen/serializers/builder_serializer.py | 46 ++++++++++++------- 1 file changed, 29 insertions(+), 17 deletions(-) diff --git a/packages/http-client-python/generator/pygen/codegen/serializers/builder_serializer.py b/packages/http-client-python/generator/pygen/codegen/serializers/builder_serializer.py index df02a4c8349..b1da889bed6 100644 --- a/packages/http-client-python/generator/pygen/codegen/serializers/builder_serializer.py +++ b/packages/http-client-python/generator/pygen/codegen/serializers/builder_serializer.py @@ -793,6 +793,34 @@ def _create_body_parameter( retval.extend(self._serialize_body_parameter(builder)) return retval + @staticmethod + def _collapsed_binary_bytes_overload(builder: OperationType) -> Optional[OperationType]: + """Return the binary overload of a binary ``bytes`` body, or ``None``. + + A binary ``bytes`` body pairs a ``bytes`` overload (binary content type) with the added + ``IO[bytes]`` overload. Both serialize to raw content on the same content kwarg, so body + serialization collapses to a single unconditional assignment. This returns the binary + overload to serialize in that case, or ``None`` when the isinstance branch is needed. + """ + if not builder.overloads: + return None + binary_ov = next( + (o for o in builder.overloads if isinstance(o.parameters.body_parameter.type, BinaryType)), None + ) + other_ov = next( + (o for o in builder.overloads if not isinstance(o.parameters.body_parameter.type, BinaryType)), None + ) + if ( + binary_ov is not None + and other_ov is not None + and isinstance(other_ov.parameters.body_parameter.type, ByteArraySchema) + and other_ov.parameters.body_parameter.default_content_type != "application/json" + and binary_ov.request_builder.parameters.body_parameter.client_name + == other_ov.request_builder.parameters.body_parameter.client_name + ): + return cast(OperationType, binary_ov) + return None + def _initialize_overloads(self, builder: OperationType, is_paging: bool = False) -> list[str]: retval: list[str] = [] # For paging, we put body parameter in local place outside `prepare_request` @@ -822,23 +850,7 @@ def _initialize_overloads(self, builder: OperationType, is_paging: bool = False) # emit a single unconditional assignment instead of an `isinstance` branch (which would be # redundant and confuse mypy's type narrowing). Since the assignment is unconditional, the # `_ = None` pre-init below is skipped for this case as well. - collapsed_binary_bytes_overload: Optional[OperationType] = None - if builder.overloads: - binary_bytes_binary_ov = next( - (o for o in builder.overloads if isinstance(o.parameters.body_parameter.type, BinaryType)), None - ) - binary_bytes_other_ov = next( - (o for o in builder.overloads if not isinstance(o.parameters.body_parameter.type, BinaryType)), None - ) - if ( - binary_bytes_binary_ov is not None - and binary_bytes_other_ov is not None - and isinstance(binary_bytes_other_ov.parameters.body_parameter.type, ByteArraySchema) - and binary_bytes_other_ov.parameters.body_parameter.default_content_type != "application/json" - and binary_bytes_binary_ov.request_builder.parameters.body_parameter.client_name - == binary_bytes_other_ov.request_builder.parameters.body_parameter.client_name - ): - collapsed_binary_bytes_overload = cast(OperationType, binary_bytes_binary_ov) + collapsed_binary_bytes_overload = self._collapsed_binary_bytes_overload(builder) if not all_dpg_model_overloads and collapsed_binary_bytes_overload is None: for v in sorted(set(client_names), key=client_names.index):