Support tagged unions when the discriminator field is in a generic wrapper, not in the union type
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 48/100
Research direction
Start by reading configure_tagged_union, especially its union.args handling, and trace how the discriminator tag_name is resolved. Determine whether KafkaMessage[Data] | KafkaMessage[Heartbeat] can be configured with the wrapper-level type field, and verify conversion for both payload variants.
Written by the indexing model from the issue text.
Description
Hello, I’m not sure if I just can’t figure out how to do it or if it’s not supported.
I have a generic message envelope like this:
@frozen
class KafkaMessage(Generic[T]):
type: str # discriminator
payload: T
And payload can be one of several types:
@frozen
class Data: ...
@frozen
class Heartbeat: ...
I’d like to define and structure:
type KafkaMessageUnion = KafkaMessage[Data] | KafkaMessage[Heartbeat]
configure_tagged_union(KafkaMessageUnion, CONVERTER, tag_name="type")
however this fails on very first line of configure_tagged_union - args = union.__args__
Is it possible to get around this somehow?
- Dominant language
- Python
- Stars
- 1.1k
- Forks
- 159
- Avg merge
- 12h 21m
- Merged PRs (30d)
- 6
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from python-attrs/cattrs
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
python-attrs/cattrs#761 · 2 comments ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 64/100
python-attrs/cattrs#513 · 4 comments ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 35/100
python-attrs/cattrs#779 ·
-
Difficulty 3/5 1-2 days Newbie friendliness 85/100
python-attrs/cattrs#774 ·
-
Difficulty 5/5 Over a week Newbie friendliness 35/100
python-attrs/cattrs#746 · 2 comments ·
All issues in python-attrs/cattrs
Similar issues
-
triage/confirmed
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
agentscope-ai/agentscope#2775 ·
-
comp/desktop P3 type/bug
Difficulty 1/5 Under an hour Newbie friendliness 92/100
NousResearch/hermes-agent#118866 ·
-
bug
Difficulty 1/5 Under an hour Newbie friendliness 90/100
apache/cloudstack#14222 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 82/100