Conversation
Up to standards ✅🟢 Issues
|
There was a problem hiding this comment.
Pull request overview
This PR migrates the field-data request “parameter container” types from NamedTuple to @dataclass, while attempting to preserve the legacy NamedTuple-style helper APIs (_asdict(), _replace(), iteration/indexing) for downstream compatibility.
Changes:
- Replaced
SurfaceFieldDataRequest,ScalarFieldDataRequest,VectorFieldDataRequest, andPathlinesFieldDataRequestfromNamedTupleto@dataclasswith a_NamedTupleCompatmixin. - Adjusted
PathlinesFieldDataRequest.zonesto usedefault_factory=listand updated a couple of internal call sites to passzonesdirectly from kwargs. - Updated the field-documentation helper to store docs in a dataclass-specific attribute.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
src/ansys/fluent/core/services/field_data.py |
Removes local zones temporary variables and forwards zones directly from kwargs in pathlines request construction. |
src/ansys/fluent/core/field_data_interfaces.py |
Converts request containers to dataclasses and adds a compatibility layer to emulate prior NamedTuple conveniences. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| For dataclass fields, this stores documentation in a class attribute | ||
| that Sphinx and documentation tools can use to render field documentation | ||
| in attribute/member tables. | ||
| """ | ||
| for field_name, field_doc in field_docs.items(): | ||
| getattr(cls, field_name).__doc__ = field_doc | ||
| # Store field documentation in a class attribute for Sphinx discovery | ||
| cls.__dataclass_field_docs__ = field_docs |
There was a problem hiding this comment.
_set_namedtuple_field_docs() now stores docs on cls.__dataclass_field_docs__, but that attribute doesn’t appear to be consumed anywhere else in the codebase (no references found). As-is, this likely won’t affect Sphinx/autodoc output and may regress the per-field documentation that previously worked via NamedTuple descriptors. Consider attaching docs via dataclasses.field(metadata={...}) (and wiring Sphinx to read it), or adding an explicit Sphinx hook/extension that reads __dataclass_field_docs__ and emits member docs.
There was a problem hiding this comment.
@copilot apply changes based on this feedback
There was a problem hiding this comment.
Added a Sphinx autodoc-process-docstring hook in doc/source/conf.py (commit 3122002) that reads the __dataclass_field_docs__ mapping stored on each dataclass and injects the per-field documentation into attribute docstrings during Sphinx processing. This restores the per-field member documentation that previously worked via NamedTuple property descriptors (which carried __doc__ directly on the descriptor object).
…_field_docs__ Agent-Logs-Url: https://github.com/ansys/pyfluent/sessions/465fae24-3285-4e8b-989d-30018468c47f Co-authored-by: prmukherj <109645853+prmukherj@users.noreply.github.com>
Context
SurfaceFieldDataRequest,ScalarFieldDataRequest,VectorFieldDataRequest, andPathlinesFieldDataRequestwereNamedTuplesubclasses. NamedTuple property descriptors carry__doc__directly, so_set_namedtuple_field_docs()could patch per-field Sphinx docs at runtime. After migration to@dataclass, docs were stored incls.__dataclass_field_docs__but nothing consumed that attribute, silently dropping per-field API docs.Change Summary
field_data_interfaces.py: Converted the four request containers fromNamedTupleto@dataclasswith a_NamedTupleCompatmixin preserving_asdict(),_replace(), iteration, and indexing. Updated_set_namedtuple_field_docs()to store docs incls.__dataclass_field_docs__(since dataclass fields have no property descriptor to patch__doc__on). FixedPathlinesFieldDataRequest.zonesto usedefault_factory=list.field_data.py: Minor internal call-site updates to passzonesfromkwargsdirectly.doc/source/conf.py: Added_inject_dataclass_field_docs— anautodoc-process-docstringSphinx hook that reads__dataclass_field_docs__on any dataclass and injects per-field docs into empty attribute docstrings, restoring the Sphinx member-table output that previously worked via NamedTuple descriptors.Rationale
The Sphinx hook is the minimal fix: it bridges the gap between dataclass fields (no descriptor
__doc__) and Sphinx autodoc without requiring verbosedataclasses.field(metadata={"doc": ...})rewrites across every field definition.Impact
_asdict(),_replace(), tuple unpacking, or index access continues to work unchanged via the_NamedTupleCompatmixin.