mirror of
https://github.com/RustPython/RustPython.git
synced 2026-06-09 22:49:57 +09:00
fix subs_tvars to working on nested GenericAlias
Signed-off-by: snowapril <sinjihng@gmail.com>
This commit is contained in:
@@ -209,27 +209,33 @@ fn subs_tvars(
|
||||
argitems: &[PyObjectRef],
|
||||
vm: &VirtualMachine,
|
||||
) -> PyResult {
|
||||
obj.clone_class()
|
||||
.get_attr("__parameters__")
|
||||
obj.clone()
|
||||
.get_attr("__parameters__", vm)
|
||||
.ok()
|
||||
.and_then(|sub_params| {
|
||||
PyTupleRef::try_from_object(vm, sub_params)
|
||||
.ok()
|
||||
.map(|sub_params| {
|
||||
let sub_args = sub_params
|
||||
.as_slice()
|
||||
.iter()
|
||||
.map(|arg| {
|
||||
if let Some(idx) = tuple_index(params, arg) {
|
||||
argitems[idx].clone()
|
||||
} else {
|
||||
arg.clone()
|
||||
}
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
let sub_args: PyObjectRef = PyTuple::new_ref(sub_args, &vm.ctx).into();
|
||||
obj.get_item(sub_args, vm)
|
||||
if sub_params.len() > 0 {
|
||||
let sub_args = sub_params
|
||||
.as_slice()
|
||||
.iter()
|
||||
.map(|arg| {
|
||||
if let Some(idx) = tuple_index(params, arg) {
|
||||
argitems[idx].clone()
|
||||
} else {
|
||||
arg.clone()
|
||||
}
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
let sub_args: PyObjectRef = PyTuple::new_ref(sub_args, &vm.ctx).into();
|
||||
Some(obj.get_item(sub_args, vm))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
})
|
||||
})
|
||||
.flatten()
|
||||
.unwrap_or(Ok(obj))
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user