Conversation
📝 WalkthroughWalkthroughRemoved Changes
Sequence Diagram(s)sequenceDiagram
participant Caller
participant PyObject
participant VM
participant TypeUtils
Caller->>PyObject: object_isinstance(obj, cls)
alt cls is a type
PyObject->>TypeUtils: subtype check (is subclass)
TypeUtils-->>PyObject: result
else cls is not a type
PyObject->>VM: get_attribute_opt(obj, "__class__")
VM-->>PyObject: class_obj or None
alt class_obj found
PyObject->>TypeUtils: abstract_issubclass(class_obj, cls)
TypeUtils-->>PyObject: result
else not found
PyObject-->>Caller: return False
end
end
PyObject-->>Caller: final bool
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
The optimization to skip __class__ lookup based on getattro check was incorrect: a class can override __class__ as a property while still using standard __getattribute__. Revert to always performing the lookup, matching CPython's object_isinstance behavior.
There was a problem hiding this comment.
🧹 Nitpick comments (1)
crates/vm/src/protocol/object.rs (1)
579-607: Add focused regression tests for__class__-drivenisinstancesemantics.Given this revert fixes a prior optimization, please add coverage for objects overriding
__getattribute__/__class__to prevent future regressions in this path.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@crates/vm/src/protocol/object.rs` around lines 579 - 607, Add focused regression tests that exercise object_isinstance's fallback path when instances override __getattribute__ or __class__; create tests that call isinstance(obj, SomeType) where obj provides a custom __getattribute__ and a dynamic __class__ attribute so the branch that uses vm.get_attribute_opt(self.to_owned(), identifier!(vm, __class__)) and then calls abstract_issubclass or PyTypeRef::try_from_object is executed; specifically target the code paths in object_isinstance (the branch guarded by let Some(i_cls) = vm.get_attribute_opt(...)) and ensure both the i_cls Type conversion (PyTypeRef::try_from_object) and the abstract_issubclass call are covered to detect regressions of the reverted optimization.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@crates/vm/src/protocol/object.rs`:
- Around line 579-607: Add focused regression tests that exercise
object_isinstance's fallback path when instances override __getattribute__ or
__class__; create tests that call isinstance(obj, SomeType) where obj provides a
custom __getattribute__ and a dynamic __class__ attribute so the branch that
uses vm.get_attribute_opt(self.to_owned(), identifier!(vm, __class__)) and then
calls abstract_issubclass or PyTypeRef::try_from_object is executed;
specifically target the code paths in object_isinstance (the branch guarded by
let Some(i_cls) = vm.get_attribute_opt(...)) and ensure both the i_cls Type
conversion (PyTypeRef::try_from_object) and the abstract_issubclass call are
covered to detect regressions of the reverted optimization.
wrong optimization
Summary by CodeRabbit