Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove update_json_schema (bad practice func) #9125

Merged
merged 3 commits into from Mar 27, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions pydantic/_internal/_std_types_schema.py
Expand Up @@ -33,7 +33,7 @@
from pydantic.types import Strict

from ..config import ConfigDict
from ..json_schema import JsonSchemaValue, update_json_schema
from ..json_schema import JsonSchemaValue
from . import _known_annotated_metadata, _typing_extra, _validators
from ._core_utils import get_type_ref
from ._internal_dataclass import slots_true
Expand Down Expand Up @@ -87,7 +87,7 @@ def get_enum_core_schema(enum_type: type[Enum], config: ConfigDict) -> CoreSchem
def get_json_schema(schema: CoreSchema, handler: GetJsonSchemaHandler) -> JsonSchemaValue:
json_schema = handler(schema)
original_schema = handler.resolve_ref_schema(json_schema)
update_json_schema(original_schema, js_updates)
original_schema.update(js_updates)
return json_schema

# we don't want to add the missing to the schema if it's the default one
Expand All @@ -113,7 +113,7 @@ def get_json_schema(schema: CoreSchema, handler: GetJsonSchemaHandler) -> JsonSc
def get_json_schema_no_cases(_, handler: GetJsonSchemaHandler) -> JsonSchemaValue:
json_schema = handler(core_schema.enum_schema(enum_type, cases, sub_type=sub_type, ref=enum_ref))
original_schema = handler.resolve_ref_schema(json_schema)
update_json_schema(original_schema, js_updates)
original_schema.update(js_updates)
return json_schema

# Use an isinstance check for enums with no cases.
Expand Down
16 changes: 0 additions & 16 deletions pydantic/json_schema.py
Expand Up @@ -89,22 +89,6 @@
_MODE_TITLE_MAPPING: dict[JsonSchemaMode, str] = {'validation': 'Input', 'serialization': 'Output'}


def update_json_schema(schema: JsonSchemaValue, updates: dict[str, Any]) -> JsonSchemaValue:
"""Update a JSON schema in-place by providing a dictionary of updates.

This function sets the provided key-value pairs in the schema and returns the updated schema.

Args:
schema: The JSON schema to update.
updates: A dictionary of key-value pairs to set in the schema.

Returns:
The updated JSON schema.
"""
schema.update(updates)
return schema


JsonSchemaWarningKind = Literal['skipped-choice', 'non-serializable-default']
"""
A type alias representing the kinds of warnings that can be emitted during JSON schema generation.
Expand Down