feat: Initial bulk of type checking + setup#4761
Conversation
| } | ||
| 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( |
There was a problem hiding this comment.
This was changed as sadly there's no way to type transform a typedict to have optional keys (python isn't typescript, sad)
|
I'll try and get to the conflicts soonish, probably more useful to get the ruff changes in first |
…s/pyfluent into jhilton/typing-improvements
…s/pyfluent into jhilton/typing-improvements
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 toerr_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.
There was a problem hiding this comment.
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__updatesui_modeto GUI whenconfig.show_fluent_guiis enabled, but this happens after_get_argvals_and_session(argvals)has already computed derived values (e.g.,graphics_driver) using the pre-overrideui_mode. Setui_modebefore calling_get_argvals_and_session, or recompute the derived fields after overridingui_modeto avoid mismatched launcher configuration.
src/ansys/fluent/core/services/_protocols.py:38ServiceProtocolcurrently declares an__init__(channel, metadata)signature. Many service classes in this PR require additional constructor parameters (e.g.,fluent_error_state), andFluentConnection.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:756create_grpc_service()is typed as takingservice: type[S]whereSis bound toServiceProtocol, but it always callsservice(self._channel, self._metadata, *args). With the currentServiceProtocolconstructor 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.
| 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")) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
| 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) |
There was a problem hiding this comment.
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.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
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``. |
There was a problem hiding this comment.
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.
| Session object or configuration dictionary if ``dry_run = True``. | |
| Session object or tuple[str, str] if ``dry_run = True``. |
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