Skip to content

[ContentUnderstanding] Remove ContentRange class and use plain strings for content range#45788

Merged
changjian-wang merged 4 commits intochangjian-wang/add-contentrange-samples-doc-audio-videofrom
copilot/sub-pr-45679
Mar 19, 2026
Merged

[ContentUnderstanding] Remove ContentRange class and use plain strings for content range#45788
changjian-wang merged 4 commits intochangjian-wang/add-contentrange-samples-doc-audio-videofrom
copilot/sub-pr-45679

Conversation

Copy link
Contributor

Copilot AI commented Mar 19, 2026

Removes the ContentRange helper class entirely from the Python SDK. Content range values are now passed as plain strings directly — the only supported approach.

Changes

  • Deleted models/_content_range.py — removed the ContentRange class
  • Deleted tests/test_content_range.py — tests for the now-removed class
  • models/_patch.py: Removed ContentRange import and "ContentRange" from __all__
  • _patch.py / aio/_patch.py: Changed content_range parameter type from Optional[Union[str, ContentRange]] to Optional[str]; removed str(content_range) conversion; updated docstrings
  • Binary samples (sample_analyze_binary.py / async): Removed ContentRange import; replaced all factory calls with plain strings (e.g., ContentRange.pages_from(3)"3-", ContentRange.combine(...)"1-3,5,9-"); removed redundant [START *_with_raw_content_range] sections that duplicated values already shown in the typed content range sections
  • URL samples (sample_analyze_url.py / async): Removed ContentRange import and timedelta import; replaced all factory calls with plain strings (e.g., ContentRange.time_range(timedelta(0), timedelta(seconds=5))"0-5000", ContentRange.time_range_from(timedelta(seconds=10))"10000-"); removed redundant [START *_with_raw_content_range] sections for video and audio that duplicated "0-5000" and "5000-" already shown above
  • Tests: Updated test_sample_analyze_binary.py and test_sample_analyze_url.py to remove ContentRange import and replace all factory calls with plain strings; simplified test methods to use plain strings directly
# Before — typed factory methods
content_range=ContentRange.pages_from(3)
content_range=str(ContentRange.time_range(timedelta(0), timedelta(seconds=5)))

# After — plain string passed directly
content_range="3-"
content_range="0-5000"

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Co-authored-by: changjian-wang <15209050+changjian-wang@users.noreply.github.com>
Copilot AI changed the title [WIP] [ContentUnderstanding] Add ContentRange samples for document, video, and audio [ContentUnderstanding] Use plain strings for raw content range samples Mar 19, 2026
Copilot AI requested a review from changjian-wang March 19, 2026 02:19
@changjian-wang changjian-wang marked this pull request as ready for review March 19, 2026 02:32
@changjian-wang
Copy link
Member

@copilot If should remove class models/_content_range.py and related code?

Copy link
Contributor Author

Copilot AI commented Mar 19, 2026

@copilot If should remove class models/_content_range.py and related code?

Based on the previous feedback ("Python/JS samples should use plain strings as the direct equivalent"), removing ContentRange is a reasonable option to simplify the Python SDK. However, the class still provides real value:

  • Timedelta conversion: ContentRange.time_range(timedelta(0), timedelta(seconds=5))"0-5000" handles the ms conversion automatically — users don't need to manually calculate milliseconds.
  • Input validation: catches bad inputs (page < 1, end < start, negative times) before the API call.
  • Discoverability: factory methods (.pages_from(), .time_range(), etc.) appear in IDE autocomplete, helping users learn the wire format.

My recommendation: keep ContentRange as it adds genuine value (especially for time ranges), but the plain string approach should be the primary demonstration in samples (which is already done after the last update). The class acts as a convenience helper, not a required abstraction.

If you decide you want me to remove it, I can:

  1. Delete models/_content_range.py
  2. Remove the export from models/_patch.py
  3. Update _patch.py / aio/_patch.py to change Union[str, ContentRange] back to str
  4. Update all samples and tests to replace typed factory calls with their plain-string equivalents (e.g., ContentRange.time_range(timedelta(0), timedelta(seconds=5))"0-5000")

Let me know if you'd like me to proceed with the removal.

@changjian-wang
Copy link
Member

@copilot If should remove class models/_content_range.py and related code?

Based on the previous feedback ("Python/JS samples should use plain strings as the direct equivalent"), removing ContentRange is a reasonable option to simplify the Python SDK. However, the class still provides real value:

  • Timedelta conversion: ContentRange.time_range(timedelta(0), timedelta(seconds=5))"0-5000" handles the ms conversion automatically — users don't need to manually calculate milliseconds.
  • Input validation: catches bad inputs (page < 1, end < start, negative times) before the API call.
  • Discoverability: factory methods (.pages_from(), .time_range(), etc.) appear in IDE autocomplete, helping users learn the wire format.

My recommendation: keep ContentRange as it adds genuine value (especially for time ranges), but the plain string approach should be the primary demonstration in samples (which is already done after the last update). The class acts as a convenience helper, not a required abstraction.

If you decide you want me to remove it, I can:

  1. Delete models/_content_range.py
  2. Remove the export from models/_patch.py
  3. Update _patch.py / aio/_patch.py to change Union[str, ContentRange] back to str
  4. Update all samples and tests to replace typed factory calls with their plain-string equivalents (e.g., ContentRange.time_range(timedelta(0), timedelta(seconds=5))"0-5000")

Let me know if you'd like me to proceed with the removal.

Yes, please proceed with the removal. We only use raw string instead of type class.

Co-authored-by: changjian-wang <15209050+changjian-wang@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Mar 19, 2026

@copilot If should remove class models/_content_range.py and related code?

Based on the previous feedback ("Python/JS samples should use plain strings as the direct equi...

Done in commit 0087ef7c. Removed the ContentRange class and all related code:

  • Deleted models/_content_range.py and tests/test_content_range.py
  • Removed "ContentRange" from models/_patch.py __all__
  • Updated _patch.py / aio/_patch.py: content_range parameter is now Optional[str] (no more Union[str, ContentRange]), removed the str(content_range) conversion
  • Updated all 4 sample files to remove the ContentRange import and replace factory calls with equivalent plain strings (e.g., ContentRange.pages_from(3)"3-", ContentRange.combine(...)"1-3,5,9-")
  • Updated both test files to use plain strings directly and remove the factory-method-vs-raw-string comparison sections

Copilot AI changed the title [ContentUnderstanding] Use plain strings for raw content range samples [ContentUnderstanding] Remove ContentRange class and use plain strings for content range Mar 19, 2026
Copilot AI requested a review from changjian-wang March 19, 2026 03:20
@changjian-wang
Copy link
Member

@copilot In file sdk/contentunderstanding/azure-ai-contentunderstanding/samples/async_samples/sample_analyze_binary_async.py, content_range="1-3,5,9-", the content_range="1-3,5,9-" appears twice. Is this reasonable?

Now that ContentRange class is removed and all content ranges are plain
strings, the [START *_with_raw_content_range] sections duplicated values
already shown in the typed content range sections (e.g. "1-3,5,9-" appeared
twice in binary samples, "0-5000" twice in video URL samples). Removed the
redundant sections from all four sample files.

Co-authored-by: changjian-wang <15209050+changjian-wang@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Mar 19, 2026

@copilot In file sdk/contentunderstanding/azure-ai-contentunderstanding/samples/async_samples/sample_analyze_binary_async.py, content_range="1-3,5,9-", the content_range="1-3,5,9-" a...

Correct — those were leftover "raw string" sections from when ContentRange existed to contrast factory methods vs plain strings. Now that all content ranges are plain strings, the [START *_with_raw_content_range] sections duplicated values already shown above. Removed them from all four sample files in 41e718d6.

@changjian-wang changjian-wang merged commit 8f8f84e into changjian-wang/add-contentrange-samples-doc-audio-video Mar 19, 2026
3 checks passed
@changjian-wang changjian-wang deleted the copilot/sub-pr-45679 branch March 19, 2026 05:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants