From 8e915f808bff69adc2f39a0c1534d3e1e8ec57df Mon Sep 17 00:00:00 2001 From: yanyongyu Date: Sat, 3 Jul 2021 11:50:56 +0800 Subject: [PATCH] :art: fix linter error --- nonebot/drivers/fastapi.py | 5 +++-- nonebot/log.py | 10 +++++----- nonebot/permission.py | 4 ++-- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/nonebot/drivers/fastapi.py b/nonebot/drivers/fastapi.py index c9de4107..9e013a5f 100644 --- a/nonebot/drivers/fastapi.py +++ b/nonebot/drivers/fastapi.py @@ -195,8 +195,9 @@ class Driver(ReverseDriver): self, http_request) if not x_self_id: - raise HTTPException(response and response.status or 401, - response.body) + raise HTTPException( + response and response.status or 401, response and + response.body and response.body.decode("utf-8")) if x_self_id in self._clients: logger.warning("There's already a reverse websocket connection," diff --git a/nonebot/log.py b/nonebot/log.py index 0acb8a20..61fbd8af 100644 --- a/nonebot/log.py +++ b/nonebot/log.py @@ -48,11 +48,11 @@ class Filter: self.level: Union[int, str] = "DEBUG" def __call__(self, record): - module = sys.modules.get(record["name"]) + module_name: str = record["name"] + module = sys.modules.get(module_name) if module: - module_name = getattr(module, "__module_name__", record["name"]) - record["name"] = module_name - record["name"] = record["name"].split(".")[0] + module_name = getattr(module, "__module_name__", module_name) + record["name"] = module_name.split(".")[0] levelno = logger.level(self.level).no if isinstance(self.level, str) else self.level return record["level"].no >= levelno @@ -67,7 +67,7 @@ class LoguruHandler(logging.Handler): level = record.levelno frame, depth = logging.currentframe(), 2 - while frame.f_code.co_filename == logging.__file__: + while frame and frame.f_code.co_filename == logging.__file__: frame = frame.f_back depth += 1 diff --git a/nonebot/permission.py b/nonebot/permission.py index 69134fac..68c34f82 100644 --- a/nonebot/permission.py +++ b/nonebot/permission.py @@ -141,8 +141,8 @@ def USER(*user: str, perm: Optional[Permission] = None): """ async def _user(bot: "Bot", event: "Event") -> bool: - return event.get_session_id() in user and bool(perm) and await perm( - bot, event) + return bool(event.get_session_id() in user and perm and + await perm(bot, event)) return Permission(_user)