From f2b6f0859980f0a32a2fde39c4bdcde85cd6b485 Mon Sep 17 00:00:00 2001 From: yanyongyu Date: Fri, 7 Aug 2020 17:05:08 +0800 Subject: [PATCH] change typing manage --- nonebot/__init__.py | 2 +- nonebot/adapters/__init__.py | 2 +- nonebot/adapters/cqhttp.py | 2 +- nonebot/config.py | 3 ++- nonebot/drivers/__init__.py | 2 +- nonebot/drivers/fastapi.py | 2 +- nonebot/event.py | 2 +- nonebot/matcher.py | 2 +- nonebot/message.py | 2 +- nonebot/plugin.py | 3 +-- nonebot/rule.py | 2 +- nonebot/typing.py | 9 ++++++++- 12 files changed, 20 insertions(+), 13 deletions(-) diff --git a/nonebot/__init__.py b/nonebot/__init__.py index cef2f0a0..e28f87a1 100644 --- a/nonebot/__init__.py +++ b/nonebot/__init__.py @@ -3,10 +3,10 @@ import logging import importlib -from typing import Optional from ipaddress import IPv4Address from nonebot.log import logger +from nonebot.typing import Optional from nonebot.config import Env, Config from nonebot.drivers import BaseDriver diff --git a/nonebot/adapters/__init__.py b/nonebot/adapters/__init__.py index ef6f4cc5..274c82c3 100644 --- a/nonebot/adapters/__init__.py +++ b/nonebot/adapters/__init__.py @@ -3,9 +3,9 @@ import abc from functools import reduce -from typing import Dict, Union, Iterable, Optional from nonebot.config import Config +from nonebot.typing import Dict, Union, Iterable, Optional class BaseBot(abc.ABC): diff --git a/nonebot/adapters/cqhttp.py b/nonebot/adapters/cqhttp.py index ed509ba0..9efeff44 100644 --- a/nonebot/adapters/cqhttp.py +++ b/nonebot/adapters/cqhttp.py @@ -2,7 +2,6 @@ # -*- coding: utf-8 -*- import re -from typing import Tuple, Iterable, Optional import httpx @@ -11,6 +10,7 @@ from nonebot.config import Config from nonebot.message import handle_event from nonebot.drivers import BaseWebSocket from nonebot.exception import ApiNotAvailable +from nonebot.typing import Tuple, Iterable, Optional from nonebot.adapters import BaseBot, BaseMessage, BaseMessageSegment diff --git a/nonebot/config.py b/nonebot/config.py index 1e8da0ec..e236d42b 100644 --- a/nonebot/config.py +++ b/nonebot/config.py @@ -5,11 +5,12 @@ import os from pathlib import Path from datetime import timedelta from ipaddress import IPv4Address -from typing import Set, Dict, Union, Mapping, Optional from pydantic import BaseSettings from pydantic.env_settings import SettingsError, env_file_sentinel, read_env_file +from nonebot.typing import Set, Dict, Union, Mapping, Optional + class BaseConfig(BaseSettings): diff --git a/nonebot/drivers/__init__.py b/nonebot/drivers/__init__.py index 0028a827..70ab96d4 100644 --- a/nonebot/drivers/__init__.py +++ b/nonebot/drivers/__init__.py @@ -2,10 +2,10 @@ # -*- coding: utf-8 -*- import abc -from typing import Optional from ipaddress import IPv4Address from nonebot.config import Config +from nonebot.typing import Optional class BaseDriver(abc.ABC): diff --git a/nonebot/drivers/fastapi.py b/nonebot/drivers/fastapi.py index 5c22c94e..7a6ba0ef 100644 --- a/nonebot/drivers/fastapi.py +++ b/nonebot/drivers/fastapi.py @@ -3,7 +3,6 @@ import json import logging -from typing import Dict, Optional from ipaddress import IPv4Address import uvicorn @@ -14,6 +13,7 @@ from fastapi import Body, status, Header, FastAPI, WebSocket as FastAPIWebSocket from nonebot.log import logger from nonebot.config import Config from nonebot.adapters import BaseBot +from nonebot.typing import Dict, Optional from nonebot.adapters.cqhttp import Bot as CQBot from nonebot.drivers import BaseDriver, BaseWebSocket diff --git a/nonebot/event.py b/nonebot/event.py index d88138d8..6f4db964 100644 --- a/nonebot/event.py +++ b/nonebot/event.py @@ -1,7 +1,7 @@ #!/usr/bin/env python3 # -*- coding: utf-8 -*- -from typing import Any, Dict, Optional +from nonebot.typing import Any, Dict, Optional class Event(dict): diff --git a/nonebot/matcher.py b/nonebot/matcher.py index 96cc01dd..25f75535 100644 --- a/nonebot/matcher.py +++ b/nonebot/matcher.py @@ -4,11 +4,11 @@ from functools import wraps from datetime import datetime from collections import defaultdict -from typing import Type, List, Dict, Optional, Callable from nonebot.event import Event from nonebot.typing import Handler from nonebot.rule import Rule, user +from nonebot.typing import Type, List, Dict, Optional, Callable from nonebot.exception import PausedException, RejectedException, FinishedException matchers: Dict[int, List[Type["Matcher"]]] = defaultdict(list) diff --git a/nonebot/message.py b/nonebot/message.py index cfa1918c..b199c8c1 100644 --- a/nonebot/message.py +++ b/nonebot/message.py @@ -3,11 +3,11 @@ import asyncio from datetime import datetime -from typing import Set, Callable from nonebot.log import logger from nonebot.event import Event from nonebot.matcher import matchers +from nonebot.typing import Set, Callable from nonebot.exception import IgnoredException _event_preprocessors: Set[Callable] = set() diff --git a/nonebot/plugin.py b/nonebot/plugin.py index 50576842..5016aef2 100644 --- a/nonebot/plugin.py +++ b/nonebot/plugin.py @@ -4,11 +4,10 @@ import os import re import importlib -from types import ModuleType -from typing import Set, Dict, Type, Optional from nonebot.log import logger from nonebot.matcher import Matcher +from nonebot.typing import Set, Dict, Type, Optional, ModuleType from nonebot.rule import Rule, metaevent, message, notice, request plugins: Dict[str, "Plugin"] = {} diff --git a/nonebot/rule.py b/nonebot/rule.py index 7f3f68fa..ab81489f 100644 --- a/nonebot/rule.py +++ b/nonebot/rule.py @@ -2,9 +2,9 @@ # -*- coding: utf-8 -*- import re -from typing import Union, Callable, Optional from nonebot.event import Event +from nonebot.typing import Union, Callable, Optional class Rule: diff --git a/nonebot/typing.py b/nonebot/typing.py index 378ae29e..400666fe 100644 --- a/nonebot/typing.py +++ b/nonebot/typing.py @@ -1,6 +1,13 @@ #!/usr/bin/env python3 # -*- coding: utf-8 -*- -from typing import Callable, Awaitable +from types import ModuleType +from typing import TYPE_CHECKING +from typing import Any, Set, List, Dict, Type, Tuple, Mapping +from typing import Union, Optional, Iterable, Callable, Awaitable + +if TYPE_CHECKING: + from nonebot.adapters import BaseBot as Bot + from nonebot.event import Event Handler = Callable[["Bot", "Event", dict], Awaitable[None]]