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
This commit is contained in:
Yubin Kim authored and GitHub committed 2026-08-01 14:38:58 +09:00
1 parent 16bb018d31
commit dc1cae490b
2 files changed
+4 -2

No files matched your search

-1
View File
@@ -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
+4 -1
View File
@@ -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!(