Visitar URL original
Specialized ops by youknowone · Pull Request #7322 · RustPython/RustPython · GitHub
Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix slot wrapper override for inherited attributes
For __getattribute__: only use getattro_wrapper when the type
itself defines the attribute; otherwise inherit native slot from
base class via MRO.

For __setattr__/__delattr__: only store setattro_wrapper when
the type has its own __setattr__ or __delattr__; otherwise keep
the inherited base slot.
  • Loading branch information
youknowone committed Mar 4, 2026
commit c9a40ceeae23c675de004b2bd3f83692d4907f9d
20 changes: 17 additions & 3 deletions crates/vm/src/types/slot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -830,10 +830,16 @@ impl PyType {
}
}) {
self.slots.getattro.store(Some(func));
} else {
// __getattribute__ is a Python method somewhere in MRO;
} else if self.attributes.read().contains_key(name) {
// Self defines __getattribute__ as a non-native method;
// use the wrapper to dispatch through it.
self.slots.getattro.store(Some(getattro_wrapper));
} else {
// __getattribute__ not defined in self; inherit native
// slot from base class. This handles the common case where
// object.__getattribute__ is a method_descriptor alongside
// the native getattro slot.
accessor.inherit_from_mro(self);
}
} else {
accessor.inherit_from_mro(self);
Expand All @@ -848,7 +854,15 @@ impl PyType {
}) {
self.slots.setattro.store(Some(func));
} else {
self.slots.setattro.store(Some(setattro_wrapper));
let has_own = {
let guard = self.attributes.read();
guard.contains_key(identifier!(ctx, __setattr__))
|| guard.contains_key(identifier!(ctx, __delattr__))
};
if has_own {
self.slots.setattro.store(Some(setattro_wrapper));
}
// If !has_own: slot already inherited from base during type creation
}
} else {
accessor.inherit_from_mro(self);
Expand Down