better warnings/errors
This commit is contained in:
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
||||
|
||||
[project]
|
||||
name = "scgenerator"
|
||||
version = "0.3.23"
|
||||
version = "0.3.24"
|
||||
description = "Simulate nonlinear pulse propagation in optical fibers"
|
||||
readme = "README.md"
|
||||
authors = [{ name = "Benoit Sierro", email = "benoit.sierro@iap.unibe.ch" }]
|
||||
|
||||
@@ -3,8 +3,9 @@ from __future__ import annotations
|
||||
import datetime as datetime_module
|
||||
import json
|
||||
import os
|
||||
import warnings
|
||||
from copy import copy, deepcopy
|
||||
from dataclasses import dataclass, field
|
||||
from dataclasses import dataclass, field, fields
|
||||
from functools import lru_cache, wraps
|
||||
from math import isnan
|
||||
from pathlib import Path
|
||||
@@ -431,6 +432,12 @@ class Parameters:
|
||||
@classmethod
|
||||
def from_json(cls, s: str) -> Parameters:
|
||||
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)
|
||||
|
||||
@classmethod
|
||||
|
||||
@@ -126,7 +126,8 @@ class VariableParameter:
|
||||
other_len := len(getattr(instance, self.sync.private_name))
|
||||
):
|
||||
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:
|
||||
|
||||
Reference in New Issue
Block a user