mirror of
https://github.com/nonebot/nonebot2.git
synced 2025-06-21 11:59:22 +00:00
🐛 fix error on python 3.9+
This commit is contained in:
parent
bbaf156826
commit
a85ee6555f
@ -6,7 +6,6 @@ import collections
|
|||||||
import dataclasses
|
import dataclasses
|
||||||
from functools import wraps, partial
|
from functools import wraps, partial
|
||||||
from contextlib import asynccontextmanager
|
from contextlib import asynccontextmanager
|
||||||
from typing_extensions import GenericAlias # type: ignore
|
|
||||||
from typing_extensions import ParamSpec, get_args, get_origin
|
from typing_extensions import ParamSpec, get_args, get_origin
|
||||||
from typing import (
|
from typing import (
|
||||||
Any,
|
Any,
|
||||||
@ -53,16 +52,16 @@ def generic_check_issubclass(
|
|||||||
try:
|
try:
|
||||||
return issubclass(cls, class_or_tuple)
|
return issubclass(cls, class_or_tuple)
|
||||||
except TypeError:
|
except TypeError:
|
||||||
if get_origin(cls) is Union:
|
origin = get_origin(cls)
|
||||||
|
if origin is Union:
|
||||||
for type_ in get_args(cls):
|
for type_ in get_args(cls):
|
||||||
if type_ is not type(None) and not generic_check_issubclass(
|
if type_ is not type(None) and not generic_check_issubclass(
|
||||||
type_, class_or_tuple
|
type_, class_or_tuple
|
||||||
):
|
):
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
elif isinstance(cls, GenericAlias):
|
elif origin:
|
||||||
origin = get_origin(cls)
|
return issubclass(origin, class_or_tuple)
|
||||||
return bool(origin and issubclass(origin, class_or_tuple))
|
|
||||||
raise
|
raise
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user