Skip to content

Commit 7744e95

Browse files
authored
Merge pull request RustPython#4651 from minhrongcon2000/fix/add-arg-index
Add ArgIndex according to RustPython#4629
2 parents 64aef5c + 3f871f0 commit 7744e95

File tree

1 file changed

+30
-1
lines changed

1 file changed

+30
-1
lines changed

vm/src/function/number.rs

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::{AsObject, PyObjectRef, PyResult, TryFromObject, VirtualMachine};
1+
use crate::{builtins::PyIntRef, AsObject, PyObjectRef, PyResult, TryFromObject, VirtualMachine};
22
use num_complex::Complex64;
33
use std::ops::Deref;
44

@@ -125,3 +125,32 @@ impl TryFromObject for ArgIntoBool {
125125
})
126126
}
127127
}
128+
129+
// Implement ArgIndex to seperate between "true" int and int generated by index
130+
#[derive(Debug)]
131+
#[repr(transparent)]
132+
pub struct ArgIndex {
133+
value: PyIntRef,
134+
}
135+
136+
impl From<ArgIndex> for PyIntRef {
137+
fn from(arg: ArgIndex) -> Self {
138+
arg.value
139+
}
140+
}
141+
142+
impl Deref for ArgIndex {
143+
type Target = PyIntRef;
144+
145+
fn deref(&self) -> &Self::Target {
146+
&self.value
147+
}
148+
}
149+
150+
impl TryFromObject for ArgIndex {
151+
fn try_from_object(vm: &VirtualMachine, obj: PyObjectRef) -> PyResult<Self> {
152+
Ok(Self {
153+
value: obj.try_index(vm)?,
154+
})
155+
}
156+
}

0 commit comments

Comments
 (0)