Skip to content

feat: runtime typechecking - #5375

Open
mayankansys wants to merge 22 commits into
mainfrom
feat/Runtime_typechecking_4739
Open

mayankansys wants to merge 22 commits into
mainfrom
feat/Runtime_typechecking_4739

Conversation

@mayankansys

@mayankansys mayankansys commented Sep 5, 2026 •

Copy link
Copy Markdown
Collaborator

Context

PyFluent had no runtime type-checking mechanism to catch API misuse early. Type errors propagated downstream as obscure failures, making debugging difficult for users. This PR opt-in runtime type-checking support (e.g., via beartype), configurable via environment variable.

Change Summary

This PR implements abstraction layer + config, implicit-Optional fixes and decorator fixes.

  • A new module _type_checking.py which is a thin wrapper around the type-checking library. (e.g., via beartype)
  • Added runtime_type_checking descriptor to Config class, reading from PYFLUENT_RUNTIME_TYPE_CHECKING env var ( which must be set before import )
  • Annotation cleanups : implicit-Optional parameters, setting up signatures on both deprecation decorators for interospection compatibility.
  • Dependencies etc.

Impact

Now Pyfluent will support the runtime typechecking. When disabled (the default), there is no impact on the API surface. When enabled, type violations are reported as PyFluentTypeCheckingError exceptions. The feature is optional and can be installed via pip install ansys-fluent-core[type-checking] users who do not install the type-checking extra can continue using PyFluent without beartype.

#NOTE: There are further upcoming PRs as well.

@codacy-production

codacy-production Bot commented Sep 5, 2026 •

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.

Comment thread tests/test_runtime_type_checking.py Outdated
return x

assert fn(1) == 1
with pytest.raises(BeartypeCallHintParamViolation):

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Ideally, we should not directly emit beartype specific exceptions from PyFluent and ask our users to handle them. The backends-specific exception should be kept behind a PyFluent-owned exception.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Correct @mkundu1. I have added it now, initially planner to make it Pyfluent owned exception in the Phase 2.

@github-actions github-actions Bot added documentation Documentation related (improving, adding, etc) maintenance General maintenance of the repo (libraries, cicd, etc) dependencies Related to dependencies labels Sep 16, 2026
TConfig = TypeVar("TConfig", bound="Config")


# ``TConfig`` is bound to a forward reference which cannot be resolved while the

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Should we keep the decorator ? If we didn't put the decorator we get the beartype.roar.BeartypecallHintForwardRefException.

@github-actions github-actions Bot added the CI/CD label Sep 25, 2026
@@ -0,0 +1,391 @@
# Copyright (C) 2021 - 2026 Synopsys, Inc. and ANSYS, Inc. All rights reserved.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

This is the demo script file for the local testing only. This will be removed later.

@mayankansys
mayankansys marked this pull request as ready for review September 25, 2026 19:32
@mayankansys mayankansys linked an issue Sep 25, 2026 that may be closed by this pull request
>>> config.runtime_type_checking
True

Passing an argument of the wrong type then raises a ``beartype.roar.BeartypeCallHintParamViolation``.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This should be updated with the new pyfluent-specific exception type.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Sure. I'll do in the upcoming commit.

@mkundu1 mkundu1 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Changes looks good. Are we already running something in the CI (which would require installing the optional ansys-fluent-core[type-checking] package in the CI workflow)?

@mayankansys

mayankansys commented Sep 27, 2026 •

Copy link
Copy Markdown
Collaborator Author

Changes looks good. Are we already running something in the CI (which would require installing the optional ansys-fluent-core[type-checking] package in the CI workflow)?

@mkundu1 No, the type-checking extra is NOT currently installed in CI. But planned to add in the last phase. Would it be correct to add in the last phase. Is it the correct approach or should I add it in the current phase.

This branch has not been deployed

No deployments
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) maintenance General maintenance of the repo (libraries, cicd, etc) new feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Ensure support for runtime type-checking

3 participants