cornflakes.decorator.field
- cornflakes.decorator.field(attr=None, /, *, default=<cornflakes.types._MISSING_TYPE object>, default_factory=<cornflakes.types._MISSING_TYPE object>, init=True, repr=True, hash=None, compare=True, metadata=None, kw_only=<cornflakes.types._MISSING_TYPE object>, validator=<cornflakes.types._MISSING_TYPE object>, aliases=None, ignore=False, cli=True, title=None, description=None, exclude=None, include=None, const=None, gt=None, ge=None, lt=None, le=None, multiple_of=None, allow_inf_nan=True, max_digits=None, decimal_places=None, min_items=None, max_items=None, unique_items=None, min_length=None, max_length=None, allow_mutation=True, regex=None, discriminator=None, no_default=False, **extra)
This function is used instead of exposing Field creation directly.
So that a type checker can be told (via overloads) that this is a function whose type depends on its parameters. This function is used instead of exposing Field creation directly, so that a type checker can be told (via overloads) that this is a function whose type depends on its parameters.
- Parameter:
attr (Field | Any | None) – Attribute name on the class to be used to store the field.
default (_MISSING_TYPE | Any) – Default value for field.
default_factory (_MISSING_TYPE | _WithoutDefault | Callable) – Default factory for field.
init (bool | None) – Field will be included in __init__ method.
repr (bool | None) – Field will be included in __repr__ method.
hash (bool | _MISSING_TYPE | None) – Field will be included in __hash__ method.
compare (bool | None) – Field will be included in __eq__ method.
metadata (Any | None) – Field will be included in metadata.
kw_only (_MISSING_TYPE | bool) – Field will be included in __init__ method as keyword only.
validator (Callable[[str], Any] | _MISSING_TYPE | None) – Validator for field.
aliases (List[str] | str | None) – Aliases for config data (will be used to read from config files).
ignore (bool | None) – Field will be ignored when writing to_ini etc.
cli (bool | None) – Field will be included in cli on option_config.
title (str | None) – Can be any string, used in the schema.
description (str | None) – can be any string, used in the schema.
exclude (List[str] | str | None) – exclude this field while dumping. Takes same values as the
includeandexcludearguments on the.dictmethod.include (List[str] | str | None) – include this field while dumping. Takes same values as the
includeandexcludearguments on the.dictmethod.const (bool | None) – this field is required and must take it’s default value
gt (int | float | None) – only applies to numbers, requires the field to be „greater than“. The schema will have an
exclusiveMinimumvalidation keywordge (int | float | None) – only applies to numbers, requires the field to be „greater than or equal to“. The schema will have a
minimumvalidation keywordlt (int | float | None) – only applies to numbers, requires the field to be „less than“. The schema will have an
exclusiveMaximumvalidation keywordle (int | float | None) – only applies to numbers, requires the field to be „less than or equal to“. The schema will have a
maximumvalidation keywordmultiple_of (int | float | None) – only applies to numbers, requires the field to be „a multiple of“. The schema will have a
multipleOfvalidation keywordallow_inf_nan (bool | None) – only applies to numbers, allows the field to be NaN or infinity (+inf or -inf), which is a valid Python float. Default True, set to False for compatibility with JSON.
max_digits (int | None) – only applies to Decimals, requires the field to have a maximum number of digits within the decimal. It does not include a zero before the decimal point or trailing decimal zeroes.
decimal_places (int | None) – only applies to Decimals, requires the field to have at most a number of decimal places allowed. It does not include trailing decimal zeroes.
min_items (int | None) – only applies to lists, requires the field to have a minimum number of elements. The schema will have a
minItemsvalidation keywordmax_items (int | None) – only applies to lists, requires the field to have a maximum number of elements. The schema will have a
maxItemsvalidation keywordunique_items (bool | None) – only applies to lists, requires the field not to have duplicated elements. The schema will have a
uniqueItemsvalidation keywordmin_length (int | None) – only applies to strings, requires the field to have a minimum length. The schema will have a
minLengthvalidation keywordmax_length (int | None) – only applies to strings, requires the field to have a maximum length. The schema will have a
maxLengthvalidation keywordallow_mutation (bool | None) – a boolean which defaults to True. When False, the field raises a TypeError if the field is assigned on an instance. The BaseModel Config must set validate_assignment to True
regex (str | None) – only applies to strings, requires the field match against a regular expression pattern string. The schema will have a
patternvalidation keyworddiscriminator (str | None) – only useful with a (discriminated a.k.a. tagged) Union of sub models with a common field. The discriminator is the name of this common field to shorten validation and improve generated schema
repr – show this field in the representation
no_default (bool) – if True, the field will not have a default value, even if a default value is specified
extra (Any) – any additional keyword arguments will be added as is to the schema
- Rückgabe:
A dataclass field.
- Verursacht:
ValueError – if both default and default_factory are specified.