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

Is discord.py-stubs no longer needed as of discord.py 2.0.0 ? #171

Open
richfromm opened this issue Oct 6, 2022 · 3 comments
Open

Is discord.py-stubs no longer needed as of discord.py 2.0.0 ? #171

richfromm opened this issue Oct 6, 2022 · 3 comments

Comments

@richfromm
Copy link

richfromm commented Oct 6, 2022

Apologies if opening an issue is not the best way to ask this question, I wasn't sure how else to.

I have some code using discord.py (https://github.com/richfromm/slack2discord) to which I'm adding mypy support. I had earlier seen the warning:

/Users/rich/.virtualenvs/slack2discord/lib/python3.10/site-packages/discord/app_commands/commands.py:72: error: Cannot find implementation or library stub for module named "discord.ext.commands"
/Users/rich/.virtualenvs/slack2discord/lib/python3.10/site-packages/discord/app_commands/commands.py:72: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports

Which caused me to find and try installing this library.

But I see that if I first install the latest discord.py (currently 2.0.1), when I install discord.py-stubs, it downgrades discord.py to 1.7.3.

Looking further, I see that 1.7.3 is the latest release of discord.py-stubs (see https://github.com/bryanforbes/discord.py-stubs/tags), and that 1.7.3 is the end of the 1.x line for discord.py (see https://github.com/Rapptz/discord.py/tags), and that the versions need to match (https://github.com/bryanforbes/discord.py-stubs#version-numbering-scheme).

So I was about to open an issue asking when this stubs library would be updated for 2.0.0. and 2.0.1, but taking a look at the diffs in discord.py 2.0.0, I see that it now already includes mypy typing hints:
Rapptz/discord.py@v1.7.3...v2.0.0

And indeed, if I start over with a fresh virtualenv, I am no longer seeing the above error when running mypy with discord.py 2.0.1 installed and discord.py-stubs not installed at all.

So is this library no longer needed moving forward, and if so, should that be noted in the README ? (I can add some text and open a PR if you agree and would like me to take care of it.)

richfromm added a commit to richfromm/slack2discord that referenced this issue Oct 6, 2022
our virtualenv needs to additionally install
* pip install mypy
* pip install types-decorator
* pip install types-requests

this should definitely noted, and maybe even explicitly supported
somehow, maybe it's time for a requirements.txt file (and/or a
separate requirements-dev.txt file), and dropping the reference
to (and support of) pyv.

note that you should **not** `pip install discord.py-stubs`. the last
version of this is 1.7.3, and it must be consistent with
discord.py (currently 2.0.1), and doing so forces a downgrade. and
discord.utils.setup_logging (which we use in slack2discord.py) doesn't
exist in 1.7.3

but it appears to be no longer needed, as discord.py now has mypy
typing hints as of 2.0.0. see:

bryanforbes/discord.py-stubs#171
Rapptz/discord.py#5935
Rapptz/discord.py#7342
@bryanforbes
Copy link
Owner

discord.py is fully typed starting in 2.0, so there's no need to use stubs anymore. If you'd like to open a PR to add that to the README, I'd be very grateful.

@richfromm
Copy link
Author

Sure, I'll add something to the README

But while I've got your attention, I think I know why I was a bit confused initially, and I'm wondering if you have a clue what's going on. I'm in the process of adding mypy typing hints to my project, and it's currently passing. However, when I run mypy, every other time (precisely), it gives me the warning I included above, about not being able to find an implementation or library stub for discord.ext.commands. As in, I can put it in a tight loop, not touching anything at all, and it alternates fail, pass, fail, pass, etc. See below. Any clue what might be going on? Could this be an issue with discord.py? A bug in mypy? I know mypy does some local caching (there's a .mypy_cache dir), but I don't know the details of how that works. This is with discord.py 2.0.1, mypy 0.982, and python 3.10.7

(slack2discord) rich@richmbp21 slack2discord % while [ true ]; do date; echo "BEGIN mypy"; mypy slack2discord.py; echo $?; echo "END mypy"; echo; sleep 1; done
while [ true ]; do date; echo "BEGIN mypy"; mypy slack2discord.py; echo $?; echo "END mypy"; echo; sleep 1; done
Thu Oct  6 17:23:04 PDT 2022
BEGIN mypy
/Users/rich/.virtualenvs/slack2discord/lib/python3.10/site-packages/discord/app_commands/commands.py:72: error: Cannot find implementation or library stub for module named "discord.ext.commands"
/Users/rich/.virtualenvs/slack2discord/lib/python3.10/site-packages/discord/app_commands/commands.py:72: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports
Found 1 error in 1 file (checked 1 source file)
1
END mypy

Thu Oct  6 17:23:09 PDT 2022
BEGIN mypy
Success: no issues found in 1 source file
0
END mypy

Thu Oct  6 17:23:14 PDT 2022
BEGIN mypy
/Users/rich/.virtualenvs/slack2discord/lib/python3.10/site-packages/discord/app_commands/commands.py:72: error: Cannot find implementation or library stub for module named "discord.ext.commands"
/Users/rich/.virtualenvs/slack2discord/lib/python3.10/site-packages/discord/app_commands/commands.py:72: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports
Found 1 error in 1 file (checked 1 source file)
1
END mypy

Thu Oct  6 17:23:18 PDT 2022
BEGIN mypy
Success: no issues found in 1 source file
0
END mypy

Thu Oct  6 17:23:23 PDT 2022
BEGIN mypy
/Users/rich/.virtualenvs/slack2discord/lib/python3.10/site-packages/discord/app_commands/commands.py:72: error: Cannot find implementation or library stub for module named "discord.ext.commands"
/Users/rich/.virtualenvs/slack2discord/lib/python3.10/site-packages/discord/app_commands/commands.py:72: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports
Found 1 error in 1 file (checked 1 source file)
1
END mypy

Thu Oct  6 17:23:27 PDT 2022
BEGIN mypy
Success: no issues found in 1 source file
0
END mypy

@richfromm
Copy link
Author

richfromm commented Oct 7, 2022

The offending line is at https://github.com/Rapptz/discord.py/blob/8f19cfe72925a1dd493c8e92525186d34915d0a9/discord/app_commands/commands.py#L72:

    # Generally, these two libraries are supposed to be separate from each other.
    # However, for type hinting purposes it's unfortunately necessary for one to
    # reference the other to prevent type checking errors in callbacks
    from discord.ext.commands import Cog

UPDATE: I think it should be:

    from discord.ext.commands.cog import Cog

Making that change locally in my virtualenv fixes the issue. No clue why the behavior would fail in the way it did without that change, though.

Anyway, it's outside the scope of this repo, I'll file an issue in discord.py

UPDATE2: There's already an issue:
Rapptz/discord.py#8473
And it's already been fixed, but isn't in the latest release as of this writing, but I'm not sure if I agree with the fix:
Rapptz/discord.py@e196167#diff-edc6201f259e50254d3bc72339d8935f50a795fee7f4f0056c31e0641635c493

Regardless, that is indeed outside of the scope of this stub, although if I was going to put a disclaimer about it not being needed, but mypy doesn't quite work yet (which I think is the case, as the fix hasn't been released), that might influence my text. So for the immediate time I'm going to hold off a day or so and see if I get a response to any of my comments.

richfromm added a commit to richfromm/slack2discord that referenced this issue Feb 12, 2023
our virtualenv needs to additionally install
* pip install mypy
* pip install types-decorator
* pip install types-requests

this should definitely noted, and maybe even explicitly supported
somehow, maybe it's time for a requirements.txt file (and/or a
separate requirements-dev.txt file), and dropping the reference
to (and support of) pyv.

note that you should **not** `pip install discord.py-stubs`. the last
version of this is 1.7.3, and it must be consistent with
discord.py (currently 2.0.1), and doing so forces a downgrade. and
discord.utils.setup_logging (which we use in slack2discord.py) doesn't
exist in 1.7.3

but it appears to be no longer needed, as discord.py now has mypy
typing hints as of 2.0.0. see:

bryanforbes/discord.py-stubs#171
Rapptz/discord.py#5935
Rapptz/discord.py#7342
richfromm added a commit to richfromm/slack2discord that referenced this issue Feb 14, 2023
our virtualenv needs to additionally install
* pip install mypy
* pip install types-decorator
* pip install types-requests

this should definitely noted, and maybe even explicitly supported
somehow, maybe it's time for a requirements.txt file (and/or a
separate requirements-dev.txt file), and dropping the reference
to (and support of) pyv.

note that you should **not** `pip install discord.py-stubs`. the last
version of this is 1.7.3, and it must be consistent with
discord.py (currently 2.0.1), and doing so forces a downgrade. and
discord.utils.setup_logging (which we use in slack2discord.py) doesn't
exist in 1.7.3

but it appears to be no longer needed, as discord.py now has mypy
typing hints as of 2.0.0. see:

bryanforbes/discord.py-stubs#171
Rapptz/discord.py#5935
Rapptz/discord.py#7342
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants