Skip to content

Commit

Permalink
Post-rebase fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
FasterSpeeding committed Jan 30, 2023
1 parent e958bea commit ee38be0
Show file tree
Hide file tree
Showing 14 changed files with 152 additions and 461 deletions.
321 changes: 1 addition & 320 deletions dev-requirements/flake8.txt

Large diffs are not rendered by default.

7 changes: 5 additions & 2 deletions tanjun/_internal/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,10 @@

_ContextT = typing.TypeVar("_ContextT", bound=tanjun.Context)
_CoroT = collections.Coroutine[typing.Any, typing.Any, _T]
_TreeT = dict["str | _IndexKeys", "_TreeT | list[tuple[list[str], tanjun.MessageCommand[typing.Any]]]"]
_TreeT = dict[
typing.Union[str, "_IndexKeys"],
typing.Union["_TreeT", list[tuple[list[str], tanjun.MessageCommand[typing.Any]]]],
]


_KeyT = typing.TypeVar("_KeyT")
Expand Down Expand Up @@ -155,7 +158,7 @@ def __len__(self) -> int:
_KEYWORD_TYPES = {inspect.Parameter.KEYWORD_ONLY, inspect.Parameter.POSITIONAL_OR_KEYWORD}


def get_kwargs(callback: collections.Callable[..., typing.Any], /) -> list[str] | None:
def get_kwargs(callback: collections.Callable[..., typing.Any], /) -> typing.Union[list[str], None]:
"""Get a list of the keyword argument names for a callback.
Parameters
Expand Down
10 changes: 6 additions & 4 deletions tanjun/abc.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@
CommandCallbackSig = collections.Callable[..., _CoroT[None]]
"""Deprecated type hint used to represent any command callback."""

MetaEventSig = collections.Callable[..., _CoroT[None] | None]
MetaEventSig = collections.Callable[..., typing.Union[_CoroT[None], None]]
"""Type hint of a client callback.
The positional arguments this is guaranteed depend on the event name its being
Expand All @@ -134,7 +134,7 @@
if typing.TYPE_CHECKING:
_P = typing_extensions.ParamSpec("_P")

_MaybeAwaitable = collections.Callable[_P, _CoroT[_T] | _T]
_MaybeAwaitable = collections.Callable[_P, typing.Union[_CoroT[_T], _T]]

_AutocompleteSig = collections.Callable[
typing_extensions.Concatenate["AutocompleteContext", _AutocompleteValueT, _P], _CoroT[None]
Expand Down Expand Up @@ -205,7 +205,9 @@
This must be asynchronous and return [None][].
"""

_ErrorHookSig = _MaybeAwaitable[typing_extensions.Concatenate[_ContextT_contra, Exception, _P], bool | None]
_ErrorHookSig = _MaybeAwaitable[
typing_extensions.Concatenate[_ContextT_contra, Exception, _P], typing.Optional[bool]
]

ErrorHookSig = _ErrorHookSig[_ContextT_contra, ...]
"""Type hint of the callback used as a unexpected command error hook.
Expand All @@ -223,7 +225,7 @@
"""

_ParserHookSig = _MaybeAwaitable[
typing_extensions.Concatenate[_ContextT_contra, "errors.ParserError", _P], bool | None
typing_extensions.Concatenate[_ContextT_contra, "errors.ParserError", _P], typing.Optional[bool]
]

ParserHookSig = _ParserHookSig[_ContextT_contra, ...]
Expand Down
21 changes: 10 additions & 11 deletions tanjun/annotations.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@

import abc
import datetime
import enum
import itertools
import operator
import typing
Expand All @@ -98,19 +97,19 @@
_T = typing.TypeVar("_T")
_P = typing_extensions.ParamSpec("_P")
__ConverterSig = collections.Callable[
typing_extensions.Concatenate[str, _P], collections.Coroutine[typing.Any, typing.Any, _T] | _T,
typing_extensions.Concatenate[str, _P], typing.Union[collections.Coroutine[typing.Any, typing.Any, _T], _T],
]
_ConverterSig = __ConverterSig[..., _T]
_ChannelTypeIsh = type[hikari.PartialChannel] | int
_ChoiceUnion = int | float | str
_ChannelTypeIsh = typing.Union[type[hikari.PartialChannel], int]
_ChoiceUnion = typing.Union[int, float, str]
_ChoiceT = typing.TypeVar("_ChoiceT", int, float, str)
_CommandUnion = slash.SlashCommand[typing.Any] | message.MessageCommand[typing.Any]
_CommandUnion = typing.Union[slash.SlashCommand[typing.Any], message.MessageCommand[typing.Any]]
_CommandUnionT = typing.TypeVar("_CommandUnionT", bound=_CommandUnion)
_EnumT = typing.TypeVar("_EnumT", bound=enum.Enum)
_NumberT = typing.TypeVar("_NumberT", float, int)


_MentionableUnion = hikari.User | hikari.Role
_MentionableUnion = typing.Union[hikari.User, hikari.Role]


class _ConfigIdentifier(abc.ABC):
Expand Down Expand Up @@ -306,7 +305,7 @@ def set_config(self, config: _ArgConfig, /) -> None:


class _ConvertedMeta(abc.ABCMeta):
def __getitem__(cls, converters: _ConverterSig[_T] | tuple[_ConverterSig[_T]], /) -> type[_T]:
def __getitem__(cls, converters: typing.Union[_ConverterSig[_T], tuple[_ConverterSig[_T]]], /) -> type[_T]:
if not isinstance(converters, tuple):
converters = (converters,)

Expand Down Expand Up @@ -971,7 +970,7 @@ def __getitem__(cls, type_: type[_T], /) -> type[typing.Union[hikari.Snowflake,
descriptor = SnowflakeOr()

return typing.cast(
type[typing.Union[hikari.Snowflake, _T]],
"type[typing.Union[hikari.Snowflake, _T]]",
typing.Annotated[typing.Union[hikari.Snowflake, type_], descriptor],
)

Expand Down Expand Up @@ -1154,8 +1153,8 @@ def __init__(self, parameter: inspect.Parameter, /, *, description: typing.Optio
self.default: typing.Any = parsing.UNDEFINED if parameter.default is parameter.empty else parameter.default
self.description: typing.Optional[str] = description
self.empty_value: typing.Union[parsing.UndefinedT, typing.Any] = parsing.UNDEFINED
self.float_converter: collections.Callable[[float], typing.Any] | None = None
self.int_converter: collections.Callable[[int], typing.Any] | None = None
self.float_converter: typing.Optional[collections.Callable[[float], typing.Any]] = None
self.int_converter: typing.Optional[collections.Callable[[int], typing.Any]] = None
# The float and int converters are just for Choices[Enum].
self.is_greedy: bool = False
self.is_positional: typing.Optional[bool] = None
Expand All @@ -1169,7 +1168,7 @@ def __init__(self, parameter: inspect.Parameter, /, *, description: typing.Optio
self.range_or_slice: typing.Union[range, slice, None] = None
self.slash_name: str = parameter.name
self.snowflake_converter: typing.Optional[collections.Callable[[str], hikari.Snowflake]] = None
self.str_converters: collections.Sequence[_ConverterSig[typing.Any]] | None = None
self.str_converters: typing.Optional[collections.Sequence[_ConverterSig[typing.Any]]] = None

def finalise_slice(self) -> None:
if not self.range_or_slice:
Expand Down
62 changes: 31 additions & 31 deletions tanjun/checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,12 @@

class _AnyCallback(typing.Protocol[_ContextT_contra]):
async def __call__(
self, ctx: _ContextT_contra, /, *, localiser: dependencies.AbstractLocaliser | None = None
self, ctx: _ContextT_contra, /, *, localiser: typing.Optional[dependencies.AbstractLocaliser] = None
) -> bool:
raise NotImplementedError

_CommandT = typing.TypeVar("_CommandT", bound=tanjun.ExecutableCommand[typing.Any])
_CallbackReturnT = _CommandT | collections.Callable[[_CommandT], _CommandT]
_CallbackReturnT = typing.Union[_CommandT, collections.Callable[[_CommandT], _CommandT]]
_MenuCommandT = typing.TypeVar("_MenuCommandT", bound=tanjun.MenuCommand[typing.Any, typing.Any])
_MessageCommandT = typing.TypeVar("_MessageCommandT", bound=tanjun.MessageCommand[typing.Any])
_SlashCommandT = typing.TypeVar("_SlashCommandT", bound=tanjun.BaseSlashCommand)
Expand All @@ -97,8 +97,8 @@ def _add_to_command(command: _CommandT, check: tanjun.AnyCheckSig, follow_wrappe


def _optional_kwargs(
command: _CommandT | None, check: tanjun.AnyCheckSig, follow_wrapped: bool
) -> _CommandT | collections.Callable[[_CommandT], _CommandT]:
command: typing.Optional[_CommandT], check: tanjun.AnyCheckSig, follow_wrapped: bool
) -> typing.Union[_CommandT, collections.Callable[[_CommandT], _CommandT]]:
if command:
return _add_to_command(command, check, follow_wrapped)

Expand Down Expand Up @@ -1015,12 +1015,12 @@ def with_check(

def with_check(
check: tanjun.CheckSig[typing.Any], /, *, follow_wrapped: bool = False
) -> (
collections.Callable[[_CommandT], _CommandT]
| collections.Callable[[_MenuCommandT], _MenuCommandT]
| collections.Callable[[_MessageCommandT], _MessageCommandT]
| collections.Callable[[_SlashCommandT], _SlashCommandT]
):
) -> typing.Union[
collections.Callable[[_CommandT], _CommandT],
collections.Callable[[_MenuCommandT], _MenuCommandT],
collections.Callable[[_MessageCommandT], _MessageCommandT],
collections.Callable[[_SlashCommandT], _SlashCommandT],
]:
"""Add a generic check to a command.
Parameters
Expand Down Expand Up @@ -1115,12 +1115,12 @@ def with_all_checks(

def with_all_checks(
check: tanjun.CheckSig[typing.Any], /, *checks: tanjun.CheckSig[typing.Any], follow_wrapped: bool = False
) -> (
collections.Callable[[_CommandT], _CommandT]
| collections.Callable[[_MenuCommandT], _MenuCommandT]
| collections.Callable[[_MessageCommandT], _MessageCommandT]
| collections.Callable[[_SlashCommandT], _SlashCommandT]
):
) -> typing.Union[
collections.Callable[[_CommandT], _CommandT],
collections.Callable[[_MenuCommandT], _MenuCommandT],
collections.Callable[[_MessageCommandT], _MessageCommandT],
collections.Callable[[_SlashCommandT], _SlashCommandT],
]:
"""Add a check which will pass if all the provided checks pass through a decorator call.
This ensures that the callbacks are run in the order they were supplied in
Expand Down Expand Up @@ -1160,7 +1160,7 @@ def __init__(
self._suppress = suppress

async def __call__(
self, ctx: _ContextT, /, *, localiser: alluka.Injected[dependencies.AbstractLocaliser | None] = None
self, ctx: _ContextT, /, *, localiser: alluka.Injected[typing.Optional[dependencies.AbstractLocaliser]] = None
) -> bool:
for check in self._checks:
try:
Expand Down Expand Up @@ -1240,8 +1240,8 @@ def with_any_checks(
check: tanjun.CheckSig[tanjun.MenuContext],
/,
*checks: tanjun.CheckSig[tanjun.MenuContext],
error: collections.Callable[[], Exception] | None = None,
error_message: str | collections.Mapping[str, str] | None,
error: typing.Optional[collections.Callable[[], Exception]] = None,
error_message: typing.Union[str, collections.Mapping[str, str], None],
follow_wrapped: bool = False,
halt_execution: bool = False,
suppress: tuple[type[Exception], ...] = (errors.CommandError, errors.HaltExecution),
Expand All @@ -1254,8 +1254,8 @@ def with_any_checks(
check: tanjun.CheckSig[tanjun.MessageContext],
/,
*checks: tanjun.CheckSig[tanjun.MessageContext],
error: collections.Callable[[], Exception] | None = None,
error_message: str | collections.Mapping[str, str] | None,
error: typing.Optional[collections.Callable[[], Exception]] = None,
error_message: typing.Union[str, collections.Mapping[str, str], None],
follow_wrapped: bool = False,
halt_execution: bool = False,
suppress: tuple[type[Exception], ...] = (errors.CommandError, errors.HaltExecution),
Expand All @@ -1268,8 +1268,8 @@ def with_any_checks(
check: tanjun.CheckSig[tanjun.SlashContext],
/,
*checks: tanjun.CheckSig[tanjun.SlashContext],
error: collections.Callable[[], Exception] | None = None,
error_message: str | collections.Mapping[str, str] | None,
error: typing.Optional[collections.Callable[[], Exception]] = None,
error_message: typing.Union[str, collections.Mapping[str, str], None],
follow_wrapped: bool = False,
halt_execution: bool = False,
suppress: tuple[type[Exception], ...] = (errors.CommandError, errors.HaltExecution),
Expand All @@ -1281,17 +1281,17 @@ def with_any_checks(
check: tanjun.CheckSig[typing.Any],
/,
*checks: tanjun.CheckSig[typing.Any],
error: collections.Callable[[], Exception] | None = None,
error_message: str | collections.Mapping[str, str] | None,
error: typing.Optional[collections.Callable[[], Exception]] = None,
error_message: typing.Union[str, collections.Mapping[str, str], None],
follow_wrapped: bool = False,
halt_execution: bool = False,
suppress: tuple[type[Exception], ...] = (errors.CommandError, errors.HaltExecution),
) -> (
collections.Callable[[_CommandT], _CommandT]
| collections.Callable[[_MenuCommandT], _MenuCommandT]
| collections.Callable[[_MessageCommandT], _MessageCommandT]
| collections.Callable[[_SlashCommandT], _SlashCommandT]
):
) -> typing.Union[
collections.Callable[[_CommandT], _CommandT],
collections.Callable[[_MenuCommandT], _MenuCommandT],
collections.Callable[[_MessageCommandT], _MessageCommandT],
collections.Callable[[_SlashCommandT], _SlashCommandT],
]:
"""Add a check which'll pass if any of the provided checks pass through a decorator call.
This ensures that the callbacks are run in the order they were supplied in
Expand Down
28 changes: 15 additions & 13 deletions tanjun/clients.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,9 @@
from typing_extensions import Self

_CheckSigT = typing.TypeVar("_CheckSigT", bound=tanjun.AnyCheckSig)
_AppCmdResponse = (
hikari.api.InteractionMessageBuilder
| hikari.api.InteractionDeferredBuilder
| hikari.api.InteractionModalBuilder
)
_AppCmdResponse = typing.Union[
hikari.api.InteractionMessageBuilder, hikari.api.InteractionDeferredBuilder, hikari.api.InteractionModalBuilder,
]
_EventT = typing.TypeVar("_EventT", bound=hikari.Event)
_ListenerCallbackSigT = typing.TypeVar("_ListenerCallbackSigT", bound=tanjun.ListenerCallbackSig[typing.Any])
_MetaEventSigT = typing.TypeVar("_MetaEventSigT", bound=tanjun.MetaEventSig)
Expand Down Expand Up @@ -492,11 +490,11 @@ async def __call__(self) -> None:


def _log_clients(
cache: hikari.api.Cache | None,
events: hikari.api.EventManager | None,
server: hikari.api.InteractionServer | None,
cache: typing.Optional[hikari.api.Cache],
events: typing.Optional[hikari.api.EventManager],
server: typing.Optional[hikari.api.InteractionServer],
rest: hikari.api.RESTClient,
shards: hikari.ShardAware | None,
shards: typing.Optional[hikari.ShardAware],
event_managed: bool,
/,
) -> None:
Expand Down Expand Up @@ -3079,17 +3077,21 @@ def _try_unsubscribe(
pass


@dataclasses.dataclass(slots=True)
@dataclasses.dataclass
class _LoadModule:
path: str | pathlib.Path
__slots__ = ("path",)

path: typing.Union[str, pathlib.Path]

def __call__(self) -> types.ModuleType:
return importlib.import_module(self.path) if isinstance(self.path, str) else _get_path_module(self.path)


@dataclasses.dataclass(slots=True)
@dataclasses.dataclass
class _ReloadModule:
path: types.ModuleType | pathlib.Path
__slots__ = ("path",)

path: typing.Union[types.ModuleType, pathlib.Path]

def __call__(self) -> types.ModuleType:
return _get_path_module(self.path) if isinstance(self.path, pathlib.Path) else importlib.reload(self.path)
36 changes: 18 additions & 18 deletions tanjun/commands/menu.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@

import typing

import hikari

from .. import _internal
from .. import abc as tanjun
from .. import components
Expand All @@ -54,14 +56,12 @@
_MessageCallbackSigT = typing.TypeVar("_MessageCallbackSigT", bound=tanjun.MenuCallbackSig[hikari.Message])
_UserCallbackSigT = typing.TypeVar("_UserCallbackSigT", bound=tanjun.MenuCallbackSig[hikari.InteractionMember])

_AnyCommandT = (
tanjun.MenuCommand[_AnyCallbackSigT, typing.Any]
| tanjun.MessageCommand[_AnyCallbackSigT]
| tanjun.SlashCommand[_AnyCallbackSigT]
)
_CallbackishT = _AnyCallbackSigT | _AnyCommandT[_AnyCallbackSigT]

import hikari
_AnyCommandT = typing.Union[
tanjun.MenuCommand[_AnyCallbackSigT, typing.Any],
tanjun.MessageCommand[_AnyCallbackSigT],
tanjun.SlashCommand[_AnyCallbackSigT],
]
_CallbackishT = typing.Union[_AnyCallbackSigT, _AnyCommandT[_AnyCallbackSigT]]

_AnyMenuCallbackSigT = typing.TypeVar("_AnyMenuCallbackSigT", bound=tanjun.MenuCallbackSig[typing.Any])
_MenuTypeT = typing.TypeVar(
Expand Down Expand Up @@ -336,15 +336,15 @@ def __init__(
self: MenuCommand[_UserCallbackSigT, typing.Literal[hikari.CommandType.USER]],
callback: _UserCallbackSigT,
type_: typing.Literal[hikari.CommandType.USER],
name: str | collections.Mapping[str, str],
name: typing.Union[str, collections.Mapping[str, str]],
/,
*,
always_defer: bool = False,
default_member_permissions: hikari.Permissions | int | None = None,
default_to_ephemeral: bool | None = None,
dm_enabled: bool | None = None,
default_member_permissions: typing.Union[hikari.Permissions, int, None] = None,
default_to_ephemeral: typing.Optional[bool] = None,
dm_enabled: typing.Optional[bool] = None,
is_global: bool = True,
_wrapped_command: tanjun.ExecutableCommand[typing.Any] | None = None,
_wrapped_command: typing.Optional[tanjun.ExecutableCommand[typing.Any]] = None,
) -> None:
...

Expand Down Expand Up @@ -372,15 +372,15 @@ def __init__(
self: MenuCommand[_MessageCallbackSigT, typing.Literal[hikari.CommandType.MESSAGE]],
callback: _MessageCallbackSigT,
type_: typing.Literal[hikari.CommandType.MESSAGE],
name: str | collections.Mapping[str, str],
name: typing.Union[str, collections.Mapping[str, str]],
/,
*,
always_defer: bool = False,
default_member_permissions: hikari.Permissions | int | None = None,
default_to_ephemeral: bool | None = None,
dm_enabled: bool | None = None,
default_member_permissions: typing.Union[hikari.Permissions, int, None] = None,
default_to_ephemeral: typing.Optional[bool] = None,
dm_enabled: typing.Optional[bool] = None,
is_global: bool = True,
_wrapped_command: tanjun.ExecutableCommand[typing.Any] | None = None,
_wrapped_command: typing.Optional[tanjun.ExecutableCommand[typing.Any]] = None,
) -> None:
...

Expand Down
Loading

0 comments on commit ee38be0

Please sign in to comment.