ClassVisitor

class mlfarm.core.ClassVisitor[source]

Extends BaseVisitor and transforms dicts into objects is a specific key is present.

visit_dict(obj)[source]

If the argument has the “class” key, an instance of that class will be returned.

Parameters:obj (dict) – May have the “class” key, if not the parent visit_dict is called.
Returns:If the “builder” key is also present the backend instance of ClassBuilder is returned.
Return type:dict | object | ClassBuilder
>>> class A:
...     def __init__(self, a):
...         self.a = a
...
>>> cv = ClassVisitor()
>>> data = {
...     "class": "__main__.A",
...     "builder": True,
...     "args": {
...         "a": 1
...     }
... }
...
>>> a = cv.visit(data)
>>> a().a
1
>>> a(a=2).a
2