Skip to content

Commit 0a88bee

Browse files
authored
Warn when a bool is used as a file descriptor (#9555)
1 parent 8df4bf3 commit 0a88bee

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

‎crates/vm/src/stdlib/_io.rs‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,14 @@ pub struct Fildes(pub i32);
6868
impl TryFromObject for Fildes {
6969
fn try_from_object(vm: &VirtualMachine, obj: PyObjectRef) -> PyResult<Self> {
7070
use crate::builtins::int;
71+
if obj.class().is(vm.ctx.types.bool_type) {
72+
crate::stdlib::_warnings::warn(
73+
vm.ctx.exceptions.runtime_warning,
74+
"bool is used as a file descriptor".to_owned(),
75+
1,
76+
vm,
77+
)?;
78+
}
7179
let int = match obj.downcast::<int::PyInt>() {
7280
Ok(i) => i,
7381
Err(obj) => {

0 commit comments

Comments
 (0)