diff --git a/Lib/_sre.py b/Lib/_sre.py index 644ecef3a0..e498b89978 100644 --- a/Lib/_sre.py +++ b/Lib/_sre.py @@ -1155,17 +1155,17 @@ class _CharsetDispatcher(_Dispatcher): block_index = char_code >> 8 # NB: there are CODESIZE block indices per bytecode a = array.array("B") - a.fromstring(array.array(CODESIZE == 2 and "H" or "I", - [ctx.peek_code(block_index / CODESIZE)]).tostring()) + a.frombytes(array.array(CODESIZE == 2 and "H" or "I", + [ctx.peek_code(block_index // CODESIZE)]).tobytes()) block = a[block_index % CODESIZE] - ctx.skip_code(256 / CODESIZE) # skip block indices - block_value = ctx.peek_code(block * (32 / CODESIZE) + ctx.skip_code(256 // CODESIZE) # skip block indices + block_value = ctx.peek_code(block * (32 // CODESIZE) + ((char_code & 255) >> (CODESIZE == 2 and 4 or 5))) if block_value & (1 << (char_code & ((8 * CODESIZE) - 1))): return self.ok else: - ctx.skip_code(256 / CODESIZE) # skip block indices - ctx.skip_code(count * (32 / CODESIZE)) # skip blocks + ctx.skip_code(256 // CODESIZE) # skip block indices + ctx.skip_code(count * (32 // CODESIZE)) # skip blocks def unknown(self, ctx): return False diff --git a/vm/src/cformat.rs b/vm/src/cformat.rs index e67fd07154..00aa4769b8 100644 --- a/vm/src/cformat.rs +++ b/vm/src/cformat.rs @@ -225,14 +225,13 @@ impl CFormatSpec { "-" }; - // TODO: Support precision let magnitude_string = match self.format_type { CFormatType::Float(CFloatType::PointDecimal) => { - if Some(CFormatQuantity::Amount(6)) != self.precision { - return Err("Not yet implemented for %#.#f types".to_string()); - } else { - format!("{:.6}", magnitude) - } + let precision = match self.precision { + Some(CFormatQuantity::Amount(p)) => p, + _ => 6, + }; + format!("{:.*}", precision, magnitude) } CFormatType::Float(CFloatType::Exponent(_)) => { return Err("Not yet implemented for %e and %E".to_string())