dev #10

Merged
李衍志523370910113 merged 238 commits from dev into master 2025-03-05 16:20:39 +08:00
Showing only changes of commit dfe836109c - Show all commits

View File

@ -33,7 +33,9 @@ def get_conf_stage(
fn, parser_model = processed_dict[parser]
fn(parser_model, conf_stage.parsers[idx])
jon-lee marked this conversation as resolved Outdated

should loop through conf_stage.parsers here and update the with field according to the parser name.

should loop through `conf_stage.parsers` here and update the `with` field according to the parser name.

I think its already implemented in each of the fix_parsers functions

I think its already implemented in each of the `fix_parsers` functions

No, do not find the parser in the fix_xxx function. Instead, iterate through the parsers here and decide how to fill in the with.

No, do not find the parser in the `fix_xxx` function. Instead, iterate through the parsers here and decide how to fill in the `with`.

resolved.

resolved.

Use a dict to store parser name, field, function to process.

    process_dict: Dict[
        str, Tuple[Callable[[result.ParserConfig, BaseModel], None], BaseModel]
    ] = {
        "clangtidy": (fix_keyword, task_stage.clangtidy),
        "keyword": (fix_keyword, task_stage.keyword),
        "diff": (fix_diff, task_stage.diff),
    }
    for i, parser in enumerate(task_stage.parsers):
        if parser in process_dict:
            func, parser_model = process_dict[parser]
            func(conf_stage.parsers[i], parser_model)
Use a dict to store parser name, field, function to process. ``` process_dict: Dict[ str, Tuple[Callable[[result.ParserConfig, BaseModel], None], BaseModel] ] = { "clangtidy": (fix_keyword, task_stage.clangtidy), "keyword": (fix_keyword, task_stage.keyword), "diff": (fix_diff, task_stage.diff), } for i, parser in enumerate(task_stage.parsers): if parser in process_dict: func, parser_model = process_dict[parser] func(conf_stage.parsers[i], parser_model) ```

resolved.

resolved.
elif parser == "diff":
jon-lee marked this conversation as resolved Outdated

Do we need to support both kinds of names?

Do we need to support both kinds of names?

probably yes, since it is easy for new ta to type it wrong

probably yes, since it is easy for new ta to type it wrong

parsers name should be a str enum, force them to use the correct names

parsers name should be a str enum, force them to use the correct names

ok, then removed.

ok, then removed.
fix_diff(task_stage, task_conf, conf_stage.parsers[idx], conf_stage)
fix_diff(
jon-lee marked this conversation as resolved Outdated

underscore

underscore

fixed

fixed
task_stage, task_conf, conf_stage.parsers[idx], conf_stage.executor
)
else:
continue
return conf_stage
@ -88,7 +90,7 @@ def get_executor_with(
def fix_keyword(
keyword_config: task.ParserKeyword, keyword_parser_: result.Parser
keyword_config: task.ParserKeyword, keyword_parser: result.Parser
) -> None:
jon-lee marked this conversation as resolved Outdated

The reason for the suffix in keyword_parser_?

The reason for the suffix in `keyword_parser_`?

just forgot to remove, sorry

just forgot to remove, sorry
keyword_weight: List[result.KeywordConfig] = []
unique_weight = list(set(keyword_config.weight))
@ -102,7 +104,7 @@ def fix_keyword(
else:
continue
keyword_parser_.with_.update(
keyword_parser.with_.update(
result.KeywordMatchConfig(
matches=keyword_weight,
).model_dump(by_alias=True)
@ -134,8 +136,6 @@ def fix_dummy(
dummy_parser_config: task.ParserDummy, dummy_parser: result.Parser
) -> None:
# we don't use dummy parser in real application
if dummy_parser_config is None:
return
dummy_parser.with_.update(
result.DummyConfig(
jon-lee marked this conversation as resolved Outdated

When will it be None?

When will it be None?
score=dummy_parser_config.score,
@ -156,9 +156,8 @@ def fix_diff(
task_stage: task.Stage,
task_conf: task.Config,
diff_parser_config: result.Parser,
conf_stage: result.StageDetail,
diff_executor: result.Executor,
) -> None:
jon-lee marked this conversation as resolved Outdated

move continue to the other branch to reduce nesting

move `continue` to the other branch to reduce nesting

I mean

if parser not in keyword_parser:
    continue
if getattr(task_stage, parser, None) is None:
    continue
if score != score_:
    continue
I mean ``` if parser not in keyword_parser: continue ``` ``` if getattr(task_stage, parser, None) is None: continue ```` ``` if score != score_: continue ````

fixed.

fixed.
diff_parser = diff_parser_config
skip = task_stage.skip
cases = task_stage.cases
finalized_cases = [case for case in cases if case not in skip]
@ -215,10 +214,9 @@ def fix_diff(
)
)
if diff_parser:
diff_parser.with_.update(
result.DiffConfig(name="diff", cases=parser_cases).model_dump(by_alias=True)
)
conf_stage.executor.with_.cases = stage_cases
diff_parser_config.with_.update(
result.DiffConfig(name="diff", cases=parser_cases).model_dump(by_alias=True)
)
diff_executor.with_.cases = stage_cases
return