From 5f1f6626d98a273fcc90ed2b38c66f335ec994b7 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 27 Apr 2026 06:49:50 +0000 Subject: [PATCH 1/6] Initial plan From 1d9959dca5052cafd3ce6a360c5482de90b39838 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 27 Apr 2026 06:54:09 +0000 Subject: [PATCH 2/6] Drop Python 3.9, bump min version to 3.10 in http-client-python Agent-Logs-Url: https://github.com/microsoft/typespec/sessions/4528d934-af72-4520-89b9-5de603ef92d6 Co-authored-by: msyyc <70930885+msyyc@users.noreply.github.com> --- .chronus/changes/python-drop-39-2026-4-27-6-50-0.md | 8 ++++++++ packages/http-client-python/emitter/src/run-python3.ts | 2 +- .../http-client-python/eng/scripts/ci/config/mypy.ini | 2 +- .../http-client-python/eng/scripts/ci/config/pylintrc | 2 +- .../eng/scripts/ci/config/pyrightconfig.json | 2 +- packages/http-client-python/eng/scripts/ci/lint.ts | 2 +- packages/http-client-python/eng/scripts/ci/run_pylint.py | 2 +- .../eng/scripts/setup/build_pygen_wheel.py | 6 +++--- packages/http-client-python/eng/scripts/setup/install.py | 6 +++--- packages/http-client-python/eng/scripts/setup/install.ts | 2 +- packages/http-client-python/eng/scripts/setup/prepare.py | 4 ++-- .../http-client-python/eng/scripts/setup/run-python3.ts | 2 +- .../pygen/codegen/serializers/general_serializer.py | 2 +- .../templates/packaging_templates/README.md.jinja2 | 6 +++--- packages/http-client-python/generator/setup.py | 1 - 15 files changed, 28 insertions(+), 21 deletions(-) create mode 100644 .chronus/changes/python-drop-39-2026-4-27-6-50-0.md diff --git a/.chronus/changes/python-drop-39-2026-4-27-6-50-0.md b/.chronus/changes/python-drop-39-2026-4-27-6-50-0.md new file mode 100644 index 00000000000..e33c6d85c08 --- /dev/null +++ b/.chronus/changes/python-drop-39-2026-4-27-6-50-0.md @@ -0,0 +1,8 @@ +--- +# Change versionKind to one of: internal, fix, dependencies, feature, deprecation, breaking +changeKind: breaking +packages: + - "@typespec/http-client-python" +--- + +Drop support for Python 3.9. The minimum supported Python version is now 3.10. Python 3.9 reached end-of-life and is no longer supported by upstream Python. diff --git a/packages/http-client-python/emitter/src/run-python3.ts b/packages/http-client-python/emitter/src/run-python3.ts index 9336f672672..422a28be733 100644 --- a/packages/http-client-python/emitter/src/run-python3.ts +++ b/packages/http-client-python/emitter/src/run-python3.ts @@ -11,7 +11,7 @@ import { patchPythonPath } from "./system-requirements.js"; export async function runPython3(...args: string[]) { const command = await patchPythonPath(["python", ...args], { - version: ">=3.9", + version: ">=3.10", environmentVariable: "AUTOREST_PYTHON_EXE", }); cp.execSync(command.join(" "), { diff --git a/packages/http-client-python/eng/scripts/ci/config/mypy.ini b/packages/http-client-python/eng/scripts/ci/config/mypy.ini index 829e96d3673..6bd11f1f115 100644 --- a/packages/http-client-python/eng/scripts/ci/config/mypy.ini +++ b/packages/http-client-python/eng/scripts/ci/config/mypy.ini @@ -1,6 +1,6 @@ # global configurations [mypy] -python_version = 3.9 +python_version = 3.10 # Exclude mypy check for sub client tests exclude = .*/clientinitialization/.*\.py diff --git a/packages/http-client-python/eng/scripts/ci/config/pylintrc b/packages/http-client-python/eng/scripts/ci/config/pylintrc index 85b2a1b8f8d..387021335fc 100644 --- a/packages/http-client-python/eng/scripts/ci/config/pylintrc +++ b/packages/http-client-python/eng/scripts/ci/config/pylintrc @@ -1,5 +1,5 @@ [MASTER] -py-version=3.9 +py-version=3.10 ignore-patterns=test_*,conftest,setup reports=no diff --git a/packages/http-client-python/eng/scripts/ci/config/pyrightconfig.json b/packages/http-client-python/eng/scripts/ci/config/pyrightconfig.json index 86b3a380220..ef8340726d5 100644 --- a/packages/http-client-python/eng/scripts/ci/config/pyrightconfig.json +++ b/packages/http-client-python/eng/scripts/ci/config/pyrightconfig.json @@ -2,5 +2,5 @@ "reportUnnecessaryCast": "warning", "reportTypeCommentUsage": true, "reportMissingImports": false, - "pythonVersion": "3.9" + "pythonVersion": "3.10" } diff --git a/packages/http-client-python/eng/scripts/ci/lint.ts b/packages/http-client-python/eng/scripts/ci/lint.ts index 9dad879a992..37c9469fd8a 100644 --- a/packages/http-client-python/eng/scripts/ci/lint.ts +++ b/packages/http-client-python/eng/scripts/ci/lint.ts @@ -169,7 +169,7 @@ async function lintPygenSource(): Promise { "generator/pygen", "--rcfile=eng/scripts/ci/config/pylintrc", "--recursive=y", - "--py-version=3.9", + "--py-version=3.10", ]); } diff --git a/packages/http-client-python/eng/scripts/ci/run_pylint.py b/packages/http-client-python/eng/scripts/ci/run_pylint.py index 5a44df63e9c..c184c56a3de 100644 --- a/packages/http-client-python/eng/scripts/ci/run_pylint.py +++ b/packages/http-client-python/eng/scripts/ci/run_pylint.py @@ -43,7 +43,7 @@ def _single_dir_pylint(mod): "--evaluation=(max(0, 0 if fatal else 10.0 - ((float(5 * error + warning + refactor + convention + info)/ statement) * 10)))", "--output-format=parseable", "--recursive=y", - "--py-version=3.9", + "--py-version=3.10", ] if is_azure: pylint_args.append("--load-plugins=pylint_guidelines_checker") diff --git a/packages/http-client-python/eng/scripts/setup/build_pygen_wheel.py b/packages/http-client-python/eng/scripts/setup/build_pygen_wheel.py index 74687b91167..40416a0991d 100644 --- a/packages/http-client-python/eng/scripts/setup/build_pygen_wheel.py +++ b/packages/http-client-python/eng/scripts/setup/build_pygen_wheel.py @@ -7,8 +7,8 @@ # -------------------------------------------------------------------------- import sys -if not sys.version_info >= (3, 9, 0): - raise Exception("Autorest for Python extension requires Python 3.9 at least") +if not sys.version_info >= (3, 10, 0): + raise Exception("Autorest for Python extension requires Python 3.10 at least") try: from package_manager import detect_package_manager, PackageManagerNotFoundError @@ -18,7 +18,7 @@ raise Exception("Your Python installation doesn't have a suitable package manager (pip or uv) available") -# Now we have a package manager (pip or uv) and Py >= 3.9, go to work +# Now we have a package manager (pip or uv) and Py >= 3.10, go to work from pathlib import Path diff --git a/packages/http-client-python/eng/scripts/setup/install.py b/packages/http-client-python/eng/scripts/setup/install.py index 8a3532f1ab9..487acc67b1c 100644 --- a/packages/http-client-python/eng/scripts/setup/install.py +++ b/packages/http-client-python/eng/scripts/setup/install.py @@ -7,9 +7,9 @@ # -------------------------------------------------------------------------- import sys -if not sys.version_info >= (3, 9, 0): +if not sys.version_info >= (3, 10, 0): print( - "Warning: Autorest for Python extension requires Python 3.9 at least. We will run your code with Pyodide since your Python version isn't adequate." + "Warning: Autorest for Python extension requires Python 3.10 at least. We will run your code with Pyodide since your Python version isn't adequate." ) sys.exit(2) # Exit code 2 for inadequate environment @@ -32,7 +32,7 @@ sys.exit(2) # Exit code 2 for inadequate environment -# Now we have a package manager (uv or pip) and Py >= 3.9, go to work +# Now we have a package manager (uv or pip) and Py >= 3.10, go to work # At this point, both Python and package manager are confirmed to be available # Any failures from here should fail the npm install, not fallback to Pyodide diff --git a/packages/http-client-python/eng/scripts/setup/install.ts b/packages/http-client-python/eng/scripts/setup/install.ts index 18100a6046a..0835e6e4cfd 100644 --- a/packages/http-client-python/eng/scripts/setup/install.ts +++ b/packages/http-client-python/eng/scripts/setup/install.ts @@ -7,7 +7,7 @@ async function main() { try { // First try to resolve Python path pythonCommand = await patchPythonPath(["python", "./eng/scripts/setup/install.py"], { - version: ">=3.9", + version: ">=3.10", environmentVariable: "AUTOREST_PYTHON_EXE", }); } catch (error) { diff --git a/packages/http-client-python/eng/scripts/setup/prepare.py b/packages/http-client-python/eng/scripts/setup/prepare.py index ff405d552df..6e6de3d547c 100644 --- a/packages/http-client-python/eng/scripts/setup/prepare.py +++ b/packages/http-client-python/eng/scripts/setup/prepare.py @@ -7,9 +7,9 @@ # -------------------------------------------------------------------------- import sys -if not sys.version_info >= (3, 9, 0): +if not sys.version_info >= (3, 10, 0): raise Warning( - "Autorest for Python extension requires Python 3.9 at least. We will run your code with Pyodide since your Python version isn't adequate." + "Autorest for Python extension requires Python 3.10 at least. We will run your code with Pyodide since your Python version isn't adequate." ) from pathlib import Path diff --git a/packages/http-client-python/eng/scripts/setup/run-python3.ts b/packages/http-client-python/eng/scripts/setup/run-python3.ts index 9336f672672..422a28be733 100644 --- a/packages/http-client-python/eng/scripts/setup/run-python3.ts +++ b/packages/http-client-python/eng/scripts/setup/run-python3.ts @@ -11,7 +11,7 @@ import { patchPythonPath } from "./system-requirements.js"; export async function runPython3(...args: string[]) { const command = await patchPythonPath(["python", ...args], { - version: ">=3.9", + version: ">=3.10", environmentVariable: "AUTOREST_PYTHON_EXE", }); cp.execSync(command.join(" "), { diff --git a/packages/http-client-python/generator/pygen/codegen/serializers/general_serializer.py b/packages/http-client-python/generator/pygen/codegen/serializers/general_serializer.py index ce907c55427..55b399bd391 100644 --- a/packages/http-client-python/generator/pygen/codegen/serializers/general_serializer.py +++ b/packages/http-client-python/generator/pygen/codegen/serializers/general_serializer.py @@ -28,7 +28,7 @@ "corehttp": "1.0.0b6", } -MIN_PYTHON_VERSION = "3.9" +MIN_PYTHON_VERSION = "3.10" MAX_PYTHON_VERSION = "3.13" diff --git a/packages/http-client-python/generator/pygen/codegen/templates/packaging_templates/README.md.jinja2 b/packages/http-client-python/generator/pygen/codegen/templates/packaging_templates/README.md.jinja2 index d95a3a89db8..d40beb74273 100644 --- a/packages/http-client-python/generator/pygen/codegen/templates/packaging_templates/README.md.jinja2 +++ b/packages/http-client-python/generator/pygen/codegen/templates/packaging_templates/README.md.jinja2 @@ -3,7 +3,7 @@ # Microsoft Azure SDK for Python This is the Microsoft {{options["package-pprint-name"]}} Client Library. -This package has been tested with Python 3.9+. +This package has been tested with Python 3.10+. For a more complete view of Azure libraries, see the [azure sdk python release](https://aka.ms/azsdk/python/all). # Usage @@ -40,7 +40,7 @@ python -m pip install {{ options["package-name"] }} #### Prequisites -- Python 3.9 or later is required to use this package. +- Python 3.10 or later is required to use this package. - You need an [Azure subscription][azure_sub] to use this package. - An existing {{ options["package-pprint-name"] }} instance. @@ -121,7 +121,7 @@ This package is generated by `@typespec/http-client-python` with Typespec. ### Prequisites -- Python 3.9 or later is required to use this package. +- Python 3.10 or later is required to use this package. ### Install the package diff --git a/packages/http-client-python/generator/setup.py b/packages/http-client-python/generator/setup.py index 99996b606f3..f432970c9a7 100644 --- a/packages/http-client-python/generator/setup.py +++ b/packages/http-client-python/generator/setup.py @@ -35,7 +35,6 @@ "Development Status :: 4 - Beta", "Programming Language :: Python", "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", "Programming Language :: Python :: 3.12", From 86df43aff4024fb453a71c602fefebdbe6d1f8ab Mon Sep 17 00:00:00 2001 From: Yuchao Yan Date: Mon, 27 Apr 2026 15:42:21 +0800 Subject: [PATCH 3/6] Apply suggestion from @msyyc --- .chronus/changes/python-drop-39-2026-4-27-6-50-0.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.chronus/changes/python-drop-39-2026-4-27-6-50-0.md b/.chronus/changes/python-drop-39-2026-4-27-6-50-0.md index e33c6d85c08..c35e26f1dcc 100644 --- a/.chronus/changes/python-drop-39-2026-4-27-6-50-0.md +++ b/.chronus/changes/python-drop-39-2026-4-27-6-50-0.md @@ -1,6 +1,6 @@ --- # Change versionKind to one of: internal, fix, dependencies, feature, deprecation, breaking -changeKind: breaking +changeKind: deprecation packages: - "@typespec/http-client-python" --- From e2658e1a31ec6475a68af909bccb60b8562f6251 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 27 Apr 2026 16:11:00 +0000 Subject: [PATCH 4/6] Drop Python 3.9 compat: clean up typing_extensions and version checks - model_type.py: remove sys.version_info >= (3, 8) check for Literal, just use `from typing import Literal` directly (generator requires 3.10+) - client.py: use version_modules to generate conditional Self import (typing.Self on 3.11+, typing_extensions.Self on 3.10) - model_base.py.jinja2: replace unconditional typing_extensions.Self with sys.version_info >= (3, 11) conditional import - serialization.py.jinja2: same Self conditional import - model_base.py.jinja2: replace typing.Dict with built-in dict Agent-Logs-Url: https://github.com/microsoft/typespec/sessions/0f0373c2-a172-4430-b890-208867183d7b Co-authored-by: iscai-msft <43154838+iscai-msft@users.noreply.github.com> --- .../generator/pygen/codegen/models/client.py | 3 ++- .../generator/pygen/codegen/models/model_type.py | 8 +------- .../pygen/codegen/templates/model_base.py.jinja2 | 9 +++++++-- .../pygen/codegen/templates/serialization.py.jinja2 | 6 +++++- 4 files changed, 15 insertions(+), 11 deletions(-) diff --git a/packages/http-client-python/generator/pygen/codegen/models/client.py b/packages/http-client-python/generator/pygen/codegen/models/client.py index fd0e25538dd..abb4d83c49d 100644 --- a/packages/http-client-python/generator/pygen/codegen/models/client.py +++ b/packages/http-client-python/generator/pygen/codegen/models/client.py @@ -291,11 +291,12 @@ def imports(self, async_mode: bool, **kwargs) -> FileImport: ImportType.SDKCORE, ) - # import for "Self" + # import for "Self" (typing.Self available from Python 3.11+) file_import.add_submodule_import( "typing_extensions", "Self", ImportType.STDLIB, + version_modules=(((3, 11), "typing", None),), ) if self.need_cloud_setting: file_import.add_submodule_import("typing", "cast", ImportType.STDLIB) diff --git a/packages/http-client-python/generator/pygen/codegen/models/model_type.py b/packages/http-client-python/generator/pygen/codegen/models/model_type.py index d0784f81efb..76ef6e8be8d 100644 --- a/packages/http-client-python/generator/pygen/codegen/models/model_type.py +++ b/packages/http-client-python/generator/pygen/codegen/models/model_type.py @@ -5,8 +5,7 @@ # -------------------------------------------------------------------------- from enum import Enum from collections import OrderedDict -from typing import Any, Optional, TYPE_CHECKING, cast -import sys +from typing import Any, Literal, Optional, TYPE_CHECKING, cast from .utils import add_to_pylint_disable, NamespaceType, LOCALS_LENGTH_LIMIT from .base import BaseType from .constant_type import ConstantType @@ -14,11 +13,6 @@ from .imports import FileImport, ImportType, TypingSection from ...utils import NAME_LENGTH_LIMIT -if sys.version_info >= (3, 8): - from typing import Literal -else: - from typing_extensions import Literal # type: ignore - if TYPE_CHECKING: from .code_model import CodeModel diff --git a/packages/http-client-python/generator/pygen/codegen/templates/model_base.py.jinja2 b/packages/http-client-python/generator/pygen/codegen/templates/model_base.py.jinja2 index 326ff1f4f2c..095c0ac303f 100644 --- a/packages/http-client-python/generator/pygen/codegen/templates/model_base.py.jinja2 +++ b/packages/http-client-python/generator/pygen/codegen/templates/model_base.py.jinja2 @@ -19,7 +19,12 @@ from datetime import datetime, date, time, timedelta, timezone from json import JSONEncoder import xml.etree.ElementTree as ET from collections.abc import MutableMapping -from typing_extensions import Self +import sys + +if sys.version_info >= (3, 11): + from typing import Self +else: + from typing_extensions import Self import isodate from {{ code_model.core_library }}.exceptions import DeserializationError from {{ code_model.core_library }}{{ "" if code_model.is_azure_flavor else ".utils" }} import CaseInsensitiveEnumMeta @@ -617,7 +622,7 @@ class Model(_MyMutableMapping): class_name = self.__class__.__name__ if len(args) > 1: raise TypeError(f"{class_name}.__init__() takes 2 positional arguments but {len(args) + 1} were given") - dict_to_pass: typing.Dict[str, typing.Any] = {} + dict_to_pass: dict[str, typing.Any] = {} if args: if isinstance(args[0], ET.Element): dict_to_pass.update(self._init_from_xml(args[0])) diff --git a/packages/http-client-python/generator/pygen/codegen/templates/serialization.py.jinja2 b/packages/http-client-python/generator/pygen/codegen/templates/serialization.py.jinja2 index 8298b962da3..2645daa57dd 100644 --- a/packages/http-client-python/generator/pygen/codegen/templates/serialization.py.jinja2 +++ b/packages/http-client-python/generator/pygen/codegen/templates/serialization.py.jinja2 @@ -35,7 +35,11 @@ except ImportError: import xml.etree.ElementTree as ET import isodate # type: ignore -from typing_extensions import Self + +if sys.version_info >= (3, 11): + from typing import Self +else: + from typing_extensions import Self from {{ code_model.core_library }}.exceptions import DeserializationError, SerializationError from {{ code_model.core_library }}.serialization import NULL as CoreNull From bce23785c548bafe9715e455a5de164224bbc0e7 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 27 Apr 2026 20:08:34 +0000 Subject: [PATCH 5/6] fix: auto-add `import sys` when version-conditional imports are generated The `_serialize_versioned_package` function generates `if sys.version_info >=` checks but `sys` was not being imported. Add `_add_sys_import_if_needed()` to `FileImportSerializer.__str__` to automatically add `import sys` whenever any `version_modules` imports are present in the file. Fixes NameError: name 'sys' is not defined in generated _client.py files. Agent-Logs-Url: https://github.com/microsoft/typespec/sessions/c39c3758-fcf0-425a-8636-8b292579b6fa Co-authored-by: iscai-msft <43154838+iscai-msft@users.noreply.github.com> --- .../pygen/codegen/serializers/import_serializer.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/packages/http-client-python/generator/pygen/codegen/serializers/import_serializer.py b/packages/http-client-python/generator/pygen/codegen/serializers/import_serializer.py index 94fecd5e46b..56d4c902faa 100644 --- a/packages/http-client-python/generator/pygen/codegen/serializers/import_serializer.py +++ b/packages/http-client-python/generator/pygen/codegen/serializers/import_serializer.py @@ -79,6 +79,13 @@ def _add_type_checking_import(self): if any(self.file_import.get_imports_from_section(TypingSection.TYPING)): self.file_import.add_submodule_import("typing", "TYPE_CHECKING", ImportType.STDLIB) + def _add_sys_import_if_needed(self): + all_imports = list(self.file_import.get_imports_from_section(TypingSection.REGULAR)) + list( + self.file_import.get_imports_from_section(TypingSection.TYPING) + ) + if any(i.version_modules for i in all_imports): + self.file_import.add_import("sys", ImportType.STDLIB) + def get_typing_definitions(self) -> str: def declare_definition(type_name: str, type_definition: TypeDefinition) -> list[str]: ret: list[str] = [] @@ -95,6 +102,7 @@ def declare_definition(type_name: str, type_definition: TypeDefinition) -> list[ def __str__(self) -> str: self._add_type_checking_import() + self._add_sys_import_if_needed() regular_imports = "" regular_imports_list = self._get_imports_list(TypingSection.REGULAR) From 24f3918ff822724ff15a04e796b6312cbc9f24cd Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 28 Apr 2026 02:18:05 +0000 Subject: [PATCH 6/6] fix: emit versioned imports at end of imports to satisfy pylint - Move `if sys.version_info >= (3, 11)` Self import block to after all other imports in `model_base.py.jinja2` and `serialization.py.jinja2` - Remove duplicate `import sys` in `model_base.py.jinja2` - Update `_get_import_clauses` to emit all versioned imports after all regular imports across all import types, fixing wrong-import-position errors in generated `_client.py` files Agent-Logs-Url: https://github.com/microsoft/typespec/sessions/09068dd1-b11f-48cd-a78a-fa047be09e96 Co-authored-by: msyyc <70930885+msyyc@users.noreply.github.com> --- .../pygen/codegen/serializers/import_serializer.py | 13 +++++++++---- .../pygen/codegen/templates/model_base.py.jinja2 | 12 ++++++------ .../pygen/codegen/templates/serialization.py.jinja2 | 6 +++--- 3 files changed, 18 insertions(+), 13 deletions(-) diff --git a/packages/http-client-python/generator/pygen/codegen/serializers/import_serializer.py b/packages/http-client-python/generator/pygen/codegen/serializers/import_serializer.py index 56d4c902faa..f1a5b93b2f9 100644 --- a/packages/http-client-python/generator/pygen/codegen/serializers/import_serializer.py +++ b/packages/http-client-python/generator/pygen/codegen/serializers/import_serializer.py @@ -50,20 +50,25 @@ def _serialize_import_type(imports: list[ImportModel], delimiter: str) -> str: import_list = [] for module_name in sorted(set(i.module_name for i in imports)): normal_imports = [i for i in imports if i.module_name == module_name and not i.version_modules] - versioned_imports = [i for i in imports if i.module_name == module_name and i.version_modules] if normal_imports: import_list.append(_serialize_package(normal_imports, delimiter)) - for i in versioned_imports: - import_list.append(_serialize_versioned_package(i, delimiter)) return delimiter.join(import_list) +def _serialize_versioned_imports(imports: list[ImportModel], delimiter: str) -> str: + """Serialize all versioned imports together, to be emitted after all regular imports.""" + return delimiter.join(_serialize_versioned_package(i, delimiter) for i in imports if i.version_modules) + + def _get_import_clauses(imports: list[ImportModel], delimiter: str) -> list[str]: import_clause = [] for import_type in ImportType: - imports_with_import_type = [i for i in imports if i.import_type == import_type] + imports_with_import_type = [i for i in imports if i.import_type == import_type and not i.version_modules] if imports_with_import_type: import_clause.append(_serialize_import_type(imports_with_import_type, delimiter)) + versioned = [i for i in imports if i.version_modules] + if versioned: + import_clause.append(_serialize_versioned_imports(versioned, delimiter)) return import_clause diff --git a/packages/http-client-python/generator/pygen/codegen/templates/model_base.py.jinja2 b/packages/http-client-python/generator/pygen/codegen/templates/model_base.py.jinja2 index 095c0ac303f..258b741a8dd 100644 --- a/packages/http-client-python/generator/pygen/codegen/templates/model_base.py.jinja2 +++ b/packages/http-client-python/generator/pygen/codegen/templates/model_base.py.jinja2 @@ -19,22 +19,22 @@ from datetime import datetime, date, time, timedelta, timezone from json import JSONEncoder import xml.etree.ElementTree as ET from collections.abc import MutableMapping -import sys - -if sys.version_info >= (3, 11): - from typing import Self -else: - from typing_extensions import Self import isodate from {{ code_model.core_library }}.exceptions import DeserializationError from {{ code_model.core_library }}{{ "" if code_model.is_azure_flavor else ".utils" }} import CaseInsensitiveEnumMeta from {{ code_model.core_library }}.{{ "" if code_model.is_azure_flavor else "runtime." }}pipeline import PipelineResponse from {{ code_model.core_library }}.serialization import _Null + {% if code_model.has_external_type %} from {{ code_model.core_library }}.serialization import TypeHandlerRegistry {% endif %} from {{ code_model.core_library }}.rest import HttpResponse +if sys.version_info >= (3, 11): + from typing import Self +else: + from typing_extensions import Self + _LOGGER = logging.getLogger(__name__) __all__ = ["SdkJSONEncoder", "Model", "rest_field", "rest_discriminator"] diff --git a/packages/http-client-python/generator/pygen/codegen/templates/serialization.py.jinja2 b/packages/http-client-python/generator/pygen/codegen/templates/serialization.py.jinja2 index 2645daa57dd..de51bf9343f 100644 --- a/packages/http-client-python/generator/pygen/codegen/templates/serialization.py.jinja2 +++ b/packages/http-client-python/generator/pygen/codegen/templates/serialization.py.jinja2 @@ -36,14 +36,14 @@ import xml.etree.ElementTree as ET import isodate # type: ignore +from {{ code_model.core_library }}.exceptions import DeserializationError, SerializationError +from {{ code_model.core_library }}.serialization import NULL as CoreNull + if sys.version_info >= (3, 11): from typing import Self else: from typing_extensions import Self -from {{ code_model.core_library }}.exceptions import DeserializationError, SerializationError -from {{ code_model.core_library }}.serialization import NULL as CoreNull - _BOM = codecs.BOM_UTF8.decode(encoding="utf-8") JSON = MutableMapping[str, Any]