Skip to content

Commit dd04586

Browse files
committed
fix(options): Improve input_type handling in Option class
1 parent c5cb487 commit dd04586

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

discord/commands/options.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -375,17 +375,21 @@ def _strip_none_type(input_type):
375375
if input_type is type(None):
376376
raise TypeError("Option type cannot be only NoneType")
377377

378-
if isinstance(input_type, (types.UnionType, tuple)):
379-
args = (
380-
get_args(input_type)
381-
if isinstance(input_type, types.UnionType)
382-
else input_type
383-
)
378+
args = ()
379+
if isinstance(input_type, types.UnionType):
380+
args = get_args(input_type)
381+
elif getattr(input_type, "__origin__", None) is Union:
382+
args = get_args(input_type)
383+
elif isinstance(input_type, tuple):
384+
args = input_type
385+
386+
if args:
384387
filtered = tuple(t for t in args if t is not type(None))
385388
if not filtered:
386389
raise TypeError("Option type cannot be only NoneType")
387390
if len(filtered) == 1:
388391
return filtered[0]
392+
389393
return filtered
390394

391395
return input_type

0 commit comments

Comments
 (0)