Fix json loading
With some small amount of error detection.
This commit is contained in:
parent
dac2d47246
commit
d592cc3050
@ -21,7 +21,7 @@
|
|||||||
|
|
||||||
from itertools import chain, repeat, product as iproduct
|
from itertools import chain, repeat, product as iproduct
|
||||||
from collections import deque
|
from collections import deque
|
||||||
from typing import FrozenSet, Iterable, List, Dict, Tuple
|
from typing import FrozenSet, Iterable, List, Dict, Tuple, Optional
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
@ -83,7 +83,15 @@ class Relation:
|
|||||||
with open(filename) as fp:
|
with open(filename) as fp:
|
||||||
from json import load as jload
|
from json import load as jload
|
||||||
from typedload import load
|
from typedload import load
|
||||||
return load(jload(fp), Relation)
|
loaded = jload(fp)
|
||||||
|
header = Header(loaded['header'])
|
||||||
|
content = []
|
||||||
|
for row in loaded['content']:
|
||||||
|
if len(row) != len(header):
|
||||||
|
raise ValueError(f'Line {row} contains an incorrect amount of values')
|
||||||
|
t_row: Tuple[Optional[Union[int, float, str, Rdate]], ...] = load(row, Tuple[Optional[Union[int, float, str, Rdate]], ...])
|
||||||
|
content.append(t_row)
|
||||||
|
return Relation(header, frozenset(content))
|
||||||
|
|
||||||
def save(self, filename: Union[Path, str]) -> None:
|
def save(self, filename: Union[Path, str]) -> None:
|
||||||
'''
|
'''
|
||||||
|
Loading…
x
Reference in New Issue
Block a user