Skip to content
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

型アノテーションを付けた #277

Closed
wants to merge 20 commits into from
Closed

型アノテーションを付けた #277

wants to merge 20 commits into from

Conversation

Azuki-bar
Copy link
Member

@Azuki-bar Azuki-bar commented Nov 15, 2022

Close #276
型アノテーションを付けました。ついでにflake8に沿ったコードに修正

チェックに通るように機械的に行ったので間違っている可能性が大いにあります。どんどん指摘してください

@github-actions github-actions bot added the ci-cd label Nov 15, 2022
@Azuki-bar
Copy link
Member Author

今型アノテーションを付けたりOptionalな型に対してガードを付けたりしています

@n4o847 DiaPlanner.pyの50行目から始まるダイヤの設定に対して型の不一致が起こっています。
直したいのですがセクションnがどのセクションか分からないので直せません。
直すのを協力していただけませんか?

@n4o847
Copy link
Collaborator

n4o847 commented Nov 15, 2022

行き違ってしまいましたが、#279 を立てているのでそちらをマージしてもらえれば大丈夫だと思います

@Azuki-bar
Copy link
Member Author

行き違ってしまいましたが、#279 を立てているのでそちらをマージしてもらえれば大丈夫だと思います

あ!気づいていませんでした!取り込みます。
ありがとうございます

@Azuki-bar Azuki-bar requested a review from n4o847 November 15, 2022 17:13
@Azuki-bar Azuki-bar marked this pull request as ready for review November 15, 2022 17:13
@n4o847
Copy link
Collaborator

n4o847 commented Nov 15, 2022

なかなかに破壊的な変更が含まれていると思いますが、正直この辺のアルゴリズムは @thgcMtdh の担当で、これで正常に動くかどうかは僕だけじゃ保証できないんですよね……

@n4o847 n4o847 requested a review from thgcMtdh November 15, 2022 17:19
@n4o847
Copy link
Collaborator

n4o847 commented Nov 15, 2022

全然大丈夫ライン

  • import *, is None, == True などの構文的な箇所
  • Optional つけたり、アノテーション上のみ変わっている部分

まあ大丈夫ライン

  • 今まで None 判定されずに通っていて、エラーが起こり得た部分

怪しいライン

  • 仮のデフォルト値を設定している部分
  • 制御構造が変わっている部分

とかなんですけど、ちょっとチェックに気合が必要なので、時間かかりそう……

@Azuki-bar
Copy link
Member Author

Azuki-bar commented Nov 15, 2022

めちゃくちゃ重い変更を投げている自覚があるのでレビューはゆっくりで全然問題ありません!

もしチェックに時間がかかる かつ 型のチェッカー導入にコストが見合わないと考える のであれば型チェックをCiから外すこともありだと考えています。(とりあえずflake8の静的解析だけ導入する)

@Azuki-bar Azuki-bar mentioned this pull request Nov 16, 2022
Copy link
Collaborator

@thgcMtdh thgcMtdh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ATOで若干ロジック修正、あとは軽微なコメント等をつけてコミットしました。マージして大丈夫だと思われます

train.currentSection.id == testSection.id
and train.mileage >= testSection.stationPosition
):
if train.mileage >= testSection.stationPosition:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

train.currentSection.id==testsection.id に対応する条件が消えてる?

if testSection.station != None:
if testSection is None:
# FIXME; 型ガードのために適当な値を返している
return 0.0
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ここは return 0.0 でよさそう(train.currentSection が取れないのはやばいので、停止距離0.0で停止した方がよい)

train = self.__state.getTrainInSection(junction.getOutSection()) # 前方セクションにいる列車を取得
if train == None: # 前方セクションに在線なし
in_section = junction.getInSection()
out_section = junction.getOutSection()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

snake_case と camelCase だけ修正

@thgcMtdh
Copy link
Collaborator

thgcMtdh commented Nov 16, 2022

これを現行のmainと結合するのがきわめて破壊的作業なのか(型アノテーションによる変更と、停止指示を速度指令からストップレールに変えたことによるロジック変更が混ざったconflictが生じる)、とりあえず atuo_operation 部分については責任もって conflict 解消を試みます。

@thgcMtdh
Copy link
Collaborator

thgcMtdh commented Nov 17, 2022

そもそも、train.currentSectionjunction.getOutSection()None になることは物理的にあってはならないので、Optional ではなく必ず Section 型として、Section以外の代入を禁止するほうがシンプルだこれ。
→別の用事のため13時から作業再開

@n4o847
Copy link
Collaborator

n4o847 commented Nov 17, 2022

@thgcMtdh レビュー & conflict 解決ありがとう!!

そもそも、train.currentSection や junction.getOutSection() が None になることは物理的にあってはならないので、Optional ではなく必ず Section 型として、Section以外の代入を禁止するほうがシンプルだこれ。

たしかに、設計としてはその方が正しそう

WSL 環境なら

sudo apt install make
pip -r requirements.dev.txt

して、push する前に back/auto_operation

make format  # 自動整形
make staticcheck  # 静的解析
make typecheck  # 型チェック

などすると上記3つがローカルで試せます

@Azuki-bar
Copy link
Member Author

このPR、作業量が多いので一回閉じてもう一度やり直す or やらない 方法を取ってもよいと考えています
いかがでしょう?意見を聞かせてください

@thgcMtdh @n4o847

@thgcMtdh
Copy link
Collaborator

1回閉じましょうかね。諸々会場の実機で確認すべき点を優先したく考えています。

@n4o847
Copy link
Collaborator

n4o847 commented Nov 17, 2022

そうですね〜

他グループのリポジトリにコードを入れる以上、負の遺産になってしまわないようにコードを綺麗にしたいという気持ちはやまやまなのですが、現状を鑑みてそれ以外の箇所がヤバいので……

調布祭の後でもコード整備のお手伝いはしますので、これは一旦 close でいいかもしれません

@Azuki-bar
Copy link
Member Author

破壊します
ご迷惑おかけしました

@Azuki-bar Azuki-bar closed this Nov 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

auto_operation に型アノテーションを付けて周る
3 participants