Skip to content

Commit 47ef145

Browse files
committed
Fix some miscellaneous stuff
Int division in _sre.py, float precision printf formatting
1 parent adfd298 commit 47ef145

File tree

2 files changed

+11
-12
lines changed

2 files changed

+11
-12
lines changed

Lib/_sre.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -1155,17 +1155,17 @@ def set_bigcharset(self, ctx):
11551155
block_index = char_code >> 8
11561156
# NB: there are CODESIZE block indices per bytecode
11571157
a = array.array("B")
1158-
a.fromstring(array.array(CODESIZE == 2 and "H" or "I",
1159-
[ctx.peek_code(block_index / CODESIZE)]).tostring())
1158+
a.frombytes(array.array(CODESIZE == 2 and "H" or "I",
1159+
[ctx.peek_code(block_index // CODESIZE)]).tobytes())
11601160
block = a[block_index % CODESIZE]
1161-
ctx.skip_code(256 / CODESIZE) # skip block indices
1162-
block_value = ctx.peek_code(block * (32 / CODESIZE)
1161+
ctx.skip_code(256 // CODESIZE) # skip block indices
1162+
block_value = ctx.peek_code(block * (32 // CODESIZE)
11631163
+ ((char_code & 255) >> (CODESIZE == 2 and 4 or 5)))
11641164
if block_value & (1 << (char_code & ((8 * CODESIZE) - 1))):
11651165
return self.ok
11661166
else:
1167-
ctx.skip_code(256 / CODESIZE) # skip block indices
1168-
ctx.skip_code(count * (32 / CODESIZE)) # skip blocks
1167+
ctx.skip_code(256 // CODESIZE) # skip block indices
1168+
ctx.skip_code(count * (32 // CODESIZE)) # skip blocks
11691169
def unknown(self, ctx):
11701170
return False
11711171

vm/src/cformat.rs

+5-6
Original file line numberDiff line numberDiff line change
@@ -225,14 +225,13 @@ impl CFormatSpec {
225225
"-"
226226
};
227227

228-
// TODO: Support precision
228+
let precision = match self.precision {
229+
Some(CFormatQuantity::Amount(p)) => p,
230+
_ => 6,
231+
};
229232
let magnitude_string = match self.format_type {
230233
CFormatType::Float(CFloatType::PointDecimal) => {
231-
if Some(CFormatQuantity::Amount(6)) != self.precision {
232-
return Err("Not yet implemented for %#.#f types".to_string());
233-
} else {
234-
format!("{:.6}", magnitude)
235-
}
234+
format!("{:.*}", precision, magnitude)
236235
}
237236
CFormatType::Float(CFloatType::Exponent(_)) => {
238237
return Err("Not yet implemented for %e and %E".to_string())

0 commit comments

Comments
 (0)