run.py: ルーティング関数の戻り値に型ヒントを追加#764
Merged
Hiroshiba merged 41 commits intoVOICEVOX:masterfrom Oct 16, 2023
Merged
Conversation
…lass of HTMLResponse)
…class of HTMLResponse)
Hiroshiba
reviewed
Oct 9, 2023
Hiroshiba
approved these changes
Oct 16, 2023
Member
Hiroshiba
left a comment
There was a problem hiding this comment.
LGTM!!!
調整ありがとうございます!
ず〜〜っと型ワーニングが出ていたの気になってたので嬉しいです!!!
Merged
takana-v
pushed a commit
to voicevox-bridge/bridge-plugin
that referenced
this pull request
Nov 28, 2023
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
内容
run.pyのルーティング関数(@app.getなどがついている関数)の戻り値に型ヒントを追加し、mypyのno-untyped-defエラーをルーティング関数に限って解消します。誤ったオブジェクトを返すことによる不具合を型レベルで防げます。
変更量を少なくするため、ルーティング関数以外は変更していません。
合わせて変更した点
List[Type] -> list[Type]、Tuple[Type] -> tuple[Type]Optional[Type] -> Type | None/core_versionsの戻り値の型が実際にはResponseだがlist[str]で型ヒントがついていたのをResponseに修正list[str]にする場合、Responseではないオブジェクトを返すように修正が必要/installed_librariesのdocstringの戻り値の型の誤りを修正setting_get(),setting_post()のresponse_classをHTMLResponseからResponseに変更startlette.templating._TemplateResponse型が返るが、この型はHTMLResponseを継承しておらず、Responseを直接継承しているHTMLResponseを継承する変更がマージされているが、まだリリースされていないResponseを継承したオブジェクトを返すとresponse_classは無視される(FastAPIのソースコード@c1adce4)ので、実は設定する必要がない。そのままでもいいかもしれないけれど、戻り値の型との不一致は混乱するので避けたい未修正な点(ルーティング関数内のmypy型エラー出力)
Details
関連 Issue
スクリーンショット・動画など
その他
mypyを実行
poetry run mypy .