mirror of
https://github.com/RustPython/RustPython.git
synced 2026-10-28 18:59:04 +08:00
cli: avoid panic when -X int_max_str_digits has no value (#8677)
Signed-off-by: cuishuang <imcusg@gmail.com>
This commit is contained in:
1 parent
fb88ea834f
commit
521b75ec4a
2 files changed
+37
-2
No files matched your search
@@ -0,0 +1,35 @@
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
for option in (
|
||||
"int_max_str_digits",
|
||||
"int_max_str_digits=639",
|
||||
"int_max_str_digits=invalid",
|
||||
):
|
||||
result = subprocess.run(
|
||||
[sys.executable, "-E", "-X", option, "-c", "pass"],
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.PIPE,
|
||||
)
|
||||
assert result.returncode == 1, (option, result.returncode, result.stderr)
|
||||
assert b"-X int_max_str_digits: invalid limit" in result.stderr, (
|
||||
option,
|
||||
result.stderr,
|
||||
)
|
||||
assert b"panicked" not in result.stderr, (option, result.stderr)
|
||||
|
||||
for digits in (640, 0):
|
||||
result = subprocess.run(
|
||||
[
|
||||
sys.executable,
|
||||
"-E",
|
||||
"-X",
|
||||
f"int_max_str_digits={digits}",
|
||||
"-c",
|
||||
"import sys; print(sys.get_int_max_str_digits())",
|
||||
],
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.PIPE,
|
||||
)
|
||||
assert result.returncode == 0, (digits, result.returncode, result.stderr)
|
||||
assert result.stdout.strip() == str(digits).encode(), (digits, result.stdout)
|
||||
+2
-2
@@ -339,8 +339,8 @@ pub fn parse_opts() -> Result<(Settings, RunMode), lexopt::Error> {
|
||||
};
|
||||
}
|
||||
"int_max_str_digits" => {
|
||||
settings.int_max_str_digits = match value.unwrap().parse() {
|
||||
Ok(digits) if digits == 0 || digits >= 640 => digits,
|
||||
settings.int_max_str_digits = match value.and_then(|value| value.parse().ok()) {
|
||||
Some(digits) if digits == 0 || digits >= 640 => digits,
|
||||
_ => {
|
||||
error!(
|
||||
"Fatal Python error: config_init_int_max_str_digits: \
|
||||
|
||||
Reference in new issue
Block a user