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

Method replace

crates/vm/src/builtins/code.rs:1157–1325  ·  view source on GitHub ↗
(&self, args: ReplaceArgs, vm: &VirtualMachine)

Source from the content-addressed store, hash-verified

1155
1156 #[pymethod]
1157 pub fn replace(&self, args: ReplaceArgs, vm: &VirtualMachine) -> PyResult<Self> {
1158 let ReplaceArgs {
1159 co_posonlyargcount,
1160 co_argcount,
1161 co_kwonlyargcount,
1162 co_filename,
1163 co_firstlineno,
1164 co_consts,
1165 co_name,
1166 co_names,
1167 co_flags,
1168 co_varnames,
1169 co_nlocals,
1170 co_stacksize,
1171 co_code,
1172 co_linetable,
1173 co_exceptiontable,
1174 co_freevars,
1175 co_cellvars,
1176 co_qualname,
1177 } = args;
1178 let posonlyarg_count = match co_posonlyargcount {
1179 OptionalArg::Present(posonlyarg_count) => posonlyarg_count,
1180 OptionalArg::Missing => self.code.posonlyarg_count,
1181 };
1182
1183 let arg_count = match co_argcount {
1184 OptionalArg::Present(arg_count) => arg_count,
1185 OptionalArg::Missing => self.code.arg_count,
1186 };
1187
1188 let source_path = match co_filename {
1189 OptionalArg::Present(source_path) => source_path,
1190 OptionalArg::Missing => self.source_path().to_owned(),
1191 };
1192
1193 let first_line_number = match co_firstlineno {
1194 OptionalArg::Present(first_line_number) => OneIndexed::new(first_line_number as _),
1195 OptionalArg::Missing => self.code.first_line_number,
1196 };
1197
1198 let kwonlyarg_count = match co_kwonlyargcount {
1199 OptionalArg::Present(kwonlyarg_count) => kwonlyarg_count,
1200 OptionalArg::Missing => self.code.kwonlyarg_count,
1201 };
1202
1203 let constants = match co_consts {
1204 OptionalArg::Present(constants) => constants,
1205 OptionalArg::Missing => self.code.constants.iter().map(|x| x.0.clone()).collect(),
1206 };
1207
1208 let obj_name = match co_name {
1209 OptionalArg::Present(obj_name) => obj_name,
1210 OptionalArg::Missing => self.code.obj_name.to_owned(),
1211 };
1212
1213 let names = match co_names {
1214 OptionalArg::Present(names) => names,

Callers 1

__replace__Method · 0.45

Calls 15

newFunction · 0.85
collectMethod · 0.80
to_vecMethod · 0.80
ErrClass · 0.50
to_ownedMethod · 0.45
source_pathMethod · 0.45
mapMethod · 0.45
iterMethod · 0.45
cloneMethod · 0.45
derefMethod · 0.45
to_pyobjectMethod · 0.45
to_objectMethod · 0.45

Tested by

no test coverage detected