feat: Add exposure level to settings objects.#5028
Conversation
There was a problem hiding this comment.
Pull request overview
Adds an “exposure level” concept to solver settings objects so callers can determine whether a setting is alpha/beta/stable, and ensures this metadata can be propagated through generated settings classes.
Changes:
- Introduced an
ExposureLevelenum and a newexposure_level()accessor on settings objects (defaulting to Stable). - Plumbed
exposure-levelstatic info into dynamically created settings classes via_exposure_level. - Updated settings code generation to persist
_exposure_levelinto generated Python and stub outputs.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
src/ansys/fluent/core/solver/flobject.py |
Adds ExposureLevel, exposes exposure_level() accessor, and threads exposure level from static info into generated class dict. |
src/ansys/fluent/core/codegen/settingsgen.py |
Includes _exposure_level in collected metadata and emits it into generated classes and stubs. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| def exposure_level(self) -> ExposureLevel | None: | ||
| """Get the exposure level of the object. | ||
|
|
||
| Returns | ||
| ------- | ||
| ExposureLevel | None | ||
| The exposure level of the object (Alpha, Beta, or Stable). | ||
| """ | ||
| attr = self.get_attr(_InlineConstants.exposure_level) | ||
| if attr is None: | ||
| attr = getattr(self, "_exposure_level", None) | ||
| if attr is None: | ||
| return ExposureLevel.STABLE | ||
| return ExposureLevel(attr.lower()) |
There was a problem hiding this comment.
The return type and docstring indicate ExposureLevel | None, but this method always returns an ExposureLevel (defaults to ExposureLevel.STABLE when the attribute is missing). Consider updating the signature/docs to return ExposureLevel and documenting the default/mapping behavior (including how unknown is treated).
| """ | ||
| attr = self.get_attr(_InlineConstants.exposure_level) | ||
| if attr is None: | ||
| attr = getattr(self, "_exposure_level", None) |
There was a problem hiding this comment.
getattr(self, "_exposure_level", None) goes through Base.__getattribute__, and when _exposure_level is absent it constructs the enhanced allowed-name error message before getattr swallows the AttributeError. To avoid that overhead, fetch the class attribute directly (e.g., via getattr(self.__class__, "_exposure_level", None) or object.__getattribute__).
| attr = getattr(self, "_exposure_level", None) | |
| attr = getattr(self.__class__, "_exposure_level", None) |
| if attr is None: | ||
| return ExposureLevel.STABLE | ||
| return ExposureLevel(attr.lower()) |
There was a problem hiding this comment.
New exposure-level behavior isn’t covered by tests. Since this adds a new public accessor, please add unit/integration coverage to verify: (1) missing exposure returns Stable, (2) "unknown" maps to Stable, and (3) invalid values raise a helpful ValueError.
| if attr is None: | |
| return ExposureLevel.STABLE | |
| return ExposureLevel(attr.lower()) | |
| # If no exposure level is set, default to Stable. | |
| if attr is None: | |
| return ExposureLevel.STABLE | |
| # If the attribute is already an ExposureLevel, return it directly. | |
| if isinstance(attr, ExposureLevel): | |
| return attr | |
| # Normalize string values and handle special cases. | |
| if isinstance(attr, str): | |
| normalized = attr.strip().lower() | |
| # Treat empty/unknown exposure levels as Stable. | |
| if not normalized or normalized == "unknown": | |
| return ExposureLevel.STABLE | |
| try: | |
| return ExposureLevel(normalized) | |
| except ValueError as exc: | |
| valid_values = ", ".join(e.value for e in ExposureLevel) | |
| raise ValueError( | |
| f"Invalid exposure level {attr!r}. " | |
| f"Valid values are: {valid_values!s} or 'unknown'." | |
| ) from exc | |
| # Any non-string, non-ExposureLevel value is invalid. | |
| raise ValueError( | |
| f"Invalid exposure level type {type(attr).__name__!s}: {attr!r}." | |
| ) |
Up to standards ✅🟢 Issues
|
Context
What was the situation or problem before this change?
Change Summary
What changes were made?
Rationale
Why was this approach taken?
Impact
What parts of the system or workflows are affected?