MCPcopy Index your code
hub / github.com/RustPython/RustPython / __class_getitem__

Method __class_getitem__

crates/vm/src/builtins/union.rs:174–193  ·  view source on GitHub ↗
(
        _cls: crate::builtins::PyTypeRef,
        args: PyObjectRef,
        vm: &VirtualMachine,
    )

Source from the content-addressed store, hash-verified

172
173 #[pyclassmethod]
174 fn __class_getitem__(
175 _cls: crate::builtins::PyTypeRef,
176 args: PyObjectRef,
177 vm: &VirtualMachine,
178 ) -> PyResult {
179 // Convert args to tuple if not already
180 let args_tuple = if let Some(tuple) = args.downcast_ref::<PyTuple>() {
181 tuple.to_owned()
182 } else {
183 PyTuple::new_ref(vec![args], &vm.ctx)
184 };
185
186 // Check for empty union
187 if args_tuple.is_empty() {
188 return Err(vm.new_type_error("Cannot create empty Union"));
189 }
190
191 // Create union using make_union to properly handle None -> NoneType conversion
192 make_union(&args_tuple, vm)
193 }
194}
195
196fn is_unionable(obj: PyObjectRef, vm: &VirtualMachine) -> bool {

Callers

nothing calls this directly

Calls 4

make_unionFunction · 0.85
ErrClass · 0.50
to_ownedMethod · 0.45
is_emptyMethod · 0.45

Tested by

no test coverage detected