any decorator from `discord.utils` (`copy_doc` in my case) turns into `Divergent` class
Summary
anything that uses decorators from discord.utils turns into Divergent class, copy_doc in my case
Reproduction Steps
- use any function that uses a decorator from
discord.utils.,@discord.utils.copy_docin my case - check the type,
tyis the type checker - it's marked as
Divergent
Minimal Reproducible Code
# ...
@self.slash_command()
async def command(ctx: ApplicationContext):
msg = await ctx.respond("...")
# msg marked as Divergent
Expected Results
@discord.utils.copy_doc decorator should pass types it required to or something.
like Interaction | WebhookMessage in case of ApplicationContext.respond function
Actual Results
returned value is marked as Divergent
System Information
- Python v3.14.4-final
- py-cord v2.6.1-final
- aiohttp v3.13.5
- system info: Windows 10 10.0.19045
- type checker:
ty - IDE:
Zed
Checklist
- [x] I have searched the open issues for duplicates.
- [x] I have shown the entire traceback, if possible.
- [x] I have removed my token from display, if visible.
Additional Context
the image
turns out utils also maked as Divergent, which affects the decorator as i suspect others as well?
Could you please share what IDE / Editor you are using as well as which type checker ? I can't reproduce the issue on my end unfortunately.
Also could you please upgrade to the latest pycord version (2.8.0) ?
Could you please share what IDE / Editor you are using as well as which type checker ? I can't reproduce the issue on my end unfortunately.
oh i'm sorry, i thought i did, sure.
yeah, it's not a default one but ty.
any IDE have the issue, but Zed in my case
Also could you please upgrade to the latest pycord version (2.8.0) ?
did it, no effect
- Python v3.14.6-final
- py-cord v2.8.None-final
- aiohttp v3.13.5
- system info: Windows 10 10.0.19045
Unfortunately this seems to be an issue with decorators in ty. basedpyright and mypy for example seem to pick this up just fine (see below). I tried changing the decorator around to various more specific forms (e.g. using ParamSpec) but it does not seem like ty managed to work with that either.
I did not find a specific open issue related to this in ty but did see ongoing work related to transparent decorators.
I personally would not suggest relying on ty at the moment. Even if it is out of beta it is imho still way too unstable for any production use. I would recommend you try using a different type checker in the meantime :/
basedpyright vs mypy vs ty:
$ uvx basedpyright .\repro_issue_3275.py
repro_issue_3275.py:4:20 - warning: Import "Any" is not accessed (reportUnusedImport)
repro_issue_3275.py:10:9 - warning: Type of parameter "original" is partially unknown
Parameter type is "(...) -> Unknown" (reportUnknownParameterType)
repro_issue_3275.py:10:19 - error: Expected type arguments for generic class "Callable" (reportMissingTypeArgument)
repro_issue_3275.py:14:20 - error: Cannot assign to attribute "__signature__" for class "object*"
Attribute "__signature__" is unknown (reportAttributeAccessIssue)
repro_issue_3275.py:14:46 - warning: Argument type is partially unknown
Argument corresponds to parameter "obj" in function "signature"
Argument type is "(...) -> Unknown" (reportUnknownArgumentType)
repro_issue_3275.py:29:13 - information: Type of "foo" is "() -> None"
repro_issue_3275.py:31:13 - information: Type of "foo()" is "None"
repro_issue_3275.py:32:13 - information: Type of "bar" is "() -> None"
repro_issue_3275.py:34:13 - information: Type of "bar()" is "None"
2 errors, 3 warnings, 4 notes
$ uvx mypy repro_issue_3275.py
repro_issue_3275.py:30: note: Revealed type is "def ()"
repro_issue_3275.py:32: note: Revealed type is "None"
repro_issue_3275.py:33: note: Revealed type is "def ()"
repro_issue_3275.py:35: note: Revealed type is "None"
Success: no issues found in 1 source file
$ uvx ty check --output-format concise repro_issue_3275.py
repro_issue_3275.py:30:13: info[revealed-type] Revealed type: `def foo() -> None`
repro_issue_3275.py:32:13: info[revealed-type] Revealed type: `None`
repro_issue_3275.py:33:13: info[revealed-type] Revealed type: `(...) -> Unknown`
repro_issue_3275.py:34:1: error[type-assertion-failure] Type `None` does not match asserted type `Unknown`
repro_issue_3275.py:35:13: info[revealed-type] Revealed type: `Unknown`
Found 5 diagnostics
Test Code
from typing_extensions import reveal_type, assert_type
from inspect import signature
from collections.abc import Callable
from typing import Any, TypeVar
T = TypeVar("T")
def copy_doc(
original: Callable,
) -> Callable[[T], T]:
def decorator(overridden: T) -> T:
overridden.__doc__ = original.__doc__
overridden.__signature__ = signature(original) # type: ignore
return overridden
return decorator
def foo() -> None:
pass
@copy_doc(foo)
def bar() -> None:
pass
reveal_type(foo)
assert_type(foo(), None)
reveal_type(foo())
reveal_type(bar)
assert_type(bar(), None)
reveal_type(bar())
If you (or anyone else) has more insight on fixing this on our end, feel free to comment & I will reopen the issue.