From 4bdc2d47c130c0f7134ef9a65371ba63ac57efe6 Mon Sep 17 00:00:00 2001 From: John Pham Date: Sun, 19 Feb 2023 20:09:54 +0700 Subject: [PATCH] Make common::repr throw error instead of panic (#4520) --- ast/src/constant.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/ast/src/constant.rs b/ast/src/constant.rs index adec47a12c..54aa7594d2 100644 --- a/ast/src/constant.rs +++ b/ast/src/constant.rs @@ -1,3 +1,5 @@ +use std::fmt::Error; + use num_bigint::BigInt; pub use rustpython_compiler_core::ConversionFlag; @@ -42,7 +44,7 @@ impl std::fmt::Display for Constant { Constant::None => f.pad("None"), Constant::Bool(b) => f.pad(if *b { "True" } else { "False" }), Constant::Str(s) => rustpython_common::str::repr(s).fmt(f), - Constant::Bytes(b) => f.pad(&rustpython_common::bytes::repr(b)), + Constant::Bytes(b) => f.pad(&rustpython_common::bytes::repr(b).map_err(|_err| Error)?), Constant::Int(i) => i.fmt(f), Constant::Tuple(tup) => { if let [elt] = &**tup {