Skip to content

Commit bda42ac

Browse files
committed
fix miswork on TypeVar arguments
Signed-off-by: snowapril <sinjihng@gmail.com>
1 parent 33de69a commit bda42ac

File tree

1 file changed

+22
-18
lines changed

1 file changed

+22
-18
lines changed

vm/src/builtins/genericalias.rs

+22-18
Original file line numberDiff line numberDiff line change
@@ -204,24 +204,28 @@ fn subs_tvars(
204204
argitems: &[PyObjectRef],
205205
vm: &VirtualMachine,
206206
) -> PyResult {
207-
let sub_params = obj.clone().get_attr("__parameters__", vm)?;
208-
if let Ok(sub_params) = PyTupleRef::try_from_object(vm, sub_params) {
209-
let sub_args = sub_params
210-
.as_slice()
211-
.iter()
212-
.map(|arg| {
213-
if let Some(idx) = tuple_index(params, arg) {
214-
argitems[idx].clone()
215-
} else {
216-
arg.clone()
217-
}
218-
})
219-
.collect::<Vec<_>>();
220-
let sub_args: PyObjectRef = PyTuple::new_ref(sub_args, &vm.ctx).into();
221-
obj.get_item(sub_args, vm)
222-
} else {
223-
Ok(obj)
224-
}
207+
obj.clone_class()
208+
.get_attr("__parameters__")
209+
.and_then(|sub_params| {
210+
PyTupleRef::try_from_object(vm, sub_params)
211+
.ok()
212+
.map(|sub_params| {
213+
let sub_args = sub_params
214+
.as_slice()
215+
.iter()
216+
.map(|arg| {
217+
if let Some(idx) = tuple_index(params, arg) {
218+
argitems[idx].clone()
219+
} else {
220+
arg.clone()
221+
}
222+
})
223+
.collect::<Vec<_>>();
224+
let sub_args: PyObjectRef = PyTuple::new_ref(sub_args, &vm.ctx).into();
225+
obj.get_item(sub_args, vm)
226+
})
227+
})
228+
.unwrap_or(Ok(obj))
225229
}
226230

227231
impl AsMapping for PyGenericAlias {

0 commit comments

Comments
 (0)