Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(typing): proper VoiceClient.play() return value #2324

Merged
merged 5 commits into from
Jan 21, 2024

Conversation

solaluset
Copy link
Contributor

Summary

Properly annotate return value of VoiceClient.play

Consider this code:

import discord


bot = discord.Bot()


@bot.event
async def on_ready() -> None:
    g = bot.guilds[0]
    ch = g.voice_channels[0]
    c: discord.VoiceClient = await ch.connect()

    # valid
    c.play(discord.FFmpegOpusAudio("something.mp3"))
    await c.play(discord.FFmpegOpusAudio("something.mp3"), wait_finish=True)

    # invalid
    await c.play(discord.FFmpegOpusAudio("something.mp3"))


bot.run("")

Mypy says:

repro4.py:15: error: "play" of "VoiceClient" does not return a value  [func-returns-value]
repro4.py:18: error: "play" of "VoiceClient" does not return a value  [func-returns-value]
Found 2 errors in 1 file (checked 1 source file)

After applying the fix:

repro4.py:18: error: Incompatible types in "await" (actual type "None", expected type "Awaitable[Any]")  [misc]
Found 1 error in 1 file (checked 1 source file)

Information

  • This PR fixes an issue.
  • This PR adds something new (e.g. new method or parameters).
  • This PR is a breaking change (e.g. methods or parameters removed/renamed).
  • This PR is not a code change (e.g. documentation, README, typehinting,
    examples, ...).

Checklist

  • I have searched the open pull requests for duplicates.
  • If code changes were made then they have been tested.
    • I have updated the documentation to reflect the changes.
  • If type: ignore comments were used, a comment is also left explaining why.
  • I have updated the changelog to include these changes.

discord/voice_client.py Outdated Show resolved Hide resolved
discord/voice_client.py Outdated Show resolved Hide resolved
discord/voice_client.py Show resolved Hide resolved
discord/voice_client.py Outdated Show resolved Hide resolved
@Dorukyum Dorukyum enabled auto-merge (squash) January 20, 2024 05:20
@Dorukyum Dorukyum requested a review from Lulalaby January 20, 2024 05:43
@Dorukyum Dorukyum merged commit 0cd9ac9 into Pycord-Development:master Jan 21, 2024
29 checks passed
@solaluset solaluset deleted the play-retval-annot branch January 21, 2024 06:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants