You are viewing a plain text version of this content. The canonical link for it is here.
Posted to discuss-archive@tvm.apache.org by "junrushao (via GitHub)" <gi...@apache.org> on 2026/04/20 06:58:21 UTC
[PR] fix(dunder): refresh late-installed slots [tvm-ffi]
junrushao opened a new pull request, #561:
URL: https://github.com/apache/tvm-ffi/pull/561
(no comment)
--
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: discuss-archive-unsubscribe@tvm.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org
For additional commands, e-mail: discuss-archive-help@tvm.apache.org
Re: [PR] fix(dataclass): refresh late-installed slots [tvm-ffi]
Posted by "junrushao (via GitHub)" <gi...@apache.org>.
junrushao closed pull request #561: fix(dataclass): refresh late-installed slots
URL: https://github.com/apache/tvm-ffi/pull/561
--
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: discuss-archive-unsubscribe@tvm.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org
For additional commands, e-mail: discuss-archive-help@tvm.apache.org
Re: [PR] fix(dataclasses): refresh late-installed slots [tvm-ffi]
Posted by "gemini-code-assist[bot] (via GitHub)" <gi...@apache.org>.
gemini-code-assist[bot] commented on code in PR #561:
URL: https://github.com/apache/tvm-ffi/pull/561#discussion_r3108804137
##########
python/tvm_ffi/_dunder.py:
##########
@@ -429,3 +429,13 @@ def __hash__(self: Any) -> int:
if match_args:
_set_match_args(cls, type_info)
+
+ # Refresh CPython slots after late dunder installation. Object subclasses
+ # backed by tvm-ffi can otherwise expose the Python attribute while `hash()`
+ # or rich comparisons still use the pre-install identity slots.
+ for name in ("__eq__", "__ne__", "__lt__", "__le__", "__gt__", "__ge__", "__hash__"):
+ if name in cls.__dict__:
+ setattr(cls, name, cls.__dict__[name])
+ inherited_hash = getattr(cls, "__hash__", None)
+ if "__hash__" not in cls.__dict__ and inherited_hash not in (None, object.__hash__):
+ setattr(cls, "__hash__", inherited_hash)
Review Comment:

When `__eq__` is added to a class via `setattr` (as done earlier in this function), CPython automatically nullifies the `tp_hash` slot (effectively setting `__hash__` to `None`) to maintain the invariant that objects with custom equality should be unhashable by default. Consequently, `getattr(cls, "__hash__", None)` might return `None` even if a parent class defines a valid hash, because it sees the newly nullified slot on `cls`. To correctly restore an inherited hash, you should look up the attribute on the parent classes specifically using `super()`.
```suggestion
inherited_hash = getattr(super(cls, cls), "__hash__", None)
if "__hash__" not in cls.__dict__ and inherited_hash not in (None, object.__hash__):
setattr(cls, "__hash__", inherited_hash)
```
--
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: discuss-archive-unsubscribe@tvm.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org
For additional commands, e-mail: discuss-archive-help@tvm.apache.org