Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit7bf8378

Browse files
committed
type.__getattribute__ should be bound to type!
1 parenta389b55 commit7bf8378

File tree

3 files changed

+20
-11
lines changed

3 files changed

+20
-11
lines changed

‎tests/snippets/class.py‎

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,9 @@ def kungfu(x):
4242

4343

4444
bar=Bar()
45-
bar.fubar(2)
4645

47-
# TODO: make below work:
48-
#Bar.fubar(2)
46+
bar.fubar(2)
47+
Bar.fubar(2)
4948

5049
bar.kungfu(3)
51-
# TODO: make below work:
52-
# Bar.kungfu(3)
53-
50+
Bar.kungfu(3)

‎vm/src/obj/objtype.rs‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ pub fn init(context: &PyContext) {
2929
type_type.set_attr("__class__", context.new_member_descriptor(type_new));
3030
type_type.set_attr("__repr__", context.new_rustfunc(type_repr));
3131
type_type.set_attr("__prepare__", context.new_rustfunc(type_prepare));
32+
type_type.set_attr("__getattribute__", context.new_rustfunc(type_getattribute));
3233
}
3334

3435
fntype_mro(vm:&mutVirtualMachine,args:PyFuncArgs) ->PyResult{
@@ -85,7 +86,7 @@ pub fn get_type_name(typ: &PyObjectRef) -> String {
8586
}
8687

8788
pubfntype_new(vm:&mutVirtualMachine,args:PyFuncArgs) ->PyResult{
88-
debug!("type.__new__{:?}", args);
89+
debug!("type.__new__{:?}", args);
8990
if args.args.len() ==2{
9091
arg_check!(
9192
vm,

‎vm/src/vm.rs‎

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ use super::obj::objsequence;
1717
usesuper::obj::objstr;
1818
usesuper::obj::objtype;
1919
usesuper::pyobject::{
20-
AttributeProtocol,DictProtocol,PyContext,PyFuncArgs,PyObjectKind,PyObjectRef,PyResult,
21-
TypeProtocol,
20+
AttributeProtocol,DictProtocol,IdProtocol,PyContext,PyFuncArgs,PyObjectKind,PyObjectRef,
21+
PyResult,TypeProtocol,
2222
};
2323
usesuper::stdlib;
2424
usesuper::sysmodule;
@@ -93,7 +93,11 @@ impl VirtualMachine {
9393
}
9494

9595
pubfnnew_bound_method(&self,function:PyObjectRef,object:PyObjectRef) ->PyObjectRef{
96-
self.ctx.new_bound_method(function, object)
96+
if object.is(&self.get_none()){
97+
function
98+
}else{
99+
self.ctx.new_bound_method(function, object)
100+
}
97101
}
98102

99103
pubfnget_type(&self) ->PyObjectRef{
@@ -202,7 +206,13 @@ impl VirtualMachine {
202206
let cls = obj.typ();
203207
match cls.get_attr(method_name){
204208
Some(func) =>{
205-
trace!("vm.call_method {:?} {:?} -> {:?}", obj, method_name, func);
209+
trace!(
210+
"vm.call_method {:?} {:?} {:?} -> {:?}",
211+
obj,
212+
cls,
213+
method_name,
214+
func
215+
);
206216
let wrapped =self.call_get_descriptor(func, obj.clone())?;
207217
self.invoke(wrapped, args)
208218
}
@@ -423,6 +433,7 @@ impl VirtualMachine {
423433

424434
// get_attribute should be used for full attribute access (usually from user code).
425435
pubfnget_attribute(&mutself,obj:PyObjectRef,attr_name:PyObjectRef) ->PyResult{
436+
trace!("vm.__getattribute__: {:?} {:?}", obj, attr_name);
426437
self.call_method(&obj,"__getattribute__",vec![attr_name])
427438
}
428439

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp