Skip to content

Commit

Permalink
🐛 fix(sqla): generic_issubclass() with Literal args or no subscri…
Browse files Browse the repository at this point in the history
…pted `cls`
  • Loading branch information
ProgramRipper committed Jun 28, 2024
1 parent b282fc8 commit f0c8864
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions nonebot_plugin_orm/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from nonebot.params import Depends
from nonebot import logger, get_driver
from sqlalchemy.sql.selectable import ExecutableReturnsRows
from nonebot.typing import origin_is_union, origin_is_literal, all_literal_values
from nonebot.typing import origin_is_union, origin_is_literal

if sys.version_info >= (3, 9):
from importlib.resources import files
Expand Down Expand Up @@ -170,17 +170,17 @@ def generic_issubclass(scls: Any, cls: Any) -> Any:
if origin_is_union(cls_origin):
return generic_issubclass(scls, cls_args)

if origin_is_literal(scls) and origin_is_literal(cls):
return set(all_literal_values(scls)) <= set(all_literal_values(cls))
if origin_is_literal(scls_origin) and origin_is_literal(cls_origin):
return set(scls_args) <= set(cls_args)

try:
if not issubclass(scls_origin, cls_origin):
return False
except TypeError:
return False

if len(scls_args) == 1 and len(cls_args) <= 1:
return generic_issubclass(scls_args[0], (cls_args or (Any,))[0])
if not cls_args:
return True

return len(scls_args) == len(cls_args) and all(
map(generic_issubclass, scls_args, cls_args)
Expand Down

0 comments on commit f0c8864

Please sign in to comment.