I have the following class
@dataclass_json
@dataclass
class Source:
type: str =None
label: str =None
path: str = None
and the two subclasses:
@dataclass_json
@dataclass
class Csv(Source):
csv_path: str=None
delimiter: str=';'
and
@dataclass_json
@dataclass
class Parquet(Source):
parquet_path: str=None
Given now the dictionary:
parquet={type: 'Parquet', label: 'events', path: '/.../test.parquet', parquet_path: '../../result.parquet'}
csv={type: 'Csv', label: 'events', path: '/.../test.csv', csv_path: '../../result.csv', delimiter:','}
Now I would like to do something like
Source().from_dict(csv)
and that the output will be the class Csv or Parquet. I understand that if you initiate the class source you just "upload" the parameters with the method "from dict", but is there any posibility in doing this by some type of inheritence without using a "Constructor" which makes a if-else if-else over all possible 'types'?
Pureconfig, a Scala Library, creates different case classes when the attribute 'type' has the name of the desired subclass. In Python this is possible?