fgnt/padertorch

Support dataclass default_factory

thequilo opened this issue · 0 comments

default_factory for dataclasses is not supported. Finding the default args for the class fails.

import padertorch as pt

from dataclasses import dataclass, field
@dataclass
class A(pt.Configurable):
    a: dict = field(default_factory=dict)

A.get_config()

gives

Traceback (most recent call last):
...
TypeError: Object of type _HAS_DEFAULT_FACTORY_CLASS is not JSON serializable
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
...
ValueError: Invalid config.
See above exception msg from json.dumps and below the sub config:
{'factory': 'A', 'a': <factory>}