Skip to content

Commit 35d1a6c

Browse files
LumabotsLulalaby
authored andcommitted
fix: improve handling of Union and tuple types in option input_type validation
1 parent bc5b9a3 commit 35d1a6c

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

discord/commands/options.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -372,12 +372,15 @@ def _strip_none_type(input_type):
372372
if input_type is type(None):
373373
raise TypeError("Option type cannot be only NoneType")
374374

375-
if isinstance(input_type, (types.UnionType, tuple)):
376-
args = (
377-
get_args(input_type)
378-
if isinstance(input_type, types.UnionType)
379-
else input_type
380-
)
375+
args = ()
376+
if isinstance(input_type, types.UnionType):
377+
args = get_args(input_type)
378+
elif getattr(input_type, "__origin__", None) is Union:
379+
args = get_args(input_type)
380+
elif isinstance(input_type, tuple):
381+
args = input_type
382+
383+
if args:
381384
filtered = tuple(t for t in args if t is not type(None))
382385
if not filtered:
383386
raise TypeError("Option type cannot be only NoneType")

0 commit comments

Comments
 (0)