mirror of
https://github.com/python/cpython.git
synced 2025-10-21 14:12:27 +00:00
gh-99606: Make code generated for an empty f-string identical to that of a normal empty string (#112407)
This commit is contained in:
parent
418d585feb
commit
fb202af447
3 changed files with 18 additions and 2 deletions
|
@ -8,6 +8,7 @@
|
|||
# Unicode identifiers in tests is allowed by PEP 3131.
|
||||
|
||||
import ast
|
||||
import dis
|
||||
import os
|
||||
import re
|
||||
import types
|
||||
|
@ -1738,5 +1739,14 @@ print(f'''{{
|
|||
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()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue