Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion disnake/app_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 6 additions & 6 deletions disnake/automod.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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}"
Expand Down
2 changes: 1 addition & 1 deletion disnake/channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion disnake/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
2 changes: 1 addition & 1 deletion disnake/components.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand Down
8 changes: 5 additions & 3 deletions disnake/embeds.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion disnake/ext/commands/interaction_bot_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(" -")

Expand Down
4 changes: 2 additions & 2 deletions disnake/ext/commands/params.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"""
Expand Down
10 changes: 5 additions & 5 deletions disnake/ext/tasks/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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))

Expand Down
2 changes: 1 addition & 1 deletion disnake/flags.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."
Expand Down
4 changes: 2 additions & 2 deletions disnake/guild.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion disnake/i18n.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 1 addition & 3 deletions disnake/player.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion disnake/raw_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion disnake/ui/action_row.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion disnake/ui/container.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions disnake/ui/item.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions disnake/ui/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion tests/ui/test_components.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading