mirror of
https://github.com/RustPython/RustPython.git
synced 2026-10-28 18:59:04 +08:00
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:
1 parent
16bb018d31
commit
dc1cae490b
2 files changed
+4
-2
No files matched your search
Vendored
-1
@@ -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
|
||||
|
||||
@@ -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!(
|
||||
|
||||
Reference in new issue
Block a user