-
Couldn't load subscription status.
- Fork 0
fix(typing): Typing fixes #18
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
base: main
Are you sure you want to change the base?
Conversation
- Use `Any` instead of `any` - Import `__future__.annotations` for compatibility - Use `|` operator instead of `Union[]` - Only use `Any` if `Any` is used in the union - Fix `super().__init__()` arguments - None check if required - Use `ABC` base class to `AbstractHandlerBase`, use `@abstractmethod` to the class's methods
| self.count += 1 | ||
|
|
||
| def get_endpoint(self, method: str, path: str, params: Optional[dict] = None) -> Optional[EndPoint]: | ||
| def get_endpoint(self, method: str, path: str, params: dict = {}) -> Optional[EndPoint]: |
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.
引数のデフォルト値が mutable です。
| self.call_handler(path.path, {}, queries) | ||
| else: | ||
| if "Content-Type" in self.request.headers: | ||
| if self.request.headers is not None and "Content-Type" in self.request.headers: |
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.
self.request.headers がNoneになることはありません。
|
|
||
|
|
||
| class AbstractHandlerBase(StreamRequestHandler): | ||
| class AbstractHandlerBase(ABC, StreamRequestHandler): |
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.
Abstractである必要がありません
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.
このクラスからの継承を止めて、子クラスで維持させた方がいいかもしれません。
全部の子クラスで使用されている関数があればabcを使用します。
src/endpoint.py
Outdated
| from __future__ import annotations | ||
| from typing import Union, Optional | ||
|
|
||
| from typing import Optional, Any, Literal |
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.
Python3.7での互換性を保てません。
| raise ParseException("MALFORMED_HEADER") | ||
|
|
||
| self._response.headers.add(*kv) | ||
| self._response.headers.add(*kv) if self._response.headers is not None else None |
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.
self._response.headersが None になることはありません。
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.
Noneチェックが必要ない型にするには__init__からNone定義をしている箇所を削除する必要があります。
| self.multiple = True | ||
| elif req.headers["Connection"] == "close": | ||
| self.multiple = False | ||
| if req.headers is not None: |
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.
req.headersがNoneになることはありません。
|
|
||
| def handle_switch(self): | ||
| try: | ||
| if self.request is None: |
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.
self.request がNoneになることはありません。
| self.logger.info(get_log_name(), '%s -- %s %s -- "%s %s"' % | ||
| (kwargs["client"], kwargs["code"], "" if kwargs["message"] is None else kwargs["message"], | ||
| self.request.method, kwargs["path"])) | ||
| self.request.method if self.request is not None else "<no method>", kwargs["path"])) |
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.
self.request がNoneになることはありません。
| ep = endpoint.loader.get_endpoint(self.request.method, path, path_param) | ||
| ep: Optional[endpoint.EndPoint] = None | ||
|
|
||
| if self.request is not None and self.request.method is not None: |
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.
self.request やself.request.methodNoneになることはありません。
レビューを承認する前に入念に確認してください。見落としがあるかもしれません。
anyの代わりにAnyを使用-
any()を指定していることになっています。__future__.annotationsfor compatibility- 互換性維持のため。
|operator instead ofUnion[]-
__future__.annotationsが適用されている状態でこの記法ができます。AnyifAnyis used in the union-
Anyはすべての型を通すため、UnionやOptionalである意味がありません。Anyを使用したくない場合は代わりの型をレビューでリクエストしてください。super().__init__()arguments- 一部
super().__init__()の引数が間違っていた箇所があります。-
Noneがチェックされていない箇所にNoneチェックを入れました。ABCbase class toAbstractHandlerBase, use@abstractmethodto the class's methods-
ABCが使用されていないため入れましたが、なにか理由があれば修正します。以下の推奨事項があります。修正願います。
TypedDictを使用したdictのキーの固定tuple[]の型の設定Anyが使用されている箇所の代替となる型の指定Authorizationヘッダーのチェック部分でのNoneチェックの実装