Skip to content

Make TargetConfiguration.ensure_can_handle behavior dispatch exhaustive (P311-03) - #3998

Merged
Roman Lutz (romanlutz) merged 4 commits into
microsoft:mainfrom
Sainath-Reddy7:p311-03/ensure-can-handle-dispatch
Nov 6, 2026
Merged

Roman Lutz (romanlutz) merged 4 commits into
microsoft:mainfrom
Sainath-Reddy7:p311-03/ensure-can-handle-dispatch

Conversation

@Sainath-Reddy7

Copy link
Copy Markdown
Contributor

Description

Implements the P311-03 TargetConfiguration.ensure_can_handle focused case from #3166 (reserved in the table, due 2026-11-10).

ensure_can_handle checked only UnsupportedCapabilityBehavior.RAISE by equality; every other value — ADAPT and anything a future enum revision adds — fell through to the same generic error, so a new member would silently dispatch to the ADAPT path with no type-check signal. This replaces the check with explicit RAISE/ADAPT dispatch plus a TYPE_CHECKING-only assert_never guard, the same pattern as the merged human_labeled_dataset dispatch (#3830).

Unchanged, per the item's constraints:

  • native-support and configured-normalizer early returns;
  • missing-policy handling (KeyError → the "no handling policy exists" error);
  • both existing error messages, byte-identical;
  • the historical runtime fallback for values outside the declared enum (the ADAPT error);
  • open string, custom-callable and provider-extension dispatch.

Tests

  • New test_ensure_can_handle_unknown_behavior_keeps_historical_fallback pins the fallback with an out-of-enum behavior value (class-level patch, since CapabilityHandlingPolicy is frozen).
  • Existing RAISE / missing-policy / ADAPT-without-normalizer / override tests cover both explicit branches and the preserved messages.
  • tests/unit/prompt_target/target/test_target_configuration.py: 40/40 pass locally; ty check on both changed files: all checks passed.

Checklist

AI assistance disclosure: prepared with an AI coding agent (GLM-5.3) under my direction; I reviewed each line, ran the suite and type checks locally, and stand behind the change.

Copilot AI balanced review requested due to automatic review settings November 6, 2026 06:25

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 insufficient remaining quota. Try requesting a review at a lower effort level.

…ve (P311-03)

Replace the single RAISE equality check plus implicit fall-through
with explicit RAISE/ADAPT dispatch and a TYPE_CHECKING-only
assert_never guard, following the human_labeled_dataset pattern
(microsoft#3830): a future UnsupportedCapabilityBehavior member now surfaces
during type checking instead of silently taking the ADAPT path.
Native-support and configured-normalizer early returns, missing-policy
handling, both error messages and the historical runtime fallback for
values outside the declared enum are unchanged; a new regression pins
that fallback with an out-of-enum behavior value.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@romanlutz
Roman Lutz (romanlutz) added this pull request to the merge queue Nov 6, 2026
Merged via the queue into microsoft:main with commit 174e660 Nov 6, 2026
57 checks passed
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.

3 participants