-
-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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: library stub not found #8473
Conversation
I can't reproduce the issue this intends to fix with pyright, with mypy...
You might need to add namespace-packages to your mypy config
which is something the error actually points you to |
# main.py
import discord
from discord import app_commands
@app_commands.command()
async def main(interaction: discord.Interaction) -> None:
...
This is a reproducible example. Looking at #8327, I personally think this is not an ideal import. |
As pointed out previously, you can resolve this as a configuration change. mypy supports changing the behavior of import discovery. Trimming what I had above to only what's needed to show that, and including the error from mypy which also informed you of this:
vs
|
@mikeshardmind Are there any problems with these code changes? |
mypy's error there literally tells you to do this if this is the reason for it not detecting the import, see the link in the error message. Beyond this, you can change it on a per-package basis. you don't need to change the behavior globally.
Possibly (such as inconsistencies in import, churn for no tangible gain, etc) but I wasn't exactly reviewing the code, just pointing out that this shouldn't be an issue. |
In my opinion, considering the issues mentioned above, I think these changes are meaningful changes to maintain consistency. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. Though I can't make any promises that I'll care about this for internal code. My comment pertained to external code. What @mikeshardmind said is correct, considering discord.py makes extensive use of namespace packages you need to enable the feature for it to work as expected on mypy.
Fwiw, I am able to reproduce this problem with discord.py 2.0.1 and mypy 0.982 and python 3.10.7, but in a bizarre way, it alternates between failing and passing: But from inspection (only) I'm wondering if the fix is correct or not: |
Are you running mypy with |
Summary
When I check the file with mypy, it says that the stub cannot be found.
discord\app_commands\commands.py:89: error: Cannot find implementation or library stub for module named "discord.ext.commands"
#7743 (comment)
Perhaps it has something to do with the issue comment.
Checklist