Skip to content

Commit

Permalink
Update min/max types for better type checking
Browse files Browse the repository at this point in the history
  • Loading branch information
Dorukyum committed Jul 6, 2022
1 parent 43c0864 commit e21f08d
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions discord/commands/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,17 +194,20 @@ def __init__(self, input_type: Any = str, /, description: Optional[str] = None,

if self.input_type == SlashCommandOptionType.integer:
minmax_types = (int, type(None))
minmax_typehint = Optional[int]
elif self.input_type == SlashCommandOptionType.number:
minmax_types = (int, float, type(None))
minmax_typehint = Optional[Union[int, float]]
else:
minmax_types = (type(None),)
minmax_typehint = Optional[Union[minmax_types]] # type: ignore
minmax_typehint = type(None)

if self.input_type == SlashCommandOptionType.string:
minmax_length_types = (int, type(None))
minmax_length_typehint = Optional[int]
else:
minmax_length_types = (type(None),)
minmax_length_typehint = Optional[Union[minmax_length_types]] # type: ignore
minmax_length_typehint = type(None)

self.min_value: minmax_typehint = kwargs.pop("min_value", None)
self.max_value: minmax_typehint = kwargs.pop("max_value", None)
Expand Down

0 comments on commit e21f08d

Please sign in to comment.