-
Notifications
You must be signed in to change notification settings - Fork 59
Typing improvements #4761
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Typing improvements #4761
Conversation
| UnexpectedKeywordArgument | ||
| If an unexpected keyword argument is provided. | ||
| Notes | ||
| ----- | ||
| In job scheduler environments (e.g., SLURM, LSF, PBS), resources and compute nodes are allocated, | ||
| and core counts are queried from these environments before being passed to Fluent. | ||
| """ | ||
| insecure_mode_env = os.getenv("PYFLUENT_CONTAINER_INSECURE_MODE") == "1" | ||
| if certificates_folder is None and not insecure_mode and not insecure_mode_env: | ||
| raise ValueError( | ||
| "To launch Fluent in secure gRPC mode, set `certificates_folder`." | ||
| ) | ||
| if certificates_folder is not None and insecure_mode: | ||
| raise ValueError( | ||
| "`certificates_folder` and `insecure_mode` cannot be set at the same time." | ||
| ) | ||
|
|
||
| locals_ = locals().copy() | ||
| argvals = { | ||
| arg: locals_.get(arg) | ||
| for arg in inspect.getargvalues(inspect.currentframe()).args | ||
| } | ||
| 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.
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)
|
|
||
| @property | ||
| def tui(self): | ||
| def tui(self) -> "main_menu": | ||
| """Instance of ``main_menu`` on which Fluent's SolverTUI methods can be | ||
| executed.""" | ||
| return self._base_meshing.tui | ||
| return cast("main_menu", self._base_meshing.tui) | ||
|
|
||
| @property | ||
| def meshing(self): | ||
| def meshing(self) -> "meshing_root": | ||
| """Datamodel root of meshing.""" | ||
| return self._base_meshing.meshing | ||
| return cast("meshing_root", self._base_meshing.meshing) | ||
|
|
||
| @property | ||
| def meshing_utilities(self): | ||
| def meshing_utilities(self) -> "meshing_utilities_root | None": | ||
| """Datamodel root of meshing_utilities.""" | ||
| return self._base_meshing.meshing_utilities | ||
| if self.get_fluent_version() >= FluentVersion.v242: | ||
| return cast("meshing_utilities_root", self._base_meshing.meshing_utilities) | ||
| return None | ||
|
|
||
| @property | ||
| def workflow(self): | ||
| def workflow(self) -> "workflow_root": | ||
| """Datamodel root of workflow.""" | ||
| return self._base_meshing.workflow | ||
| return cast("workflow_root", self._base_meshing.workflow) | ||
|
|
||
| @property | ||
| def meshing_workflow(self): | ||
| """Full API to meshing and meshing_workflow.""" | ||
| return self._base_meshing.meshing_workflow | ||
| return cast("meshing_workflow_root", self._base_meshing.meshing_workflow) | ||
|
|
||
| def watertight(self): | ||
| """Get a new watertight workflow.""" | ||
| return self._base_meshing.watertight_workflow() | ||
|
|
||
| def fault_tolerant(self): | ||
| """Get a new fault-tolerant workflow.""" | ||
| return self._base_meshing.fault_tolerant_workflow() | ||
|
|
||
| def two_dimensional_meshing(self): | ||
| """Get a new 2D meshing workflow.""" | ||
| return self._base_meshing.two_dimensional_meshing_workflow() | ||
|
|
||
| def load_workflow(self, file_path: PathType): | ||
| """Load a saved workflow.""" | ||
| return self._base_meshing.load_workflow(file_path=os.fspath(file_path)) | ||
|
|
||
| def create_workflow(self): | ||
| """Create a meshing workflow.""" | ||
| return self._base_meshing.create_workflow() | ||
|
|
||
| @property | ||
| def current_workflow(self): | ||
| """Current meshing workflow.""" | ||
| return self._base_meshing.current_workflow | ||
|
|
||
| def topology_based(self): | ||
| """Get a new topology-based meshing workflow. | ||
| Raises | ||
| ------ | ||
| AttributeError | ||
| If beta features are not enabled in Fluent. | ||
| """ | ||
| if not self._is_beta_enabled: | ||
| raise BetaFeaturesNotEnabled("Topology-based meshing") | ||
| return self._base_meshing.topology_based_meshing_workflow() | ||
|
|
||
| @property | ||
| def PartManagement(self): | ||
| def PartManagement(self) -> "partmanagement_root": | ||
| """Datamodel root of PartManagement.""" | ||
| return self._base_meshing.PartManagement | ||
| return cast("partmanagement_root", self._base_meshing.PartManagement) | ||
|
|
||
| @property | ||
| def PMFileManagement(self): | ||
| def PMFileManagement(self) -> "pmfilemanagement_root": | ||
| """Datamodel root of PMFileManagement.""" | ||
| return self._base_meshing.PMFileManagement | ||
| return cast("pmfilemanagement_root", self._base_meshing.PMFileManagement) | ||
|
|
||
| @property | ||
| def preferences(self): | ||
| def preferences(self) -> "preferences_root": | ||
| """Datamodel root of preferences.""" | ||
| return self._base_meshing.preferences | ||
| return cast("preferences_root", self._base_meshing.preferences) | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These need to be reconsidered cause they currently will not work as they are trying to use modules as types which isn't supported. @mkundu1 is there a class version of these (in pyi form) that we could use instead to make type checkers happy?
| def __call__(self): | ||
| return self.get_state() | ||
|
|
||
| def __getattribute__(self, item: str): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs better typing desperately as it will allow you use basically anything at type time currently
|
I'll try and get to the conflicts soonish, probably more useful to get the ruff changes in first |
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