Summary
I have a hierarchical model in which some deeply nested values reference ID values in another part of the tree (as in IDREF in XML Schema). I would like to generate a consistent structure where every reference actually exists. If this were only one part with refs and another with IDs, I would probably find a solution with PostGenerated, but unfortunately, there are multiple places with ID definitions and multiple places referencing them, one branch containing even one kind of ID definition and at the same time references towards another branch with other IDs.
Basic Example
@dataclass
class X:
x_id: int
x_name: str
@dataclass
class Y:
y_id: int
xs_used: list[int]
y_name: str
@dataclass
class DefinitionsOfX:
xs: list[X]
@dataclass
class DefinitionsOfY:
ys: list[Y]
@dataclass
class UsageOfY:
info1: str
info2: int
current_y: int
@dataclass
class LargeTree:
branch1: DefinitionsOfX
branch2: DefinitionsOfY
branch3: list[UsageOfY]
Here, LargeTree.branch3.*.current_y references LargeTree.branch2.ys.*.y_id and LargeTree.branch2.ys.*.xs_used.* references LargeTree.branch1.xs.*.x_id (with * indicating "every" or "some", I think you get the point). It could also involve a Mapping with the declared IDs as keys.
It would be great to have a way to specify this.
Drawbacks and Impact
Generation of fields would have to build a dependency graph and generate in the right order; if the dependency graph were to contain cycles, it would even necessitate a multi-pass strategy, I guess.
Unresolved questions
No response
Summary
I have a hierarchical model in which some deeply nested values reference ID values in another part of the tree (as in
IDREFin XML Schema). I would like to generate a consistent structure where every reference actually exists. If this were only one part with refs and another with IDs, I would probably find a solution withPostGenerated, but unfortunately, there are multiple places with ID definitions and multiple places referencing them, one branch containing even one kind of ID definition and at the same time references towards another branch with other IDs.Basic Example
Here,
LargeTree.branch3.*.current_yreferencesLargeTree.branch2.ys.*.y_idandLargeTree.branch2.ys.*.xs_used.*referencesLargeTree.branch1.xs.*.x_id(with*indicating "every" or "some", I think you get the point). It could also involve aMappingwith the declared IDs as keys.It would be great to have a way to specify this.
Drawbacks and Impact
Generation of fields would have to build a dependency graph and generate in the right order; if the dependency graph were to contain cycles, it would even necessitate a multi-pass strategy, I guess.
Unresolved questions
No response