Skip to content

Commit 9254fd5

Browse files
conradleeclaude
andcommitted
Remove dead code: simplify_nullable_unions feature
GoogleJsonSchemaTransformer was the only user of simplify_nullable_unions=True. After removing it (because Google now supports type: 'null' natively), this feature became completely unused, causing coverage to drop to 99.97%. Removed: - simplify_nullable_unions parameter from JsonSchemaTransformer.__init__ - self.simplify_nullable_unions assignment - Conditional call to _simplify_nullable_union() in _handle_union() - Entire _simplify_nullable_union() static method (18 lines) Verified no other references exist in the codebase. This restores 100% test coverage. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent db5968a commit 9254fd5

File tree

1 file changed

+0
-26
lines changed

1 file changed

+0
-26
lines changed

pydantic_ai_slim/pydantic_ai/_json_schema.py

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,13 @@ def __init__(
2525
*,
2626
strict: bool | None = None,
2727
prefer_inlined_defs: bool = False,
28-
simplify_nullable_unions: bool = False,
2928
):
3029
self.schema = schema
3130

3231
self.strict = strict
3332
self.is_strict_compatible = True # Can be set to False by subclasses to set `strict` on `ToolDefinition` when set not set by user explicitly
3433

3534
self.prefer_inlined_defs = prefer_inlined_defs
36-
self.simplify_nullable_unions = simplify_nullable_unions
3735

3836
self.defs: dict[str, JsonSchema] = self.schema.get('$defs', {})
3937
self.refs_stack: list[str] = []
@@ -146,10 +144,6 @@ def _handle_union(self, schema: JsonSchema, union_kind: Literal['anyOf', 'oneOf'
146144

147145
handled = [self._handle(member) for member in members]
148146

149-
# convert nullable unions to nullable types
150-
if self.simplify_nullable_unions:
151-
handled = self._simplify_nullable_union(handled)
152-
153147
if len(handled) == 1:
154148
# In this case, no need to retain the union
155149
return handled[0] | schema
@@ -159,26 +153,6 @@ def _handle_union(self, schema: JsonSchema, union_kind: Literal['anyOf', 'oneOf'
159153
schema[union_kind] = handled
160154
return schema
161155

162-
@staticmethod
163-
def _simplify_nullable_union(cases: list[JsonSchema]) -> list[JsonSchema]:
164-
# TODO: Should we move this to relevant subclasses? Or is it worth keeping here to make reuse easier?
165-
if len(cases) == 2 and {'type': 'null'} in cases:
166-
# Find the non-null schema
167-
non_null_schema = next(
168-
(item for item in cases if item != {'type': 'null'}),
169-
None,
170-
)
171-
if non_null_schema:
172-
# Create a new schema based on the non-null part, mark as nullable
173-
new_schema = deepcopy(non_null_schema)
174-
new_schema['nullable'] = True
175-
return [new_schema]
176-
else: # pragma: no cover
177-
# they are both null, so just return one of them
178-
return [cases[0]]
179-
180-
return cases
181-
182156

183157
class InlineDefsJsonSchemaTransformer(JsonSchemaTransformer):
184158
"""Transforms the JSON Schema to inline $defs."""

0 commit comments

Comments
 (0)