Merge pull request #3475 from hrchu/pep604

Allow writing union types as X | Y
This commit is contained in:
Jeong YunWon
2021-11-29 03:10:01 +09:00
committed by GitHub

View File

@@ -381,6 +381,15 @@ impl PyType {
fn mro(zelf: PyRef<Self>) -> Vec<PyObjectRef> {
zelf.iter_mro().map(|cls| cls.clone().into()).collect()
}
#[pymethod(name = "__ror__")]
#[pymethod(magic)]
pub fn or(zelf: PyRef<Self>, other: PyObjectRef, vm: &VirtualMachine) -> PyResult {
let union = vm.import("typing", None, 0)?.get_attr("Union", vm)?;
let getitem = vm.get_method(union, "__getitem__").unwrap();
vm.invoke(&getitem?, ((zelf, other),))
}
#[pyslot]
fn slot_new(metatype: PyTypeRef, args: FuncArgs, vm: &VirtualMachine) -> PyResult {
vm_trace!("type.__new__ {:?}", args);