Skip to content

Commit 6f7aa5a

Browse files
committed
get mypy slack2discord.py to pass
our virtualenv needs to additionally install * pip install mypy * pip install types-decorator * pip install types-requests this should definitely noted, and maybe even explicitly supported somehow, maybe it's time for a requirements.txt file (and/or a separate requirements-dev.txt file), and dropping the reference to (and support of) pyv. note that you should **not** `pip install discord.py-stubs`. the last version of this is 1.7.3, and it must be consistent with discord.py (currently 2.0.1), and doing so forces a downgrade. and discord.utils.setup_logging (which we use in slack2discord.py) doesn't exist in 1.7.3 but it appears to be no longer needed, as discord.py now has mypy typing hints as of 2.0.0. see: bryanforbes/discord.py-stubs#171 Rapptz/discord.py#5935 Rapptz/discord.py#7342
1 parent ed92448 commit 6f7aa5a

File tree

2 files changed

+20
-5
lines changed

2 files changed

+20
-5
lines changed

CHANGES.md

+4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
## Current releases, on [this fork](https://github.com/richfromm/slack2discord)
44

5+
### 2.7 (in progress)
6+
7+
* Add mypy typing hints
8+
59
### 2.6
610

711
* During parsing, skip any attached files that have been deleted

slack2discord/client.py

+16-5
Original file line numberDiff line numberDiff line change
@@ -329,10 +329,21 @@ async def discord_retry(coro, desc="making discord HTTP API call", *args, **kwar
329329
Use this by wrapping a Discord API function that you wish to call, and decorating that
330330
function with an optional description. For example:
331331
332-
@discord_retry(desc="description of call")
332+
@discord_retry(desc="description of call") # type: ignore[call-arg]
333333
async def wrapper_func(self, discord_obj, arg1, arg2):
334334
await discord_obj.discord_func(arg1, arg2)
335335
336+
The comment at the end of the decorator line is to suppress errors like the following
337+
when running the mypy static type checker:
338+
339+
slack2discord/client.py:371: error: Unexpected keyword argument "desc" for "discord_retry" of "DiscordClient"
340+
341+
mypy is confused by our use of parametrized decorator via the decorator module (see
342+
https://github.com/micheles/decorator/blob/master/docs/documentation.md#decorator-factories),
343+
which allows us to annotate this function with just `@decorator` and then use it below via
344+
@discord_retry(desc="foo"). I'm too lazy to try to figure out exactly what's going wrong
345+
and how to truly fix it, so for now I am just suppressing the error. Suggestions for actual
346+
fixes are welcome.
336347
"""
337348
# seconds to wait on subsequent retries
338349
# not used in the rate limiting case, where the retry is explicitly provided
@@ -368,7 +379,7 @@ async def wrapper_func(self, discord_obj, arg1, arg2):
368379
logger.info(f"Will retry #{retry_count} after {retry_sec} seconds, press Ctrl-C to abort")
369380
await asyncio.sleep(retry_sec)
370381

371-
@discord_retry(desc="sending message to channel")
382+
@discord_retry(desc="sending message to channel") # type: ignore[call-arg]
372383
async def send_msg_to_channel(self, channel, send_kwargs):
373384
"""
374385
Send a single message to a channel
@@ -382,7 +393,7 @@ async def send_msg_to_channel(self, channel, send_kwargs):
382393

383394
return await channel.send(**send_kwargs)
384395

385-
@discord_retry(desc="creating thread")
396+
@discord_retry(desc="creating thread") # type: ignore[call-arg]
386397
async def create_thread(self, root_message, thread_name):
387398
"""
388399
Create a thread rooted at the given message, with the given name.
@@ -396,7 +407,7 @@ async def create_thread(self, root_message, thread_name):
396407

397408
return await root_message.create_thread(name=thread_name)
398409

399-
@discord_retry(desc="sending message to thread")
410+
@discord_retry(desc="sending message to thread") # type: ignore[call-arg]
400411
async def send_msg_to_thread(self, thread, send_kwargs):
401412
"""
402413
Send a single message to a thread
@@ -410,7 +421,7 @@ async def send_msg_to_thread(self, thread, send_kwargs):
410421

411422
return await thread.send(**send_kwargs)
412423

413-
@discord_retry(desc="adding files to message")
424+
@discord_retry(desc="adding files to message") # type: ignore[call-arg]
414425
async def add_files_to_message(self, message, add_files_args):
415426
"""
416427
Add files to a message by uploading as attachments

0 commit comments

Comments
 (0)