gemini-code-assist[bot] commented on code in PR #52:
URL: https://github.com/apache/tvm-ffi/pull/52#discussion_r2374463161


##########
python/tvm_ffi/dataclasses/field.py:
##########
@@ -72,6 +75,19 @@ def field(
         A zero-argument callable that produces the default.  This matches the
         semantics of :func:`dataclasses.field` and is useful for mutable
         defaults such as ``list`` or ``dict``.
+    init : bool, default True
+        If ``True`` the field is included in the generated ``__init__``.
+        If ``False`` the field is omitted from input arguments of ``__init__``.
+
+    Note
+    ----
+    Only at most one of ``default`` or ``default_factory`` may be given.
+
+    If ``default`` or ``default_factory`` is given, or ``init=True``, the field
+    will be forwarded to the C++ ``__ffi_init__`` constructor. In case where
+    ``init=False``, but a default factory is given, the initial value is still
+    computed via the factory, and forwarded to the C++ side, but the user 
cannot
+    feed its value via ``__init__``.

Review Comment:
   Certainly! I've drafted a revised docstring for the `field` function that 
aims to clarify the behavior regarding `init` and forwarding to the C++ 
`__ffi_init__` constructor. This version breaks down the logic into distinct 
cases, making it easier to understand:
   
   1.  **Explicitly states the conditions for forwarding to C++ 
`__ffi_init__`**.
   2.  **Clearly separates the behavior when `init=True` versus `init=False`**.
   3.  **Adds the missing explanation for fields with `init=False` and no 
default value**, specifying that they are not forwarded to C++ and must be 
initialized by the C++ constructor.
   
   This should make the documentation much clearer for users. Please let me 
know if you'd like any further adjustments!
   
   ```suggestion
       The decision to forward a field to the C++ ``__ffi_init__`` constructor
       depends on its configuration:
   
       *   If ``init=True``, the field's value (from user input or 
default/factory)
           is forwarded.
       *   If ``init=False``:
           *   With a ``default`` or ``default_factory``, its computed value is
               forwarded. The user cannot provide this value via Python 
``__init__``.
           *   Without a ``default`` or ``default_factory``, the field is *not*
               forwarded to C++ ``__ffi_init__`` and must be initialized by the
               C++ constructor.
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to