!!! abstract "Usage Documentation" [`AliasPath` and `AliasChoices`](../concepts/alias.md#aliaspath-and-aliaschoices) A data class used by `validation_alias` as a convenience to create aliases. Attributes: choices: A list containing a string or `AliasPath`.
| 56 | |
| 57 | @dataclasses.dataclass(**_internal_dataclass.slots_true) |
| 58 | class AliasChoices: |
| 59 | """!!! abstract "Usage Documentation" |
| 60 | [`AliasPath` and `AliasChoices`](../concepts/alias.md#aliaspath-and-aliaschoices) |
| 61 | |
| 62 | A data class used by `validation_alias` as a convenience to create aliases. |
| 63 | |
| 64 | Attributes: |
| 65 | choices: A list containing a string or `AliasPath`. |
| 66 | """ |
| 67 | |
| 68 | choices: list[str | AliasPath] |
| 69 | |
| 70 | def __init__(self, first_choice: str | AliasPath, *choices: str | AliasPath) -> None: |
| 71 | self.choices = [first_choice] + list(choices) |
| 72 | |
| 73 | def convert_to_aliases(self) -> list[list[str | int]]: |
| 74 | """Converts arguments to a list of lists containing string or integer aliases. |
| 75 | |
| 76 | Returns: |
| 77 | The list of aliases. |
| 78 | """ |
| 79 | aliases: list[list[str | int]] = [] |
| 80 | for c in self.choices: |
| 81 | if isinstance(c, AliasPath): |
| 82 | aliases.append(c.convert_to_aliases()) |
| 83 | else: |
| 84 | aliases.append([c]) |
| 85 | return aliases |
| 86 | |
| 87 | |
| 88 | @dataclasses.dataclass(**_internal_dataclass.slots_true) |
no outgoing calls