From 5a9878d127d731d9b6aedba20e4ec64ccf06ed1b Mon Sep 17 00:00:00 2001 From: MegasKomnenos Date: Sat, 25 Mar 2023 16:34:55 +0900 Subject: [PATCH 1/2] Fix issue with cformat for bytesinner converting bytes key to string for pattern matching --- Lib/test/test_bytes.py | 2 -- vm/src/cformat.rs | 5 ++++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/Lib/test/test_bytes.py b/Lib/test/test_bytes.py index b632637d38..baf84642ee 100644 --- a/Lib/test/test_bytes.py +++ b/Lib/test/test_bytes.py @@ -704,8 +704,6 @@ def test_rindex(self): self.assertEqual(b.rindex(i, 3, 9), 7) self.assertRaises(ValueError, b.rindex, w, 1, 3) - # TODO: RUSTPYTHON - @unittest.expectedFailure def test_mod(self): b = self.type2test(b'hello, %b!') orig = b diff --git a/vm/src/cformat.rs b/vm/src/cformat.rs index 2b8dd4b0b9..d8b95afd43 100644 --- a/vm/src/cformat.rs +++ b/vm/src/cformat.rs @@ -293,7 +293,10 @@ pub(crate) fn cformat_bytes( CFormatPart::Literal(literal) => result.append(literal), CFormatPart::Spec(spec) => { let value = match &spec.mapping_key { - Some(key) => values_obj.get_item(key.as_str(), vm)?, + Some(key) => { + let k = vm.ctx.new_bytes(key.as_str().as_bytes().to_vec()); + values_obj.get_item(k.as_object(), vm)? + } None => unreachable!(), }; let mut part_result = spec_format_bytes(vm, spec, value)?; From 846c8afde1f227a9cc5ee269c2535d1f59e190e8 Mon Sep 17 00:00:00 2001 From: MegasKomnenos Date: Sat, 25 Mar 2023 19:22:18 +0900 Subject: [PATCH 2/2] The test is still failing, so the flag should be left as is --- Lib/test/test_bytes.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Lib/test/test_bytes.py b/Lib/test/test_bytes.py index baf84642ee..b632637d38 100644 --- a/Lib/test/test_bytes.py +++ b/Lib/test/test_bytes.py @@ -704,6 +704,8 @@ def test_rindex(self): self.assertEqual(b.rindex(i, 3, 9), 7) self.assertRaises(ValueError, b.rindex, w, 1, 3) + # TODO: RUSTPYTHON + @unittest.expectedFailure def test_mod(self): b = self.type2test(b'hello, %b!') orig = b