Wavelink icon indicating copy to clipboard operation
Wavelink copied to clipboard

get_player return type hint issue

Open Midorina opened this issue 4 years ago • 2 comments

This function's return type hint is causing confusion and creating a warning when a custom class to the cls is provided and the custom class is used in type hinting by the user.

https://github.com/PythonistaGuild/Wavelink/blob/3e11c16516dd89791c1247032045385979736554/wavelink/client.py#L275

voice_player: user_lib.CustomPlayer = wavelink.get_player(guild_id, cls=user_lib.CustomPlayer)

> Expected type 'CustomPlayer', got 'Player' instead

I thought about changing the return type hint from Player to Union[Player, Any] and make a pull request, but that wouldn't make sense, as the hint is correct. It technically returns a Player object.

If I change my type hint, then my IDE does not recognize the attributes and methods of my CustomPlayer.

What should be done in this case?

Midorina avatar Aug 13 '21 22:08 Midorina

Submit a pr changing the annotation for cls to Optional[typing.Type[PlayerT]] where PlayerT is typing.TypeVar("PlayerT", bound="Player") and then change the return type the PlayerT

Gobot1234 avatar Aug 13 '21 22:08 Gobot1234

Submit a pr changing the annotation for cls to Optional[typing.Type[PlayerT]] where PlayerT is typing.TypeVar("PlayerT", bound="Player") and then change the return type the PlayerT

didn't know I could do this, thank you, I created the PR

Midorina avatar Aug 13 '21 22:08 Midorina

This issue is for an oudated version of Wavelink. Closing this, thanks! 👍

EvieePy avatar Jun 18 '23 13:06 EvieePy