Skip to content

Commit 422107c

Browse files
authored
fix: Datamodel __setattr__ (#3175)
* fix: Datamodel __setattr__ * Update set_state on Command Arguments. * Revert set_state change. * Refactor. * Refactor. * Update test marker.
1 parent a04bbb1 commit 422107c

File tree

2 files changed

+53
-17
lines changed

2 files changed

+53
-17
lines changed

src/ansys/fluent/core/services/datamodel_se.py

Lines changed: 37 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -843,13 +843,14 @@ def __init__(
843843
) -> None:
844844
"""__init__ method of PyStateContainer class."""
845845
super().__init__()
846-
self.service: DatamodelService = service
847-
self.rules = rules
848-
if path is None:
849-
self.path = []
850-
else:
851-
self.path = path
852-
self.cached_attrs = {}
846+
self.__dict__.update(
847+
dict(
848+
service=service,
849+
rules=rules,
850+
path=[] if path is None else path,
851+
cached_attrs={},
852+
)
853+
)
853854

854855
def get_remote_state(self) -> Any:
855856
"""Get state of the current object."""
@@ -1791,13 +1792,16 @@ def __init__(
17911792
parent_arg,
17921793
) -> None:
17931794
"""__init__ method of PyCommandArgumentsSubItem class."""
1794-
self.parent = parent
1795-
self.name = name
1796-
1797-
self.service = service
1798-
self.rules = rules
1799-
self.path = path
1800-
self.parent_arg = parent_arg
1795+
self.__dict__.update(
1796+
dict(
1797+
parent=parent,
1798+
name=name,
1799+
service=service,
1800+
rules=rules,
1801+
path=path,
1802+
parent_arg=parent_arg,
1803+
)
1804+
)
18011805

18021806
def get_state(self) -> Any:
18031807
"""Get state of the command argument."""
@@ -1834,6 +1838,12 @@ def help(self) -> None:
18341838
"""Get help."""
18351839
pass
18361840

1841+
def __setattr__(self, key, value):
1842+
if isinstance(value, PyCommandArgumentsSubItem):
1843+
super().__setattr__(key, value)
1844+
else:
1845+
getattr(self, key).set_state(value)
1846+
18371847

18381848
class PyCommandArguments(PyStateContainer):
18391849
"""Class representing command arguments in datamodel."""
@@ -1848,11 +1858,15 @@ def __init__(
18481858
static_info,
18491859
) -> None:
18501860
"""__init__ method of PyCommandArguments class."""
1851-
self.static_info = static_info
18521861
super().__init__(service, rules, path)
1862+
self.__dict__.update(
1863+
dict(
1864+
static_info=static_info,
1865+
command=command,
1866+
id=id,
1867+
)
1868+
)
18531869
self.path.append((command, id))
1854-
self.command = command
1855-
self.id = id
18561870

18571871
def __del__(self) -> None:
18581872
try:
@@ -1887,6 +1901,12 @@ def get_attr(self, attrib: str) -> Any:
18871901
"""
18881902
return self._get_remote_attr(attrib)
18891903

1904+
def __setattr__(self, key, value):
1905+
if isinstance(value, PyCommandArgumentsSubItem):
1906+
super().__setattr__(key, value)
1907+
else:
1908+
getattr(self, key).set_state(value)
1909+
18901910

18911911
class PyTextualCommandArgumentsSubItem(PyCommandArgumentsSubItem, PyTextual):
18921912
"""Class representing textual command argument in datamodel."""

tests/test_datamodel_service.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -784,6 +784,22 @@ def test_on_affected_lifetime_with_delete_all_child_objects(new_solver_session):
784784
assert "/test/affected/A:A1-1" not in solver._se_service.subscriptions
785785

786786

787+
@pytest.mark.fluent_version(">=23.2")
788+
def test_set_command_args_and_sub_args(new_meshing_session):
789+
meshing = new_meshing_session
790+
ig = meshing.meshing.ImportGeometry.create_instance()
791+
792+
# Command Arguments
793+
assert ig.MeshUnit() == "m"
794+
ig.MeshUnit = "mm"
795+
assert ig.MeshUnit() == "mm"
796+
797+
# Command Arguments SubItem
798+
assert ig.CadImportOptions.OneZonePer() == "body"
799+
ig.CadImportOptions.OneZonePer = "face"
800+
assert ig.CadImportOptions.OneZonePer() == "face"
801+
802+
787803
@pytest.mark.fluent_version(">=24.1")
788804
def test_dynamic_dependency(new_meshing_session):
789805
meshing = new_meshing_session

0 commit comments

Comments
 (0)