Skip to content

feat: call .name() if it's a SettingsBase + Path support#4932

Open
Gobot1234 wants to merge 10 commits into
mainfrom
jhilton/less-stringly-typoed
Open

feat: call .name() if it's a SettingsBase + Path support#4932
Gobot1234 wants to merge 10 commits into
mainfrom
jhilton/less-stringly-typoed

Conversation

@Gobot1234

@Gobot1234 Gobot1234 commented Feb 16, 2026

Copy link
Copy Markdown
Collaborator

Context

Currently you have to retype the name of a setting object if you reference that same object in another place. E.g. think report plots and report files. Closes #4844

Change Summary

A small check to set_state to call .name if it's a SettingsObject.

Rationale

This makes the settings api less stringly typed

Impact

Just flobject and a few tests.

Further Expansion of this could be to type the dependant relations e.g. a report file can only take a report plot object and not another settings object.

Copilot AI review requested due to automatic review settings February 16, 2026 14:22

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR aims to reduce “stringly typed” usage in the settings API by allowing string-valued settings to accept a settings object reference and automatically convert it to its .name().

Changes:

  • Update Textual.set_state to convert SettingsBase inputs with .name() into a string before setting state.
  • Introduce a SettingsBaseWithName Protocol to reflect the new accepted input shape in type hints.
  • Add a Filename.set_state override intending to accept pathlib.Path inputs.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/ansys/fluent/core/solver/flobject.py
Comment thread src/ansys/fluent/core/solver/flobject.py
Comment thread src/ansys/fluent/core/solver/flobject.py Outdated
_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.
Comment thread src/ansys/fluent/core/solver/flobject.py
@Gobot1234 Gobot1234 changed the title feat: call .name if it's a SettingsBase feat: call .name if it's a SettingsBase + Path support Feb 16, 2026
Copilot AI review requested due to automatic review settings February 16, 2026 15:15

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/ansys/fluent/core/solver/flobject.py
Comment thread src/ansys/fluent/core/solver/flobject.py Outdated
Comment thread src/ansys/fluent/core/solver/flobject.py
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings February 16, 2026 16:34

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/ansys/fluent/core/solver/flobject.py
Comment thread src/ansys/fluent/core/solver/flobject.py
Comment thread src/ansys/fluent/core/solver/flobject.py
Copilot AI review requested due to automatic review settings May 1, 2026 15:38
@codacy-production

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 5 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/ansys/fluent/core/solver/flobject.py Outdated
Comment thread doc/changelog.d/4932.added.md Outdated
Comment on lines +993 to +996
def set_state(self, state: PathType | None = None, **kwargs):
if state is not None:
state = os.fspath(state)
return super().set_state(state, **kwargs)
Comment thread tests/test_settings_api.py Outdated
Comment on lines +1089 to +1101
self,
state: Sequence[str | SettingsBaseWithName | VariableDescriptor] | None = None,
**kwargs,
):
if isinstance(state, Sequence):
state = [
(
entry.name()
if isinstance(entry, SettingsBase) and hasattr(entry, "name")
else entry
)
for entry in state
]
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@Gobot1234 Gobot1234 changed the title feat: call .name if it's a SettingsBase + Path support feat: call .name() if it's a SettingsBase + Path support Jul 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support for a less stringly-typed settings api

3 participants