Skip to content
1 change: 1 addition & 0 deletions doc/changelog.d/4932.added.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Call .name if it's a SettingsBase
19 changes: 17 additions & 2 deletions src/ansys/fluent/core/solver/flobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@

from __future__ import annotations

import collections
import collections.abc
from contextlib import contextmanager, nullcontext
import fnmatch
import hashlib
Expand All @@ -49,6 +49,7 @@
import logging
import os
import os.path
from pathlib import Path
import pickle
import string
import sys
Expand All @@ -61,12 +62,14 @@
Generic,
List,
NewType,
Protocol,
Tuple,
TypeVar,
Union,
_eval_type,
get_args,
get_origin,
override,
)
Comment thread
Gobot1234 marked this conversation as resolved.
Outdated
import warnings
import weakref
Expand Down Expand Up @@ -673,10 +676,15 @@ def units(self) -> str | None:
return get_si_unit_for_fluent_quantity(quantity)


class SettingsBaseWithName(Protocol):
__class__: type["SettingsBase"] # pyright: ignore[reportIncompatibleMethodOverride]
name: Callable[[], str]


class Textual(Property):
"""Exposes attribute accessor on settings object - specific to string objects."""

def set_state(self, state: StateT | None = None, **kwargs):
def set_state(self, state: str | VariableDescriptor | SettingsBaseWithName | None = None, **kwargs):
"""Set the state of the object.

Parameters
Expand All @@ -691,6 +699,9 @@ def set_state(self, state: StateT | None = None, **kwargs):
TypeError
If state is not a string.
"""
Comment thread
Gobot1234 marked this conversation as resolved.
if isinstance(state, SettingsBase) and hasattr(state, "name"):
state = state.name()
Comment thread
Gobot1234 marked this conversation as resolved.
Comment thread
Gobot1234 marked this conversation as resolved.
Comment thread
Gobot1234 marked this conversation as resolved.

allowed_types = (str, VariableDescriptor)

if not isinstance(state, allowed_types):
Expand Down Expand Up @@ -948,6 +959,10 @@ class Filename(SettingsBase[str], Textual):

_state_type = str

@override
def set_state(self, state: Path | str | None = None, **kwargs):

Copilot AI Feb 16, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Filename.set_state now accepts a Path, but it forwards the Path directly to Textual.set_state, which only allows str/VariableDescriptor and will raise TypeError. Convert Path to str (or extend the allowed types) before calling super().set_state.

Suggested change
def set_state(self, state: Path | str | None = None, **kwargs):
def set_state(self, state: Path | str | None = None, **kwargs):
if isinstance(state, Path):
state = str(state)

Copilot uses AI. Check for mistakes.
return super().set_state(state, **kwargs)
Comment thread
Gobot1234 marked this conversation as resolved.
Comment on lines +1108 to +1111

def file_purpose(self):
"""Specifies whether this file is used as input or output by Fluent."""
return self.get_attr(_InlineConstants.file_purpose)
Expand Down
Loading