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


##########
docs/conf.py:
##########
@@ -291,7 +292,9 @@ def _link_inherited_members(app, what, name, obj, options, 
lines) -> None:  # no
     # If it comes from builtins we already hide it; no link needed
     if base in _py_native_classes or getattr(base, "__module__", "") == 
"builtins":
         return
-    owner_fq = 
f"{base.__module__}.{base.__qualname__}".replace("tvm_ffi.core.", "tvm_ffi.")
+    owner_fq = f"{base.__module__}.{base.__qualname__}".replace(
+        "tvm_ffi.core.", "tvm_ffi."
+    ).replace(".CObject", ".Object")

Review Comment:
   ![medium](https://www.gstatic.com/codereviewagent/medium-priority.svg)
   
   The use of `.replace(".CObject", ".Object")` is a bit fragile, as it could 
incorrectly modify a class name that contains "CObject" but doesn't end with it 
(e.g., `MyCObjectFoo`). While you've noted this isn't an issue in the current 
codebase, we can make it more robust for the future by only performing the 
replacement if the string ends with `.CObject`.
   
   ```suggestion
       owner_fq = 
f"{base.__module__}.{base.__qualname__}".replace("tvm_ffi.core.", "tvm_ffi.")
       if owner_fq.endswith(".CObject"):
           owner_fq = owner_fq.removesuffix(".CObject") + ".Object"
   ```



##########
docs/guides/dataclass_reflection.rst:
##########
@@ -0,0 +1,467 @@
+..  Licensed to the Apache Software Foundation (ASF) under one
+    or more contributor license agreements.  See the NOTICE file
+    distributed with this work for additional information
+    regarding copyright ownership.  The ASF licenses this file
+    to you under the Apache License, Version 2.0 (the
+    "License"); you may not use this file except in compliance
+    with the License.  You may obtain a copy of the License at
+
+..    http://www.apache.org/licenses/LICENSE-2.0
+
+..  Unless required by applicable law or agreed to in writing,
+    software distributed under the License is distributed on an
+    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+    KIND, either express or implied.  See the License for the
+    specific language governing permissions and limitations
+    under the License.
+
+.. _dataclass-reflection:
+
+Dataclass-Style Reflection
+==========================
+
+TVM-FFI's reflection system provides Python-dataclass-style features for C++
+classes: auto-generated constructors, default values, keyword-only parameters,
+repr, hashing, comparison, and deep copy. These features are enabled by
+per-field and per-class traits registered via
+:cpp:class:`~tvm::ffi::reflection::ObjectDef`.
+
+This guide assumes familiarity with :doc:`export_func_cls` and
+:doc:`../concepts/object_and_class`.
+
+
+Quick Start
+-----------
+
+Define a C++ object with fields, register it with traits, and use it from
+Python with full dataclass semantics:
+
+.. code-block:: cpp
+
+   #include <tvm/ffi/tvm_ffi.h>
+
+   namespace ffi = tvm::ffi;
+
+   class PointObj : public ffi::Object {
+    public:
+     int64_t x;
+     int64_t y;
+     ffi::String label;
+
+     static constexpr bool _type_mutable = true;
+     TVM_FFI_DECLARE_OBJECT_INFO_FINAL("my_ext.Point", PointObj, ffi::Object);
+   };
+
+   TVM_FFI_STATIC_INIT_BLOCK() {
+     namespace refl = ffi::reflection;
+     refl::ObjectDef<PointObj>()
+         .def_rw("x", &PointObj::x)
+         .def_rw("y", &PointObj::y)
+         .def_rw("label", &PointObj::label, refl::default_(""));
+   }
+
+No ``refl::init<>()`` call is needed — the reflection system auto-generates a
+packed ``__ffi_init__`` from the reflected fields:
+
+.. code-block:: python
+
+   import tvm_ffi
+
+   @tvm_ffi.register_object("my_ext.Point")
+   class Point(tvm_ffi.Object):
+       x: int
+       y: int
+       label: str
+
+   p = Point(1, 2)                # positional args
+   p = Point(1, 2, label="origin")  # keyword arg with default

Review Comment:
   ![medium](https://www.gstatic.com/codereviewagent/medium-priority.svg)
   
   For clarity in the example, it would be better to use different variable 
names for the two `Point` instances. Reassigning `p` immediately can be 
slightly confusing for readers.
   
   ```suggestion
      p1 = Point(1, 2)                # positional args
      p2 = Point(1, 2, label="origin")  # keyword arg with default
   ```



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