From cc216a0cce54c9d1d9b94e2ee460e27f5c491338 Mon Sep 17 00:00:00 2001 From: Yubin Kim Date: Tue, 28 Jul 2026 07:51:57 +0900 Subject: [PATCH] Bind method descriptor when __get__ owner is omitted `method_descriptor.__get__(obj)` raised a TypeError when the owner (the optional second argument) was omitted, because the METHOD-flag branch required the owner to be a type. Match CPython: a missing owner binds to `obj`, while a non-type owner still raises "needs a type, not ...". Assisted-by: Claude Code:claude-opus-4-8 --- Lib/test/test_types.py | 1 - crates/vm/src/builtins/descriptor.rs | 5 ++++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/Lib/test/test_types.py b/Lib/test/test_types.py index 63bc0803e79..2b48e6789b6 100644 --- a/Lib/test/test_types.py +++ b/Lib/test/test_types.py @@ -660,7 +660,6 @@ def test_method_descriptor_types(self): self.assertIsInstance(int.from_bytes, types.BuiltinMethodType) self.assertIsInstance(int.__new__, types.BuiltinMethodType) - @unittest.expectedFailure # TODO: RUSTPYTHON; TypeError: descriptor 'read' needs a type, not 'StringIO', as arg 2 def test_method_descriptor_crash(self): # gh-132747: The default __get__() implementation in C was unable # to handle a second argument of None when called from Python diff --git a/crates/vm/src/builtins/descriptor.rs b/crates/vm/src/builtins/descriptor.rs index 537c2e39c9a..5c0662e9fef 100644 --- a/crates/vm/src/builtins/descriptor.rs +++ b/crates/vm/src/builtins/descriptor.rs @@ -79,7 +79,10 @@ impl GetDescriptor for PyMethodDescriptor { let bound = match obj { Some(obj) => { if descr.method.flags.contains(PyMethodFlags::METHOD) { - if cls.is_some_and(|c| c.fast_isinstance(vm.ctx.types.type_type)) { + if cls + .as_ref() + .is_none_or(|c| c.fast_isinstance(vm.ctx.types.type_type)) + { obj } else { return Err(vm.new_type_error(format!(