better warnings/errors
This commit is contained in:
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|||||||
|
|
||||||
[project]
|
[project]
|
||||||
name = "scgenerator"
|
name = "scgenerator"
|
||||||
version = "0.3.23"
|
version = "0.3.24"
|
||||||
description = "Simulate nonlinear pulse propagation in optical fibers"
|
description = "Simulate nonlinear pulse propagation in optical fibers"
|
||||||
readme = "README.md"
|
readme = "README.md"
|
||||||
authors = [{ name = "Benoit Sierro", email = "benoit.sierro@iap.unibe.ch" }]
|
authors = [{ name = "Benoit Sierro", email = "benoit.sierro@iap.unibe.ch" }]
|
||||||
|
|||||||
@@ -3,8 +3,9 @@ from __future__ import annotations
|
|||||||
import datetime as datetime_module
|
import datetime as datetime_module
|
||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
|
import warnings
|
||||||
from copy import copy, deepcopy
|
from copy import copy, deepcopy
|
||||||
from dataclasses import dataclass, field
|
from dataclasses import dataclass, field, fields
|
||||||
from functools import lru_cache, wraps
|
from functools import lru_cache, wraps
|
||||||
from math import isnan
|
from math import isnan
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
@@ -431,6 +432,12 @@ class Parameters:
|
|||||||
@classmethod
|
@classmethod
|
||||||
def from_json(cls, s: str) -> Parameters:
|
def from_json(cls, s: str) -> Parameters:
|
||||||
decoded = json.loads(s, object_hook=custom_decode_hook)
|
decoded = json.loads(s, object_hook=custom_decode_hook)
|
||||||
|
extras = set(decoded) - cls._p_names
|
||||||
|
if len(extras) > 0:
|
||||||
|
warnings.warn(f"extra keys (ignored) in parameter json: {extras!r}")
|
||||||
|
for e in extras:
|
||||||
|
decoded.pop(e)
|
||||||
|
|
||||||
return cls(**decoded)
|
return cls(**decoded)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
|
|||||||
@@ -126,7 +126,8 @@ class VariableParameter:
|
|||||||
other_len := len(getattr(instance, self.sync.private_name))
|
other_len := len(getattr(instance, self.sync.private_name))
|
||||||
):
|
):
|
||||||
raise ValueError(
|
raise ValueError(
|
||||||
f"sequence of len {this_len} doesn't match syncronized sequence of len {other_len}"
|
f"sequence {self.public_name!r} of len {this_len} doesn't match syncronized "
|
||||||
|
f"sequence {self.sync.public_name!r} of len {other_len}"
|
||||||
)
|
)
|
||||||
|
|
||||||
def _error_no_default(self) -> ValueError:
|
def _error_no_default(self) -> ValueError:
|
||||||
|
|||||||
Reference in New Issue
Block a user