Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .chronus/changes/python-drop-39-2026-4-27-6-50-0.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
# Change versionKind to one of: internal, fix, dependencies, feature, deprecation, breaking
changeKind: deprecation
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.
2 changes: 1 addition & 1 deletion packages/http-client-python/emitter/src/run-python3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(" "), {
Expand Down
Original file line number Diff line number Diff line change
@@ -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

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[MASTER]
py-version=3.9
py-version=3.10
ignore-patterns=test_*,conftest,setup
reports=no

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
"reportUnnecessaryCast": "warning",
"reportTypeCommentUsage": true,
"reportMissingImports": false,
"pythonVersion": "3.9"
"pythonVersion": "3.10"
}
2 changes: 1 addition & 1 deletion packages/http-client-python/eng/scripts/ci/lint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ async function lintPygenSource(): Promise<boolean> {
"generator/pygen",
"--rcfile=eng/scripts/ci/config/pylintrc",
"--recursive=y",
"--py-version=3.9",
"--py-version=3.10",
]);
}

Expand Down
2 changes: 1 addition & 1 deletion packages/http-client-python/eng/scripts/ci/run_pylint.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down
6 changes: 3 additions & 3 deletions packages/http-client-python/eng/scripts/setup/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

Expand Down
2 changes: 1 addition & 1 deletion packages/http-client-python/eng/scripts/setup/install.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions packages/http-client-python/eng/scripts/setup/prepare.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(" "), {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,14 @@
# --------------------------------------------------------------------------
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
from .property import Property
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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"corehttp": "1.0.0b6",
}

MIN_PYTHON_VERSION = "3.9"
MIN_PYTHON_VERSION = "3.10"
MAX_PYTHON_VERSION = "3.13"


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand All @@ -79,6 +84,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] = []
Expand All @@ -95,6 +107,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)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +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
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"]
Expand Down Expand Up @@ -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]))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.

Expand Down Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,15 @@ except ImportError:
import xml.etree.ElementTree as ET

import isodate # type: ignore
from typing_extensions import Self

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

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

JSON = MutableMapping[str, Any]
Expand Down
1 change: 0 additions & 1 deletion packages/http-client-python/generator/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Loading