diff --git a/redbot/__init__.py b/redbot/__init__.py index a429c2c37..edf21f713 100644 --- a/redbot/__init__.py +++ b/redbot/__init__.py @@ -4,10 +4,6 @@ import discord # Let's do all the dumb version checking in one place. - -if sys.version_info < (3, 5, 2): - typing.TYPE_CHECKING = False - if discord.version_info.major < 1: print("You are not running the rewritten version of discord.py.\n\n" "In order to use Red v3 you MUST be running d.py version" diff --git a/redbot/core/bot.py b/redbot/core/bot.py index 6c5eb773d..2c3598278 100644 --- a/redbot/core/bot.py +++ b/redbot/core/bot.py @@ -18,7 +18,7 @@ from . import ( ) from .help_formatter import Help, help as help_ -from typing import TYPE_CHECKING +from .utils import TYPE_CHECKING if TYPE_CHECKING: from aiohttp_json_rpc import JsonRpc diff --git a/redbot/core/core_commands.py b/redbot/core/core_commands.py index 97e60b1a4..0e84d6d4f 100644 --- a/redbot/core/core_commands.py +++ b/redbot/core/core_commands.py @@ -18,9 +18,8 @@ from redbot.core import rpc from redbot.core import __version__ from redbot.core.context import RedContext -from typing import TYPE_CHECKING - -from redbot.core.utils.chat_formatting import pagify, box +from .utils import TYPE_CHECKING +from .utils.chat_formatting import pagify, box if TYPE_CHECKING: from redbot.core.bot import Red diff --git a/redbot/core/data_manager.py b/redbot/core/data_manager.py index b8b2c5386..a3ee5db44 100644 --- a/redbot/core/data_manager.py +++ b/redbot/core/data_manager.py @@ -1,6 +1,6 @@ import sys from pathlib import Path -from typing import TYPE_CHECKING, List +from typing import List import hashlib import shutil import logging @@ -8,6 +8,7 @@ import logging import appdirs from .json_io import JsonIO +from .utils import TYPE_CHECKING if TYPE_CHECKING: from . import Config diff --git a/redbot/core/rpc.py b/redbot/core/rpc.py index 8d4b0d0ab..2aeb7bc7f 100644 --- a/redbot/core/rpc.py +++ b/redbot/core/rpc.py @@ -1,5 +1,3 @@ -from typing import NewType, TYPE_CHECKING - import asyncio from aiohttp.web import Application @@ -7,6 +5,8 @@ from aiohttp_json_rpc import JsonRpc import logging +from .utils import TYPE_CHECKING, NewType + if TYPE_CHECKING: from .bot import Red diff --git a/redbot/core/utils/__init__.py b/redbot/core/utils/__init__.py index e69de29bb..3b8197b8c 100644 --- a/redbot/core/utils/__init__.py +++ b/redbot/core/utils/__init__.py @@ -0,0 +1,12 @@ +__all__ = ['TYPE_CHECKING', 'NewType'] + +try: + from typing import TYPE_CHECKING +except ImportError: + TYPE_CHECKING = False + +try: + from typing import NewType +except ImportError: + def NewType(name, tp): + return type(name, (tp,), {})