Skip to content

Commit 23aa4a7

Browse files
authored
Merge pull request RustPython#436 from Tom1380/master
Fix RustPython#390.
2 parents 89495e1 + 7e1589d commit 23aa4a7

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

vm/src/obj/objfunction.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,13 @@ pub fn init(context: &PyContext) {
1515
context.new_member_descriptor(function_code),
1616
);
1717

18+
let builtin_function_or_method_type = &context.builtin_function_or_method_type;
19+
context.set_attr(
20+
&builtin_function_or_method_type,
21+
"__get__",
22+
context.new_rustfunc(bind_method),
23+
);
24+
1825
let member_descriptor_type = &context.member_descriptor_type;
1926
context.set_attr(
2027
&member_descriptor_type,

vm/src/pyobject.rs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ pub struct PyContext {
142142
pub type_type: PyObjectRef,
143143
pub zip_type: PyObjectRef,
144144
pub function_type: PyObjectRef,
145+
pub builtin_function_or_method_type: PyObjectRef,
145146
pub property_type: PyObjectRef,
146147
pub module_type: PyObjectRef,
147148
pub bound_method_type: PyObjectRef,
@@ -193,6 +194,12 @@ impl PyContext {
193194
let classmethod_type = create_type("classmethod", &type_type, &object_type, &dict_type);
194195
let staticmethod_type = create_type("staticmethod", &type_type, &object_type, &dict_type);
195196
let function_type = create_type("function", &type_type, &object_type, &dict_type);
197+
let builtin_function_or_method_type = create_type(
198+
"builtin_function_or_method",
199+
&type_type,
200+
&object_type,
201+
&dict_type,
202+
);
196203
let property_type = create_type("property", &type_type, &object_type, &dict_type);
197204
let super_type = create_type("super", &type_type, &object_type, &dict_type);
198205
let generator_type = create_type("generator", &type_type, &object_type, &dict_type);
@@ -273,6 +280,7 @@ impl PyContext {
273280
slice_type,
274281
object: object_type,
275282
function_type,
283+
builtin_function_or_method_type,
276284
super_type,
277285
property_type,
278286
generator_type,
@@ -410,6 +418,10 @@ impl PyContext {
410418
self.function_type.clone()
411419
}
412420

421+
pub fn builtin_function_or_method_type(&self) -> PyObjectRef {
422+
self.builtin_function_or_method_type.clone()
423+
}
424+
413425
pub fn property_type(&self) -> PyObjectRef {
414426
self.property_type.clone()
415427
}
@@ -546,7 +558,7 @@ impl PyContext {
546558
PyObjectPayload::RustFunction {
547559
function: Box::new(function),
548560
},
549-
self.function_type(),
561+
self.builtin_function_or_method_type(),
550562
)
551563
}
552564

@@ -556,7 +568,7 @@ impl PyContext {
556568
) -> PyObjectRef {
557569
PyObject::new(
558570
PyObjectPayload::RustFunction { function },
559-
self.function_type(),
571+
self.builtin_function_or_method_type(),
560572
)
561573
}
562574

0 commit comments

Comments
 (0)