Repository navigation
MAINT Return Self from WebSearchConfig.from_metadata (P311-01) - #3626
Open
Julio César Suástegui (juliosuas) wants to merge 1 commit into
Open
Julio César Suástegui (juliosuas) wants to merge 1 commit into
Julio César Suástegui (juliosuas) wants to merge 1 commit into
Conversation
Annotate WebSearchConfig.from_metadata with Self. Both paths (absent policy via cls() and explicit policy via cls.model_validate) already construct the calling class; add subclass runtime and assert_type coverage plus coverage for modes, read-only Mapping input, metadata non-mutation, frozen/extra-forbid validation, invalid payloads and metadata/JSON round trips. Refs microsoft#3166.
This branch has not been deployed
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.
Description
WebSearchConfig.from_metadatais annotated as returningWebSearchConfig, but both of its paths build the calling class:cls()when no policy is present, andcls.model_validate(...)when one is. This annotates it withtyping.Self, so a subclass gets its own type back from the type checker. Runtime behavior is unchanged; only the return annotation and its docstring line change.This follows the same pattern as #3529 (
HarmDefinition.from_yaml) and #3577 (JsonResponseConfig.from_metadata), and covers the remainingWebSearchConfig.from_metadatacase in P311-01.Related: #3166
Tests and Documentation
Added tests in
tests/unit/models/test_web_search_config.py:assert_typefor both paths (absent policy and explicit policy)Mappinginput, and that the input metadata is not mutatedRan on the rebased branch (current
main):ruff checkandruff format --checkon the two touched filesty checkonpyritand the two touched filespytest tests/unit/models/test_web_search_config.py(37 passed)The wider
pytest tests/unit/models(2527 passed) andtests/unit/prompt_targetsuites were run just before the last rebase ontomain, which only brought dependency bumps and an unrelated Docker change.No documentation change is needed, since this is a typing-only change.
AI-assisted; reviewed and tested by me.