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


##########
python/tvm_ffi/container.py:
##########
@@ -143,6 +144,15 @@ def __repr__(self) -> str:
             return type(self).__name__ + "(chandle=None)"
         return "[" + ", ".join([x.__repr__() for x in self]) + "]"
 
+    def __add__(self, other: Sequence[T]) -> Array[T]:
+        """Concatenate two arrays."""
+        # Suppress: Argument 1 to "Array" has incompatible type "chain[T]"; 
expected "Sequence[T]"
+        return type(self)(itertools.chain(self, other))  # type: 
ignore[arg-type]
+
+    def __radd__(self, other: Sequence[T]) -> Array[T]:
+        """Concatenate two arrays."""
+        return type(self)(itertools.chain(other, self))  # type: 
ignore[arg-type]

Review Comment:
   ![medium](https://www.gstatic.com/codereviewagent/medium-priority.svg)
   
   While this implementation for `__add__` and `__radd__` is efficient as it 
avoids creating an intermediate list, the use of `type: ignore` indicates a 
mismatch between the `Array.__init__` signature (which expects a `Sequence`) 
and the `itertools.chain` return type (which is an `Iterator`).
   
   The root cause seems to be that `Array.__init__` is typed to accept a 
`Sequence[T]`, but its implementation using `*input_list` can handle any 
`Iterable[T]`. 
   
   To resolve this properly and improve overall type safety, consider changing 
the signature of `Array.__init__` to accept an `Iterable[T]` instead of 
`Sequence[T]`. This would make your implementation of `__add__` and `__radd__` 
type-safe without needing to ignore type errors. This change could be part of a 
follow-up PR if you prefer to keep this one focused.



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