Fix --rich-traceback-extra-lines cli flag

* Merge pull request #5028
This commit is contained in:
jack1142 2021-05-19 14:00:31 +02:00 committed by GitHub
parent 606c2f50ba
commit fa4990f327
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -74,19 +74,26 @@ async def interactive_config(red, token_set, prefix_set, *, print_header=True):
return token return token
def positive_int(arg: str) -> int: def non_negative_int(arg: str) -> int:
try: try:
x = int(arg) x = int(arg)
except ValueError: except ValueError:
raise argparse.ArgumentTypeError("Message cache size has to be a number.") raise argparse.ArgumentTypeError("The argument has to be a number.")
if x < 0:
raise argparse.ArgumentTypeError("The argument has to be a non-negative integer.")
if x > sys.maxsize:
raise argparse.ArgumentTypeError(
f"The argument has to be lower than or equal to {sys.maxsize}."
)
return x
def message_cache_size_int(arg: str) -> int:
x = non_negative_int(arg)
if x < 1000: if x < 1000:
raise argparse.ArgumentTypeError( raise argparse.ArgumentTypeError(
"Message cache size has to be greater than or equal to 1000." "Message cache size has to be greater than or equal to 1000."
) )
if x > sys.maxsize:
raise argparse.ArgumentTypeError(
f"Message cache size has to be lower than or equal to {sys.maxsize}."
)
return x return x
@ -230,7 +237,7 @@ def parse_cli_flags(args):
) )
parser.add_argument( parser.add_argument(
"--message-cache-size", "--message-cache-size",
type=positive_int, type=message_cache_size_int,
default=1000, default=1000,
help="Set the maximum number of messages to store in the internal message cache.", help="Set the maximum number of messages to store in the internal message cache.",
) )
@ -265,7 +272,7 @@ def parse_cli_flags(args):
) )
parser.add_argument( parser.add_argument(
"--rich-traceback-extra-lines", "--rich-traceback-extra-lines",
type=positive_int, type=non_negative_int,
default=0, default=0,
help="Set the number of additional lines of code before and after the executed line" help="Set the number of additional lines of code before and after the executed line"
" that should be shown in tracebacks generated by Rich.\n" " that should be shown in tracebacks generated by Rich.\n"