Skip to content

Commit 2276914

Browse files
authored
fix: fixes enum to support stringified annotations (#2367)
fixes #2359
1 parent 8984b86 commit 2276914

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,8 @@ These changes are available on the `master` branch, but have not yet been releas
241241
creation. ([#1296](https://github.com/Pycord-Development/pycord/issues/1296))
242242
- Fixed keyword argument wildcard of `bridge.has_permissions` having the wrong type
243243
hint. ([#2364](https://github.com/Pycord-Development/pycord/pull/2364))
244+
- Fixed enum to support stringified annotations.
245+
([#2367](https://github.com/Pycord-Development/pycord/pull/2367))
244246

245247
## [2.4.1] - 2023-03-20
246248

discord/enums.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -800,9 +800,13 @@ def from_datatype(cls, datatype):
800800
# Type checking fails for this case, so ignore it.
801801
return cls.from_datatype(datatype.__args__) # type: ignore
802802

803-
if datatype.__name__ in ["Member", "User"]:
803+
if isinstance(datatype, str):
804+
datatype_name = datatype
805+
else:
806+
datatype_name = datatype.__name__
807+
if datatype_name in ["Member", "User"]:
804808
return cls.user
805-
if datatype.__name__ in [
809+
if datatype_name in [
806810
"GuildChannel",
807811
"TextChannel",
808812
"VoiceChannel",
@@ -814,14 +818,14 @@ def from_datatype(cls, datatype):
814818
"DMChannel",
815819
]:
816820
return cls.channel
817-
if datatype.__name__ == "Role":
821+
if datatype_name == "Role":
818822
return cls.role
819-
if datatype.__name__ == "Attachment":
823+
if datatype_name == "Attachment":
820824
return cls.attachment
821-
if datatype.__name__ == "Mentionable":
825+
if datatype_name == "Mentionable":
822826
return cls.mentionable
823827

824-
if issubclass(datatype, str):
828+
if isinstance(datatype, str) or issubclass(datatype, str):
825829
return cls.string
826830
if issubclass(datatype, bool):
827831
return cls.boolean

0 commit comments

Comments
 (0)