Skip to content
Merged
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
20 changes: 12 additions & 8 deletions discord/commands/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -372,19 +372,23 @@ def _strip_none_type(input_type):
if input_type is type(None):
raise TypeError("Option type cannot be only NoneType")

if isinstance(input_type, (types.UnionType, tuple)):
args = (
get_args(input_type)
if isinstance(input_type, types.UnionType)
else input_type
)
args = ()
if isinstance(input_type, types.UnionType):
args = get_args(input_type)
elif getattr(input_type, "__origin__", None) is Union:
args = get_args(input_type)
elif isinstance(input_type, tuple):
args = input_type

if args:
filtered = tuple(t for t in args if t is not type(None))
if not filtered:
raise TypeError("Option type cannot be only NoneType")
if len(filtered) == 1:
return filtered[0]
return filtered

if all(getattr(t, "__origin__", None) is Literal for t in filtered):
return Union[filtered]
return Union[filtered]
return input_type

def to_dict(self) -> dict:
Expand Down
Loading