[Batch] Fix #33284: Fix Python 3.14 typing compatibility for batch module#33298
[Batch] Fix #33284: Fix Python 3.14 typing compatibility for batch module#33298YangAn-microsoft wants to merge 3 commits intoAzure:devfrom
Conversation
❌AzureCLI-FullTest
|
️✔️AzureCLI-BreakingChangeTest
|
|
Thank you for your contribution! We will review the pull request and get back to you soon. |
|
The git hooks are available for azure-cli and azure-cli-extensions repos. They could help you run required checks before creating the PR. Please sync the latest code with latest dev branch (for azure-cli) or main branch (for azure-cli-extensions). pip install azdev --upgrade
azdev setup -c <your azure-cli repo path> -r <your azure-cli-extensions repo path>
|
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Updates the Azure CLI batch command module to be compatible with Python 3.14 typing/introspection changes, and aligns build/test/release tooling and docs to Python 3.14.
Changes:
- Reworked batch model type introspection to rely on
get_type_hints()/get_args()instead of_nameand regex onstr()of typing objects. - Added additional normalization in type conversion to handle Python 3.14 pipe unions and fully-qualified names.
- Bumped Python version references across packaging metadata, CI pipelines, release scripts, and docs to 3.14.
Reviewed changes
Copilot reviewed 22 out of 22 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| src/azure-cli/setup.py | Advertises Python 3.14 support in package classifiers. |
| src/azure-cli/azure/cli/command_modules/batch/_command_type.py | Fixes typing introspection/type-string normalization for Python 3.14. |
| src/azure-cli-testsdk/setup.py | Advertises Python 3.14 support in package classifiers. |
| src/azure-cli-telemetry/setup.py | Advertises Python 3.14 support in package classifiers. |
| src/azure-cli-core/setup.py | Advertises Python 3.14 support in package classifiers. |
| scripts/release/macos/cask_generate.py | Updates help text example to Python 3.14. |
| scripts/release/macos/build_binary_tar_gz.py | Updates default Python version and packaging layout doc to 3.14. |
| scripts/release/homebrew/docker/formula_generate.py | Updates Homebrew formula generation to Python 3.14. |
| scripts/release/debian/build.sh | Updates embedded Python version used for Debian builds to 3.14.x. |
| scripts/regression_test/regression_test.yml | Runs regression tests using Python 3.14. |
| doc/install_linux_prerequisites.md | Updates stated supported Python range to include 3.14. |
| doc/extensions/authoring.md | Updates extension authoring guidance/examples to Python 3.14. |
| doc/command_guidelines.md | Updates coding practices to require Python 3.14 compatibility. |
| build_scripts/windows/scripts/build.cmd | Updates embedded Python version used for Windows builds to 3.14.x. |
| azure-pipelines.yml | Updates CI matrix/defaults and tasks to use Python 3.14. |
| azure-pipelines-full-tests.yml | Updates full tests pipeline to Python 3.14. |
| .azure-pipelines/templates/macos/macos-sign-notarize-jobs.yml | Updates macOS signing/notarization template default Python to 3.14. |
| .azure-pipelines/templates/macos/macos-publish-jobs.yml | Updates macOS publish template default Python to 3.14. |
| .azure-pipelines/templates/macos/macos-cask-generation-and-tests.yml | Updates macOS cask generation/tests template default Python to 3.14. |
| .azure-pipelines/templates/macos/macos-build-jobs.yml | Updates macOS build template docs/default Python to 3.14. |
| .azure-pipelines/macos-standalone-release.yml | Updates standalone macOS release pipeline default Python to 3.14. |
| .azure-pipelines/breaking-change-tests.yml | Updates breaking change tests to run on Python 3.14. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
In Python 3.14, several breaking changes affect how type annotations are
represented:
- The private _name attribute was removed from Union/Optional types
- str(Optional[X]) now produces X | None (pipe syntax) instead of
yping.Optional[X]
- get_type_hints() resolves ForwardRef strings to actual classes, so
str() on resolved types produces fully-qualified names like
�zure.batch.models._models.Foo instead of ForwardRef('_models.Foo')
Fix by replacing all version-specific introspection with stable public APIs:
1. get_optional_state(): replace _name == 'Optional' check with
ype(None) in get_args(type_hint), which works identically in all
Python versions.
2. get_track1_attribute_map(): replace raw cls.__annotations__
iteration (which contains unresolved ForwardRef strings) with
get_type_hints() to get resolved types, then use get_args() to
detect optional/union patterns instead of regex on string
representations.
3. convert_to_track1_type(): add handlers for:
- Top-level pipe union syntax: A | None -> A
- Inner pipe union syntax: List[str | SomeType] -> List[SomeType]
- <enum 'Name'> string representations (in addition to <class>)
- Fully-qualified �zure.batch.models. and _enums. prefixes
produced when get_type_hints() resolves ForwardRefs to real classes
Verified: batch.json doc output is bit-for-bit identical between
Python 3.13 and Python 3.14 after this fix.
- prefer non-str member for top-level pipe unions - make inner pipe cleanup regex robust to whitespace - add _enums alias mapping for get_type_hints - remove debug print from attribute map - keep _models alias mapped to azure.batch.models exports
93e65ca to
14dc288
Compare
|
Hi @cRui861 @wanghoppe @dpwatrous @wiboris, Note: 2 remaining check failures are expected to be addressed by #33302 |
Related command
az batchDescription
The
az batchcommands fail to load arguments under Python 3.14 due to two breaking changes in thetypingmodule:_nameattribute was removed fromOptional/Uniontypesstr()representation changed to pipe syntax (e.g.X | Noneinstead oftyping.Optional[X])This fix replaces version-specific introspection with stable public APIs (
get_args,get_type_hints) that work identically in Python 3.13 and 3.14.Testing Guide
Run the batch argument loading test:
Passes on both Python 3.13 and 3.14 with identical argument counts.