Skip to content

Commit 12ff712

Browse files
bobzhangclaude
andcommitted
refactor(argparse): use 'is' pattern for Some-or-noop match blocks (3 files)
Same shape as #3533 but in three other argparse files: - `parser.mbt`: `match cmd.build_error { Some(err) => raise err; None => () }` and `match parent_matches.parsed_subcommand { Some(...) => big-block; None => () }` - `parser_validate.mbt`: `match cmd.build_error { Some(err) => raise err; None => () }` - `help_render.mbt`: `match arg.env { Some(env_name) => notes.push(...); None => () }` Replaced with `if X is Some(y) { ... }` form. Semantics-preserving: `moon test -p argparse` (225/225) passes and `moon info` produces no `.mbti` change. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 2cdcfa8 commit 12ff712

3 files changed

Lines changed: 12 additions & 18 deletions

File tree

argparse/help_render.mbt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -349,9 +349,8 @@ fn positional_display(arg : Arg) -> String {
349349
///|
350350
fn arg_doc(arg : Arg) -> String {
351351
let notes = []
352-
match arg.env {
353-
Some(env_name) => notes.push("[env: \{env_name}]")
354-
None => ()
352+
if arg.env is Some(env_name) {
353+
notes.push("[env: \{env_name}]")
355354
}
356355
if arg.info
357356
is (OptionInfo(default_values~, ..) | PositionalInfo(default_values~, ..)) &&

argparse/parser.mbt

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -339,9 +339,8 @@ fn parse_command_impl(
339339
command_path : String,
340340
seed_matches : Matches,
341341
) -> Matches raise {
342-
match cmd.build_error {
343-
Some(err) => raise err
344-
None => ()
342+
if cmd.build_error is Some(err) {
343+
raise err
345344
}
346345
let args = cmd.args
347346
let groups = cmd.groups
@@ -588,15 +587,12 @@ fn parse_command_impl(
588587
cmd, args, groups, matches, positionals, positional_values, env_args, env,
589588
)
590589
validate_relationships(parent_matches, args)
591-
match parent_matches.parsed_subcommand {
592-
Some((sub_name, sub_m)) => {
593-
// After parent parsing, copy the final globals into the subcommand.
594-
propagate_globals_to_child(
595-
parent_matches, sub_m, child_globals, child_local_non_globals,
596-
)
597-
parent_matches.parsed_subcommand = Some((sub_name, sub_m))
598-
}
599-
None => ()
590+
if parent_matches.parsed_subcommand is Some((sub_name, sub_m)) {
591+
// After parent parsing, copy the final globals into the subcommand.
592+
propagate_globals_to_child(
593+
parent_matches, sub_m, child_globals, child_local_non_globals,
594+
)
595+
parent_matches.parsed_subcommand = Some((sub_name, sub_m))
600596
}
601597
return parent_matches
602598
}

argparse/parser_validate.mbt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,8 @@ fn validate_command(
9494
groups : Array[ArgGroup],
9595
inherited_globals : Array[Arg],
9696
) -> Unit raise ArgBuildError {
97-
match cmd.build_error {
98-
Some(err) => raise err
99-
None => ()
97+
if cmd.build_error is Some(err) {
98+
raise err
10099
}
101100
validate_inherited_global_shadowing(args, inherited_globals)
102101
validate_group_defs(args, groups)

0 commit comments

Comments
 (0)