@@ -185,6 +185,23 @@ def _range_to_str_len(min_value: int, max_value: int) -> Tuple[int, int]:
185185 return min (min_ , max_ ), max (min_ , max_ )
186186
187187
188+ def _unbound_range_to_str_len (
189+ min_value : Optional [int ], max_value : Optional [int ]
190+ ) -> Tuple [Optional [int ], Optional [int ]]:
191+ if min_value is not None and max_value is not None :
192+ return _range_to_str_len (min_value , max_value )
193+
194+ elif min_value is not None and min_value > 0 :
195+ # 0 < min_value <= max_value == inf
196+ return _int_to_str_len (min_value ), None
197+
198+ elif max_value is not None and max_value < 0 :
199+ # -inf == min_value <= max_value < 0
200+ return None , _int_to_str_len (max_value )
201+
202+ return None , None
203+
204+
188205class Injection (Generic [P , T_ ]):
189206 """Represents a slash command injection.
190207
@@ -771,21 +788,10 @@ def parse_annotation(self, annotation: Any, converter_mode: bool = False) -> boo
771788 if annotation is not int :
772789 raise TypeError ("Large integers must be annotated with int or LargeInt" )
773790 self .type = str
774-
775- if self .min_value is not None and self .max_value is not None :
776- # honestly would rather assert than type ignore these
777- self .min_length , self .max_length = _range_to_str_len (
778- self .min_value , # pyright: ignore
779- self .max_value , # pyright: ignore
780- )
781-
782- elif self .min_value is not None and self .min_value > 0 :
783- # 0 < min_value <= max_value == inf
784- self .min_length = _int_to_str_len (self .min_value ) # pyright: ignore
785-
786- elif self .max_value is not None and self .max_value < 0 :
787- # -inf == max_value <= min_value < 0
788- self .max_length = _int_to_str_len (self .max_value ) # pyright: ignore
791+ self .min_length , self .max_length = _unbound_range_to_str_len (
792+ self .min_value , # type: ignore
793+ self .max_value , # type: ignore
794+ )
789795
790796 elif annotation in self .TYPES :
791797 self .type = annotation
0 commit comments