# Unicode identifiers in tests is allowed by PEP 3131.
import ast
+import dis
import os
import re
import types
self.assertIn(rb'\1', stdout)
self.assertEqual(len(stderr.strip().splitlines()), 2)
+ def test_fstring_without_formatting_bytecode(self):
+ # f-string without any formatting should emit the same bytecode
+ # as a normal string. See gh-99606.
+ def get_code(s):
+ return [(i.opname, i.oparg) for i in dis.get_instructions(s)]
+
+ for s in ["", "some string"]:
+ self.assertEqual(get_code(f"'{s}'"), get_code(f"f'{s}'"))
+
if __name__ == '__main__':
unittest.main()
}
else {
VISIT_SEQ(c, expr, e->v.JoinedStr.values);
- if (asdl_seq_LEN(e->v.JoinedStr.values) != 1) {
- ADDOP_I(c, loc, BUILD_STRING, asdl_seq_LEN(e->v.JoinedStr.values));
+ if (value_count > 1) {
+ ADDOP_I(c, loc, BUILD_STRING, value_count);
+ }
+ else if (value_count == 0) {
+ _Py_DECLARE_STR(empty, "");
+ ADDOP_LOAD_CONST_NEW(c, loc, Py_NewRef(&_Py_STR(empty)));
}
}
return SUCCESS;