Skip to content

Commit 8aba502

Browse files
fix: Fix deprecated behaviour (#3948)
For "deprecated" settings, we should hide the exposure, but not block the access. With the current PR changes, we get the following behaviour in both pyfluent and pyconsole: ``` >>> v1 = solver.settings.results.graphics.vector.create() >>> v1.scale.scale_f = 4 >>> "scale" in dir(v1) False ``` Nightly dev doc run - https://github.com/ansys/pyfluent/actions/runs/14606954687 --------- Co-authored-by: pyansys-ci-bot <[email protected]>
1 parent 154fb05 commit 8aba502

File tree

3 files changed

+39
-28
lines changed

3 files changed

+39
-28
lines changed

doc/changelog.d/3948.fixed.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix deprecated behaviour

src/ansys/fluent/core/solver/flobject.py

+18-13
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,8 @@ def get_attr(
410410
def _is_deprecated(self) -> bool:
411411
"""Whether the object is deprecated in a specific Fluent version.'"""
412412
deprecated_version = self.get_attrs(["deprecated-version"])
413+
if deprecated_version:
414+
deprecated_version = deprecated_version.get("attrs", deprecated_version)
413415
deprecated_version = (
414416
deprecated_version.get("deprecated-version") if deprecated_version else None
415417
)
@@ -419,7 +421,7 @@ def _is_deprecated(self) -> bool:
419421

420422
def is_active(self) -> bool:
421423
"""Whether the object is active."""
422-
attr = self.get_attr(_InlineConstants.is_active) and not self._is_deprecated()
424+
attr = self.get_attr(_InlineConstants.is_active)
423425
return False if attr is False else True
424426

425427
def _check_stable(self) -> None:
@@ -955,7 +957,7 @@ def _command_query_name_filter(
955957
for name in names:
956958
if name not in excluded and name.startswith(prefix):
957959
child = getattr(parent, name)
958-
if child.is_active():
960+
if child.is_active() and not child._is_deprecated():
959961
ret.append([name, child.__class__.__bases__[0].__name__, child.__doc__])
960962
return ret
961963

@@ -1067,25 +1069,28 @@ def to_python_keys(cls, value):
10671069
def get_active_child_names(self):
10681070
"""Names of children that are currently active."""
10691071
ret = []
1070-
for child in self.child_names:
1071-
if getattr(self, child).is_active():
1072-
ret.append(child)
1072+
for child_name in self.child_names:
1073+
child = getattr(self, child_name)
1074+
if child.is_active() and not child._is_deprecated():
1075+
ret.append(child_name)
10731076
return ret
10741077

10751078
def get_active_command_names(self):
10761079
"""Names of commands that are currently active."""
10771080
ret = []
1078-
for command in self.command_names:
1079-
if getattr(self, command).is_active():
1080-
ret.append(command)
1081+
for command_name in self.command_names:
1082+
command = getattr(self, command_name)
1083+
if command.is_active() and not command._is_deprecated():
1084+
ret.append(command_name)
10811085
return ret
10821086

10831087
def get_active_query_names(self):
10841088
"""Names of queries that are currently active."""
10851089
ret = []
1086-
for query in self.query_names:
1087-
if getattr(self, query).is_active():
1088-
ret.append(query)
1090+
for query_name in self.query_names:
1091+
query = getattr(self, query_name)
1092+
if query.is_active() and not query._is_deprecated():
1093+
ret.append(query_name)
10891094
return ret
10901095

10911096
def __dir__(self):
@@ -1111,7 +1116,7 @@ def get_completer_info(self, prefix="", excluded=None) -> List[List[str]]:
11111116
for child_name in self.child_names:
11121117
if child_name not in excluded and child_name.startswith(prefix):
11131118
child = getattr(self, child_name)
1114-
if child.is_active():
1119+
if child.is_active() and not child._is_deprecated():
11151120
ret.append(
11161121
[
11171122
child_name,
@@ -1667,7 +1672,7 @@ def get_completer_info(self, prefix="", excluded=None) -> List[List[str]]:
16671672
for argument_name in self.argument_names:
16681673
if argument_name not in excluded and argument_name.startswith(prefix):
16691674
argument = getattr(self, argument_name)
1670-
if argument.is_active():
1675+
if argument.is_active() and not argument._is_deprecated():
16711676
ret.append(
16721677
[
16731678
argument_name,

tests/test_settings_api.py

+20-15
Original file line numberDiff line numberDiff line change
@@ -678,7 +678,6 @@ def test_return_types_of_operations_on_named_objects(mixing_elbow_settings_sessi
678678
assert var3.obj_name == "air-copied"
679679

680680

681-
@pytest.mark.skip("https://github.com/ansys/pyfluent/issues/3813")
682681
@pytest.mark.fluent_version(">=25.1")
683682
def test_settings_with_deprecated_flag(mixing_elbow_settings_session):
684683
solver = mixing_elbow_settings_session
@@ -703,23 +702,23 @@ def test_settings_with_deprecated_flag(mixing_elbow_settings_session):
703702
== "25.1"
704703
)
705704

706-
# Deprecated objects should not be active
707-
assert not graphics.contour["contour-velocity"].range_option.is_active()
705+
# User won't normally find deprecated objects in the settings API, so it is OK to leave them active.
708706
assert graphics.contour["contour-velocity"].range_options.is_active()
709707

708+
# https://github.com/ansys/pyfluent/issues/3813
710709
# in 'get_state'
711-
if solver.get_fluent_version() >= FluentVersion.v252:
712-
# From v252 'get_state' behaviour is to be corrected in Fluent.
713-
assert not {"range_option", "coloring"}.issubset(
714-
set(graphics.contour["contour-velocity"].get_state())
715-
)
716-
assert {"range_options", "colorings"}.issubset(
717-
set(graphics.contour["contour-velocity"].get_state())
718-
)
719-
else:
720-
assert {"range_option", "range_options", "coloring", "colorings"}.issubset(
721-
set(graphics.contour["contour-velocity"].get_state())
722-
)
710+
# if solver.get_fluent_version() >= FluentVersion.v252:
711+
# # From v252 'get_state' behaviour is to be corrected in Fluent.
712+
# assert not {"range_option", "coloring"}.issubset(
713+
# set(graphics.contour["contour-velocity"].get_state())
714+
# )
715+
# assert {"range_options", "colorings"}.issubset(
716+
# set(graphics.contour["contour-velocity"].get_state())
717+
# )
718+
# else:
719+
# assert {"range_option", "range_options", "coloring", "colorings"}.issubset(
720+
# set(graphics.contour["contour-velocity"].get_state())
721+
# )
723722

724723
# in 'child_names'
725724
# 'child_names', 'command_names' and 'query_names' will remain unchanged.
@@ -763,6 +762,12 @@ def test_settings_with_deprecated_flag(mixing_elbow_settings_session):
763762
"create_output_parameter",
764763
)
765764

765+
v1 = solver.settings.results.graphics.vector.create()
766+
assert v1.scale.scale_f() == 1.0
767+
v1.scale.scale_f = 2.0
768+
assert v1.scale.scale_f() == 2.0
769+
assert "scale" not in dir(v1)
770+
766771

767772
@pytest.fixture
768773
def use_runtime_python_classes(monkeypatch: pytest.MonkeyPatch):

0 commit comments

Comments
 (0)