Skip to content

Comments

feat: Initial bulk of type checking + setup#4761

Open
Gobot1234 wants to merge 72 commits intomainfrom
jhilton/typing-improvements
Open

feat: Initial bulk of type checking + setup#4761
Gobot1234 wants to merge 72 commits intomainfrom
jhilton/typing-improvements

Conversation

@Gobot1234
Copy link
Collaborator

Context

Duplicate of #4500 but on the ansys remote. Looking at this code more, I realise I've ran pyupgrade on this so don't merge this till I get the rest of the ruff stuff set up. I'm also realising there are 3 issues tied up in this, apologies for that.
Fixes #4489 and fixes #4490
Helps with #4543

Change Summary

Added a bunch of initial types for the public facing library part of #4738

Comment on lines 187 to 200
}
self.argvals, self.new_session = _get_argvals_and_session(argvals)
if self.argvals["start_timeout"] is None:
self.argvals, self.new_session = _get_argvals_and_session(
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This was changed as sadly there's no way to type transform a typedict to have optional keys (python isn't typescript, sad)

@Gobot1234
Copy link
Collaborator Author

I'll try and get to the conflicts soonish, probably more useful to get the ruff changes in first

@github-actions github-actions bot added documentation Documentation related (improving, adding, etc) examples Publishing PyFluent examples maintenance General maintenance of the repo (libraries, cicd, etc) dependencies Related to dependencies labels Jan 15, 2026
@Gobot1234 Gobot1234 marked this pull request as ready for review January 15, 2026 03:19
Copilot AI review requested due to automatic review settings January 15, 2026 03:19
Copilot AI review requested due to automatic review settings February 17, 2026 14:13
Copy link
Contributor

Copilot AI left a comment

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 92 out of 94 changed files in this pull request and generated no new comments.


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

Copilot AI review requested due to automatic review settings February 17, 2026 14:21
Copy link
Contributor

Copilot AI left a comment

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 92 out of 94 changed files in this pull request and generated 1 comment.

Comments suppressed due to low confidence (3)

src/ansys/fluent/core/launcher/watchdog.py:1

  • Use f-string instead of .format() for consistency with the rest of the codebase. Change to err_content = f\"Watchdog - {f.read().replace('\\n', '')}\"
    src/ansys/fluent/core/module_config.py:1
  • The FIXME comment should clarify the intended resolution. Consider adding a TODO for when Python 3.10 support is dropped, or wrap this in a version check to use the proper method when available.
    src/ansys/fluent/core/session_utilities.py:1
  • Add a comment explaining why this pyright directive is needed. This helps maintainers understand the intent and whether it can be removed in the future.

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

Copilot AI review requested due to automatic review settings February 17, 2026 15:21
Copy link
Contributor

Copilot AI left a comment

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 92 out of 94 changed files in this pull request and generated 3 comments.

Comments suppressed due to low confidence (3)

src/ansys/fluent/core/launcher/slurm_launcher.py:578

  • SlurmLauncher.__init__ updates ui_mode to GUI when config.show_fluent_gui is enabled, but this happens after _get_argvals_and_session(argvals) has already computed derived values (e.g., graphics_driver) using the pre-override ui_mode. Set ui_mode before calling _get_argvals_and_session, or recompute the derived fields after overriding ui_mode to avoid mismatched launcher configuration.
    src/ansys/fluent/core/services/_protocols.py:38
  • ServiceProtocol currently declares an __init__(channel, metadata) signature. Many service classes in this PR require additional constructor parameters (e.g., fluent_error_state), and FluentConnection.create_grpc_service() explicitly forwards *args. This makes the protocol too strict and can cause type-checking failures/incompatibilities. Update the protocol to accept *args: Any, **kwargs: Any (or model the callable/factory differently) so services with additional required parameters still conform.
    src/ansys/fluent/core/fluent_connection.py:756
  • create_grpc_service() is typed as taking service: type[S] where S is bound to ServiceProtocol, but it always calls service(self._channel, self._metadata, *args). With the current ServiceProtocol constructor type, this call is not type-safe and will be rejected by type checkers for any service needing extra args. Consider loosening the bound (e.g., a Protocol with __init__(channel, metadata, *args, **kwargs)) or changing the generic to reflect the forwarded arguments.
    def create_grpc_service(self, service: type[S], *args) -> S:
        """Create a gRPC service.

        Parameters
        ----------
        service : Any
            service class
        args : Any, optional
            additional arguments, by default empty

        Returns
        -------
        Any
            service object
        """
        return service(self._channel, self._metadata, *args)

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

Comment on lines +219 to +223
self.argvals, self.new_session = _get_argvals_and_session(kwargs)
self.file_transfer_service = kwargs.get("file_transfer_service")
if pyfluent.config.show_fluent_gui:
ui_mode = UIMode.GUI
self.argvals["ui_mode"] = UIMode(ui_mode)
if self.argvals["start_timeout"] is None:
kwargs["ui_mode"] = UIMode.GUI
self.argvals["ui_mode"] = UIMode(kwargs.get("ui_mode"))
Copy link

Copilot AI Feb 17, 2026

Choose a reason for hiding this comment

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

In StandaloneLauncher.__init__, ui_mode is overridden when config.show_fluent_gui is set after calling _get_argvals_and_session(kwargs). That helper computes derived values (notably graphics_driver) based on the original ui_mode, so this ordering can leave graphics_driver inconsistent with the final GUI mode. Move the show_fluent_gui override so kwargs['ui_mode'] is set before _get_argvals_and_session, or recompute the dependent fields afterward.

Copilot uses AI. Check for mistakes.
@Gobot1234 Gobot1234 disabled auto-merge February 17, 2026 15:54
@Gobot1234 Gobot1234 enabled auto-merge (squash) February 17, 2026 15:54
Copilot AI review requested due to automatic review settings February 17, 2026 15:55
Copy link
Contributor

Copilot AI left a comment

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 92 out of 94 changed files in this pull request and generated 6 comments.


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

Comment on lines +354 to +363
for (
k,
v,
) in cast(
list[tuple[str, Any]],
inspect.getmembers_static( # pyright: ignore[reportAttributeAccessIssue]
self
),
):
# FIXME: This is an actual bug due to not being in 3.10 (added in 3.11)
Copy link

Copilot AI Feb 17, 2026

Choose a reason for hiding this comment

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

The inspect.getmembers_static method was added in Python 3.11. Since this code uses a cast and includes a FIXME comment indicating this is a bug, the code will fail on Python 3.10 and earlier. Either remove this functionality for older Python versions, add a version check with a fallback, or update the minimum Python version requirement.

Copilot uses AI. Check for mistakes.
Gobot1234 and others added 2 commits February 18, 2026 01:47
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings February 18, 2026 10:35
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copy link
Contributor

Copilot AI left a comment

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 93 out of 95 changed files in this pull request and generated 1 comment.


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

:class:`~ansys.fluent.core.session_solver.Solver`, \
:class:`~ansys.fluent.core.session_solver_icing.SolverIcing`, dict]
:class:`~ansys.fluent.core.session_solver_icing.SolverIcing`, tuple[str, str]]
Session object or configuration dictionary if ``dry_run = True``.
Copy link

Copilot AI Feb 18, 2026

Choose a reason for hiding this comment

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

The launch_fluent function has default values for dimension and precision but these should match the docstring and typical usage. The defaults are set to Dimension.THREE and Precision.DOUBLE, which matches issue #4490's goal of providing informative defaults instead of None. However, the function signature shows these defaults are provided, but the docstring in the Returns section still mentions "configuration dictionary if dry_run = True" when it should say "tuple[str, str] if dry_run = True" to match the new type annotation.

Suggested change
Session object or configuration dictionary if ``dry_run = True``.
Session object or tuple[str, str] if ``dry_run = True``.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CI/CD dependencies Related to dependencies documentation Documentation related (improving, adding, etc) examples Publishing PyFluent examples maintenance General maintenance of the repo (libraries, cicd, etc) new feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Avoid having default None where a more informative default can be provided Make launch/connect_to_fluent and kwarg only

5 participants