diff --git a/.cspell.dict/cpython.txt b/.cspell.dict/cpython.txt index 26921e04080..8acb1468f66 100644 --- a/.cspell.dict/cpython.txt +++ b/.cspell.dict/cpython.txt @@ -15,6 +15,7 @@ cellvar cellvars cmpop denom +DICTFLAG dictoffset elts excepthandler @@ -28,6 +29,7 @@ heaptype HIGHRES IMMUTABLETYPE Itertool +keeped kwonlyarg kwonlyargs lasti @@ -48,6 +50,7 @@ PYTHREAD_NAME SA_ONSTACK SOABI stackdepth +stginfo stringlib structseq subparams diff --git a/crates/vm/src/buffer.rs b/crates/vm/src/buffer.rs index 13cebfc6a28..cf49d6815c0 100644 --- a/crates/vm/src/buffer.rs +++ b/crates/vm/src/buffer.rs @@ -238,10 +238,23 @@ impl FormatCode { _ => 1, }; + // Skip whitespace (Python ignores whitespace in format strings) + while let Some(b' ' | b'\t' | b'\n' | b'\r') = chars.peek() { + chars.next(); + } + // determine format char: - let c = chars - .next() - .ok_or_else(|| "repeat count given without format specifier".to_owned())?; + let c = match chars.next() { + Some(c) => c, + None => { + // If we have a repeat count but only whitespace follows, error + if repeat != 1 { + return Err("repeat count given without format specifier".to_owned()); + } + // Otherwise, we're done parsing + break; + } + }; // Check for embedded null character if c == 0 {