Skip to content

Commit d079c7c

Browse files
committed
♻️ move copy_doc to private
1 parent 6c57d5e commit d079c7c

File tree

8 files changed

+31
-33
lines changed

8 files changed

+31
-33
lines changed

discord/channel.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030

3131
import discord.abc
3232

33-
from .utils.private import bytes_to_base64_data, get_as_snowflake
33+
from .utils.private import bytes_to_base64_data, get_as_snowflake, copy_doc
3434
from . import utils
3535
from .asset import Asset
3636
from .emoji import GuildEmoji
@@ -244,7 +244,7 @@ def type(self) -> ChannelType:
244244
def _sorting_bucket(self) -> int:
245245
return ChannelType.text.value
246246

247-
@utils.copy_doc(discord.abc.GuildChannel.permissions_for)
247+
@copy_doc(discord.abc.GuildChannel.permissions_for)
248248
def permissions_for(self, obj: Member | Role, /) -> Permissions:
249249
base = super().permissions_for(obj)
250250

@@ -295,7 +295,7 @@ async def edit(self, **options) -> _TextChannel:
295295
"""Edits the channel."""
296296
raise NotImplementedError
297297

298-
@utils.copy_doc(discord.abc.GuildChannel.clone)
298+
@copy_doc(discord.abc.GuildChannel.clone)
299299
async def clone(self, *, name: str | None = None, reason: str | None = None) -> TextChannel:
300300
return await self._clone_impl(
301301
{
@@ -1581,7 +1581,7 @@ def voice_states(self) -> dict[int, VoiceState]:
15811581
if value.channel and value.channel.id == self.id
15821582
}
15831583

1584-
@utils.copy_doc(discord.abc.GuildChannel.permissions_for)
1584+
@copy_doc(discord.abc.GuildChannel.permissions_for)
15851585
def permissions_for(self, obj: Member | Role, /) -> Permissions:
15861586
base = super().permissions_for(obj)
15871587

@@ -1945,7 +1945,7 @@ def type(self) -> ChannelType:
19451945
"""The channel's Discord type."""
19461946
return ChannelType.voice
19471947

1948-
@utils.copy_doc(discord.abc.GuildChannel.clone)
1948+
@copy_doc(discord.abc.GuildChannel.clone)
19491949
async def clone(self, *, name: str | None = None, reason: str | None = None) -> VoiceChannel:
19501950
return await self._clone_impl(
19511951
{"bitrate": self.bitrate, "user_limit": self.user_limit},
@@ -2481,7 +2481,7 @@ def type(self) -> ChannelType:
24812481
"""The channel's Discord type."""
24822482
return ChannelType.stage_voice
24832483

2484-
@utils.copy_doc(discord.abc.GuildChannel.clone)
2484+
@copy_doc(discord.abc.GuildChannel.clone)
24852485
async def clone(self, *, name: str | None = None, reason: str | None = None) -> StageChannel:
24862486
return await self._clone_impl({}, name=name, reason=reason)
24872487

@@ -2744,7 +2744,7 @@ def is_nsfw(self) -> bool:
27442744
"""Checks if the category is NSFW."""
27452745
return self.nsfw
27462746

2747-
@utils.copy_doc(discord.abc.GuildChannel.clone)
2747+
@copy_doc(discord.abc.GuildChannel.clone)
27482748
async def clone(self, *, name: str | None = None, reason: str | None = None) -> CategoryChannel:
27492749
return await self._clone_impl({"nsfw": self.nsfw}, name=name, reason=reason)
27502750

@@ -2810,7 +2810,7 @@ async def edit(self, *, reason=None, **options):
28102810
# the payload will always be the proper channel payload
28112811
return self.__class__(state=self._state, guild=self.guild, data=payload) # type: ignore
28122812

2813-
@utils.copy_doc(discord.abc.GuildChannel.move)
2813+
@copy_doc(discord.abc.GuildChannel.move)
28142814
async def move(self, **kwargs):
28152815
kwargs.pop("category", None)
28162816
await super().move(**kwargs)

discord/commands/context.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
from typing import Callable, Awaitable
5555

5656
from ..utils import cached_property
57+
from ..utils.private import copy_doc
5758

5859
T = TypeVar("T")
5960
CogT = TypeVar("CogT", bound="Cog")
@@ -258,17 +259,17 @@ def unselected_options(self) -> list[Option] | None:
258259
return None
259260

260261
@property
261-
@discord.utils.copy_doc(InteractionResponse.send_modal)
262+
@copy_doc.copy_doc(InteractionResponse.send_modal)
262263
def send_modal(self) -> Callable[..., Awaitable[Interaction]]:
263264
return self.interaction.response.send_modal
264265

265266
@property
266-
@discord.utils.copy_doc(Interaction.respond)
267+
@copy_doc.copy_doc(Interaction.respond)
267268
def respond(self, *args, **kwargs) -> Callable[..., Awaitable[Interaction | WebhookMessage]]:
268269
return self.interaction.respond
269270

270271
@property
271-
@discord.utils.copy_doc(InteractionResponse.send_message)
272+
@copy_doc.copy_doc(InteractionResponse.send_message)
272273
def send_response(self) -> Callable[..., Awaitable[Interaction]]:
273274
if not self.interaction.response.is_done():
274275
return self.interaction.response.send_message
@@ -278,7 +279,7 @@ def send_response(self) -> Callable[..., Awaitable[Interaction]]:
278279
)
279280

280281
@property
281-
@discord.utils.copy_doc(Webhook.send)
282+
@copy_doc.copy_doc(Webhook.send)
282283
def send_followup(self) -> Callable[..., Awaitable[WebhookMessage]]:
283284
if self.interaction.response.is_done():
284285
return self.followup.send
@@ -288,7 +289,7 @@ def send_followup(self) -> Callable[..., Awaitable[WebhookMessage]]:
288289
)
289290

290291
@property
291-
@discord.utils.copy_doc(InteractionResponse.defer)
292+
@copy_doc.copy_doc(InteractionResponse.defer)
292293
def defer(self) -> Callable[..., Awaitable[None]]:
293294
return self.interaction.response.defer
294295

@@ -322,7 +323,7 @@ async def delete(self, *, delay: float | None = None) -> None:
322323
return await self.interaction.delete_original_response(delay=delay)
323324

324325
@property
325-
@discord.utils.copy_doc(Interaction.edit_original_response)
326+
@copy_doc.copy_doc(Interaction.edit_original_response)
326327
def edit(self) -> Callable[..., Awaitable[InteractionMessage]]:
327328
return self.interaction.edit_original_response
328329

discord/ext/commands/bot.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ def __init__(
133133
self.help_command = DefaultHelpCommand() if help_command is MISSING else help_command
134134
self.strip_after_prefix = options.get("strip_after_prefix", False)
135135

136-
@discord.utils.copy_doc(discord.Client.close)
136+
@discord.utils.private.copy_doc(discord.Client.close)
137137
async def close(self) -> None:
138138
for extension in tuple(self.__extensions):
139139
try:

discord/ext/commands/context.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import discord.abc
3333
import discord.utils
3434
from discord.message import Message
35+
from discord.utils.private import copy_doc
3536

3637
if TYPE_CHECKING:
3738
from typing_extensions import ParamSpec
@@ -398,10 +399,10 @@ async def send_help(self, *args: Any) -> Any:
398399
except CommandError as e:
399400
await cmd.on_help_command_error(self, e)
400401

401-
@discord.utils.copy_doc(Message.reply)
402+
@copy_doc(Message.reply)
402403
async def reply(self, content: str | None = None, **kwargs: Any) -> Message:
403404
return await self.message.reply(content, **kwargs)
404405

405-
@discord.utils.copy_doc(Message.forward_to)
406+
@copy_doc(Message.forward_to)
406407
async def forward_to(self, channel: discord.abc.Messageable, **kwargs: Any) -> Message:
407408
return await self.message.forward_to(channel, **kwargs)

discord/member.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434

3535
import discord.abc
3636

37-
3837
from . import utils
3938
from .activity import ActivityTypes, create_activity
4039
from .asset import Asset
@@ -45,7 +44,7 @@
4544
from .permissions import Permissions
4645
from .user import BaseUser, User, _UserTag
4746
from .utils import MISSING
48-
from .utils.private import parse_time, SnowflakeList
47+
from .utils.private import parse_time, SnowflakeList, copy_doc
4948

5049
__all__ = (
5150
"VoiceState",
@@ -202,7 +201,7 @@ def general(self, *args, **kwargs):
202201
return general
203202

204203
func = generate_function(attr)
205-
func = utils.copy_doc(value)(func)
204+
func = copy_doc(value)(func)
206205
setattr(cls, attr, func)
207206

208207
return cls

discord/utils/__init__.py

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,12 @@
2727

2828
import collections.abc
2929
import json
30-
from inspect import signature as _signature
3130
from typing import (
3231
TYPE_CHECKING,
3332
Any,
3433
AsyncIterator,
3534
Callable,
3635
Generic,
37-
Iterable,
3836
Iterator,
3937
Mapping,
4038
Protocol,
@@ -202,15 +200,6 @@ def count(self, value: Any) -> int:
202200
return self.__proxied.count(value)
203201

204202

205-
def copy_doc(original: Callable) -> Callable[[T], T]:
206-
def decorator(overridden: T) -> T:
207-
overridden.__doc__ = original.__doc__
208-
overridden.__signature__ = _signature(original) # type: ignore
209-
return overridden
210-
211-
return decorator
212-
213-
214203
async def get_or_fetch(obj, attr: str, id: int, *, default: Any = MISSING) -> Any:
215204
"""|coro|
216205

discord/utils/private.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import warnings
1212
from _bisect import bisect_left
1313
from base64 import b64encode
14-
from inspect import isawaitable
14+
from inspect import isawaitable, signature
1515
from typing import (
1616
TYPE_CHECKING,
1717
Any,
@@ -447,3 +447,12 @@ def get(self, element: int) -> int | None:
447447
def has(self, element: int) -> bool:
448448
i = bisect_left(self, element)
449449
return i != len(self) and self[i] == element
450+
451+
452+
def copy_doc(original: Callable) -> Callable[[T], T]:
453+
def decorator(overridden: T) -> T:
454+
overridden.__doc__ = original.__doc__
455+
overridden.__signature__ = signature(original) # type: ignore
456+
return overridden
457+
458+
return decorator

tests/test_utils.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
from discord.utils import (
3232
MISSING,
3333
_cached_property,
34-
copy_doc,
3534
find,
3635
generate_snowflake,
3736
get,

0 commit comments

Comments
 (0)