arganic.arguments
Argument
Argument class.
Represents an argument with properties such as name, default value, and validation rules. Provides a method for validation.
Attributes:
-
name
(str
) –The name of the argument.
-
default
((Any, optional)
) –The default value of the argument.
-
read_only
(bool, default=True
) –Whether the argument is read-only.
-
required
(bool, default=True
) –Whether the argument is required.
-
type
((Type | tuple[Type], optional)
) –The data type(s) of the argument value.
-
validator
((Validator | tuple[Validator], optional)
) –A Validator object or list of Validator objects used to validate the argument value.
-
choices
((tuple, optional)
) –A tuple of choices the argument value can take.
Methods:
-
validate
–Validate the argument value based on the specified rules.
Examples:
Example of a full-featured argument construction:
choices
property
Optional
A list of choices limiting the values that the supplied arguments can have.
default
property
Optional
The default value the argument will take if no value is provided.
read_only
property
Default=True
The argument is read-only, so it can no longer be modified.
required
property
Default=True
The argument is required if the value is missing: an Exception will occur.
type
property
Optional
Defines the type(s) of values accepted for this argument, if the type provided is not valid an Exception will occur.
validator
property
validate
Validate the argument value based on the specified rules.
Parameters:
-
value
(Any
) –The value to validate.
Returns:
-
bool
–True if the value is valid, False otherwise.
Raises:
-
TypeError
–If the value is not of the specified type.
-
ValueError
–If the value is required but not provided, or if it is not among the specified choices.
ArgumentHandler
Handles arguments or properties for decorated classes, methods or functions.
Attributes
values: dict The provided arguments values validated and correctly formatted.
Methods:
-
get
–Retrieves the value of a specified argument or property.
-
set
–Sets the value of a specified argument or property.
get
Retrieves the value of a specified argument or property.
Parameters:
-
key
(str
) –The key of the argument or property to retrieve.
Returns:
-
Any
–The value of the argument or property.
class_properties
class_properties(**_properties: Argument) -> Callable
Decorator for class properties.
A decorator for class properties allowing you to define the data managed by the class during construction and then access these values within the class.
Parameters:
Returns:
-
Callable
–The decorator function.
function_arguments
function_arguments(**_arguments: Argument) -> Callable
Decorator for function arguments.
A decorator for functions allowing you to constrain the arguments provided during the call but also to find the correctly formatted values within the function.
Parameters:
Returns:
-
Callable
–The decorator function.
method_arguments
method_arguments(**_arguments: Argument) -> Callable
Decorator for method arguments.
A decorator for class methods allowing you to constrain the arguments provided during the call but also to find the correctly formatted values within the method.
Parameters:
Returns:
-
Callable
–The decorator function.