Skip to content

Commit 5d6ce6c

Browse files
committed
OsPathOrFd calls __index__
1 parent 7b08953 commit 5d6ce6c

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

vm/src/stdlib/os.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,9 +130,9 @@ pub(crate) enum OsPathOrFd {
130130

131131
impl TryFromObject for OsPathOrFd {
132132
fn try_from_object(vm: &VirtualMachine, obj: PyObjectRef) -> PyResult<Self> {
133-
let r = match obj.downcast::<PyInt>() {
134-
Ok(int) => Self::Fd(int.try_to_primitive(vm)?),
135-
Err(obj) => Self::Path(obj.try_into_value(vm)?),
133+
let r = match obj.try_index_opt(vm) {
134+
Some(int) => Self::Fd(int?.try_to_primitive(vm)?),
135+
None => Self::Path(obj.try_into_value(vm)?),
136136
};
137137
Ok(r)
138138
}

0 commit comments

Comments
 (0)