-
-
Notifications
You must be signed in to change notification settings - Fork 462
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
ApplicationContext attributes have wrong type annotations #2635
Comments
So i found the definition of
Again as I'm not very familiar with the codebase, I don't know why this is a thing. But simply replacing this with
fixes this. Is this a good solution or would this break something else? |
Indeed Currently the implementation is as follows: class _cached_property:
def __init__(self, function):
self.function = function
self.__doc__ = getattr(function, "__doc__")
def __get__(self, instance, owner):
if instance is None:
return self
value = self.function(instance)
setattr(instance, self.function.__name__, value)
return value
if TYPE_CHECKING:
cached_property = NewType("cached_property", property)
else:
cached_property = _cached_property So the |
@Paillat-dev thanks for your quick reply! correct me if I misunderstand but what does So unless I'm misunderstanding some context, using I did try replacing it and that does fix the issue, and within my own discord bot it caused no other problems anywhere. Could you find out if it's compatible, so that if it is, this can be implemented to fix the issue? |
|
Summary
The ctx attributes
channel
,user
andmessage
,guild
, and possible more, are typed as methods, not attributesReproduction Steps
2.6.1.dev134+g9a6cbff4
(i simply use 'git+https://github.com/Pycord-Development/pycord' in my requirements.txt)Minimal Reproducible Code
Expected Results
Expected the type annotations to treat the ctx attributes
channel
,user
andmessage
as attributes.And the syntax highlighting reflects them as such, causing following type annotations to break. (For example, theres no more autocomplete for ctx.channel.id, because the editor thinks channel is a method)
Actual Results
They get autocompleted as methods.
Intents
discord.Intents.all()
System Information
Checklist
Additional Context
full traceback:
Traceback (most recent call last):
File "C:\Users\Me\MyProject\venv\Lib\site-packages\discord\bot.py", line 1149, in invoke_application_command
await ctx.command.invoke(ctx)
File "C:\Users\Me\MyProject\venv\Lib\site-packages\discord\commands\core.py", line 435, in invoke
await injected(ctx)
File "C:\Users\Me\MyProject\venv\Lib\site-packages\discord\commands\core.py", line 138, in wrapped
ret = await coro(arg)
^^^^^^^^^^^^^^^
File "C:\Users\Me\MyProject\venv\Lib\site-packages\discord\commands\core.py", line 1486, in _invoke
await command.invoke(ctx)
File "C:\Users\Me\MyProject\venv\Lib\site-packages\discord\commands\core.py", line 435, in invoke
await injected(ctx)
File "C:\Users\Me\MyProject\venv\Lib\site-packages\discord\commands\core.py", line 146, in wrapped
raise ApplicationCommandInvokeError(exc) from exc
discord.errors.ApplicationCommandInvokeError: Application Command raised an exception: TypeError: 'TextChannel' object is not callable
I went to the definition of ApplicationContext and saw that the properties with this problem have the decorator @cached_property
Replacing this with @Property fixes the issue, but of course I'm new to the codebase so this might not be the best way to fix this.
so maybe this is the fix, or the definition of @cached_property needs some fixing
The text was updated successfully, but these errors were encountered: