Skip to content

Commit 743b360

Browse files
committed
Tidy3dBaseModel._json method that does the custom handling but also takes in kwargs
1 parent af7552e commit 743b360

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

tidy3d/components/base.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -713,6 +713,20 @@ def __eq__(self, other):
713713
def _json_string(self) -> str:
714714
"""Returns string representation of a :class:`Tidy3dBaseModel`.
715715
716+
Returns
717+
-------
718+
str
719+
Json-formatted string holding :class:`Tidy3dBaseModel` data.
720+
"""
721+
return self._json()
722+
723+
def _json(self, indent=INDENT, exclude_unset=False, **kwargs) -> str:
724+
"""Overwrites the model ``json`` representation with some extra customized handling.
725+
726+
Parameters
727+
-----------
728+
**kwargs : kwargs passed to `self.json()`
729+
716730
Returns
717731
-------
718732
str
@@ -727,12 +741,9 @@ def make_json_compatible(json_string: str) -> str:
727741
json_string = json_string.replace("Infinity", '"Infinity"')
728742
return json_string.replace(tmp_string, '"-Infinity"')
729743

730-
json_string = self.json(indent=INDENT, exclude_unset=False)
744+
json_string = self.json(indent=indent, exclude_unset=exclude_unset, **kwargs)
731745
json_string = make_json_compatible(json_string)
732746
return json_string
733-
# json_dict = json.loads(json_string)
734-
735-
# return json.dumps(json_dict)
736747

737748
@classmethod
738749
def add_type_field(cls) -> None:

0 commit comments

Comments
 (0)