Skip to content

Commit

Permalink
Fix import to appease mypy's import resolution
Browse files Browse the repository at this point in the history
  • Loading branch information
SaidBySolo authored Sep 17, 2022
1 parent ce06bee commit e196167
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions discord/app_commands/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
# 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
from discord.ext import commands

This comment has been minimized.

Copy link
@richfromm

richfromm Oct 7, 2022

This is not yet released, correct? It's not in 2.0.1 but will go in whatever is next, presumably 2.1 (but I suppose could be 2.0.2)

I've been having a bizarre situation where my use of mypy on a repo using discord.py as a library alternates between failing with the following:

/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)

and passing (that is, just re-running mypy without making any changes.

Fwiw, I was also able to fix this with the following local change:

-    from discord.ext.commands import Cog
+    from discord.ext.commands.cog import Cog

I don't know enough about the underlying issue to say which solution is "better" (or if there may be other consequences to my change, I didn't try running any unit tests, or actually using the commands in the library, with this change).

For context, see:
bryanforbes/discord.py-stubs#171 (comment)
bryanforbes/discord.py-stubs#171 (comment)


ErrorFunc = Callable[[Interaction, AppCommandError], Coroutine[Any, Any, None]]

Expand Down Expand Up @@ -105,7 +105,7 @@
UnboundError,
]
Check = Callable[['Interaction'], Union[bool, Coro[bool]]]
Binding = Union['Group', 'Cog']
Binding = Union['Group', 'commands.Cog']

This comment has been minimized.

Copy link
@richfromm

richfromm Oct 7, 2022

Is this correct, though? See my comment above. Cog is a class in the file discord/ext/commands/cog.py, and is therefore in the module discord.ext.commands.cog, yes? If the import is as was changed in line 72 above, should this not be commands.cog.Cog ?



if TYPE_CHECKING:
Expand Down

0 comments on commit e196167

Please sign in to comment.