Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fixes enum to support stringified annotations #2367

Merged
merged 1 commit into from
Feb 28, 2024
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: 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
16 changes: 10 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,14 @@ 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
Loading