Use raise from e when load driver error (#1689)

This commit is contained in:
scdhh 2023-02-09 10:24:27 +08:00 committed by GitHub
parent 720c736343
commit 4c0d4065c5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 10 additions and 10 deletions

View File

@ -27,10 +27,10 @@ from nonebot.drivers import HTTPVersion, ForwardMixin, ForwardDriver, combine_dr
try: try:
import aiohttp import aiohttp
except ImportError: # pragma: no cover except ImportError as e: # pragma: no cover
raise ImportError( raise ImportError(
"Please install aiohttp first to use this driver. `pip install nonebot2[aiohttp]`" "Please install aiohttp first to use this driver. `pip install nonebot2[aiohttp]`"
) from None ) from e
class Mixin(ForwardMixin): class Mixin(ForwardMixin):

View File

@ -37,10 +37,10 @@ try:
from fastapi.responses import Response from fastapi.responses import Response
from fastapi import FastAPI, Request, UploadFile, status from fastapi import FastAPI, Request, UploadFile, status
from starlette.websockets import WebSocket, WebSocketState, WebSocketDisconnect from starlette.websockets import WebSocket, WebSocketState, WebSocketDisconnect
except ImportError: # pragma: no cover except ImportError as e: # pragma: no cover
raise ImportError( raise ImportError(
"Please install FastAPI by using `pip install nonebot2[fastapi]`" "Please install FastAPI by using `pip install nonebot2[fastapi]`"
) from None ) from e
def catch_closed(func): def catch_closed(func):

View File

@ -31,10 +31,10 @@ from nonebot.drivers import (
try: try:
import httpx import httpx
except ImportError: # pragma: no cover except ImportError as e: # pragma: no cover
raise ImportError( raise ImportError(
"Please install httpx by using `pip install nonebot2[httpx]`" "Please install httpx by using `pip install nonebot2[httpx]`"
) from None ) from e
class Mixin(ForwardMixin): class Mixin(ForwardMixin):

View File

@ -37,10 +37,10 @@ try:
from quart import Quart, Request, Response from quart import Quart, Request, Response
from quart.datastructures import FileStorage from quart.datastructures import FileStorage
from quart import Websocket as QuartWebSocket from quart import Websocket as QuartWebSocket
except ImportError: # pragma: no cover except ImportError as e: # pragma: no cover
raise ImportError( raise ImportError(
"Please install Quart by using `pip install nonebot2[quart]`" "Please install Quart by using `pip install nonebot2[quart]`"
) from None ) from e
_AsyncCallable = TypeVar("_AsyncCallable", bound=Callable[..., Coroutine]) _AsyncCallable = TypeVar("_AsyncCallable", bound=Callable[..., Coroutine])

View File

@ -30,10 +30,10 @@ from nonebot.drivers import ForwardMixin, ForwardDriver, combine_driver
try: try:
from websockets.exceptions import ConnectionClosed from websockets.exceptions import ConnectionClosed
from websockets.legacy.client import Connect, WebSocketClientProtocol from websockets.legacy.client import Connect, WebSocketClientProtocol
except ImportError: # pragma: no cover except ImportError as e: # pragma: no cover
raise ImportError( raise ImportError(
"Please install websockets by using `pip install nonebot2[websockets]`" "Please install websockets by using `pip install nonebot2[websockets]`"
) from None ) from e
logger = logging.Logger("websockets.client", "INFO") logger = logging.Logger("websockets.client", "INFO")
logger.addHandler(LoguruHandler()) logger.addHandler(LoguruHandler())