dbt-labs / dbt-labs/hologram

support polymorphism

Open
#3 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
10
Forks
11
PR merge metrics
No merged PRs in 30d

Description

given dataclasses like:

```python
@dataclass
class A:
literal: StrLiteral('a')

@dataclass
class B:
literal: StrLiteral('b')

@dataclass
class C:
a_or_b: Union[A, B]
```

`C.to_dict({'literal': 'a'})` and `C.to_dict({'literal': 'b'})` should instantiate the right subclass for `a_or_b`.

voluptuous does this by checking all of the possible subschemas and picking the one that matches, or raises an exception if none of them match. we may want to implement something similar in `to_dict`

another approach would be to leverage json schema's `if/else` construct to specify different subschemas based on a switch field.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.