别名
Support for alias configurations.
AliasPath
dataclass
¶
Usage docs: https://pydantic.com.cn/2.9/concepts/alias#aliaspath-and-aliaschoices
A data class used by validation_alias
as a convenience to create aliases.
Attributes:
Name | Type | Description |
---|---|---|
path |
list[int | str]
|
A list of string or integer aliases. |
Source code in pydantic/aliases.py
27 28 |
|
convert_to_aliases ¶
Converts arguments to a list of string or integer aliases.
Returns:
Type | Description |
---|---|
list[str | int]
|
The list of aliases. |
Source code in pydantic/aliases.py
30 31 32 33 34 35 36 |
|
search_dict_for_path ¶
Searches a dictionary for the path specified by the alias.
Returns:
Type | Description |
---|---|
Any
|
The value at the specified path, or |
Source code in pydantic/aliases.py
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
|
AliasChoices
dataclass
¶
Usage docs: https://pydantic.com.cn/2.9/concepts/alias#aliaspath-and-aliaschoices
A data class used by validation_alias
as a convenience to create aliases.
Attributes:
Name | Type | Description |
---|---|---|
choices |
list[str | AliasPath]
|
A list containing a string or |
Source code in pydantic/aliases.py
68 69 |
|
convert_to_aliases ¶
Converts arguments to a list of lists containing string or integer aliases.
Returns:
Type | Description |
---|---|
list[list[str | int]]
|
The list of aliases. |
Source code in pydantic/aliases.py
71 72 73 74 75 76 77 78 79 80 81 82 83 |
|
AliasGenerator
dataclass
¶
AliasGenerator(
alias: Callable[[str], str] | None = None,
validation_alias: (
Callable[[str], str | AliasPath | AliasChoices]
| None
) = None,
serialization_alias: Callable[[str], str] | None = None,
)
Usage docs: https://pydantic.com.cn/2.9/concepts/alias#using-an-aliasgenerator
A data class used by alias_generator
as a convenience to create various aliases.
Attributes:
Name | Type | Description |
---|---|---|
alias |
Callable[[str], str] | None
|
A callable that takes a field name and returns an alias for it. |
validation_alias |
Callable[[str], str | AliasPath | AliasChoices] | None
|
A callable that takes a field name and returns a validation alias for it. |
serialization_alias |
Callable[[str], str] | None
|
A callable that takes a field name and returns a serialization alias for it. |
generate_aliases ¶
generate_aliases(
field_name: str,
) -> tuple[
str | None,
str | AliasPath | AliasChoices | None,
str | None,
]
Generate alias
, validation_alias
, and serialization_alias
for a field.
Returns:
Type | Description |
---|---|
tuple[str | None, str | AliasPath | AliasChoices | None, str | None]
|
A tuple of three aliases - validation, alias, and serialization. |
Source code in pydantic/aliases.py
122 123 124 125 126 127 128 129 130 131 132 |
|
本文总阅读量次