Skip to content

[CU SDK] Remove models.pyi#45514

Open
chienyuanchang wants to merge 18 commits intomainfrom
cu_sdk/models_pyi_issue
Open

[CU SDK] Remove models.pyi#45514
chienyuanchang wants to merge 18 commits intomainfrom
cu_sdk/models_pyi_issue

Conversation

@chienyuanchang
Copy link
Member

@chienyuanchang chienyuanchang commented Mar 4, 2026

Description

Please add an informative description that covers that changes made by the pull request and link all relevant issues.

If an SDK is being regenerated based on a new API spec, a link to the pull request containing these API spec changes should be included above.

From customer-reported issue: #45489

Fix type checker visibility for azure-ai-contentunderstanding models

The package included a hand-written _models.pyi stub that provided type info for the .value property on ContentField subtypes. Per PEP 561, .pyi stubs take complete precedence over .py — since the stub only declared 10 field classes, all other 41 generated model classes (e.g. AnalysisResult, AnalyzerDefinition) were invisible to pyright/mypy, causing Unknown type errors.

Fix: Deleted _models.pyi and added TYPE_CHECKING-guarded class redeclarations in models/_patch.py instead. This survives TypeSpec regeneration.

Also includes:

  • TypeSpec regeneration from spec commit 1f65642 (updated generated files: _operations.py, model_base.py, _models.py)
  • Version bump to 1.0.1 (Unreleased)
  • Added [tool.azure-sdk-conda] to pyproject.toml (fixes verifywhl CI check)
  • Added "redef" to cspell.json ignore list
  • Fixed pylint/pyright suppression comments in generated files
  • Applied Black formatting + mypy/pyright file-level directives to 30 sample files
  • Added test_model_exports_and_fields.py to verify all models in __all__ are importable, all field .value properties exist at runtime, and all TYPE_CHECKING redeclarations are properly exported through _patch.py's __all__.

Verified: pyright 0 errors, all tests passed (playback)

All SDK Contribution checklist:

  • The pull request does not introduce [breaking changes]
  • CHANGELOG is updated for new features, bug fixes or other significant changes.
  • I have read the contribution guidelines.

General Guidelines and Best Practices

  • Title of the pull request is clear and informative.
  • There are a small number of commits, each of which have an informative message. This means that previously merged commits do not appear in the history of the PR. For more information on cleaning up the commits in your PR, see this page.

Testing Guidelines

  • Pull request includes test coverage for the included changes.

@chienyuanchang chienyuanchang marked this pull request as ready for review March 4, 2026 18:49
Copilot AI review requested due to automatic review settings March 4, 2026 18:49
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR updates the azure-ai-contentunderstanding SDK package, primarily to remove the _models.pyi stub approach for type-checker support and replace it with TYPE_CHECKING-based redeclarations in models/_patch.py, alongside a small spec pointer update and a patch version bump.

Changes:

  • Removed azure/ai/contentunderstanding/models/_models.pyi and moved the .value type information to TYPE_CHECKING redeclarations in models/_patch.py.
  • Regenerated/updated generated client and utility code (operations streaming behavior now supports an internal decompress toggle; serialization/model base updates).
  • Bumped package version to 1.0.1 and updated README/CHANGELOG accordingly; updated tsp-location.yaml commit pointer.

Reviewed changes

Copilot reviewed 14 out of 14 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
sdk/contentunderstanding/azure-ai-contentunderstanding/tsp-location.yaml Updates the pinned swagger/spec commit reference.
sdk/contentunderstanding/azure-ai-contentunderstanding/azure/ai/contentunderstanding/models/_patch.py Adds TYPE_CHECKING redeclarations for ContentField* .value typing; minor formatting changes.
sdk/contentunderstanding/azure-ai-contentunderstanding/azure/ai/contentunderstanding/models/_models.pyi Deleted stub file in favor of TYPE_CHECKING redeclarations.
sdk/contentunderstanding/azure-ai-contentunderstanding/azure/ai/contentunderstanding/models/_enums.py Removes an unnecessary pylint disable.
sdk/contentunderstanding/azure-ai-contentunderstanding/azure/ai/contentunderstanding/aio/models/_patch.py Minor signature formatting.
sdk/contentunderstanding/azure-ai-contentunderstanding/azure/ai/contentunderstanding/aio/_patch.py Minor formatting change.
sdk/contentunderstanding/azure-ai-contentunderstanding/azure/ai/contentunderstanding/aio/_operations/_operations.py Regenerated async operations; adds decompress handling for streaming responses and adjusts pylint disables.
sdk/contentunderstanding/azure-ai-contentunderstanding/azure/ai/contentunderstanding/_version.py Version bump to 1.0.1.
sdk/contentunderstanding/azure-ai-contentunderstanding/azure/ai/contentunderstanding/_utils/serialization.py Regenerated utility; adjusts pylint disables header.
sdk/contentunderstanding/azure-ai-contentunderstanding/azure/ai/contentunderstanding/_utils/model_base.py Regenerated utility; equality tweak and improved XML/enum deserialization behavior; formatting changes.
sdk/contentunderstanding/azure-ai-contentunderstanding/azure/ai/contentunderstanding/_patch.py Minor formatting change.
sdk/contentunderstanding/azure-ai-contentunderstanding/azure/ai/contentunderstanding/_operations/_operations.py Regenerated sync operations; adds decompress handling for streaming responses and adjusts pylint disables.
sdk/contentunderstanding/azure-ai-contentunderstanding/README.md Adds 1.0.1 row to the SDK↔API version table.
sdk/contentunderstanding/azure-ai-contentunderstanding/CHANGELOG.md Adds 1.0.1 (Unreleased) entry describing the type-checking fix.

Replace blanket mypy/pyright suppressions with proper type-safe patterns:
- Use typing.cast() for AnalysisContent downcasts to DocumentContent/AudioVisualContent
- Use conditional expressions for Optional[dict] field access (.fields.get())
- Use 'is not None' guards for Optional[list] append
- Remove all pyright suppressions from all 16 sample files (8 sync + 8 async)
- Remove mypy assignment/union-attr suppressions from all 16 files
- Keep minimal mypy attr-defined suppression in only 4 files where needed
  (invoice samples: .value on field types; raw_json samples: .json() on response)
@chienyuanchang chienyuanchang force-pushed the cu_sdk/models_pyi_issue branch from 15f8c80 to 2edb17f Compare March 7, 2026 02:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants