cornflakes.decorator.dataclasses package
Subpackages
- cornflakes.decorator.dataclasses.validator package
- Submodules
- cornflakes.decorator.dataclasses.validator.url module
AnyUrlAnyUrl.check_kwargs()AnyUrl.fragmentAnyUrl.hostnameAnyUrl.keys()AnyUrl.netlocAnyUrl.paramsAnyUrl.passwordAnyUrl.pathAnyUrl.portAnyUrl.queryAnyUrl.query_argsAnyUrl.schemeAnyUrl.tldAnyUrl.to_dict()AnyUrl.to_tuple()AnyUrl.tokenAnyUrl.urlAnyUrl.usernameAnyUrl.validAnyUrl.validate_kwargs()
- Module contents
AnyUrlAnyUrl.check_kwargs()AnyUrl.fragmentAnyUrl.hostnameAnyUrl.keys()AnyUrl.netlocAnyUrl.paramsAnyUrl.passwordAnyUrl.pathAnyUrl.portAnyUrl.queryAnyUrl.query_argsAnyUrl.schemeAnyUrl.tldAnyUrl.to_dict()AnyUrl.to_tuple()AnyUrl.tokenAnyUrl.urlAnyUrl.usernameAnyUrl.validAnyUrl.validate_kwargs()
Module contents
custom dataclass wrapper.
- class cornflakes.decorator.dataclasses.AnyUrl(url=None, scheme='', netloc='', path='', params='', query='', fragment='', query_args=<factory>, hostname='', port=None, username=None, password=None, tld=None, valid=False, token=None)[Quellcode]
Bases:
objectDatabase URL.
- Variablen:
url – URL to init the whole object (will be overwritten with other args).
scheme – The scheme of the url
netloc – user / pw / host and port of the url
path – path of the url
query – url query
params – url params
query_args – url query_args -> parsed query
fragment – url fragment
hostname – url hostname (overwrites the netloc)
port – url port (overwrites the netloc)
username – url username (overwrites the netloc)
password – url password (overwrites the netloc)
tld – url tld if it is valid
valid – validators.url validation result
- Parameter:
url (dataclasses.InitVar[Optional[str]]) –
scheme (str) –
netloc (str) –
path (str) –
params (str) –
query (str) –
fragment (str) –
query_args (dict) –
hostname (str) –
port (int | None) –
username (str | None) –
password (str | None) –
tld (str | None) –
valid (bool) –
token (str | None) –
- classmethod check_kwargs(**kwargs)
Check dataclass types.
- Rückgabetyp:
Dict[str, Any]
- fragment: str
- hostname: str
- classmethod keys()
- netloc: str
- params: str
- password: str | None
- path: str
- port: int | None
- query: str
- query_args: dict
- scheme: str
- tld: str | None
- to_dict()
Method to convert Dataclass with slots to dict.
- Rückgabetyp:
dict
- to_tuple()
Method to convert Dataclass with slots to dict.
- Rückgabetyp:
Any
- token: str | None
- url: dataclasses.InitVar[Optional[str]] = None
- username: str | None
- valid: bool
- classmethod validate_kwargs(force=True, **kwargs)
Validate dataclass (includes type checks + validators).
- class cornflakes.decorator.dataclasses.Field(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, **extra)[Quellcode]
Bases:
FieldInstances of dataclasses Field wrapped for configs.
- Info:
currently only supported arguments are: default, default_factory, init, repr, hash, compare, metadata, kw_only, validator, alias, ignore other arguments will be ignored when initialise dataclass.
- Parameter:
default (_MISSING_TYPE | Any) –
default_factory (_MISSING_TYPE | _WithoutDefault | Callable) –
init (bool | None) –
repr (bool | None) –
hash (bool | _MISSING_TYPE | None) –
compare (bool | None) –
metadata (Any) –
kw_only (_MISSING_TYPE | bool) –
validator (Callable[[str], Any] | _MISSING_TYPE | None) –
aliases (List[str] | str | None) –
ignore (bool | None) –
cli (bool | None) –
title (str | None) –
description (str | None) –
exclude (List[str] | str | None) –
include (List[str] | str | None) –
const (bool | None) –
gt (int | float | None) –
ge (int | float | None) –
lt (int | float | None) –
le (int | float | None) –
multiple_of (int | float | None) –
allow_inf_nan (bool | None) –
max_digits (int | None) –
decimal_places (int | None) –
min_items (int | None) –
max_items (int | None) –
unique_items (bool | None) –
min_length (int | None) –
max_length (int | None) –
allow_mutation (bool | None) –
regex (str | None) –
discriminator (str | None) –
extra (Any) –
- aliases
- allow_inf_nan
- allow_mutation
- cli
- compare
- const
- decimal_places
- default
- default_factory
- description
- discriminator
- exclude
- extra
- ge
- gt
- hash
- ignore
- include
- init
- kw_only
- le
- lt
- max_digits
- max_items
- max_length
- metadata
- min_items
- min_length
- multiple_of
- name
- regex
- repr
- title
- type
- unique_items
- static validate(field)[Quellcode]
Decorator to add a validator to a field.
- Parameter:
field (Any) –
- validator
- cornflakes.decorator.dataclasses.add_slots(cls)[Quellcode]
Need to create a new class, since we can’t set __slots__ after a class has been created.
This decorator is needed to support lower python versions (newer versions has slots function inside dataclasses itself).
- cornflakes.decorator.dataclasses.check_dataclass_kwargs(dc_cls, **kwargs)[Quellcode]
Check dataclass types.
- Rückgabetyp:
Dict[str, Any]
- cornflakes.decorator.dataclasses.config(cls=None, /, *, init=True, repr=True, eq=True, order=False, unsafe_hash=False, frozen=False, kw_only=False, slots=False, match_args=True, dict_factory=None, tuple_factory=None, value_factory=None, alias_generator=None, eval_env=False, validate=False, updatable=False, ignore_none=False, files=None, sections=None, use_regex=False, is_list=False, default_loader=None, allow_empty=False, chain_configs=False, init_default_config=True, **kwargs)
Config decorator to parse INI files and implement config loader methods to config-classes.
- Parameter:
alias_generator (Callable[[str], str] | None) –
ignore_none (bool) –
value_factory (Callable | None) –
init_default_config (bool, optional) –
match_args (bool) –
slots (bool) –
kw_only (bool) –
cls (class) – The class type to create the config dataclass from.
init (bool, optional) – Whether to automatically add an __init__ method to the class. Default is True.
repr (bool, optional) – Whether to automatically add a __repr__ method to the class. Default is True.
eq (bool, optional) – Whether to automatically add an __eq__ method to the class. Default is True.
order (bool, optional) – Whether to automatically add comparison methods (__lt__, __le__, __gt__, __ge__) to the class. Default is False.
unsafe_hash (bool, optional) – Whether to add a __hash__ method to the class. Default is False.
frozen (bool, optional) – Whether to make the generated class immutable. Default is False.
dict_factory (Callable, optional) – A function that returns a dict-like object which will be used as the base of the dataclass object. Default is None.
tuple_factory (Callable, optional) – A function that returns a tuple-like object which will be used as the base of the dataclass object. Default is None.
eval_env (bool, optional) – If set to True, will evaluate environment variables in the config file. Default is False.
validate (bool, optional) – If set to True, will validate the config file upon loading. Default is False.
updatable (bool, optional) – If set to True, the config object can be updated after it’s created. Default is False.
files (Union[List[str], str], optional) – A list or a single string of file path(s) to the default config files.
sections (Union[List[str], str], optional) – A list or a single string of section name(s) in the config file(s).
use_regex (bool, optional) – If set to True, will evaluate all sections in the config file(s) by regex. Default is False.
is_list (Union[bool, int], optional) – If set to True or a positive integer, will load the Config as a list of config class objects. Default is False.
default_loader (Loader, optional) – The default config parser method.
allow_empty (bool, optional) – If set to True, an empty config result will be allowed. Default is False.
chain_configs (bool, optional) – If set to True, multiple config files will be chained into a single config. Default is False.
init_default_config – If set to True, will initialize the default config file(s) upon loading. Default is True.
kwargs (Any) –
- Rückgabe:
If a class is given as config_cls, a new decorated class is returned. If no class is given, the decorator itself is returned with the custom default arguments.
- Rückgabetyp:
Union[Type[Config], Type[ConfigGroup], Type[_T]], Callable[…, Union[Type[Config], Type[ConfigGroup], Type[_T]]]
- cornflakes.decorator.dataclasses.config_files(cls)[Quellcode]
Method to return class __config_files__.
- cornflakes.decorator.dataclasses.config_group(cls=None, /, *, init=True, repr=True, eq=True, order=False, unsafe_hash=False, frozen=False, kw_only=False, slots=False, match_args=True, dict_factory=None, tuple_factory=None, value_factory=None, alias_generator=None, eval_env=False, validate=False, updatable=False, ignore_none=False, files=None, allow_empty=None, chain_configs=False, **kwargs)
Config decorator with a Subset of configs to parse Ini Files.
- Parameter:
ignore_none (bool) –
alias_generator (Callable[[str], str] | None) –
value_factory (Callable | None) –
updatable (bool) –
validate (bool) –
eval_env (bool) –
tuple_factory (Callable | None) –
dict_factory (Callable | None) –
match_args (bool) –
slots (bool) –
kw_only (bool) –
frozen (bool) –
unsafe_hash (bool) –
order (bool) –
eq (bool) –
repr (bool) –
init (bool) –
cls (Type[_T] | None) – Config class
files (List[str] | str | None) – Default config files
allow_empty (bool | None) – Flag that allows empty config result
chain_configs (bool | None) – flag indicating whether to chain files in to single config.
kwargs – Additional args for custom dataclass. (dict_factory, eval_env. …).
- Rückgabe:
wrapped class or the wrapper itself with the custom default arguments if the config class is not
- Rückgabetyp:
Callable[[Type[_T]], Type[ConfigGroup] | Type[CornflakesDataclass] | MappingWrapper[_T]] | Type[ConfigGroup] | Type[CornflakesDataclass] | MappingWrapper[_T]
- cornflakes.decorator.dataclasses.dataclass(cls=None, /, *, init=True, repr=True, eq=True, order=False, unsafe_hash=False, frozen=False, kw_only=False, slots=False, match_args=True, dict_factory=None, tuple_factory=None, value_factory=None, eval_env=False, validate=False, updatable=False, ignore_none=False, **kwargs)
Wrapper around built-in dataclasses dataclass.
- Parameter:
cls (Type[_T] | None) –
init (bool) –
repr (bool) –
eq (bool) –
order (bool) –
unsafe_hash (bool) –
frozen (bool) –
kw_only (bool) –
slots (bool) –
match_args (bool) –
dict_factory (Callable | None) –
tuple_factory (Callable | None) –
value_factory (Callable | None) –
eval_env (bool) –
validate (bool) –
updatable (bool) –
ignore_none (bool) –
kwargs (Any) –
- Rückgabetyp:
Callable[[Type[_T]], Type[CornflakesDataclass] | MappingWrapper[_T]] | Type[CornflakesDataclass] | MappingWrapper[_T]
- cornflakes.decorator.dataclasses.dataclass_fields(cls)[Quellcode]
Method to return dataclass fields.
- cornflakes.decorator.dataclasses.dc_field_without_default(field)[Quellcode]
Checks if the dataclass has a default / default_factory.
- cornflakes.decorator.dataclasses.default(field)[Quellcode]
Method to get the default value of the dataclass.
- cornflakes.decorator.dataclasses.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.
- cornflakes.decorator.dataclasses.fields(class_or_instance)[Quellcode]
Patched method of the dataclasses fields method to ignore the custom dataclass.
- cornflakes.decorator.dataclasses.is_config(cls)[Quellcode]
Method to return flag that class is a config class.
- cornflakes.decorator.dataclasses.is_group(cls)[Quellcode]
Method to return flag that class is a config group class.
- cornflakes.decorator.dataclasses.normalized_class_name(cls)[Quellcode]
Method to return class name normalized.
- cornflakes.decorator.dataclasses.to_dict(self)[Quellcode]
Method to convert Dataclass with slots to dict.
- Rückgabetyp:
dict
- cornflakes.decorator.dataclasses.to_ini(self, out_cfg=None)[Quellcode]
Method to write an instance of the main config class of the module into an ini file.
- Parameter:
out_cfg (str | None) –
- Rückgabetyp:
bytearray | None
- cornflakes.decorator.dataclasses.to_tuple(self)[Quellcode]
Method to convert Dataclass with slots to dict.
- Rückgabetyp:
Any
- cornflakes.decorator.dataclasses.to_yaml(self, *args, out_cfg=None, **kwargs)[Quellcode]
Method to write an instance of the main config class of the module into a yaml file.
- Parameter:
out_cfg (str | None) –
- Rückgabetyp:
bytearray | None
- cornflakes.decorator.dataclasses.validate_dataclass_kwargs(dc_cls, force=True, **kwargs)[Quellcode]
Validate dataclass (includes type checks + validators).