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


##########
python/tvm_ffi/dataclasses/_utils.py:
##########
@@ -130,18 +130,28 @@ class DefaultFactory(NamedTuple):
         cur_type_info = cur_type_info.parent_type_info
     fields.reverse()
 
+    init_fields: list[tuple[TypeField, Any]] = []
+    non_init_fields: list[tuple[TypeField, Any]] = []
+    for field in fields:
+        dataclass_field = field.dataclass_field
+        if dataclass_field is None:
+            raise ValueError(f"Missing dataclass metadata for field 
`{field.name}`")
+        if getattr(dataclass_field, "init", True):
+            init_fields.append((field, dataclass_field))
+        else:
+            non_init_fields.append((field, dataclass_field))

Review Comment:
   ![medium](https://www.gstatic.com/codereviewagent/medium-priority.svg)
   
   The use of `getattr(dataclass_field, "init", True)` is quite defensive. 
Given that `fill_dataclass_field` ensures `dataclass_field` is an instance of 
`Field`, and the `Field` class constructor guarantees the `init` attribute's 
existence, a direct attribute access `dataclass_field.init` would be safe here.
   
   Direct access is slightly more performant and more explicitly states the 
expectation that `dataclass_field` will have an `init` attribute. If it were to 
be missing for some reason, an `AttributeError` would immediately highlight a 
problem in `Field`'s construction, which is often desirable for internal 
library code to fail fast.
   
   I suggest simplifying this to use direct attribute access for better clarity 
and robustness.
   
   ```suggestion
           if dataclass_field.init:
               init_fields.append((field, dataclass_field))
           else:
               non_init_fields.append((field, dataclass_field))
   ```



-- 
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