Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
26 changes: 26 additions & 0 deletions .github/workflows/test-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,30 @@ jobs:
name: ${{ matrix.python-version }}-cov-lcov
path: coverage.lcov
if-no-files-found: warn
mypy:
runs-on: ubuntu-latest
strategy:
# don't cancel any remaining jobs when one fails
fail-fast: false
# how you define a matrix strategy
matrix:
# use these pythons
python-version: [ "3.11", "3.14" ]
steps:
- uses: actions/checkout@v6
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v6
with:
python-version: ${{ matrix.python-version }}
cache: 'pip'
cache-dependency-path: |
dev-requirements.txt
setup.py

- name: Install dev dependencies
run: python -m pip install -r dev-requirements.txt
- name: Install self (dpytest)
run: python -m pip install .
- name: Run mypy
run: mypy --install-types --non-interactive

1 change: 1 addition & 0 deletions dev-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ build
flake8~=7.0.0
pynacl
typing-extensions
mypy
42 changes: 33 additions & 9 deletions discord/ext/test/_types.py
Original file line number Diff line number Diff line change
@@ -1,29 +1,53 @@
"""
Internal module for type-hinting aliases. Ensures single common definitions.
"""
from enum import Enum
import typing
from typing import Callable, Literal, Self, TypeVar, ParamSpec, Protocol

import discord
import typing

T = typing.TypeVar('T')
T = TypeVar('T')
P = ParamSpec('P')

AnyChannel = (discord.abc.GuildChannel | discord.TextChannel | discord.VoiceChannel | discord.StageChannel
| discord.DMChannel | discord.Thread | discord.GroupChannel)


class Wrapper(Protocol[P, T]):
__wrapped__: Callable[P, T]

def __call__(self, *args: P.args, **kwargs: P.kwargs) -> T:
...


class FnWithOld(Protocol[P, T]):
__old__: Callable[P, T] | None

def __call__(self, *args: P.args, **kwargs: P.kwargs) -> T:
...


class Undef(Enum):
undefined = None


undefined: Literal[Undef.undefined] = Undef.undefined

Callback = typing.Callable[..., typing.Coroutine[None, None, None]]
AnyChannel = (discord.TextChannel | discord.CategoryChannel | discord.abc.GuildChannel
| discord.abc.PrivateChannel | discord.Thread)

if typing.TYPE_CHECKING:
from discord.types import (
role, gateway, appinfo, user, guild, emoji, channel, message, sticker, # noqa: F401
scheduled_event, member # noqa: F401
role, gateway, appinfo, user, guild, emoji, channel, message, sticker, snowflake, # noqa: F401
scheduled_event, member, poll # noqa: F401
)

AnyChannelJson = channel.VoiceChannel | channel.TextChannel | channel.DMChannel | channel.CategoryChannel
else:
class OpenNamespace:
def __getattr__(self, item: str) -> typing.Self:
def __getattr__(self, item: str) -> Self:
return self

def __subclasscheck__(self, subclass: type) -> typing.Literal[True]:
def __subclasscheck__(self, subclass: type) -> Literal[True]:
return True

def __or__(self, other: T) -> T:
Expand Down
Loading