From dc1cae490be07e2ed0964095bfa762e5ba6ce3cb Mon Sep 17 00:00:00 2001 From: Yubin Kim <80163835+devyubin@users.noreply.github.com> Date: Sat, 1 Aug 2026 14:38:58 +0900 Subject: [PATCH] Bind method descriptor when __get__ owner is omitted (#8404) `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 63bc0803e..2b48e6789 100644 --- a/Lib/test/test_types.py +++ b/Lib/test/test_types.py @@ -660,7 +660,6 @@ class TypesTests(unittest.TestCase): 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 537c2e39c..5c0662e9f 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!(