pyufunc.dataclass_creation#
- pyufunc.dataclass_creation(class_name, attributes)#
Dynamically creates a dataclass with the given attributes.
- Parameters:
class_name (str) – The name of the dataclass to create.
attributes (List[Union[Tuple[str, Type, Any], Tuple[str, Any]]]) – A list of tuples where each tuple can be: - (attribute_name, type, default_value): The attribute name, type, and a default value. - (attribute_name, default_value): The attribute name and a default value, with the type inferred.
- Returns:
A new dataclass with the specified attributes.
- Return type:
Type
Example
>>> from pyufunc import dataclass_creation >>> attributes = [ ... ('attribute_one', int, 10), ... ('attribute_two', "default_value"), # Type inferred as str ... ('attribute_three', float, 0.0) ... ] >>> DynamicClass = dataclass_creation('DynamicClass', attributes) >>> instance = DynamicClass(attribute_one=1) >>> print(instance.attribute_one) 1 >>> print(instance.attribute_two) default_value >>> print(instance.attribute_three) 0.0