Skip to content

Commit

Permalink
fix: fixes enum to support stringified annotations
Browse files Browse the repository at this point in the history
fixes #2359
  • Loading branch information
jab416171 committed Feb 28, 2024
1 parent 8984b86 commit af4af89
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,8 @@ These changes are available on the `master` branch, but have not yet been releas
creation. ([#1296](https://github.com/Pycord-Development/pycord/issues/1296))
- Fixed keyword argument wildcard of `bridge.has_permissions` having the wrong type
hint. ([#2364](https://github.com/Pycord-Development/pycord/pull/2364))
- Fixed enum to support stringified annotations.
([#2367](https://github.com/Pycord-Development/pycord/pull/2367))

## [2.4.1] - 2023-03-20

Expand Down
17 changes: 11 additions & 6 deletions discord/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -800,9 +800,13 @@ def from_datatype(cls, datatype):
# Type checking fails for this case, so ignore it.
return cls.from_datatype(datatype.__args__) # type: ignore

if datatype.__name__ in ["Member", "User"]:
if isinstance(datatype, str):
datatype_name = datatype
else:
datatype_name = datatype.__name__
if datatype_name in ["Member", "User"]:
return cls.user
if datatype.__name__ in [
if datatype_name in [
"GuildChannel",
"TextChannel",
"VoiceChannel",
Expand All @@ -814,14 +818,15 @@ def from_datatype(cls, datatype):
"DMChannel",
]:
return cls.channel
if datatype.__name__ == "Role":
if datatype_name == "Role":
return cls.role
if datatype.__name__ == "Attachment":
if datatype_name == "Attachment":
return cls.attachment
if datatype.__name__ == "Mentionable":
if datatype_name == "Mentionable":
return cls.mentionable

if issubclass(datatype, str):

if isinstance(datatype, str) or issubclass(datatype, str):
return cls.string
if issubclass(datatype, bool):
return cls.boolean
Expand Down

0 comments on commit af4af89

Please sign in to comment.