From a85ee6555f661394f3fa555d436117dc6f4ea754 Mon Sep 17 00:00:00 2001 From: yanyongyu Date: Mon, 6 Dec 2021 11:27:25 +0800 Subject: [PATCH] :bug: fix error on python 3.9+ --- nonebot/utils.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/nonebot/utils.py b/nonebot/utils.py index 0c63289c..1c1f2e67 100644 --- a/nonebot/utils.py +++ b/nonebot/utils.py @@ -6,7 +6,6 @@ import collections import dataclasses from functools import wraps, partial from contextlib import asynccontextmanager -from typing_extensions import GenericAlias # type: ignore from typing_extensions import ParamSpec, get_args, get_origin from typing import ( Any, @@ -53,16 +52,16 @@ def generic_check_issubclass( try: return issubclass(cls, class_or_tuple) except TypeError: - if get_origin(cls) is Union: + origin = get_origin(cls) + if origin is Union: for type_ in get_args(cls): if type_ is not type(None) and not generic_check_issubclass( type_, class_or_tuple ): return False return True - elif isinstance(cls, GenericAlias): - origin = get_origin(cls) - return bool(origin and issubclass(origin, class_or_tuple)) + elif origin: + return issubclass(origin, class_or_tuple) raise