Skip to content

Commit adc2a2a

Browse files
Copilotmsyyciscai-msft
authored
Drop Python 3.9 support in http-client-python (min Python 3.10) (#10500)
- [x] `model_type.py`: Remove `sys.version_info >= (3, 8)` version check for `Literal` import — generator requires Python 3.10+, also removes now-unused `sys` import - [x] `client.py`: Change `Self` import generation to use version-conditional import (`typing.Self` on 3.11+, `typing_extensions.Self` on 3.10) - [x] `model_base.py.jinja2`: Replace `from typing_extensions import Self` with `if sys.version_info >= (3, 11): from typing import Self else: from typing_extensions import Self` - [x] `serialization.py.jinja2`: Same `Self` conditional import pattern - [x] `model_base.py.jinja2`: Replace `typing.Dict[str, typing.Any]` with built-in `dict[str, typing.Any]` - [x] `import_serializer.py`: Auto-add `import sys` when any `version_modules` imports are present to fix `NameError: name 'sys' is not defined` in generated `_client.py` files - [x] Fix `wrong-import-position`/`reimported` lint errors: move conditional `Self` block to end of imports in templates, remove duplicate `import sys`, and emit versioned imports at end in `_get_import_clauses` - [ ] Validate via CI --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: msyyc <70930885+msyyc@users.noreply.github.com> Co-authored-by: Yuchao Yan <yuchaoyan@microsoft.com> Co-authored-by: iscai-msft <43154838+iscai-msft@users.noreply.github.com>
1 parent 5b4d837 commit adc2a2a

20 files changed

Lines changed: 60 additions & 36 deletions

File tree

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
# Change versionKind to one of: internal, fix, dependencies, feature, deprecation, breaking
3+
changeKind: deprecation
4+
packages:
5+
- "@typespec/http-client-python"
6+
---
7+
8+
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.

packages/http-client-python/emitter/src/run-python3.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { patchPythonPath } from "./system-requirements.js";
1111

1212
export async function runPython3(...args: string[]) {
1313
const command = await patchPythonPath(["python", ...args], {
14-
version: ">=3.9",
14+
version: ">=3.10",
1515
environmentVariable: "AUTOREST_PYTHON_EXE",
1616
});
1717
cp.execSync(command.join(" "), {

packages/http-client-python/eng/scripts/ci/config/mypy.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# global configurations
22
[mypy]
3-
python_version = 3.9
3+
python_version = 3.10
44
# Exclude mypy check for sub client tests
55
exclude = .*/clientinitialization/.*\.py
66

packages/http-client-python/eng/scripts/ci/config/pylintrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[MASTER]
2-
py-version=3.9
2+
py-version=3.10
33
ignore-patterns=test_*,conftest,setup
44
reports=no
55

packages/http-client-python/eng/scripts/ci/config/pyrightconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
"reportUnnecessaryCast": "warning",
33
"reportTypeCommentUsage": true,
44
"reportMissingImports": false,
5-
"pythonVersion": "3.9"
5+
"pythonVersion": "3.10"
66
}

packages/http-client-python/eng/scripts/ci/lint.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ async function lintPygenSource(): Promise<boolean> {
169169
"generator/pygen",
170170
"--rcfile=eng/scripts/ci/config/pylintrc",
171171
"--recursive=y",
172-
"--py-version=3.9",
172+
"--py-version=3.10",
173173
]);
174174
}
175175

packages/http-client-python/eng/scripts/ci/run_pylint.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def _single_dir_pylint(mod):
4343
"--evaluation=(max(0, 0 if fatal else 10.0 - ((float(5 * error + warning + refactor + convention + info)/ statement) * 10)))",
4444
"--output-format=parseable",
4545
"--recursive=y",
46-
"--py-version=3.9",
46+
"--py-version=3.10",
4747
]
4848
if is_azure:
4949
pylint_args.append("--load-plugins=pylint_guidelines_checker")

packages/http-client-python/eng/scripts/setup/build_pygen_wheel.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
# --------------------------------------------------------------------------
88
import sys
99

10-
if not sys.version_info >= (3, 9, 0):
11-
raise Exception("Autorest for Python extension requires Python 3.9 at least")
10+
if not sys.version_info >= (3, 10, 0):
11+
raise Exception("Autorest for Python extension requires Python 3.10 at least")
1212

1313
try:
1414
from package_manager import detect_package_manager, PackageManagerNotFoundError
@@ -18,7 +18,7 @@
1818
raise Exception("Your Python installation doesn't have a suitable package manager (pip or uv) available")
1919

2020

21-
# Now we have a package manager (pip or uv) and Py >= 3.9, go to work
21+
# Now we have a package manager (pip or uv) and Py >= 3.10, go to work
2222

2323
from pathlib import Path
2424

packages/http-client-python/eng/scripts/setup/install.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
# --------------------------------------------------------------------------
88
import sys
99

10-
if not sys.version_info >= (3, 9, 0):
10+
if not sys.version_info >= (3, 10, 0):
1111
print(
12-
"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."
12+
"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."
1313
)
1414
sys.exit(2) # Exit code 2 for inadequate environment
1515

@@ -32,7 +32,7 @@
3232
sys.exit(2) # Exit code 2 for inadequate environment
3333

3434

35-
# Now we have a package manager (uv or pip) and Py >= 3.9, go to work
35+
# Now we have a package manager (uv or pip) and Py >= 3.10, go to work
3636
# At this point, both Python and package manager are confirmed to be available
3737
# Any failures from here should fail the npm install, not fallback to Pyodide
3838

packages/http-client-python/eng/scripts/setup/install.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ async function main() {
77
try {
88
// First try to resolve Python path
99
pythonCommand = await patchPythonPath(["python", "./eng/scripts/setup/install.py"], {
10-
version: ">=3.9",
10+
version: ">=3.10",
1111
environmentVariable: "AUTOREST_PYTHON_EXE",
1212
});
1313
} catch (error) {

0 commit comments

Comments
 (0)