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

Method walk

crates/codegen/src/compile.rs:4239–4293  ·  view source on GitHub ↗
(stmts: &'a [ast::Stmt], out: &mut Vec<(&'a str, &'a ast::Expr)>)

Source from the content-addressed store, hash-verified

4237 /// conditional_annotation_index stays in sync with __annotate__ enumeration.
4238 fn collect_simple_annotations(body: &[ast::Stmt]) -> Vec<(&str, &ast::Expr)> {
4239 fn walk<'a>(stmts: &'a [ast::Stmt], out: &mut Vec<(&'a str, &'a ast::Expr)>) {
4240 for stmt in stmts {
4241 match stmt {
4242 ast::Stmt::AnnAssign(ast::StmtAnnAssign {
4243 target,
4244 annotation,
4245 simple,
4246 ..
4247 }) if *simple && matches!(target.as_ref(), ast::Expr::Name(_)) => {
4248 if let ast::Expr::Name(ast::ExprName { id, .. }) = target.as_ref() {
4249 out.push((id.as_str(), annotation.as_ref()));
4250 }
4251 }
4252 ast::Stmt::If(ast::StmtIf {
4253 body,
4254 elif_else_clauses,
4255 ..
4256 }) => {
4257 walk(body, out);
4258 for clause in elif_else_clauses {
4259 walk(&clause.body, out);
4260 }
4261 }
4262 ast::Stmt::For(ast::StmtFor { body, orelse, .. })
4263 | ast::Stmt::While(ast::StmtWhile { body, orelse, .. }) => {
4264 walk(body, out);
4265 walk(orelse, out);
4266 }
4267 ast::Stmt::With(ast::StmtWith { body, .. }) => walk(body, out),
4268 ast::Stmt::Try(ast::StmtTry {
4269 body,
4270 handlers,
4271 orelse,
4272 finalbody,
4273 ..
4274 }) => {
4275 walk(body, out);
4276 for handler in handlers {
4277 let ast::ExceptHandler::ExceptHandler(
4278 ast::ExceptHandlerExceptHandler { body, .. },
4279 ) = handler;
4280 walk(body, out);
4281 }
4282 walk(orelse, out);
4283 walk(finalbody, out);
4284 }
4285 ast::Stmt::Match(ast::StmtMatch { cases, .. }) => {
4286 for case in cases {
4287 walk(&case.body, out);
4288 }
4289 }
4290 _ => {}
4291 }
4292 }
4293 }
4294 let mut annotations = Vec::new();
4295 walk(body, &mut annotations);
4296 annotations

Callers

nothing calls this directly

Calls 4

walkFunction · 0.50
as_refMethod · 0.45
pushMethod · 0.45
as_strMethod · 0.45

Tested by

no test coverage detected