Add typechecking to config from_id methods (#5564)

* [config] Add typechecking for parameters

* change instance check

* Knew it, shouldnt have added these

* black
This commit is contained in:
crayyy_zee 2022-02-21 01:50:07 +05:00 committed by GitHub
parent b0ab6186ef
commit 8d46568180
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -958,7 +958,13 @@ class Config(metaclass=ConfigMeta):
`Group <redbot.core.config.Group>` `Group <redbot.core.config.Group>`
The guild's Group object. The guild's Group object.
Raises
------
TypeError
If the given guild_id parameter is not of type int
""" """
if type(guild_id) is not int:
raise TypeError(f"guild_id should be of type int, not {guild_id.__class__.__name__}")
return self._get_base_group(self.GUILD, str(guild_id)) return self._get_base_group(self.GUILD, str(guild_id))
def guild(self, guild: discord.Guild) -> Group: def guild(self, guild: discord.Guild) -> Group:
@ -992,7 +998,15 @@ class Config(metaclass=ConfigMeta):
`Group <redbot.core.config.Group>` `Group <redbot.core.config.Group>`
The channel's Group object. The channel's Group object.
Raises
------
TypeError
If the given channel_id parameter is not of type int
""" """
if type(channel_id) is not int:
raise TypeError(
f"channel_id should be of type int, not {channel_id.__class__.__name__}"
)
return self._get_base_group(self.CHANNEL, str(channel_id)) return self._get_base_group(self.CHANNEL, str(channel_id))
def channel(self, channel: discord.abc.GuildChannel) -> Group: def channel(self, channel: discord.abc.GuildChannel) -> Group:
@ -1026,7 +1040,13 @@ class Config(metaclass=ConfigMeta):
`Group <redbot.core.config.Group>` `Group <redbot.core.config.Group>`
The role's Group object. The role's Group object.
Raises
------
TypeError
If the given role_id parameter is not of type int
""" """
if type(role_id) is not int:
raise TypeError(f"role_id should be of type int, not {role_id.__class__.__name__}")
return self._get_base_group(self.ROLE, str(role_id)) return self._get_base_group(self.ROLE, str(role_id))
def role(self, role: discord.Role) -> Group: def role(self, role: discord.Role) -> Group:
@ -1058,7 +1078,13 @@ class Config(metaclass=ConfigMeta):
`Group <redbot.core.config.Group>` `Group <redbot.core.config.Group>`
The user's Group object. The user's Group object.
Raises
------
TypeError
If the given user_id parameter is not of type int
""" """
if type(user_id) is not int:
raise TypeError(f"user_id should be of type int, not {user_id.__class__.__name__}")
return self._get_base_group(self.USER, str(user_id)) return self._get_base_group(self.USER, str(user_id))
def user(self, user: discord.abc.User) -> Group: def user(self, user: discord.abc.User) -> Group:
@ -1092,7 +1118,17 @@ class Config(metaclass=ConfigMeta):
`Group <redbot.core.config.Group>` `Group <redbot.core.config.Group>`
The member's Group object. The member's Group object.
Raises
------
TypeError
If the given guild_id or member_id parameter is not of type int
""" """
if type(guild_id) is not int:
raise TypeError(f"guild_id should be of type int, not {guild_id.__class__.__name__}")
if type(member_id) is not int:
raise TypeError(f"member_id should be of type int, not {member_id.__class__.__name__}")
return self._get_base_group(self.MEMBER, str(guild_id), str(member_id)) return self._get_base_group(self.MEMBER, str(guild_id), str(member_id))
def member(self, member: discord.Member) -> Group: def member(self, member: discord.Member) -> Group: