File tree Expand file tree Collapse file tree 2 files changed +12
-0
lines changed Expand file tree Collapse file tree 2 files changed +12
-0
lines changed Original file line number Diff line number Diff line change @@ -8,3 +8,5 @@ class A(int):
8
8
x = A (7 )
9
9
assert x == 7
10
10
assert type (x ) is A
11
+
12
+ assert int (2 ).__bool__ () == True
Original file line number Diff line number Diff line change @@ -90,6 +90,15 @@ impl FromPyObjectRef for BigInt {
90
90
}
91
91
}
92
92
93
+
94
+ fn int_bool ( vm : & mut VirtualMachine , args : PyFuncArgs ) -> PyResult {
95
+ arg_check ! (
96
+ vm,
97
+ args,
98
+ required=[ ( zelf, Some ( vm. ctx. int_type( ) ) ) ]
99
+ ) ;
100
+ Ok ( vm. ctx . new_bool ( true ) )
101
+ }
93
102
fn int_eq ( vm : & mut VirtualMachine , args : PyFuncArgs ) -> PyResult {
94
103
arg_check ! (
95
104
vm,
@@ -527,6 +536,7 @@ pub fn init(context: &PyContext) {
527
536
context. set_attr ( & int_type, "__format__" , context. new_rustfunc ( int_format) ) ;
528
537
context. set_attr ( & int_type, "__truediv__" , context. new_rustfunc ( int_truediv) ) ;
529
538
context. set_attr ( & int_type, "__xor__" , context. new_rustfunc ( int_xor) ) ;
539
+ context. set_attr ( & int_type, "__bool__" , context. new_rustfunc ( int_bool) ) ;
530
540
context. set_attr (
531
541
& int_type,
532
542
"bit_length" ,
You can’t perform that action at this time.
0 commit comments