disnake
disnake copied to clipboard
Pycharm cannot determine type when using `@utils.cached_slot_property`
Summary
Pycharm does not recognize type, which is why the method hints are not displayed
Reproduction Steps
Write code:
class TestCog(commands.Cog):
@commands.slash_command()
async def ping(self, inter: disnake.CommandInteraction) -> None:
await inter.response.send_message("Pong!")
Minimal Reproducible Code
No response
Expected Results
Type-based hints
Actual Results
Lack of hints
Intents
Intents.default()
System Information
- Python v3.10.11-final
- disnake v2.9.1-final
- disnake importlib.metadata: v2.9.1
- aiohttp v3.9.1
- system info: Linux 5.15.119 #1-NixOS x86_64
- Pycharm 2022.2.3 (Professional Edition)
Checklist
- [X] I have searched the open issues for duplicates.
- [X] I have shown the entire traceback, if possible.
- [X] I have removed my token from display, if visible.
Additional Context
-
Pycharm
bug report: https://youtrack.jetbrains.com/issue/PY-63737/PyCharm-fails-to-infer-generic-descriptor-type-when-descriptor-is-used-as-a-decorator -
Pylance
works correctly (VSCode
) - This is not a problem of the library itself, but it makes it difficult to use the library with PyCharm
- It seems that in discord.py has the same problem: https://github.com/Rapptz/discord.py/issues/7549#issuecomment-1366519045
I doubt there's anything we can do about this, unfortunately. PyCharm has been struggling to infer descriptor types (especially generic ones) correctly for a long time, and ultimately it's up to them to fix it - disnake isn't the only library affected by this. There are several open issues that are more or less related:
- https://youtrack.jetbrains.com/issue/PY-47698
- https://youtrack.jetbrains.com/issue/PY-26184
- https://youtrack.jetbrains.com/issue/PY-55531
- https://youtrack.jetbrains.com/issue/PY-21069
- https://youtrack.jetbrains.com/issue/PY-59896
Mypy and Pyright can handle these just fine, so those might be your best bet for now.
Thanks!
One of the possible solutions in PyCharm:
@commands.slash_command()
async def ping(self, inter: disnake.CommandInteraction) -> None:
assert isinstance(inter.response, disnake.InteractionResponse)
await inter.response.send_message("Pong!")
Or
@commands.slash_command()
async def ping(self, inter: disnake.CommandInteraction) -> None:
inter.response: disnake.InteractionResponse # type: ignore
await inter.response.send_message("Pong!")
This should probably be closed?