Skip to content

[http-client-python] Fix discriminator subclass :vartype pointing at non-existent symbol - #12127

Merged
iscai-msft merged 2 commits into
microsoft:mainfrom
ShivamSharma43:fix/10575-discriminator-vartype
Oct 21, 2026
Merged

iscai-msft merged 2 commits into
microsoft:mainfrom
ShivamSharma43:fix/10575-discriminator-vartype

Conversation

@ShivamSharma43

Copy link
Copy Markdown
Contributor

Summary

For discriminated subclasses, the generated :vartype of the discriminator property referenced the upper-cased enum member name as if it were a module-level symbol:

:vartype type: str or ~azure.search.documents.knowledgebases.models.MODEL_WEB_SUMMARIZATION

models.MODEL_WEB_SUMMARIZATION does not exist, so the Sphinx cross-reference cannot resolve. With this change the docstring points at the discriminator enum class, which the models module does export:

:vartype type: str or ~azure.search.documents.knowledgebases.models.KnowledgeBaseActivityRecordType

Root cause

EnumValue.docstring_type() in generator/pygen/codegen/models/enum_type.py built the reference as f"{client_namespace}.models.{self.name}", where self.name is the enum member's name, not the enum's. A discriminator property on a subclass is typed as a single EnumValue, so every discriminator subclass got the bad reference. (The type annotation, Literal[KnowledgeBaseActivityRecordType.MODEL_WEB_SUMMARIZATION], was already correct.)

Fix

Use self.enum_type.name so the reference points at the enum class. This matches what EnumType.docstring_type() already produces for the base class. generation-subdir handling is unchanged.

Tests

Added to tests/unit/test_typeddict.py, in the existing EnumValue section:

  • test_enum_value_docstring_type_references_enum_class: the docstring type is str or ~<ns>.models.Color and matches the parent EnumType's docstring type.
  • test_enum_value_docstring_type_with_generation_subdir: generation-subdir is still included in the path.
  • test_discriminator_vartype_references_enum_class: DpgModelSerializer.variable_documentation_string on a discriminator property emits :vartype type: str or ~<ns>.models.ActivityRecordType and not the member name.

All three fail on main (for example, - ...models.ActivityRecordType / + ...models.MODEL_WEB_SUMMARIZATION) and pass with this fix. black --check and pylint are clean on the changed files. A chronus changeset (fix) is included.

Fixes #10575

🤖 Generated with Claude Code

EnumValue.docstring_type built the Sphinx cross-reference from the enum
member name (e.g. ~pkg.models.MODEL_WEB_SUMMARIZATION), which is not a
symbol of the models module. Reference the enum class instead
(~pkg.models.KnowledgeBaseActivityRecordType), matching EnumType.

Fixes microsoft#10575

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@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 Oct 7, 2026
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).
1 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

@microsoft-github-policy-service microsoft-github-policy-service Bot added the stale Mark a PR that hasn't been recently updated and will be closed. label Oct 21, 2026
@microsoft-github-policy-service

Copy link
Copy Markdown
Contributor

Hi @Shivam Sharma (@ShivamSharma43). Your PR has had no update for 14 days and it is marked as a stale PR. If it is not updated within 14 additional days, the PR will automatically be closed. The stale label is removed automatically when you update or comment on your PR, or when a maintainer reviews it. You can also remove the label manually.

@ShivamSharma43

Copy link
Copy Markdown
Contributor Author

Merged the latest main (no conflicts; the change itself is unchanged: :vartype for a discriminator subclass now points at the enum member that exists in the generated code). Still relevant on current main. iscai-msft Yuchao Yan (@msyyc) could one of you take a look when you have a moment?

Copilot AI balanced review requested due to automatic review settings October 21, 2026 15:27

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@microsoft-github-policy-service microsoft-github-policy-service Bot removed the stale Mark a PR that hasn't been recently updated and will be closed. label Oct 21, 2026
@pkg-pr-new

pkg-pr-new Bot commented Oct 21, 2026

Copy link
Copy Markdown

Open in StackBlitz

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

commit: dcd98c1

@github-actions

Copy link
Copy Markdown
Contributor

All changed packages have been documented.

  • ✅ @typespec/http-client-python
Show changes

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

Fix the :vartype docstring of constant enum values (such as discriminator properties on polymorphic subclasses) to reference the enum class instead of a non-existent module-level symbol named after the enum member.

@github-actions

Copy link
Copy Markdown
Contributor

Python emitter diff

Baseline gh:88e5bd18b07d0cbd3bbe92946aff36beaf707b54 vs this PR.

Diff summary: 4 file(s), +6 / -6

Rendered diff: inline on the run summary, or the emitter-diff-html artifact.

Informational check (eng/emitter-diff); does not block the PR.

@iscai-msft iscai-msft left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks great, thanks so much Shivam Sharma (@ShivamSharma43)! sorry for the delay in getting back to you. thank you so much for contributing, Libba Lawrence (@l0lawrence) do you know when the next python release is?

@iscai-msft
iscai-msft enabled auto-merge October 21, 2026 21:02
@iscai-msft
iscai-msft added this pull request to the merge queue Oct 21, 2026
@l0lawrence

Copy link
Copy Markdown
Member

looks great, thanks so much Shivam Sharma (Shivam Sharma (@ShivamSharma43))! sorry for the delay in getting back to you. thank you so much for contributing, Libba Lawrence (Libba Lawrence (@l0lawrence)) do you know when the next python release is?

should be one later this month or early next month

Merged via the queue into microsoft:main with commit 51fe841 Oct 21, 2026
31 of 32 checks passed
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.

[Bug]: [http-client-python] Discriminator subclass :vartype points at non-existent symbol

4 participants