fix(http-client-python): avoid _enums import for constant enum values in typeddict mode#11212
Merged
msyyc merged 2 commits intoJul 9, 2026
Merged
Conversation
… in typeddict mode In models-mode: typeddict, enums are emitted as Literal aliases in types.py and _enums.py is never generated. A single constant enum value previously annotated as Literal[Color.RED] and imported Color from the nonexistent ..models._enums module. It now annotates with its literal value (e.g. Literal["red"]) and skips the _enums import. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
commit: |
Contributor
|
All changed packages have been documented.
Show changes
|
|
You can try these changes here
|
Member
Author
|
fixes #11210 |
iscai-msft
approved these changes
Jul 9, 2026
Member
Author
msyyc
approved these changes
Jul 9, 2026
tadelesh
pushed a commit
that referenced
this pull request
Jul 9, 2026
… in typeddict mode (#11212) ## Problem In `models-mode: typeddict`, enums are emitted as `Literal` aliases in `types.py` (e.g. `Color = Literal["red", "blue"]`) and `_enums.py` is **never generated**. However, a single constant enum value (`EnumValue`) still used the dpg-style annotation `Literal[Color.RED]` and imported `Color` from `..models._enums` — a module that does not exist in typeddict mode, and an attribute (`Color.RED`) that a `Literal` alias does not have. ## Fix `EnumValue`, in typeddict mode only: - `type_annotation` returns the raw literal value — `Literal["red"]` — instead of `Literal[Color.RED]`. - `imports` skips the `_enums` import (only `typing.Literal` is needed). dpg / msrest behavior is unchanged. `ConstantType` is unaffected (it already uses primitive value types). ```python # models-mode: typeddict — before (broken) from ..models._enums import Color # _enums.py never generated x: Literal[Color.RED] # Color is a Literal alias, has no .RED # after from typing import Literal x: Literal["red"] ``` This scenario is what I have a question on: ```python # models-mode: typeddict — before (broken) from ..models._enums import Foo # _enums.py never generated Foo = Literal["bar"] x: Literal[Foo.BAR] # after from typing import Literal Foo = Literal["bar"] # enums are extensible so at any time Foo could become Foo = Literal["bar", "bar2"]???? x: Literal["bar"] ``` versus where it is the whole enum type ```python # models-mode: typeddict — before (broken) from ..models._enums import Foo # _enums.py never generated Foo = Literal["bar"] x: Foo # after from typing import Literal Foo = Literal["bar"] x: Foo ``` Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
In
models-mode: typeddict, enums are emitted asLiteralaliases intypes.py(e.g.Color = Literal["red", "blue"]) and_enums.pyis never generated. However, a single constant enum value (EnumValue) still used the dpg-style annotationLiteral[Color.RED]and importedColorfrom..models._enums— a module that does not exist in typeddict mode, and an attribute (Color.RED) that aLiteralalias does not have.Fix
EnumValue, in typeddict mode only:type_annotationreturns the raw literal value —Literal["red"]— instead ofLiteral[Color.RED].importsskips the_enumsimport (onlytyping.Literalis needed).dpg / msrest behavior is unchanged.
ConstantTypeis unaffected (it already uses primitive value types).This scenario is what I have a question on:
versus where it is the whole enum type