Skip to content

Commit 13e602b

Browse files
committed
compile get_doc -> split_doc to follow split_first convention in Rust
1 parent 852afd5 commit 13e602b

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

compiler/src/compile.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ impl Compiler {
316316
let size_before = self.code_stack.len();
317317
self.symbol_table_stack.push(symbol_table);
318318

319-
let (statements, doc) = get_doc(body);
319+
let (doc, statements) = split_doc(body);
320320
if let Some(value) = doc {
321321
self.emit_constant(ConstantData::Str { value });
322322
let doc = self.name("__doc__");
@@ -1052,7 +1052,7 @@ impl Compiler {
10521052
let qualified_name = self.qualified_path.join(".");
10531053
self.push_qualified_path("<locals>");
10541054

1055-
let (body, doc_str) = get_doc(body);
1055+
let (doc_str, body) = split_doc(body);
10561056

10571057
self.compile_statements(body)?;
10581058

@@ -1171,6 +1171,7 @@ impl Compiler {
11711171
true
11721172
}
11731173

1174+
// Python/compile.c find_ann
11741175
fn find_ann(&self, body: &[ast::Stmt]) -> bool {
11751176
use ast::StmtKind::*;
11761177

@@ -1222,7 +1223,7 @@ impl Compiler {
12221223

12231224
self.push_output(bytecode::CodeFlags::empty(), 0, 0, 0, name.to_owned());
12241225

1225-
let (new_body, doc_str) = get_doc(body);
1226+
let (doc_str, body) = split_doc(body);
12261227

12271228
let dunder_name = self.name("__name__");
12281229
self.emit(Instruction::LoadGlobal(dunder_name));
@@ -1240,7 +1241,7 @@ impl Compiler {
12401241
if self.find_ann(body) {
12411242
self.emit(Instruction::SetupAnnotation);
12421243
}
1243-
self.compile_statements(new_body)?;
1244+
self.compile_statements(body)?;
12441245

12451246
let classcell_idx = self
12461247
.code_stack
@@ -2572,15 +2573,15 @@ impl Compiler {
25722573
}
25732574
}
25742575

2575-
fn get_doc(body: &[ast::Stmt]) -> (&[ast::Stmt], Option<String>) {
2576+
fn split_doc(body: &[ast::Stmt]) -> (Option<String>, &[ast::Stmt]) {
25762577
if let Some((val, body_rest)) = body.split_first() {
25772578
if let ast::StmtKind::Expr { value } = &val.node {
25782579
if let Some(doc) = try_get_constant_string(std::slice::from_ref(value)) {
2579-
return (body_rest, Some(doc));
2580+
return (Some(doc), body_rest);
25802581
}
25812582
}
25822583
}
2583-
(body, None)
2584+
(None, body)
25842585
}
25852586

25862587
fn try_get_constant_string(values: &[ast::Expr]) -> Option<String> {

0 commit comments

Comments
 (0)