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

Pycharm cannot determine type when using @utils.cached_slot_property #1146

Closed
3 tasks done
LEv145 opened this issue Jan 6, 2024 · 3 comments
Closed
3 tasks done

Pycharm cannot determine type when using @utils.cached_slot_property #1146

LEv145 opened this issue Jan 6, 2024 · 3 comments
Labels
wontfix This will not be worked on

Comments

@LEv145
Copy link
Contributor

LEv145 commented Jan 6, 2024

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!")

image
image

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

  • I have searched the open issues for duplicates.
  • I have shown the entire traceback, if possible.
  • I have removed my token from display, if visible.

Additional Context

  1. Pycharm bug report: https://youtrack.jetbrains.com/issue/PY-63737/PyCharm-fails-to-infer-generic-descriptor-type-when-descriptor-is-used-as-a-decorator
  2. Pylance works correctly (VSCode)
    image
  3. This is not a problem of the library itself, but it makes it difficult to use the library with PyCharm
  4. It seems that in discord.py has the same problem: Add custom Interaction (Context) Support Rapptz/discord.py#7549 (comment)
    image
@LEv145 LEv145 added the unconfirmed bug Something might not be working label Jan 6, 2024
@shiftinv
Copy link
Member

shiftinv commented Jan 6, 2024

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:

Mypy and Pyright can handle these just fine, so those might be your best bet for now.

@LEv145
Copy link
Contributor Author

LEv145 commented Jan 6, 2024

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!")

@shiftinv shiftinv added wontfix This will not be worked on and removed unconfirmed bug Something might not be working labels Jan 8, 2024
@elenakrittik
Copy link
Contributor

This should probably be closed?

@shiftinv shiftinv closed this as not planned Won't fix, can't repro, duplicate, stale May 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

3 participants