File tree Expand file tree Collapse file tree 2 files changed +16
-8
lines changed
Expand file tree Collapse file tree 2 files changed +16
-8
lines changed Original file line number Diff line number Diff line change @@ -36,12 +36,7 @@ def loads(string: str) -> list[GedcomStructure]:
3636 # append structure to output
3737 if level > 0 :
3838 parent = context [level - 1 ]
39- structure .parent = parent
40- structure .value = cast .cast_value (
41- text = structure .text , type_id = structure .type_id
42- )
43- if level > 0 :
44- parent .children .append (structure )
39+ parent .append_child (structure )
4540 else :
4641 records .append (structure )
4742 return records
Original file line number Diff line number Diff line change 55from dataclasses import dataclass , field
66from typing import Literal , Union
77
8- from . import const
8+ from . import cast , const
99
1010
1111@dataclass
@@ -18,7 +18,6 @@ class GedcomStructure:
1818 xref : str
1919 children : list ["GedcomStructure" ] = field (default_factory = list )
2020 parent : "GedcomStructure | None" = None
21- value : "DataType" | None = None
2221
2322 @property
2423 def type_id (self ) -> str :
@@ -33,6 +32,20 @@ def type_id(self) -> str:
3332 return const .substructures ["" ][self .tag ]
3433 return const .substructures [self .parent .type_id ][self .tag ]
3534
35+ def __post_init__ (self ):
36+ """Post-init steps: set parent on children."""
37+ for child in self .children :
38+ child .parent = self
39+
40+ def append_child (self , child : "GedcomStructure" ) -> None :
41+ """Append a child to the structure and set the child's parent to self."""
42+ child .parent = self
43+ self .children .append (child )
44+
45+ @property
46+ def value (self ) -> "DataType | None" :
47+ return cast .cast_value (text = self .text , type_id = self .type_id )
48+
3649
3750@dataclass
3851class PersonalName :
You can’t perform that action at this time.
0 commit comments