File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 33import numpy as np
44import pytest
55import tidy3d as td
6+ from pydantic import ValidationError
7+ from pydantic_core import PydanticSerializationError
68from tidy3d .components .base import Tidy3dBaseModel
79
810M = td .Medium ()
@@ -198,7 +200,7 @@ def test_attrs(tmp_path):
198200 assert obj .attrs == {"foo" : "attr" }
199201
200202 # this is still not allowed though
201- with pytest .raises (TypeError ):
203+ with pytest .raises (ValidationError ):
202204 obj .attrs = {}
203205
204206 # attrs can be modified
@@ -215,7 +217,7 @@ def test_attrs(tmp_path):
215217
216218 # attrs are in the json strings
217219 obj_json = obj3 .json ()
218- assert '{"foo": "bar"}' in obj_json
220+ assert '{"foo":"bar"}' in obj_json
219221
220222 # attrs are in the dict()
221223 obj_dict = obj3 .dict ()
@@ -230,7 +232,7 @@ def test_attrs(tmp_path):
230232
231233 # test attrs that can't be serialized
232234 obj .attrs ["not_serializable" ] = type
233- with pytest .raises (TypeError ):
235+ with pytest .raises (PydanticSerializationError ):
234236 obj .json ()
235237
236238
Original file line number Diff line number Diff line change @@ -209,10 +209,21 @@ def copy(
209209 Optional mapping of fields to overwrite (passed straight
210210 through to ``model_copy(update=...)``).
211211 """
212+ if update :
213+ allowed = set (self .model_fields ) | {
214+ f .alias for f in self .model_fields .values () if f .alias
215+ }
216+ unknown = set (update ) - allowed
217+ if unknown :
218+ raise ValueError (f"Update for '{ self .type } ' contains unknown fields: { unknown } " )
219+
212220 new_model = self .model_copy (deep = deep , update = update )
213221
214222 if validate :
215223 return self .__class__ .model_validate (new_model .model_dump ())
224+ else :
225+ # make sure cache is always cleared
226+ new_model ._cached_properties = {}
216227
217228 return new_model
218229
You can’t perform that action at this time.
0 commit comments