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

Method readlines

crates/vm/src/stdlib/_io.rs:523–546  ·  view source on GitHub ↗
(
            instance: PyObjectRef,
            hint: OptionalOption<isize>,
            vm: &VirtualMachine,
        )

Source from the content-addressed store, hash-verified

521
522 #[pymethod]
523 fn readlines(
524 instance: PyObjectRef,
525 hint: OptionalOption<isize>,
526 vm: &VirtualMachine,
527 ) -> PyResult<Vec<PyObjectRef>> {
528 let hint = hint.flatten().unwrap_or(-1);
529 if hint <= 0 {
530 return instance.try_to_value(vm);
531 }
532 let hint = hint as usize;
533 let mut ret = Vec::new();
534 let it = ArgIterable::<PyObjectRef>::try_from_object(vm, instance)?;
535 let mut full_len = 0;
536 for line in it.iter(vm)? {
537 let line = line?;
538 let line_len = line.length(vm)?;
539 ret.push(line.clone());
540 full_len += line_len;
541 if full_len > hint {
542 break;
543 }
544 }
545 Ok(ret)
546 }
547
548 #[pymethod]
549 fn writelines(

Callers

nothing calls this directly

Calls 7

newFunction · 0.85
try_to_valueMethod · 0.80
flattenMethod · 0.45
iterMethod · 0.45
lengthMethod · 0.45
pushMethod · 0.45
cloneMethod · 0.45

Tested by

no test coverage detected