Skip to content

Drop Python 3.9 support in http-client-python (min Python 3.10)#10500

Queued
Copilot wants to merge 7 commits intomainfrom
copilot/drop-python-3-9
Queued

Drop Python 3.9 support in http-client-python (min Python 3.10)#10500
Copilot wants to merge 7 commits intomainfrom
copilot/drop-python-3-9

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 27, 2026

  • 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
  • client.py: Change Self import generation to use version-conditional import (typing.Self on 3.11+, typing_extensions.Self on 3.10)
  • 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
  • serialization.py.jinja2: Same Self conditional import pattern
  • model_base.py.jinja2: Replace typing.Dict[str, typing.Any] with built-in dict[str, typing.Any]
  • 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
  • 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

Copilot AI linked an issue Apr 27, 2026 that may be closed by this pull request
@microsoft-github-policy-service microsoft-github-policy-service Bot added the emitter:client:python Issue for the Python client emitter: @typespec/http-client-python label Apr 27, 2026
Copilot AI changed the title [WIP] Update minimum Python version to 3.10 Drop Python 3.9 support in http-client-python (min Python 3.10) Apr 27, 2026
Copilot AI requested a review from msyyc April 27, 2026 06:59
@msyyc msyyc marked this pull request as ready for review April 27, 2026 07:41
Comment thread .chronus/changes/python-drop-39-2026-4-27-6-50-0.md Outdated
@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented Apr 27, 2026

Open in StackBlitz

npm i https://pkg.pr.new/@typespec/http-client-python@10500

commit: eefcc38

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 27, 2026

All changed packages have been documented.

  • @typespec/http-client-python
Show changes

@typespec/http-client-python - deprecation ✏️

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.

@azure-sdk
Copy link
Copy Markdown
Collaborator

You can try these changes here

🛝 Playground 🌐 Website 🛝 VSCode Extension

@msyyc msyyc enabled auto-merge April 27, 2026 08:17
@iscai-msft
Copy link
Copy Markdown
Member

@copilot is there anything in our generated code (for example, using typing_extensions) that we can drop now that we don't have to support 3.9? If so please also make those changes

- 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>
@iscai-msft
Copy link
Copy Markdown
Member

@copilot you've removed sys as an import in the generated code, it's still required under some instances. inspect the failures and add it back

…ated

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>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Apr 27, 2026

@copilot you've removed sys as an import in the generated code, it's still required under some instances. inspect the failures and add it back

Fixed in bce2378. The _serialize_versioned_package function was generating if sys.version_info >= ... blocks but sys was never imported. I added a _add_sys_import_if_needed() method to FileImportSerializer that automatically adds import sys whenever any version_modules imports are present in the file — the same pattern already used for TYPE_CHECKING.

Copilot AI requested a review from iscai-msft April 27, 2026 20:09
@msyyc
Copy link
Copy Markdown
Contributor

msyyc commented Apr 28, 2026

@copilot fix the following lint error of generated code:

2026-04-27T20:43:27.7312939Z ************* Module typetest.model.usage._client
2026-04-27T20:43:27.7314927Z generated/azure/typetest-model-usage/typetest/model/usage/_client.py:18: [C0413(wrong-import-position), ] Import "from azure.core import PipelineClient" should be placed at the top of the module
2026-04-27T20:43:27.7315953Z generated/azure/typetest-model-usage/typetest/model/usage/_client.py:19: [C0413(wrong-import-position), ] Import "from azure.core.pipeline import policies" should be placed at the top of the module
2026-04-27T20:43:27.7317281Z generated/azure/typetest-model-usage/typetest/model/usage/_client.py:20: [C0413(wrong-import-position), ] Import "from azure.core.rest import HttpRequest, HttpResponse" should be placed at the top of the module
2026-04-27T20:43:27.7318379Z generated/azure/typetest-model-usage/typetest/model/usage/_client.py:22: [C0413(wrong-import-position), ] Import "from ._configuration import UsageClientConfiguration" should be placed at the top of the module
2026-04-27T20:43:27.7326162Z generated/azure/typetest-model-usage/typetest/model/usage/_client.py:23: [C0413(wrong-import-position), ] Import "from ._operations import _UsageClientOperationsMixin" should be placed at the top of the module
2026-04-27T20:43:27.7332083Z generated/azure/typetest-model-usage/typetest/model/usage/_client.py:24: [C0413(wrong-import-position), ] Import "from ._utils.serialization import Deserializer, Serializer" should be placed at the top of the module
2026-04-27T20:43:27.7333224Z ************* Module typetest.model.usage._utils.serialization
2026-04-27T20:43:27.7334226Z generated/azure/typetest-model-usage/typetest/model/usage/_utils/serialization.py:48: [C0413(wrong-import-position), ] Import "from azure.core.exceptions import DeserializationError, SerializationError" should be placed at the top of the module
2026-04-27T20:43:27.7335317Z generated/azure/typetest-model-usage/typetest/model/usage/_utils/serialization.py:49: [C0413(wrong-import-position), ] Import "from azure.core.serialization import NULL as CoreNull" should be placed at the top of the module
2026-04-27T20:43:27.7339374Z ************* Module typetest.model.usage._utils.model_base
2026-04-27T20:43:27.7346113Z generated/azure/typetest-model-usage/typetest/model/usage/_utils/model_base.py:26: [W0404(reimported), ] Reimport 'sys' (imported line 15)
2026-04-27T20:43:27.7347249Z generated/azure/typetest-model-usage/typetest/model/usage/_utils/model_base.py:32: [C0413(wrong-import-position), ] Import "import isodate" should be placed at the top of the module
2026-04-27T20:43:27.7348356Z generated/azure/typetest-model-usage/typetest/model/usage/_utils/model_base.py:33: [C0413(wrong-import-position), ] Import "from azure.core.exceptions import DeserializationError" should be placed at the top of the module
2026-04-27T20:43:27.7349207Z generated/azure/typetest-model-usage/typetest/model/usage/_utils/model_base.py:34: [C0413(wrong-import-position), ] Import "from azure.core import CaseInsensitiveEnumMeta" should be placed at the top of the module
2026-04-27T20:43:27.7350093Z generated/azure/typetest-model-usage/typetest/model/usage/_utils/model_base.py:35: [C0413(wrong-import-position), ] Import "from azure.core.pipeline import PipelineResponse" should be placed at the top of the module
2026-04-27T20:43:27.7350935Z generated/azure/typetest-model-usage/typetest/model/usage/_utils/model_base.py:36: [C0413(wrong-import-position), ] Import "from azure.core.serialization import _Null" should be placed at the top of the module
2026-04-27T20:43:27.7351748Z generated/azure/typetest-model-usage/typetest/model/usage/_utils/model_base.py:37: [C0413(wrong-import-position), ] Import "from azure.core.rest import HttpResponse" should be placed at the top of the module
2026-04-27T20:43:27.7352549Z generated/azure/typetest-model-usage/typetest/model/usage/_utils/model_base.py:26: [C0412(ungrouped-imports), ] Imports from package sys are not grouped
2026-04-27T20:43:27.7353163Z ************* Module typetest.model.usage.aio._client
2026-04-27T20:43:27.7353831Z generated/azure/typetest-model-usage/typetest/model/usage/aio/_client.py:18: [C0413(wrong-import-position), ] Import "from azure.core import AsyncPipelineClient" should be placed at the top of the module
2026-04-27T20:43:27.7354831Z generated/azure/typetest-model-usage/typetest/model/usage/aio/_client.py:19: [C0413(wrong-import-position), ] Import "from azure.core.pipeline import policies" should be placed at the top of the module
2026-04-27T20:43:27.7355650Z generated/azure/typetest-model-usage/typetest/model/usage/aio/_client.py:20: [C0413(wrong-import-position), ] Import "from azure.core.rest import AsyncHttpResponse, HttpRequest" should be placed at the top of the module
2026-04-27T20:43:27.7356510Z generated/azure/typetest-model-usage/typetest/model/usage/aio/_client.py:22: [C0413(wrong-import-position), ] Import "from .._utils.serialization import Deserializer, Serializer" should be placed at the top of the module
2026-04-27T20:43:27.7357685Z generated/azure/typetest-model-usage/typetest/model/usage/aio/_client.py:23: [C0413(wrong-import-position), ] Import "from ._configuration import UsageClientConfiguration" should be placed at the top of the module
2026-04-27T20:43:27.7358397Z generated/azure/typetest-model-usage/typetest/model/usage/aio/_client.py:24: [C0413(wrong-import-position), ] Import "from ._operations import _UsageClientOperationsMixin" should be placed at the top of the module

- 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>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Apr 28, 2026

@copilot fix the following lint error of generated code:

...

Fixed in 24f3918. Three issues addressed:

  1. reimported (sys imported twice): Removed the duplicate import sys I had added in model_base.py.jinja2 (it was already imported at the top).
  2. wrong-import-position in templates: Moved the if sys.version_info >= (3, 11) ... Self block to after all from X import Y imports in both model_base.py.jinja2 and serialization.py.jinja2.
  3. wrong-import-position in generated _client.py: Updated _get_import_clauses in import_serializer.py to defer all version_modules imports to the end, so they are emitted after every regular from X import Y clause across all import types. This way from azure.core import PipelineClient is no longer flagged as coming after the if sys.version_info block.

Copilot AI requested a review from msyyc April 28, 2026 02:18
@msyyc msyyc disabled auto-merge April 28, 2026 03:21
@msyyc msyyc enabled auto-merge April 28, 2026 03:23
@msyyc msyyc added this pull request to the merge queue Apr 28, 2026
Any commits made after this event will not be merged.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

emitter:client:python Issue for the Python client emitter: @typespec/http-client-python

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Drop python 3.9

5 participants