mirror of
https://github.com/Rapptz/discord.py.git
synced 2025-05-13 17:29:50 +00:00
Normalize type formatting in TypeError
Normalize most mixed usages of `__class__`, `__class__!r`, `__class__.__name__!r` to the standard form of `__class__.__name__`
This commit is contained in:
parent
9398971705
commit
6981eb69c4
@ -1513,7 +1513,7 @@ class Messageable:
|
|||||||
reference_dict = MISSING
|
reference_dict = MISSING
|
||||||
|
|
||||||
if view and not hasattr(view, '__discord_ui_view__'):
|
if view and not hasattr(view, '__discord_ui_view__'):
|
||||||
raise TypeError(f'view parameter must be View not {view.__class__!r}')
|
raise TypeError(f'view parameter must be View not {view.__class__.__name__}')
|
||||||
|
|
||||||
if suppress_embeds:
|
if suppress_embeds:
|
||||||
from .message import MessageFlags # circular import
|
from .message import MessageFlags # circular import
|
||||||
|
@ -1850,7 +1850,7 @@ class Group:
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
if not isinstance(command, (Command, Group)):
|
if not isinstance(command, (Command, Group)):
|
||||||
raise TypeError(f'expected Command or Group not {command.__class__!r}')
|
raise TypeError(f'expected Command or Group not {command.__class__.__name__}')
|
||||||
|
|
||||||
if isinstance(command, Group) and self.parent is not None:
|
if isinstance(command, Group) and self.parent is not None:
|
||||||
# In a tree like so:
|
# In a tree like so:
|
||||||
|
@ -468,7 +468,7 @@ class Choice(Generic[ChoiceT]):
|
|||||||
return AppCommandOptionType.string
|
return AppCommandOptionType.string
|
||||||
else:
|
else:
|
||||||
raise TypeError(
|
raise TypeError(
|
||||||
f'invalid Choice value type given, expected int, str, or float but received {self.value.__class__!r}'
|
f'invalid Choice value type given, expected int, str, or float but received {self.value.__class__.__name__}'
|
||||||
)
|
)
|
||||||
|
|
||||||
async def get_translated_payload(self, translator: Translator) -> Dict[str, Any]:
|
async def get_translated_payload(self, translator: Translator) -> Dict[str, Any]:
|
||||||
|
@ -528,7 +528,7 @@ else:
|
|||||||
|
|
||||||
def __class_getitem__(cls, items) -> _TransformMetadata:
|
def __class_getitem__(cls, items) -> _TransformMetadata:
|
||||||
if not isinstance(items, tuple):
|
if not isinstance(items, tuple):
|
||||||
raise TypeError(f'expected tuple for arguments, received {items.__class__!r} instead')
|
raise TypeError(f'expected tuple for arguments, received {items.__class__.__name__} instead')
|
||||||
|
|
||||||
if len(items) != 2:
|
if len(items) != 2:
|
||||||
raise TypeError(f'Transform only accepts exactly two arguments')
|
raise TypeError(f'Transform only accepts exactly two arguments')
|
||||||
@ -540,7 +540,7 @@ else:
|
|||||||
raise TypeError(f'second argument of Transform must be a Transformer class not {transformer!r}')
|
raise TypeError(f'second argument of Transform must be a Transformer class not {transformer!r}')
|
||||||
transformer = transformer()
|
transformer = transformer()
|
||||||
elif not isinstance(transformer, Transformer):
|
elif not isinstance(transformer, Transformer):
|
||||||
raise TypeError(f'second argument of Transform must be a Transformer not {transformer.__class__!r}')
|
raise TypeError(f'second argument of Transform must be a Transformer not {transformer.__class__.__name__}')
|
||||||
|
|
||||||
return transformer
|
return transformer
|
||||||
|
|
||||||
@ -571,7 +571,7 @@ else:
|
|||||||
|
|
||||||
def __class_getitem__(cls, obj) -> _TransformMetadata:
|
def __class_getitem__(cls, obj) -> _TransformMetadata:
|
||||||
if not isinstance(obj, tuple):
|
if not isinstance(obj, tuple):
|
||||||
raise TypeError(f'expected tuple for arguments, received {obj.__class__!r} instead')
|
raise TypeError(f'expected tuple for arguments, received {obj.__class__.__name__} instead')
|
||||||
|
|
||||||
if len(obj) == 2:
|
if len(obj) == 2:
|
||||||
obj = (*obj, None)
|
obj = (*obj, None)
|
||||||
|
@ -346,7 +346,7 @@ class CommandTree(Generic[ClientT]):
|
|||||||
self._context_menus.update(current)
|
self._context_menus.update(current)
|
||||||
return
|
return
|
||||||
elif not isinstance(command, (Command, Group)):
|
elif not isinstance(command, (Command, Group)):
|
||||||
raise TypeError(f'Expected an application command, received {command.__class__!r} instead')
|
raise TypeError(f'Expected an application command, received {command.__class__.__name__} instead')
|
||||||
|
|
||||||
# todo: validate application command groups having children (required)
|
# todo: validate application command groups having children (required)
|
||||||
|
|
||||||
@ -1002,7 +1002,7 @@ class CommandTree(Generic[ClientT]):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
if translator is not None and not isinstance(translator, Translator):
|
if translator is not None and not isinstance(translator, Translator):
|
||||||
raise TypeError(f'expected None or Translator instance, received {translator.__class__!r} instead')
|
raise TypeError(f'expected None or Translator instance, received {translator.__class__.__name__} instead')
|
||||||
|
|
||||||
old_translator = self._state._translator
|
old_translator = self._state._translator
|
||||||
if old_translator is not None:
|
if old_translator is not None:
|
||||||
|
@ -2023,7 +2023,7 @@ class ForumTag(Hashable):
|
|||||||
elif isinstance(emoji, str):
|
elif isinstance(emoji, str):
|
||||||
self.emoji = PartialEmoji.from_str(emoji)
|
self.emoji = PartialEmoji.from_str(emoji)
|
||||||
else:
|
else:
|
||||||
raise TypeError(f'emoji must be a Emoji, PartialEmoji, or str not {emoji.__class__!r}')
|
raise TypeError(f'emoji must be a Emoji, PartialEmoji, or str not {emoji.__class__.__name__}')
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def from_data(cls, *, state: ConnectionState, data: ForumTagPayload) -> Self:
|
def from_data(cls, *, state: ConnectionState, data: ForumTagPayload) -> Self:
|
||||||
@ -2544,7 +2544,7 @@ class ForumChannel(discord.abc.GuildChannel, Hashable):
|
|||||||
sticker_ids: SnowflakeList = [s.id for s in stickers]
|
sticker_ids: SnowflakeList = [s.id for s in stickers]
|
||||||
|
|
||||||
if view and not hasattr(view, '__discord_ui_view__'):
|
if view and not hasattr(view, '__discord_ui_view__'):
|
||||||
raise TypeError(f'view parameter must be View not {view.__class__!r}')
|
raise TypeError(f'view parameter must be View not {view.__class__.__name__}')
|
||||||
|
|
||||||
if suppress_embeds:
|
if suppress_embeds:
|
||||||
from .message import MessageFlags # circular import
|
from .message import MessageFlags # circular import
|
||||||
|
@ -574,7 +574,7 @@ class Client:
|
|||||||
await self._async_setup_hook()
|
await self._async_setup_hook()
|
||||||
|
|
||||||
if not isinstance(token, str):
|
if not isinstance(token, str):
|
||||||
raise TypeError(f'expected token to be a str, received {token.__class__!r} instead')
|
raise TypeError(f'expected token to be a str, received {token.__class__.__name__} instead')
|
||||||
token = token.strip()
|
token = token.strip()
|
||||||
|
|
||||||
data = await self.http.static_login(token)
|
data = await self.http.static_login(token)
|
||||||
@ -888,7 +888,7 @@ class Client:
|
|||||||
if value is None or isinstance(value, AllowedMentions):
|
if value is None or isinstance(value, AllowedMentions):
|
||||||
self._connection.allowed_mentions = value
|
self._connection.allowed_mentions = value
|
||||||
else:
|
else:
|
||||||
raise TypeError(f'allowed_mentions must be AllowedMentions not {value.__class__!r}')
|
raise TypeError(f'allowed_mentions must be AllowedMentions not {value.__class__.__name__}')
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def intents(self) -> Intents:
|
def intents(self) -> Intents:
|
||||||
@ -1964,7 +1964,7 @@ class Client:
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
if not isinstance(view, View):
|
if not isinstance(view, View):
|
||||||
raise TypeError(f'expected an instance of View not {view.__class__!r}')
|
raise TypeError(f'expected an instance of View not {view.__class__.__name__}')
|
||||||
|
|
||||||
if not view.is_persistent():
|
if not view.is_persistent():
|
||||||
raise ValueError('View is not persistent. Items need to have a custom_id set and View must have no timeout')
|
raise ValueError('View is not persistent. Items need to have a custom_id set and View must have no timeout')
|
||||||
|
@ -383,7 +383,7 @@ class SelectOption:
|
|||||||
elif isinstance(value, _EmojiTag):
|
elif isinstance(value, _EmojiTag):
|
||||||
self._emoji = value._to_partial()
|
self._emoji = value._to_partial()
|
||||||
else:
|
else:
|
||||||
raise TypeError(f'expected str, Emoji, or PartialEmoji, received {value.__class__} instead')
|
raise TypeError(f'expected str, Emoji, or PartialEmoji, received {value.__class__.__name__} instead')
|
||||||
else:
|
else:
|
||||||
self._emoji = None
|
self._emoji = None
|
||||||
|
|
||||||
|
@ -189,7 +189,7 @@ class BotBase(GroupMixin[None]):
|
|||||||
raise TypeError('Both owner_id and owner_ids are set.')
|
raise TypeError('Both owner_id and owner_ids are set.')
|
||||||
|
|
||||||
if self.owner_ids and not isinstance(self.owner_ids, collections.abc.Collection):
|
if self.owner_ids and not isinstance(self.owner_ids, collections.abc.Collection):
|
||||||
raise TypeError(f'owner_ids must be a collection not {self.owner_ids.__class__!r}')
|
raise TypeError(f'owner_ids must be a collection not {self.owner_ids.__class__.__name__}')
|
||||||
|
|
||||||
if help_command is _default:
|
if help_command is _default:
|
||||||
self.help_command = DefaultHelpCommand()
|
self.help_command = DefaultHelpCommand()
|
||||||
|
@ -490,7 +490,7 @@ class Cog(metaclass=CogMeta):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
if name is not MISSING and not isinstance(name, str):
|
if name is not MISSING and not isinstance(name, str):
|
||||||
raise TypeError(f'Cog.listener expected str but received {name.__class__.__name__!r} instead.')
|
raise TypeError(f'Cog.listener expected str but received {name.__class__.__name__} instead.')
|
||||||
|
|
||||||
def decorator(func: FuncT) -> FuncT:
|
def decorator(func: FuncT) -> FuncT:
|
||||||
actual = func
|
actual = func
|
||||||
|
@ -1117,7 +1117,7 @@ else:
|
|||||||
|
|
||||||
def __class_getitem__(cls, obj) -> Range:
|
def __class_getitem__(cls, obj) -> Range:
|
||||||
if not isinstance(obj, tuple):
|
if not isinstance(obj, tuple):
|
||||||
raise TypeError(f'expected tuple for arguments, received {obj.__class__!r} instead')
|
raise TypeError(f'expected tuple for arguments, received {obj.__class__.__name__} instead')
|
||||||
|
|
||||||
if len(obj) == 2:
|
if len(obj) == 2:
|
||||||
obj = (*obj, None)
|
obj = (*obj, None)
|
||||||
|
@ -559,7 +559,7 @@ class Loop(Generic[LF]):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
if not inspect.iscoroutinefunction(coro):
|
if not inspect.iscoroutinefunction(coro):
|
||||||
raise TypeError(f'Expected coroutine function, received {coro.__class__.__name__!r}.')
|
raise TypeError(f'Expected coroutine function, received {coro.__class__.__name__}.')
|
||||||
|
|
||||||
self._before_loop = coro
|
self._before_loop = coro
|
||||||
return coro
|
return coro
|
||||||
@ -587,7 +587,7 @@ class Loop(Generic[LF]):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
if not inspect.iscoroutinefunction(coro):
|
if not inspect.iscoroutinefunction(coro):
|
||||||
raise TypeError(f'Expected coroutine function, received {coro.__class__.__name__!r}.')
|
raise TypeError(f'Expected coroutine function, received {coro.__class__.__name__}.')
|
||||||
|
|
||||||
self._after_loop = coro
|
self._after_loop = coro
|
||||||
return coro
|
return coro
|
||||||
@ -617,7 +617,7 @@ class Loop(Generic[LF]):
|
|||||||
The function was not a coroutine.
|
The function was not a coroutine.
|
||||||
"""
|
"""
|
||||||
if not inspect.iscoroutinefunction(coro):
|
if not inspect.iscoroutinefunction(coro):
|
||||||
raise TypeError(f'Expected coroutine function, received {coro.__class__.__name__!r}.')
|
raise TypeError(f'Expected coroutine function, received {coro.__class__.__name__}.')
|
||||||
|
|
||||||
self._error = coro
|
self._error = coro
|
||||||
return coro
|
return coro
|
||||||
|
@ -2902,7 +2902,8 @@ class Guild(Hashable):
|
|||||||
_entity_type = getattr(channel, '_scheduled_event_entity_type', MISSING)
|
_entity_type = getattr(channel, '_scheduled_event_entity_type', MISSING)
|
||||||
if _entity_type is None:
|
if _entity_type is None:
|
||||||
raise TypeError(
|
raise TypeError(
|
||||||
f'invalid GuildChannel type passed, must be VoiceChannel or StageChannel not {channel.__class__!r}'
|
'invalid GuildChannel type passed, must be VoiceChannel or StageChannel '
|
||||||
|
f'not {channel.__class__.__name__}'
|
||||||
)
|
)
|
||||||
if _entity_type is MISSING:
|
if _entity_type is MISSING:
|
||||||
raise TypeError('entity_type must be passed in when passing an ambiguous channel type')
|
raise TypeError('entity_type must be passed in when passing an ambiguous channel type')
|
||||||
|
@ -272,7 +272,7 @@ def _set_api_version(value: int):
|
|||||||
global INTERNAL_API_VERSION
|
global INTERNAL_API_VERSION
|
||||||
|
|
||||||
if not isinstance(value, int):
|
if not isinstance(value, int):
|
||||||
raise TypeError(f'expected int not {value.__class__!r}')
|
raise TypeError(f'expected int not {value.__class__.__name__}')
|
||||||
|
|
||||||
if value not in (9, 10):
|
if value not in (9, 10):
|
||||||
raise ValueError(f'expected either 9 or 10 not {value}')
|
raise ValueError(f'expected either 9 or 10 not {value}')
|
||||||
|
@ -976,7 +976,7 @@ class Member(discord.abc.Messageable, _UserTag):
|
|||||||
elif isinstance(until, datetime.datetime):
|
elif isinstance(until, datetime.datetime):
|
||||||
timed_out_until = until
|
timed_out_until = until
|
||||||
else:
|
else:
|
||||||
raise TypeError(f'expected None, datetime.datetime, or datetime.timedelta not {until.__class__!r}')
|
raise TypeError(f'expected None, datetime.datetime, or datetime.timedelta not {until.__class__.__name__}')
|
||||||
|
|
||||||
await self.edit(timed_out_until=timed_out_until, reason=reason)
|
await self.edit(timed_out_until=timed_out_until, reason=reason)
|
||||||
|
|
||||||
|
@ -94,7 +94,7 @@ class Object(Hashable):
|
|||||||
try:
|
try:
|
||||||
id = int(id)
|
id = int(id)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
raise TypeError(f'id parameter must be convertible to int not {id.__class__!r}') from None
|
raise TypeError(f'id parameter must be convertible to int not {id.__class__.__name__}') from None
|
||||||
self.id: int = id
|
self.id: int = id
|
||||||
self.type: Type[abc.Snowflake] = type or self.__class__
|
self.type: Type[abc.Snowflake] = type or self.__class__
|
||||||
|
|
||||||
|
@ -414,7 +414,7 @@ class ScheduledEvent(Hashable):
|
|||||||
entity_type = entity_type or getattr(channel, '_scheduled_event_entity_type', MISSING)
|
entity_type = entity_type or getattr(channel, '_scheduled_event_entity_type', MISSING)
|
||||||
if entity_type is None:
|
if entity_type is None:
|
||||||
raise TypeError(
|
raise TypeError(
|
||||||
f'invalid GuildChannel type passed, must be VoiceChannel or StageChannel not {channel.__class__!r}'
|
f'invalid GuildChannel type passed, must be VoiceChannel or StageChannel not {channel.__class__.__name__}'
|
||||||
)
|
)
|
||||||
|
|
||||||
if entity_type is not MISSING:
|
if entity_type is not MISSING:
|
||||||
|
@ -106,7 +106,7 @@ class Button(Item[V]):
|
|||||||
custom_id = os.urandom(16).hex()
|
custom_id = os.urandom(16).hex()
|
||||||
|
|
||||||
if custom_id is not None and not isinstance(custom_id, str):
|
if custom_id is not None and not isinstance(custom_id, str):
|
||||||
raise TypeError(f'expected custom_id to be str not {custom_id.__class__!r}')
|
raise TypeError(f'expected custom_id to be str not {custom_id.__class__.__name__}')
|
||||||
|
|
||||||
if url is not None:
|
if url is not None:
|
||||||
style = ButtonStyle.link
|
style = ButtonStyle.link
|
||||||
@ -117,7 +117,7 @@ class Button(Item[V]):
|
|||||||
elif isinstance(emoji, _EmojiTag):
|
elif isinstance(emoji, _EmojiTag):
|
||||||
emoji = emoji._to_partial()
|
emoji = emoji._to_partial()
|
||||||
else:
|
else:
|
||||||
raise TypeError(f'expected emoji to be str, Emoji, or PartialEmoji not {emoji.__class__}')
|
raise TypeError(f'expected emoji to be str, Emoji, or PartialEmoji not {emoji.__class__.__name__}')
|
||||||
|
|
||||||
self._underlying = ButtonComponent._raw_construct(
|
self._underlying = ButtonComponent._raw_construct(
|
||||||
custom_id=custom_id,
|
custom_id=custom_id,
|
||||||
@ -196,7 +196,7 @@ class Button(Item[V]):
|
|||||||
elif isinstance(value, _EmojiTag):
|
elif isinstance(value, _EmojiTag):
|
||||||
self._underlying.emoji = value._to_partial()
|
self._underlying.emoji = value._to_partial()
|
||||||
else:
|
else:
|
||||||
raise TypeError(f'expected str, Emoji, or PartialEmoji, received {value.__class__} instead')
|
raise TypeError(f'expected str, Emoji, or PartialEmoji, received {value.__class__.__name__} instead')
|
||||||
else:
|
else:
|
||||||
self._underlying.emoji = None
|
self._underlying.emoji = None
|
||||||
|
|
||||||
|
@ -114,7 +114,7 @@ class Select(Item[V]):
|
|||||||
self._provided_custom_id = custom_id is not MISSING
|
self._provided_custom_id = custom_id is not MISSING
|
||||||
custom_id = os.urandom(16).hex() if custom_id is MISSING else custom_id
|
custom_id = os.urandom(16).hex() if custom_id is MISSING else custom_id
|
||||||
if not isinstance(custom_id, str):
|
if not isinstance(custom_id, str):
|
||||||
raise TypeError(f'expected custom_id to be str not {custom_id.__class__!r}')
|
raise TypeError(f'expected custom_id to be str not {custom_id.__class__.__name__}')
|
||||||
|
|
||||||
options = [] if options is MISSING else options
|
options = [] if options is MISSING else options
|
||||||
self._underlying = SelectMenu._raw_construct(
|
self._underlying = SelectMenu._raw_construct(
|
||||||
|
@ -111,7 +111,7 @@ class TextInput(Item[V]):
|
|||||||
self._provided_custom_id = custom_id is not MISSING
|
self._provided_custom_id = custom_id is not MISSING
|
||||||
custom_id = os.urandom(16).hex() if custom_id is MISSING else custom_id
|
custom_id = os.urandom(16).hex() if custom_id is MISSING else custom_id
|
||||||
if not isinstance(custom_id, str):
|
if not isinstance(custom_id, str):
|
||||||
raise TypeError(f'expected custom_id to be str not {custom_id.__class__!r}')
|
raise TypeError(f'expected custom_id to be str not {custom_id.__class__.__name__}')
|
||||||
|
|
||||||
self._underlying = TextInputComponent._raw_construct(
|
self._underlying = TextInputComponent._raw_construct(
|
||||||
label=label,
|
label=label,
|
||||||
|
@ -319,7 +319,7 @@ class View:
|
|||||||
raise ValueError('maximum number of children exceeded')
|
raise ValueError('maximum number of children exceeded')
|
||||||
|
|
||||||
if not isinstance(item, Item):
|
if not isinstance(item, Item):
|
||||||
raise TypeError(f'expected Item not {item.__class__!r}')
|
raise TypeError(f'expected Item not {item.__class__.__name__}')
|
||||||
|
|
||||||
self.__weights.add_item(item)
|
self.__weights.add_item(item)
|
||||||
|
|
||||||
|
@ -1694,7 +1694,7 @@ class Webhook(BaseWebhook):
|
|||||||
raise ValueError('Webhook views require an associated state with the webhook')
|
raise ValueError('Webhook views require an associated state with the webhook')
|
||||||
|
|
||||||
if not hasattr(view, '__discord_ui_view__'):
|
if not hasattr(view, '__discord_ui_view__'):
|
||||||
raise TypeError(f'expected view parameter to be of type View not {view.__class__!r}')
|
raise TypeError(f'expected view parameter to be of type View not {view.__class__.__name__}')
|
||||||
|
|
||||||
if ephemeral is True and view.timeout is None:
|
if ephemeral is True and view.timeout is None:
|
||||||
view.timeout = 15 * 60.0
|
view.timeout = 15 * 60.0
|
||||||
|
@ -649,7 +649,7 @@ class SyncWebhook(BaseWebhook):
|
|||||||
|
|
||||||
if session is not MISSING:
|
if session is not MISSING:
|
||||||
if not isinstance(session, requests.Session):
|
if not isinstance(session, requests.Session):
|
||||||
raise TypeError(f'expected requests.Session not {session.__class__!r}')
|
raise TypeError(f'expected requests.Session not {session.__class__.__name__}')
|
||||||
else:
|
else:
|
||||||
session = requests # type: ignore
|
session = requests # type: ignore
|
||||||
return cls(data, session, token=bot_token)
|
return cls(data, session, token=bot_token)
|
||||||
@ -692,7 +692,7 @@ class SyncWebhook(BaseWebhook):
|
|||||||
|
|
||||||
if session is not MISSING:
|
if session is not MISSING:
|
||||||
if not isinstance(session, requests.Session):
|
if not isinstance(session, requests.Session):
|
||||||
raise TypeError(f'expected requests.Session not {session.__class__!r}')
|
raise TypeError(f'expected requests.Session not {session.__class__.__name__}')
|
||||||
else:
|
else:
|
||||||
session = requests # type: ignore
|
session = requests # type: ignore
|
||||||
return cls(data, session, token=bot_token) # type: ignore
|
return cls(data, session, token=bot_token) # type: ignore
|
||||||
|
Loading…
x
Reference in New Issue
Block a user