Repository navigation
feat: runtime typecheck phase 2 - #5421
mayankansys wants to merge 41 commits into
Conversation
Up to standards ✅🟢 Issues
|
| return graphics_driver | ||
|
|
||
|
|
||
| @no_runtime_type_check |
There was a problem hiding this comment.
Why these decorators are needed on private modules? Isn't there a way to deal with it generically?
There was a problem hiding this comment.
The private functions reference Meshing, Solver, and PureMeshing classes only under TYPE_CHECKING. Beartype can't resolve these names at runtime and would silently skip the functions. We exempt them explicitly to avoid noise and make the limitation clear in code.
There was a problem hiding this comment.
But is this function even called?
There was a problem hiding this comment.
Right Sean. This is a helper function which was used by me later missed to remove it.
| ) | ||
|
|
||
|
|
||
| @no_runtime_type_check |
There was a problem hiding this comment.
Again what's the standard for type checking abstract classes?
There was a problem hiding this comment.
There's no universal standard it's case-by-case. We exempt this class because its abstract methods mix unresolvable protocol types with beartype decoration.
There was a problem hiding this comment.
This reply constitutes a useful code comment, so that future readers/maintainers understand the rationale.
There was a problem hiding this comment.
# These field-data contracts use annotations imported only under TYPE_CHECKING, such as SurfaceFieldDataRequest
# and npt.NDArray. They remain available to static checkers, but beartype cannot resolve those names at runtime.
# That is why these contracts opt out; abstract classes do not generally need an exemption.| field_name: str | "ScalarVariableDescriptor" | ||
| additional_field_name: str | "ScalarVariableDescriptor" = "" | ||
| field_name: str | ScalarVariableDescriptor | ||
| additional_field_name: str = "" |
There was a problem hiding this comment.
This drops the descriptor type, but we can see the descriptor validation just below here:
_validate_scalar_variable_descriptor(self.additional_field_name).
|
Avoid uppercase characters in branch names |
…/pyfluent into feat/Updated_runtime_phase
|
|
||
| from ansys.fluent.core._tools.settings.state_types import StateType | ||
| from ansys.fluent.core._type_checking import no_runtime_type_check | ||
| from ansys.fluent.core.solver.flobject import StateType |
There was a problem hiding this comment.
This import creates a new dependency in the wrong direction. N.b. it's already defined in state_types so the issue is easily resolvable.
| from ansys.fluent.core.solver.flobject import StateType | ||
|
|
||
|
|
||
| @no_runtime_type_check |
There was a problem hiding this comment.
Why is this excluded?
| if TYPE_CHECKING: | ||
| import numpy as np | ||
| import numpy.typing as npt | ||
|
|
There was a problem hiding this comment.
The following imports are presumably guarded to avoid a reverse dependency. That needs to be commented separately from the above imports.
| :class:`~ansys.fluent.core.fields.field_data.live_field_data.LiveFieldData` is the | ||
| standard implementation. | ||
| """ | ||
|
|
There was a problem hiding this comment.
N.b. the following method is excluded but it doesn't seem necessary.
|
|
| return ip, port, password | ||
|
|
||
|
|
||
| @no_runtime_type_check |
There was a problem hiding this comment.
Is it only the factory methods that are the issue here? Could you decorate those specifically instead?
Context
PR #5375 added runtime type-checking support. When beartype is applied to the package, many public APIs were silently left unchecked because beartype only warns on decoration failures. The
no_runtime_type_checkmarker on classes also had no effect on methods - beartype checks each method individually.Change Summary
Rewrote
no_runtime_type_checkto flag class methods,classmethods,staticmethods, properties, and nested classes.Made
PathTypea real type (os.PathLike[str] | str) instead of a string.Implemented PEP 695 type statements for recursive type aliases (ValueT, StateType, DictStateType, ListStateType) enabling both static checkers and runtime validators to see identical recursive definitions instead of TYPE_CHECKING splits.
Fixed mixed-quoted hints in field-data modules; imported descriptor classes at runtime.
Exempted helpers with unresolvable hints:
_get_argvals_and_session,_get_running_session_mode,_set_state_safe, and abstract field-data classes.Enhanced check_type() function to unwrap PEP 695 TypeAliasType objects, enabling proper validation of recursive type aliases at runtime.
Added comprehensive test coverage:
Rationale
Impact
launch_fluent, object-model, and field-data APIs are now checked; proxy classes remain exempt by design.