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

Commit647cb08

Browse files
committed
Remove special case for None payload from boolval.
1 parentd278fb8 commit647cb08

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

‎tests/snippets/bools.py‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
assertbool(1)==True
1717
assertbool({})==False
1818

19+
assertbool(NotImplemented)==True
20+
assertbool(...)==True
21+
1922
ifnot1:
2023
raiseBaseException
2124

‎vm/src/obj/objbool.rs‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ impl IntoPyObject for bool {
1313
}
1414
}
1515

16-
pubfnboolval(vm:&mutVirtualMachine,obj:PyObjectRef) ->Result<bool,PyObjectRef>{
16+
pubfnboolval(vm:&mutVirtualMachine,obj:PyObjectRef) ->PyResult<bool>{
1717
ifletSome(s) = obj.payload::<PyString>(){
1818
returnOk(!s.value.is_empty());
1919
}
@@ -24,7 +24,6 @@ pub fn boolval(vm: &mut VirtualMachine, obj: PyObjectRef) -> Result<bool, PyObje
2424
PyObjectPayload::Integer{ref value} => !value.is_zero(),
2525
PyObjectPayload::Sequence{ref elements} => !elements.borrow().is_empty(),
2626
PyObjectPayload::Dict{ref elements} => !elements.borrow().is_empty(),
27-
PyObjectPayload::None{ ..} =>false,
2827
_ =>{
2928
ifletOk(f) = vm.get_method(obj.clone(),"__bool__"){
3029
let bool_res = vm.invoke(f,PyFuncArgs::default())?;

‎vm/src/obj/objnone.rs‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ pub fn init(context: &PyContext) {
55
let none_type =&context.none.typ();
66
context.set_attr(&none_type,"__new__", context.new_rustfunc(none_new));
77
context.set_attr(&none_type,"__repr__", context.new_rustfunc(none_repr));
8+
context.set_attr(&none_type,"__bool__", context.new_rustfunc(none_bool));
89
}
910

1011
fnnone_new(vm:&mutVirtualMachine,args:PyFuncArgs) ->PyResult{
@@ -20,3 +21,8 @@ fn none_repr(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
2021
arg_check!(vm, args, required =[(_zelf,Some(vm.ctx.none().typ()))]);
2122
Ok(vm.ctx.new_str("None".to_string()))
2223
}
24+
25+
fnnone_bool(vm:&mutVirtualMachine,args:PyFuncArgs) ->PyResult{
26+
arg_check!(vm, args, required =[(_zelf,Some(vm.ctx.none().typ()))]);
27+
Ok(vm.ctx.new_bool(false))
28+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp