Skip to content

Commit 95c86c1

Browse files
authored
Implement mypy + poll and get_members support (#135)
* Implement and fix mypy type checking on the crate * Implement get_members * Add support for polls in messages
1 parent 8240a26 commit 95c86c1

38 files changed

Lines changed: 1187 additions & 716 deletions

.github/workflows/test-ci.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,4 +67,30 @@ jobs:
6767
name: ${{ matrix.python-version }}-cov-lcov
6868
path: coverage.lcov
6969
if-no-files-found: warn
70+
mypy:
71+
runs-on: ubuntu-latest
72+
strategy:
73+
# don't cancel any remaining jobs when one fails
74+
fail-fast: false
75+
# how you define a matrix strategy
76+
matrix:
77+
# use these pythons
78+
python-version: [ "3.11", "3.14" ]
79+
steps:
80+
- uses: actions/checkout@v6
81+
- name: Set up Python ${{ matrix.python-version }}
82+
uses: actions/setup-python@v6
83+
with:
84+
python-version: ${{ matrix.python-version }}
85+
cache: 'pip'
86+
cache-dependency-path: |
87+
dev-requirements.txt
88+
setup.py
89+
90+
- name: Install dev dependencies
91+
run: python -m pip install -r dev-requirements.txt
92+
- name: Install self (dpytest)
93+
run: python -m pip install .
94+
- name: Run mypy
95+
run: mypy --install-types --non-interactive
7096

dev-requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ build
99
flake8~=7.0.0
1010
pynacl
1111
typing-extensions
12+
mypy

discord/ext/test/_types.py

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,53 @@
11
"""
22
Internal module for type-hinting aliases. Ensures single common definitions.
33
"""
4+
from enum import Enum
5+
import typing
6+
from typing import Callable, Literal, Self, TypeVar, ParamSpec, Protocol
47

58
import discord
6-
import typing
79

8-
T = typing.TypeVar('T')
10+
T = TypeVar('T')
11+
P = ParamSpec('P')
12+
13+
AnyChannel = (discord.abc.GuildChannel | discord.TextChannel | discord.VoiceChannel | discord.StageChannel
14+
| discord.DMChannel | discord.Thread | discord.GroupChannel)
15+
16+
17+
class Wrapper(Protocol[P, T]):
18+
__wrapped__: Callable[P, T]
19+
20+
def __call__(self, *args: P.args, **kwargs: P.kwargs) -> T:
21+
...
22+
23+
24+
class FnWithOld(Protocol[P, T]):
25+
__old__: Callable[P, T] | None
26+
27+
def __call__(self, *args: P.args, **kwargs: P.kwargs) -> T:
28+
...
29+
30+
31+
class Undef(Enum):
32+
undefined = None
33+
34+
35+
undefined: Literal[Undef.undefined] = Undef.undefined
936

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

1438
if typing.TYPE_CHECKING:
1539
from discord.types import (
16-
role, gateway, appinfo, user, guild, emoji, channel, message, sticker, # noqa: F401
17-
scheduled_event, member # noqa: F401
40+
role, gateway, appinfo, user, guild, emoji, channel, message, sticker, snowflake, # noqa: F401
41+
scheduled_event, member, poll # noqa: F401
1842
)
1943

2044
AnyChannelJson = channel.VoiceChannel | channel.TextChannel | channel.DMChannel | channel.CategoryChannel
2145
else:
2246
class OpenNamespace:
23-
def __getattr__(self, item: str) -> typing.Self:
47+
def __getattr__(self, item: str) -> Self:
2448
return self
2549

26-
def __subclasscheck__(self, subclass: type) -> typing.Literal[True]:
50+
def __subclasscheck__(self, subclass: type) -> Literal[True]:
2751
return True
2852

2953
def __or__(self, other: T) -> T:

0 commit comments

Comments
 (0)