config_wrangler.config_types.delimited_field module

config_wrangler.config_types.delimited_field.DelimitedListField(default: Any = PydanticUndefined, *, default_factory: Callable[[], Any] | None = PydanticUndefined, alias: str | None = PydanticUndefined, alias_priority: int | None = PydanticUndefined, validation_alias: str | AliasPath | AliasChoices | None = PydanticUndefined, serialization_alias: str | None = PydanticUndefined, title: str | None = PydanticUndefined, description: str | None = PydanticUndefined, examples: list[Any] | None = PydanticUndefined, exclude: bool | None = PydanticUndefined, include: bool | None = PydanticUndefined, discriminator: str | None = PydanticUndefined, json_schema_extra: dict[str, Any] | Callable[[dict[str, Any]], None] | None = PydanticUndefined, frozen: bool | None = PydanticUndefined, validate_default: bool | None = PydanticUndefined, repr: bool = PydanticUndefined, init_var: bool | None = PydanticUndefined, kw_only: bool | None = PydanticUndefined, pattern: str | None = PydanticUndefined, strict: bool | None = PydanticUndefined, gt: float | None = PydanticUndefined, ge: float | None = PydanticUndefined, lt: float | None = PydanticUndefined, le: float | None = PydanticUndefined, multiple_of: float | None = PydanticUndefined, allow_inf_nan: bool | None = PydanticUndefined, max_digits: int | None = PydanticUndefined, decimal_places: int | None = PydanticUndefined, min_length: int | None = PydanticUndefined, max_length: int | None = PydanticUndefined, delimiter: str = ',') Any[source]

Create a field for a list of objects, plus other Pydantic Field configuration options.

Pydantic standard docs:

Used to provide extra information about a field, either for the model schema or complex validation. Some arguments apply only to number fields (int, float, Decimal) and some apply only to str.

Parameters:
  • default – Default value if the field is not set.

  • default_factory – A callable to generate the default value, such as utcnow().

  • alias – An alternative name for the attribute.

  • alias_priority – Priority of the alias. This affects whether an alias generator is used.

  • validation_alias – ‘Whitelist’ validation step. The field will be the single one allowed by the alias or set of aliases defined.

  • serialization_alias – ‘Blacklist’ validation step. The vanilla field will be the single one of the alias’ or set of aliases’ fields and all the other fields will be ignored at serialization time.

  • title – Human-readable title.

  • description – Human-readable description.

  • examples – Example values for this field.

  • exclude – Whether to exclude the field from the model schema.

  • include – Whether to include the field in the model schema.

  • discriminator – Field name for discriminating the type in a tagged union.

  • json_schema_extra – Any additional JSON schema data for the schema property.

  • frozen – Whether the field is frozen.

  • validate_default – Run validation that isn’t only checking existence of defaults. True by default.

  • repr – A boolean indicating whether to include the field in the __repr__ output.

  • init_var – Whether the field should be included in the constructor of the dataclass.

  • kw_only – Whether the field should be a keyword-only argument in the constructor of the dataclass.

  • strict – If True, strict validation is applied to the field. See [Strict Mode](../usage/strict_mode.md) for details.

  • gt – Greater than. If set, value must be greater than this. Only applicable to numbers.

  • ge – Greater than or equal. If set, value must be greater than or equal to this. Only applicable to numbers.

  • lt – Less than. If set, value must be less than this. Only applicable to numbers.

  • le – Less than or equal. If set, value must be less than or equal to this. Only applicable to numbers.

  • multiple_of – Value must be a multiple of this. Only applicable to numbers.

  • min_length – Minimum length for strings.

  • max_length – Maximum length for strings.

  • pattern – Pattern for strings.

  • allow_inf_nan – Allow inf, -inf, nan. Only applicable to numbers.

  • max_digits – Maximum number of allow digits for strings.

  • decimal_places – Maximum number of decimal places allowed for numbers.

  • delimiter – delimiter to use when parsing the input value

Returns:

A new [FieldInfo][pydantic.fields.FieldInfo], the return annotation is Any so Field can be used on

type annotated fields without causing a typing error.

class config_wrangler.config_types.delimited_field.DelimitedListFieldInfo(delimiter: str, **kwargs)[source]

Bases: FieldInfo

__init__(delimiter: str, **kwargs) None[source]

This class should generally not be initialized directly; instead, use the pydantic.fields.Field function or one of the constructor classmethods.

See the signature of pydantic.fields.Field for more details about the expected arguments.

alias: str | None
alias_priority: int | None
annotation: type[Any] | None
apply_typevars_map(typevars_map: dict[Any, Any] | None, types_namespace: dict[str, Any] | None) None

Apply a typevars_map to the annotation.

This method is used when analyzing parametrized generic types to replace typevars with their concrete types.

This method applies the typevars_map to the annotation in place.

Parameters:
  • typevars_map – A dictionary mapping type variables to their concrete types.

  • types_namespace (dict | None) – A dictionary containing related types to the annotated type.

See also

pydantic._internal._generics.replace_types is used for replacing the typevars with

their concrete types.

default: Any
default_factory: Callable[[], Any] | None
delimiter: str

The delimiter to use when parsing the value into a list. (DelimitedListFieldInfo specific)

description: str | None
discriminator: str | types.Discriminator | None
examples: list[Any] | None
exclude: bool | None
static from_annotated_attribute(annotation: type[Any], default: Any) FieldInfo

Create FieldInfo from an annotation with a default value.

This is used in cases like the following:

```python import annotated_types from typing_extensions import Annotated

import pydantic

class MyModel(pydantic.BaseModel):

foo: int = 4 # <– like this bar: Annotated[int, annotated_types.Gt(4)] = 4 # <– or this spam: Annotated[int, pydantic.Field(gt=4)] = 4 # <– or this

```

Parameters:
  • annotation – The type annotation of the field.

  • default – The default value of the field.

Returns:

A field object with the passed values.

static from_annotation(annotation: type[Any]) FieldInfo

Creates a FieldInfo instance from a bare annotation.

This function is used internally to create a FieldInfo from a bare annotation like this:

```python import pydantic

class MyModel(pydantic.BaseModel):

foo: int # <– like this

```

We also account for the case where the annotation can be an instance of Annotated and where one of the (not first) arguments in Annotated is an instance of FieldInfo, e.g.:

```python import annotated_types from typing_extensions import Annotated

import pydantic

class MyModel(pydantic.BaseModel):

foo: Annotated[int, annotated_types.Gt(42)] bar: Annotated[int, pydantic.Field(gt=42)]

```

Parameters:

annotation – An annotation object.

Returns:

An instance of the field metadata.

static from_field(default: Any = PydanticUndefined, **kwargs: Unpack) FieldInfo

Create a new FieldInfo object with the Field function.

Parameters:
  • default – The default value for the field. Defaults to Undefined.

  • **kwargs – Additional arguments dictionary.

Raises:

TypeError – If ‘annotation’ is passed as a keyword argument.

Returns:

A new FieldInfo object with the given parameters.

Example

This is how you can create a field with default value like this:

```python import pydantic

class MyModel(pydantic.BaseModel):

foo: int = pydantic.Field(4)

```

frozen: bool | None
get_default(*, call_default_factory: bool = False) Any

Get the default value.

We expose an option for whether to call the default_factory (if present), as calling it may result in side effects that we want to avoid. However, there are times when it really should be called (namely, when instantiating a model via model_construct).

Parameters:

call_default_factory – Whether to call the default_factory or not. Defaults to False.

Returns:

The default value, calling the default factory if requested or None if not set.

init: bool | None
init_var: bool | None
is_required() bool

Check if the field is required (i.e., does not have a default value or factory).

Returns:

True if the field is required, False otherwise.

json_schema_extra: JsonDict | Callable[[JsonDict], None] | None
kw_only: bool | None
static merge_field_infos(*field_infos: FieldInfo, **overrides: Any) FieldInfo

Merge FieldInfo instances keeping only explicitly set attributes.

Later FieldInfo instances override earlier ones.

Returns:

A merged FieldInfo instance.

Return type:

FieldInfo

metadata: list[Any]
metadata_lookup: ClassVar[dict[str, Callable[[Any], Any] | None]] = {'allow_inf_nan': None, 'decimal_places': None, 'ge': <class 'annotated_types.Ge'>, 'gt': <class 'annotated_types.Gt'>, 'le': <class 'annotated_types.Le'>, 'lt': <class 'annotated_types.Lt'>, 'max_digits': None, 'max_length': <class 'annotated_types.MaxLen'>, 'min_length': <class 'annotated_types.MinLen'>, 'multiple_of': <class 'annotated_types.MultipleOf'>, 'pattern': None, 'strict': <class 'pydantic.types.Strict'>, 'union_mode': None}
rebuild_annotation() Any

Attempts to rebuild the original annotation for use in function signatures.

If metadata is present, it adds it to the original annotation using Annotated. Otherwise, it returns the original annotation as-is.

Note that because the metadata has been flattened, the original annotation may not be reconstructed exactly as originally provided, e.g. if the original type had unrecognized annotations, or was annotated with a call to pydantic.Field.

Returns:

The rebuilt annotation.

repr: bool
serialization_alias: str | None
title: str | None
validate_default: bool | None
validation_alias: str | AliasPath | AliasChoices | None