From d6501159e7b765a526c94b4d83524c127ad4b22f Mon Sep 17 00:00:00 2001 From: Sebastian Law <44045823+SebbyLaw@users.noreply.github.com> Date: Mon, 29 Mar 2021 20:52:14 -0700 Subject: [PATCH] [docs] copy signature from overridden and inherited methods --- discord/channel.py | 21 +++++++-------------- discord/ext/commands/context.py | 3 +-- discord/member.py | 2 +- discord/utils.py | 9 ++++++++- 4 files changed, 17 insertions(+), 18 deletions(-) diff --git a/discord/channel.py b/discord/channel.py index 7a5b95482..e63709d6f 100644 --- a/discord/channel.py +++ b/discord/channel.py @@ -141,6 +141,7 @@ class TextChannel(discord.abc.Messageable, discord.abc.GuildChannel, Hashable): def _sorting_bucket(self): return ChannelType.text.value + @utils.copy_doc(discord.abc.GuildChannel.permissions_for) def permissions_for(self, member): base = super().permissions_for(member) @@ -149,8 +150,6 @@ class TextChannel(discord.abc.Messageable, discord.abc.GuildChannel, Hashable): base.value &= ~denied.value return base - permissions_for.__doc__ = discord.abc.GuildChannel.permissions_for.__doc__ - @property def members(self): """List[:class:`Member`]: Returns all members that can see this channel.""" @@ -240,6 +239,7 @@ class TextChannel(discord.abc.Messageable, discord.abc.GuildChannel, Hashable): """ await self._edit(options, reason=reason) + @utils.copy_doc(discord.abc.GuildChannel.clone) async def clone(self, *, name=None, reason=None): return await self._clone_impl({ 'topic': self.topic, @@ -247,8 +247,6 @@ class TextChannel(discord.abc.Messageable, discord.abc.GuildChannel, Hashable): 'rate_limit_per_user': self.slowmode_delay }, name=name, reason=reason) - clone.__doc__ = discord.abc.GuildChannel.clone.__doc__ - async def delete_messages(self, messages): """|coro| @@ -651,6 +649,7 @@ class VoiceChannel(discord.abc.Connectable, discord.abc.GuildChannel, Hashable): """ return {key: value for key, value in self.guild._voice_states.items() if value.channel.id == self.id} + @utils.copy_doc(discord.abc.GuildChannel.permissions_for) def permissions_for(self, member): base = super().permissions_for(member) @@ -662,16 +661,13 @@ class VoiceChannel(discord.abc.Connectable, discord.abc.GuildChannel, Hashable): base.value &= ~denied.value return base - permissions_for.__doc__ = discord.abc.GuildChannel.permissions_for.__doc__ - + @utils.copy_doc(discord.abc.GuildChannel.clone) async def clone(self, *, name=None, reason=None): return await self._clone_impl({ 'bitrate': self.bitrate, 'user_limit': self.user_limit }, name=name, reason=reason) - clone.__doc__ = discord.abc.GuildChannel.clone.__doc__ - async def edit(self, *, reason=None, **options): """|coro| @@ -784,13 +780,12 @@ class CategoryChannel(discord.abc.GuildChannel, Hashable): """:class:`bool`: Checks if the category is NSFW.""" return self.nsfw + @utils.copy_doc(discord.abc.GuildChannel.clone) async def clone(self, *, name=None, reason=None): return await self._clone_impl({ 'nsfw': self.nsfw }, name=name, reason=reason) - clone.__doc__ = discord.abc.GuildChannel.clone.__doc__ - async def edit(self, *, reason=None, **options): """|coro| @@ -946,6 +941,7 @@ class StoreChannel(discord.abc.GuildChannel, Hashable): """:class:`ChannelType`: The channel's Discord type.""" return ChannelType.store + @utils.copy_doc(discord.abc.GuildChannel.permissions_for) def permissions_for(self, member): base = super().permissions_for(member) @@ -954,19 +950,16 @@ class StoreChannel(discord.abc.GuildChannel, Hashable): base.value &= ~denied.value return base - permissions_for.__doc__ = discord.abc.GuildChannel.permissions_for.__doc__ - def is_nsfw(self): """:class:`bool`: Checks if the channel is NSFW.""" return self.nsfw + @utils.copy_doc(discord.abc.GuildChannel.clone) async def clone(self, *, name=None, reason=None): return await self._clone_impl({ 'nsfw': self.nsfw }, name=name, reason=reason) - clone.__doc__ = discord.abc.GuildChannel.clone.__doc__ - async def edit(self, *, reason=None, **options): """|coro| diff --git a/discord/ext/commands/context.py b/discord/ext/commands/context.py index 39e5d5cd2..8df4f7301 100644 --- a/discord/ext/commands/context.py +++ b/discord/ext/commands/context.py @@ -335,7 +335,6 @@ class Context(discord.abc.Messageable): except CommandError as e: await cmd.on_help_command_error(self, e) + @discord.utils.copy_doc(discord.Message.reply) async def reply(self, content=None, **kwargs): return await self.message.reply(content, **kwargs) - - reply.__doc__ = discord.Message.reply.__doc__ diff --git a/discord/member.py b/discord/member.py index 0b6ef3237..a72e9945f 100644 --- a/discord/member.py +++ b/discord/member.py @@ -119,7 +119,7 @@ def flatten_user(cls): return general func = generate_function(attr) - func.__doc__ = value.__doc__ + func = utils.copy_doc(value)(func) setattr(cls, attr, func) return cls diff --git a/discord/utils.py b/discord/utils.py index 8049eb46c..b15f1c7b3 100644 --- a/discord/utils.py +++ b/discord/utils.py @@ -32,7 +32,7 @@ from base64 import b64encode from bisect import bisect_left import datetime import functools -from inspect import isawaitable as _isawaitable +from inspect import isawaitable as _isawaitable, signature as _signature from operator import attrgetter import json import re @@ -110,6 +110,13 @@ def parse_time(timestamp): return datetime.datetime(*map(int, re.split(r'[^\d]', timestamp.replace('+00:00', '')))) return None +def copy_doc(original): + def decorator(overriden): + overriden.__doc__ = original.__doc__ + overriden.__signature__ = _signature(original) + return overriden + return decorator + def deprecated(instead=None): def actual_decorator(func): @functools.wraps(func)