Skip to content

Commit c7ccc02

Browse files
authored
refactor!: remove all unwanted __repr__ and __str__ (#1150)
1 parent a95e2b7 commit c7ccc02

File tree

6 files changed

+13
-14
lines changed

6 files changed

+13
-14
lines changed

docs/migration.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,3 +232,7 @@ your option name! Example:
232232
~~~~~~~~~~~~~~~
233233

234234
The ``Color`` class was refactored into an enum. You may now access its contents via ``interactions.Color.COLOR``.
235+
Due to `complaints <https://www.github.com/interactions-py/library/issues/1040>`_ on str and repr magic methods, we have
236+
decided to `remove all implementations of them in the model classes <https://www.github.com/interactions.py/library/pulls/1050>`_.
237+
This affects the way you can send emojis. You can no longer use ``str(emoji)`` or ``f"{emoji}"``.
238+
Instead you will have to use ``emoji.format`` or ``f"{emoji.format}"`` to transform an emoji into a send-able form.

interactions/api/models/channel.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -478,9 +478,6 @@ def __attrs_post_init__(self): # sourcery skip: last-if-guard
478478
if not self.recipients:
479479
self.recipients = channel.recipients
480480

481-
def __repr__(self) -> str:
482-
return self.name
483-
484481
@property
485482
def typing(self) -> Union[Awaitable, ContextManager]:
486483
"""

interactions/api/models/emoji.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
__all__ = ("Emoji",)
1313

1414

15-
@define(repr=False)
15+
@define()
1616
class Emoji(ClientSerializerMixin):
1717
"""
1818
A class objecting representing an emoji.
@@ -36,10 +36,17 @@ class Emoji(ClientSerializerMixin):
3636
animated: Optional[bool] = field(default=None)
3737
available: Optional[bool] = field(default=None)
3838

39-
def __repr__(self):
39+
@property
40+
def format(self) -> str:
41+
"""
42+
Formats the emoji into a send-able form.
43+
:rtype: str
44+
"""
4045
return (
4146
f"<{'a' if self.animated else ''}:{self.name}:{self.id}>"
4247
if self.id is not None
48+
else f":{self.name}:"
49+
if self.require_colons
4350
else self.name
4451
)
4552

interactions/api/models/guild.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -482,9 +482,6 @@ def __attrs_post_init__(self): # sourcery skip: last-if-guard
482482
if not member._extras.get("guild_id"):
483483
member._extras["guild_id"] = self.id
484484

485-
def __repr__(self) -> str:
486-
return self.name
487-
488485
async def ban(
489486
self,
490487
member_id: Union[int, Member, Snowflake],

interactions/api/models/member.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,6 @@ class Member(ClientSerializerMixin, IDMixin):
6666
) # TODO: Investigate what this is for when documented by Discord.
6767
flags: int = field(repr=False) # TODO: Investigate what this is for when documented by Discord.
6868

69-
def __str__(self) -> str:
70-
return self.name or ""
71-
7269
def __getattr__(self, name):
7370
# Forward any attributes the user has to make it easier for devs
7471
try:

interactions/api/models/user.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,6 @@ class User(ClientSerializerMixin, IDMixin):
5555
public_flags: Optional[UserFlags] = field(converter=UserFlags, default=None, repr=False)
5656
bio: Optional[str] = field(default=None)
5757

58-
def __str__(self) -> str:
59-
return self.username
60-
6158
def has_public_flag(self, flag: Union[UserFlags, int]) -> bool:
6259
if self.public_flags == 0 or self.public_flags is None:
6360
return False

0 commit comments

Comments
 (0)