pyufunc.dataclass_from_dict#

pyufunc.dataclass_from_dict(name, data)#

Creates a dataclass with attributes and values based on the given dictionary. The dataclass will also support dictionary-like access via __getitem__ and __setitem__.

Parameters:
  • name (str) – The name of the dataclass to create.

  • data (Dict[str, Any]) – A dictionary where keys are attribute names and values are attribute values.

Example

>>> from pyufunc import dataclass_from_dict
>>> data = {'name': 'Alice', 'age': 30, 'city': 'New York'}
>>> Person = dataclass_from_dict('Person', data)
>>> person = Person()
>>> person.name
'Alice'
>>> person.age
30
>>> person.city
'New York'
Returns:

A dataclass with fields and values corresponding to the dictionary.

Return type:

Type