Skip to content
This repository has been archived by the owner on Mar 13, 2023. It is now read-only.

fix: parse NoArgumentConverter correctly #584

Merged
merged 2 commits into from
Aug 2, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
fix: detect no arg converters even if its a class
  • Loading branch information
AstreaTSS committed Aug 2, 2022
commit 301cec773007b68247d79888eb2c2ce4509e185e
10 changes: 7 additions & 3 deletions naff/models/naff/prefixed_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import typing
from collections import deque
from types import NoneType, UnionType
from typing import Optional, Any, Callable, Annotated, Literal, Union, TYPE_CHECKING, Type
from typing import Optional, Any, Callable, Annotated, Literal, Union, TYPE_CHECKING, Type, TypeGuard

import attrs

Expand Down Expand Up @@ -110,6 +110,10 @@ def finished(self) -> bool:
return self.index >= self.length


def _check_for_no_arg(anno: Any) -> TypeGuard[NoArgumentConverter]:
return isinstance(anno, NoArgumentConverter) or (inspect.isclass(anno) and issubclass(anno, NoArgumentConverter))


def _convert_to_bool(argument: str) -> bool:
lowered = argument.lower()
if lowered in {"yes", "y", "true", "t", "1", "enable", "on"}:
Expand Down Expand Up @@ -433,7 +437,7 @@ def _parse_parameters(self) -> None:
if typing.get_origin(anno) in {Union, UnionType}:
cmd_param.union = True
for arg in typing.get_args(anno):
if isinstance(anno, NoArgumentConverter):
if _check_for_no_arg(anno):
cmd_param.no_argument = True

if arg != NoneType:
Expand All @@ -442,7 +446,7 @@ def _parse_parameters(self) -> None:
elif not cmd_param.optional: # d.py-like behavior
cmd_param.default = None
else:
if isinstance(anno, NoArgumentConverter):
if _check_for_no_arg(anno):
cmd_param.no_argument = True

converter = _get_converter(anno, name)
Expand Down