gemini-code-assist[bot] commented on code in PR #664:
URL: https://github.com/apache/tvm-ffi/pull/664#discussion_r3577075168
##########
python/tvm_ffi/cython/type_info.pxi:
##########
@@ -691,24 +691,57 @@ class TypeField:
assert self.setter is not None
assert self.getter is not None
+ def _is_payload_enum_field(self) -> bool:
+ """Return True when this field targets a registered IntEnum/StrEnum
class."""
+ if self.ty is None or self.ty.origin_type_index <
kTVMFFIStaticObjectBegin:
+ return False
+ try:
+ cls = TYPE_INDEX_TO_CLS[self.ty.origin_type_index]
+ except (IndexError, NameError):
+ return False
+ if cls is None:
+ return False
+ for base in cls.__mro__:
+ if (
+ getattr(base, "__module__", None) == "tvm_ffi.dataclasses.enum"
+ and getattr(base, "__name__", None) in ("IntEnum", "StrEnum")
+ ):
+ return True
+ return False
+
+ def normalize_value(self, value):
+ """Normalize raw payloads for IntEnum/StrEnum fields; pass others
through."""
+ if not self._is_payload_enum_field():
+ return value
+ return globals()["_to_py_class_value"](self.ty.convert(value))
Review Comment:

Calling `_to_py_class_value` via a dynamic `globals()` lookup on every field
normalization introduces unnecessary overhead. Since `_to_py_class_value` is
defined within the same Cython module, calling it directly is much more
efficient as Cython can optimize the global lookup or resolve it directly.
```
return _to_py_class_value(self.ty.convert(value))
```
--
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]