Skip to content

Commit b9c1f31

Browse files
committed
Fix getattr to use __getattribute__ correctly
1 parent 491fde8 commit b9c1f31

File tree

3 files changed

+10
-9
lines changed

3 files changed

+10
-9
lines changed

Lib/test/test_enum.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -429,8 +429,6 @@ def red(self):
429429
green = 2
430430
blue = 3
431431

432-
# TODO: RUSTPYTHON
433-
@unittest.expectedFailure
434432
def test_enum_with_value_name(self):
435433
class Huh(Enum):
436434
name = 1
@@ -1668,8 +1666,6 @@ class Test(Base):
16681666
test = 1
16691667
self.assertIs(type(Test.test), Test)
16701668

1671-
# TODO: RUSTPYTHON
1672-
@unittest.expectedFailure
16731669
def test_subclass_duplicate_name_dynamic(self):
16741670
from types import DynamicClassAttribute
16751671
class Base(Enum):

vm/src/protocol/object.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -233,9 +233,6 @@ impl PyObject {
233233
}
234234
None => Ok(Some(attr)),
235235
}
236-
} else if let Some(getter) = obj_cls.get_attr(identifier!(vm, __getattr__)) {
237-
drop(obj_cls);
238-
vm.invoke(&getter, (self.to_owned(), name_str)).map(Some)
239236
} else {
240237
Ok(None)
241238
}

vm/src/types/slot.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,15 @@ fn call_wrapper(zelf: &PyObject, args: FuncArgs, vm: &VirtualMachine) -> PyResul
285285
}
286286

287287
fn getattro_wrapper(zelf: &PyObject, name: PyStrRef, vm: &VirtualMachine) -> PyResult {
288-
vm.call_special_method(zelf.to_owned(), identifier!(vm, __getattribute__), (name,))
288+
let __getattribute__ = identifier!(vm, __getattribute__);
289+
let __getattr__ = identifier!(vm, __getattr__);
290+
match vm.call_special_method(zelf.to_owned(), __getattribute__, (name.clone(),)) {
291+
Ok(r) => Ok(r),
292+
Err(_) if zelf.class().has_attr(__getattr__) => {
293+
vm.call_special_method(zelf.to_owned(), __getattr__, (name,))
294+
}
295+
Err(e) => Err(e),
296+
}
289297
}
290298

291299
fn setattro_wrapper(
@@ -393,7 +401,7 @@ impl PyType {
393401
"__call__" => {
394402
update_slot!(call, call_wrapper);
395403
}
396-
"__getattribute__" => {
404+
"__getattr__" | "__getattribute__" => {
397405
update_slot!(getattro, getattro_wrapper);
398406
}
399407
"__setattr__" | "__delattr__" => {

0 commit comments

Comments
 (0)