DisnakeDev / disnake

An API wrapper for Discord written in Python.
https://docs.disnake.dev
MIT License
715 stars 136 forks source link

feat(commands): Add support for `Range[LargeInt, ...]` #1201

Open Enegg opened 3 months ago

Enegg commented 3 months ago

Summary

Closes #787 This PR adds support for defining a range of accepted values for commands.LargeInt.

If both bounds are specified, we restrict the length of the string input according to the number of digits (and sign) of the bounds.

We also raise an error during conversion, if the provided value would exceed the defined range (for example Range[LargeInt, 100, 200] would have actual possible input of 100-999).

I've also implemented a check in case the developer attempts to define a range exceeding ±2**53 with the normal int type, directing them to LargeInt.

Checklist

DJStompZone commented 2 months ago

Enegg commented 2 months ago

Tangentially related: we could add slice support for defining ranges (Range[int, 0:32], String[str, :10]). Not sure how useful it'd be.