-
Notifications
You must be signed in to change notification settings - Fork 94
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix the bug of submit subcommand about Python and AtCoder's language update #718
Conversation
language update contestの問題を使ったテストケースを足すべきかもです。 |
これはなぜですか? そのテストケースにはどのような利点がありますか? それは実装の手間よりも大きいですか? |
POJ が落ちてるな |
Python 3.8.2をサポートしているコンテストが今他になく、 |
まともな返答が帰ってきてしまったので諦めてテストを書きます |
書きました。50分かけて書いたまともなやつです |
手元で通ったテストがなぜか落ちてて、よく見ると過去の私の実装が運良く動いてただけの残念コードでした。直しました。純粋な処理のはずなのに出力が一定でないのはかなりだめ。テスト書いててよかった。 |
@fukatani けっこう修正をしたのでもう一度確認してほしい。しかもできれば早めがよい (今週末までに更新したいので)。申し訳ないがよろしくお願いします 🙇 |
@@ -156,13 +156,71 @@ def select_ids_of_matched_languages(words: List[str], lang_ids: List[str], langu | |||
return result | |||
|
|||
|
|||
def is_cplusplus_description(description: str) -> bool: | |||
return 'c++' in description.lower() or 'g++' in description.lower() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ここにclangがないのはなにか理由があるでしょうか?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
以下のふたつが理由です。分かりにくいしコメントを足しておきます。
clang
だとC (Clang)
とかを巻き込んでしまうC++ (Clang)
やclang++
はC++
やg++
を部分文字列として含む
@@ -172,70 +230,72 @@ def guess_lang_ids_of_file(filename: pathlib.Path, code: bytes, language_dict, c | |||
if ext in ('cpp', 'cxx', 'cc', 'C'): | |||
log.debug('language guessing: C++') | |||
# memo: https://stackoverflow.com/questions/1545080/c-code-file-extension-cc-vs-cpp | |||
lang_ids = list(set(select('c++', lang_ids) + select('g++', lang_ids))) | |||
lang_ids = list(filter(lambda lang_id: is_cplusplus_description(language_dict[lang_id]), lang_ids)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
あまり理解できてないけど、何回もfilter(lambda lang_id: is_cplusplus_description(language_dict[lang_id])
が出てきて何回もlang_idsが再代入されるのが不思議です。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
filter(lambda lang_id: is_cplusplus_description(language_dict[lang_id])
はちょうど 1 回しか出現していないはずです。lang_ids
への代入を複数回するのは、この関数が複数の条件を用いた絞り込みをしているためです。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
# compiler
とか# version
などコメントはあるべきところに書かれてるのでわかってきました。
仕方ないのかな。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
沢山あるのはfilter(lambda lang_id: parse_cplusplus_compiler(language_dict[lang_id])
の方ですね。
@@ -0,0 +1,404 @@ | |||
import pathlib |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lang_idの獲得に失敗した時のテストも入れたほうがいいと思いますが、今回のリリースに含めるか、TODOにするかはお任せします。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TODO にしておきたい。ないよりある方がましなのは分かるが、このテストを書いておいたことで救われるという場面があまり想像できないためです。
関数が大きくなってきて、メンテが辛いコードになってきましたね。 コメントは書かれているのでなんとなくわかってはきました、雰囲気はいいと思います。 多分コメントになっている |
今回はバグ修正なのでリファクタリングには踏み込みません。 |
久しぶりに読んだらそこそこ複雑で、実際バグも複数混入してたということで、読みやすくできるならしたいです。 |
owner 権限で CI まわりの設定変更してマージしました |
AtCoder の言語更新で Python コードの提出言語判定が壊れたので修正します。
https://atcoder.jp/contests/judge-update-202004
もともと微妙にバグってたのが、
Python (3.8.2)
が部分文字列として3
と2
を含むので Python 3 かつ Python 2 の判定になって顕在化しました。