Wavelink
Wavelink copied to clipboard
get_player return type hint issue
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?
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
Submit a pr changing the annotation for cls to
Optional[typing.Type[PlayerT]]wherePlayerTistyping.TypeVar("PlayerT", bound="Player")and then change the return type thePlayerT
didn't know I could do this, thank you, I created the PR
This issue is for an oudated version of Wavelink. Closing this, thanks! 👍