Skip to content

Commit b48ce99

Browse files
committed
invalid schema wip
1 parent f389728 commit b48ce99

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

python/pydantic_core/core_schema.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,26 @@ def model_ser_schema(cls: Type[Any], schema: CoreSchema) -> ModelSerSchema:
434434
ModelSerSchema,
435435
]
436436

437+
class InvalidSchema(TypedDict, total=False):
438+
type: Required[Literal['invalid']]
439+
ref: str
440+
metadata: Dict[str, Any]
441+
442+
def invalid_schema(ref: str | None = None, metadata: Dict[str, Any] | None = None) -> InvalidSchema:
443+
"""
444+
Returns an invalid schema, used to indicate that a schema is invalid.
445+
446+
Returns a schema that matches any value, e.g.:
447+
448+
Args:
449+
ref: optional unique identifier of the schema, used to reference the schema in other places
450+
metadata: Any other information you want to include with the schema, not used by pydantic-core
451+
"""
452+
453+
return _dict_not_none(
454+
type='invalid', ref=ref, metadata=metadata
455+
)
456+
437457

438458
class ComputedField(TypedDict, total=False):
439459
type: Required[Literal['computed-field']]
@@ -2458,6 +2478,7 @@ class UnionSchema(TypedDict, total=False):
24582478
type: Required[Literal['union']]
24592479
choices: Required[List[Union[CoreSchema, Tuple[CoreSchema, str]]]]
24602480
# default true, whether to automatically collapse unions with one element to the inner validator
2481+
tagged_union_tag: str
24612482
auto_collapse: bool
24622483
custom_error_type: str
24632484
custom_error_message: str
@@ -3826,6 +3847,7 @@ def definition_reference_schema(
38263847
# union which kills performance not just for pydantic, but even for code using pydantic
38273848
if not MYPY:
38283849
CoreSchema = Union[
3850+
InvalidSchema,
38293851
AnySchema,
38303852
NoneSchema,
38313853
BoolSchema,
@@ -3882,6 +3904,7 @@ def definition_reference_schema(
38823904

38833905
# to update this, call `pytest -k test_core_schema_type_literal` and copy the output
38843906
CoreSchemaType = Literal[
3907+
'invalid',
38853908
'any',
38863909
'none',
38873910
'bool',

0 commit comments

Comments
 (0)