diff --git a/disnake/app_commands.py b/disnake/app_commands.py index fde7387012..9d1e9d1373 100644 --- a/disnake/app_commands.py +++ b/disnake/app_commands.py @@ -650,7 +650,7 @@ def dm_permission(self, value: bool) -> None: def __repr__(self) -> str: attrs = " ".join(f"{key}={getattr(self, key)!r}" for key in self.__repr_attributes__) - return f"<{type(self).__name__} {attrs}>" + return f"<{self.__class__.__name__} {attrs}>" def __str__(self) -> str: return self.name diff --git a/disnake/automod.py b/disnake/automod.py index e43189c1b3..4326715ee8 100644 --- a/disnake/automod.py +++ b/disnake/automod.py @@ -90,7 +90,7 @@ def __init__( self._metadata: AutoModActionMetadata = {} def __repr__(self) -> str: - return f"<{type(self).__name__} type={self.type!r}>" + return f"<{self.__class__.__name__} type={self.type!r}>" @classmethod def _from_dict(cls, data: AutoModActionPayload) -> Self: @@ -150,7 +150,7 @@ def custom_message(self) -> str | None: return self._metadata.get("custom_message") def __repr__(self) -> str: - return f"<{type(self).__name__} custom_message={self.custom_message!r}>" + return f"<{self.__class__.__name__} custom_message={self.custom_message!r}>" class AutoModSendAlertAction(AutoModAction): @@ -188,7 +188,7 @@ def channel_id(self) -> int: return int(self._metadata["channel_id"]) def __repr__(self) -> str: - return f"<{type(self).__name__} channel_id={self.channel_id!r}>" + return f"<{self.__class__.__name__} channel_id={self.channel_id!r}>" class AutoModTimeoutAction(AutoModAction): @@ -230,7 +230,7 @@ def duration(self) -> int: return self._metadata["duration_seconds"] def __repr__(self) -> str: - return f"<{type(self).__name__} duration={self.duration!r}>" + return f"<{self.__class__.__name__} duration={self.duration!r}>" class AutoModBlockInteractionAction(AutoModAction): @@ -439,7 +439,7 @@ def to_dict(self) -> AutoModTriggerMetadataPayload: return data def __repr__(self) -> str: - s = f"<{type(self).__name__}" + s = f"<{self.__class__.__name__}" if self.keyword_filter is not None: s += f" keyword_filter={self.keyword_filter!r}" if self.regex_patterns is not None: @@ -791,7 +791,7 @@ def __init__(self, *, data: AutoModerationActionExecutionEvent, guild: Guild) -> def __repr__(self) -> str: return ( - f"<{type(self).__name__} guild={self.guild!r} action={self.action!r}" + f"<{self.__class__.__name__} guild={self.guild!r} action={self.action!r}" f" rule_id={self.rule_id!r} rule_trigger_type={self.rule_trigger_type!r}" f" channel={self.channel!r} user_id={self.user_id!r} message_id={self.message_id!r}" f" alert_message_id={self.alert_message_id!r} content={self.content!r}" diff --git a/disnake/channel.py b/disnake/channel.py index b2667c58aa..3f8f2372cb 100644 --- a/disnake/channel.py +++ b/disnake/channel.py @@ -3402,7 +3402,7 @@ def __repr__(self) -> str: ("flags", self.flags), ) joined = " ".join(f"{k!s}={v!r}" for k, v in attrs) - return f"<{type(self).__name__} {joined}>" + return f"<{self.__class__.__name__} {joined}>" def _update(self, guild: Guild, data: ForumChannelPayload | MediaChannelPayload) -> None: self.guild: Guild = guild diff --git a/disnake/client.py b/disnake/client.py index 5c9229573e..fc2baa20a4 100644 --- a/disnake/client.py +++ b/disnake/client.py @@ -1038,7 +1038,7 @@ async def login(self, token: str) -> None: """ _log.info("logging in using static token") if not isinstance(token, str): - msg = f"token must be of type str, got {type(token).__name__} instead" + msg = f"token must be of type str, got {token.__class__.__name__} instead" raise TypeError(msg) data = await self.http.static_login(token.strip()) diff --git a/disnake/components.py b/disnake/components.py index 0212b07c0b..3384e01ef5 100644 --- a/disnake/components.py +++ b/disnake/components.py @@ -1917,7 +1917,7 @@ def handle_media_item_input(value: MediaItemInput) -> UnfurledMediaItem: return UnfurledMediaItem(value.url) assert_never(value) - msg = f"{type(value).__name__} cannot be converted to UnfurledMediaItem" + msg = f"{value.__class__.__name__} cannot be converted to UnfurledMediaItem" raise TypeError(msg) diff --git a/disnake/embeds.py b/disnake/embeds.py index 126ab89c5b..257d15534c 100644 --- a/disnake/embeds.py +++ b/disnake/embeds.py @@ -336,7 +336,7 @@ def colour(self, value: int | Colour | None) -> None: elif value is MISSING or value is None or isinstance(value, Colour): self._colour = value else: - msg = f"Expected disnake.Colour, int, or None but received {type(value).__name__} instead." + msg = f"Expected disnake.Colour, int, or None, received {value.__class__.__name__} instead." raise TypeError(msg) @colour.deleter @@ -358,7 +358,9 @@ def timestamp(self, value: datetime.datetime | None) -> None: elif value is None: self._timestamp = value else: - msg = f"Expected datetime.datetime or None received {type(value).__name__} instead" + msg = ( + f"Expected datetime.datetime or None, received {value.__class__.__name__} instead." + ) raise TypeError(msg) @property @@ -845,7 +847,7 @@ def set_default_colour(cls, value: int | Colour | None) -> Colour | None: elif isinstance(value, int): cls._default_colour = Colour(value=value) else: - msg = f"Expected disnake.Colour, int, or None but received {type(value).__name__} instead." + msg = f"Expected disnake.Colour, int, or None, received {value.__class__.__name__} instead." raise TypeError(msg) return cls._default_colour diff --git a/disnake/ext/commands/interaction_bot_base.py b/disnake/ext/commands/interaction_bot_base.py index 64a4f83210..4df2017f4d 100644 --- a/disnake/ext/commands/interaction_bot_base.py +++ b/disnake/ext/commands/interaction_bot_base.py @@ -127,7 +127,7 @@ def _format_diff(diff: _Diff) -> str: continue lines.append(label) if changes := diff[key]: - lines.extend(f" <{type(cmd).__name__} name={cmd.name!r}>" for cmd in changes) + lines.extend(f" <{cmd.__class__.__name__} name={cmd.name!r}>" for cmd in changes) else: lines.append(" -") diff --git a/disnake/ext/commands/params.py b/disnake/ext/commands/params.py index 72f9d16b0d..1f3f16d4ce 100644 --- a/disnake/ext/commands/params.py +++ b/disnake/ext/commands/params.py @@ -329,7 +329,7 @@ def _coerce_bound(value: Any, name: str) -> int | float | None: def __repr__(self) -> str: a = "..." if self.min_value is None else self.min_value b = "..." if self.max_value is None else self.max_value - return f"{type(self).__name__}[{self.underlying_type.__name__}, {a}, {b}]" + return f"{self.__class__.__name__}[{self.underlying_type.__name__}, {a}, {b}]" @classmethod @abstractmethod @@ -610,7 +610,7 @@ def register_converter(cls, annotation: Any, converter: FuncT) -> FuncT: def __repr__(self) -> str: args = ", ".join(f"{k}={'...' if v is ... else repr(v)}" for k, v in vars(self).items()) - return f"{type(self).__name__}({args})" + return f"{self.__class__.__name__}({args})" async def get_default(self, inter: ApplicationCommandInteraction) -> Any: """Gets the default for an interaction""" diff --git a/disnake/ext/tasks/__init__.py b/disnake/ext/tasks/__init__.py index 687b4d8780..c917ddd95d 100644 --- a/disnake/ext/tasks/__init__.py +++ b/disnake/ext/tasks/__init__.py @@ -87,6 +87,10 @@ def __init__( """.. note: If you overwrite ``__init__`` arguments, make sure to redefine .clone too. """ + if not inspect.iscoroutinefunction(coro): + msg = f"Expected a coroutine function, got {coro.__class__.__name__!r} instead." + raise TypeError(msg) + self.coro: LF = coro self.reconnect: bool = reconnect self.loop: asyncio.AbstractEventLoop = loop @@ -118,10 +122,6 @@ def __init__( self._last_iteration: datetime.datetime = MISSING self._next_iteration = None - if not inspect.iscoroutinefunction(self.coro): - msg = f"Expected coroutine function, not {type(self.coro).__name__!r}." - raise TypeError(msg) - async def _call_loop_function(self, name: str, *args: Any, **kwargs: Any) -> None: coro = getattr(self, "_" + name) if coro is None: @@ -623,7 +623,7 @@ def _get_time_parameter( ret: list[datetime.time] = [] for index, t in enumerate(time): if not isinstance(t, dt): - msg = f"Expected a sequence of {dt!r} for ``time``, received {type(t).__name__!r} at index {index} instead." + msg = f"Expected a sequence of {dt!r} for ``time``, received {t.__class__.__name__!r} at index {index} instead." raise TypeError(msg) ret.append(t if t.tzinfo is not None else t.replace(tzinfo=utc)) diff --git a/disnake/flags.py b/disnake/flags.py index 3dc3c84f97..e3ecc1f8ad 100644 --- a/disnake/flags.py +++ b/disnake/flags.py @@ -1091,7 +1091,7 @@ def __init__(self: NoReturn) -> None: ... def __init__(self, value: int | None = None, **kwargs: bool) -> None: if value is not None: if not isinstance(value, int): - msg = f"Expected int, received {type(value).__name__} for argument 'value'." + msg = f"Expected int, received {value.__class__.__name__} for parameter 'value'." raise TypeError(msg) if value < 0: msg = "Expected a non-negative value." diff --git a/disnake/guild.py b/disnake/guild.py index cada3bda8e..e1eb40d9a0 100644 --- a/disnake/guild.py +++ b/disnake/guild.py @@ -4228,7 +4228,7 @@ async def ban( else: msg = ( "`clean_history_duration` should be int or timedelta, " - f"not {type(clean_history_duration).__name__}" + f"not {clean_history_duration.__class__.__name__}" ) raise TypeError(msg) @@ -4317,7 +4317,7 @@ async def bulk_ban( else: msg = ( "`clean_history_duration` should be int or timedelta, " - f"not {type(clean_history_duration).__name__}" + f"not {clean_history_duration.__class__.__name__}" ) raise TypeError(msg) diff --git a/disnake/i18n.py b/disnake/i18n.py index 6e2bc98e5a..b8206719c1 100644 --- a/disnake/i18n.py +++ b/disnake/i18n.py @@ -179,7 +179,7 @@ def __init__(self, localizations: Localizations | None) -> None: self._key = None self._data = {str(k): v for k, v in localizations.items()} else: - msg = f"Invalid localizations type: {type(localizations).__name__}" + msg = f"Invalid localizations type: {localizations.__class__.__name__}" raise TypeError(msg) def _upgrade(self, key: str | None) -> None: diff --git a/disnake/player.py b/disnake/player.py index b757c2d052..279b3f60c2 100644 --- a/disnake/player.py +++ b/disnake/player.py @@ -663,9 +663,7 @@ class PCMVolumeTransformer(AudioSource, Generic[AT]): def __init__(self, original: AT, volume: float = 1.0) -> None: if not has_audioop: - msg = ( - f"audioop-lts library needed in Python >=3.13 in order to use {type(self).__name__}" - ) + msg = f"audioop-lts library needed in Python >=3.13 in order to use {self.__class__.__name__}" raise RuntimeError(msg) if not isinstance(original, AudioSource): diff --git a/disnake/raw_models.py b/disnake/raw_models.py index 6b2b011f5a..4a479a5e5b 100644 --- a/disnake/raw_models.py +++ b/disnake/raw_models.py @@ -59,7 +59,7 @@ class _RawReprMixin: def __repr__(self) -> str: value = " ".join(f"{attr}={getattr(self, attr)!r}" for attr in get_slots(type(self))) - return f"<{type(self).__name__} {value}>" + return f"<{self.__class__.__name__} {value}>" class RawMessageDeleteEvent(_RawReprMixin): diff --git a/disnake/ui/action_row.py b/disnake/ui/action_row.py index 70e099cc2f..d3841a6753 100644 --- a/disnake/ui/action_row.py +++ b/disnake/ui/action_row.py @@ -181,7 +181,7 @@ def __init__(self, *components: ActionRowChildDefaultT, id: int = 0) -> None: for component in components: if not isinstance(component, WrappedComponent): - msg = f"components should be of type WrappedComponent, got {type(component).__name__}." + msg = f"components should be of type WrappedComponent, got {component.__class__.__name__}." raise TypeError(msg) self.append_item(component) diff --git a/disnake/ui/container.py b/disnake/ui/container.py index 0e764fc7f9..c061920ca1 100644 --- a/disnake/ui/container.py +++ b/disnake/ui/container.py @@ -108,7 +108,7 @@ def accent_colour(self, value: int | Colour | None) -> None: elif value is None or isinstance(value, Colour): self._accent_colour = value else: - msg = f"Expected Colour, int, or None but received {type(value).__name__} instead." + msg = f"Expected Colour, int, or None, received {value.__class__.__name__} instead." raise TypeError(msg) accent_color = accent_colour diff --git a/disnake/ui/item.py b/disnake/ui/item.py index fc49f09b3f..6a080d69a6 100644 --- a/disnake/ui/item.py +++ b/disnake/ui/item.py @@ -41,7 +41,7 @@ def ensure_ui_component(obj: UIComponentT, name: str = "component") -> UIComponentT: if not isinstance(obj, UIComponent): - msg = f"{name} should be a valid UI component, got {type(obj).__name__}." + msg = f"{name} should be a valid UI component, got {obj.__class__.__name__}." raise TypeError(msg) return obj @@ -81,7 +81,7 @@ def __repr__(self) -> str: attrs = " ".join( f"{key.lstrip('_')}={getattr(self, key)!r}" for key in self.__repr_attributes__ ) - return f"<{type(self).__name__} {attrs}>" + return f"<{self.__class__.__name__} {attrs}>" @property def is_v2(self) -> bool: diff --git a/disnake/ui/view.py b/disnake/ui/view.py index 917cc77990..ab8d681298 100644 --- a/disnake/ui/view.py +++ b/disnake/ui/view.py @@ -228,7 +228,7 @@ def from_message(cls, message: Message, /, *, timeout: float | None = 180.0) -> continue if not isinstance(component, VALID_ACTION_ROW_MESSAGE_COMPONENT_TYPES): # can happen if message uses components v2 - msg = f"Cannot construct view from message - unexpected {type(component).__name__}" + msg = f"Cannot construct view from message - unexpected {component.__class__.__name__}" raise TypeError(msg) view.add_item(_component_to_item(component)) return view @@ -570,7 +570,7 @@ def update_from_message(self, message_id: int, components: Sequence[ComponentPay _log.warning( "cannot update view for message %d, unexpected %s", message_id, - type(row).__name__, + row.__class__.__name__, ) return diff --git a/tests/ui/test_components.py b/tests/ui/test_components.py index 167ac41661..b3634dddf2 100644 --- a/tests/ui/test_components.py +++ b/tests/ui/test_components.py @@ -42,7 +42,7 @@ @pytest.mark.parametrize( "obj", all_ui_component_objects, - ids=[type(o).__name__ for o in all_ui_component_objects], + ids=[o.__class__.__name__ for o in all_ui_component_objects], ) def test_id_property(obj: ui.UIComponent) -> None: assert obj.id == 0