Browse Source

[docs] copy signature from overridden and inherited methods

pull/6589/head
Sebastian Law 4 years ago
committed by GitHub
parent
commit
d6501159e7
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 21
      discord/channel.py
  2. 3
      discord/ext/commands/context.py
  3. 2
      discord/member.py
  4. 9
      discord/utils.py

21
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|

3
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__

2
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

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

Loading…
Cancel
Save