fix `subs_tvars` to working on nested `GenericAlias`
@@ -209,12 +209,14 @@ 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| {
+ if sub_params.len() > 0 {
let sub_args = sub_params
.as_slice()
.iter()
@@ -227,9 +229,13 @@ fn subs_tvars(
})
.collect::<Vec<_>>();
let sub_args: PyObjectRef = PyTuple::new_ref(sub_args, &vm.ctx).into();
- obj.get_item(sub_args, vm)
+ Some(obj.get_item(sub_args, vm))
+ } else {
+ None
+ }
})
})
+ .flatten()
.unwrap_or(Ok(obj))
}
