8000 Add some notes to the documentation of some of the arguments of certa… · pydantic/pydantic-core@3ea00bd · GitHub
[go: up one dir, main page]

Skip to content

Commit 3ea00bd

Browse files
Add some notes to the documentation of some of the arguments of certain CoreSchema types (#391)
* Update documentation of some of CoreSchema function arguments * Apply suggestions from code review Co-authored-by: David Montague <35119617+dmontagu@users.noreply.github.com> * Apply suggestions from code review --------- Co-authored-by: Samuel Colvin <s@muelcolvin.com>
1 parent 6616c9a commit 3ea00bd

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

pydantic_core/core_schema.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1110,6 +1110,9 @@ def tuple_positional_schema(
11101110
Args:
11111111
items_schema: The value must be a tuple with items that match these schemas
11121112
extra_schema: The value must be a tuple with items that match this schema
1113+
This was inspired by JSON schema's `prefixItems` and `items` fields.
1114+
In python's `typing.Tuple`, you can't specify a type for "extra" items -- they must all be the same type
1115+
if the length is variable. So this field won't be set from a `typing.Tuple` annotation on a pydantic model.
11131116
strict: The value must be a tuple with exactly this many items
11141117
ref: See [TODO] for details
11151118
metadata: See [TODO] for details
@@ -1218,7 +1221,9 @@ def set_schema(
12181221
items_schema: The value must be a set with items that match this schema
12191222
min_length: The value must be a set with at least this many items
12201223
max_length: The value must be a set with at most this many items
1221-
generator_max_length: The value must be a set with at most this many items
1224+
generator_max_length: At most this many items will be read from a generator before failing validation
1225+
This is important because generators can be infinite, and even with a `max_length` on the set,
1226+
an infinite generator could run forever without producing more than `max_length` distinct items.
12221227
strict: The value must be a set with exactly this many items
12231228
ref: See [TODO] for details
12241229
metadata: See [TODO] for details
@@ -1856,7 +1861,14 @@ def tagged_union_schema(
18561861
18571862
Args:
18581863
choices: The schemas to match
1864+
When retrieving a schema from `choices` using the discriminator value, if the value is a str,
1865+
it should be fed back into the `choices` map until a schema is obtained
1866+
(This approach is to prevent multiple ownership of a single schema in Rust)
18591867
discriminator: The discriminator to use to determine the schema to use
1868+
* If `discriminator` is a str, it is the name of the attribute to use as the discriminator
1869+
* If `discriminator` is a list of int/str, it should be used as a "path" to access the discriminator
1870+
* If `discriminator` is a list of lists, each inner list is a path, and the first path that exists is used
1871+
* If `discriminator` is a callable, it should return the discriminator when called on the value to validate
18601872
custom_error_type: The custom error type to use if the validation fails
18611873
custom_error_message: The custom error message to use if the validation fails
18621874
custom_error_context: The custom error context to use if the validation fails

0 commit comments

Comments
 (0)
0