mirror of
https://github.com/python/cpython.git
synced 2025-08-31 05:58:33 +00:00
bpo-37050: Remove expr_text from FormattedValue ast node, use Constant node instead (GH-13597)
When using the "=" debug functionality of f-strings, use another Constant node (or a merged constant node) instead of adding expr_text to the FormattedValue node.
This commit is contained in:
parent
695b1dd8cb
commit
6f6ff8a565
9 changed files with 87 additions and 100 deletions
|
@ -1150,6 +1150,24 @@ non-important content
|
|||
|
||||
self.assertRaises(SyntaxError, eval, "f'{C=]'")
|
||||
|
||||
# Make sure leading and following text works.
|
||||
x = 'foo'
|
||||
self.assertEqual(f'X{x=}Y', 'Xx='+repr(x)+'Y')
|
||||
|
||||
# Make sure whitespace around the = works.
|
||||
self.assertEqual(f'X{x =}Y', 'Xx ='+repr(x)+'Y')
|
||||
self.assertEqual(f'X{x= }Y', 'Xx= '+repr(x)+'Y')
|
||||
self.assertEqual(f'X{x = }Y', 'Xx = '+repr(x)+'Y')
|
||||
|
||||
# These next lines contains tabs. Backslash escapes don't
|
||||
# work in f-strings.
|
||||
# patchcheck doens't like these tabs. So the only way to test
|
||||
# this will be to dynamically created and exec the f-strings. But
|
||||
# that's such a hassle I'll save it for another day. For now, convert
|
||||
# the tabs to spaces just to shut up patchcheck.
|
||||
#self.assertEqual(f'X{x =}Y', 'Xx\t='+repr(x)+'Y')
|
||||
#self.assertEqual(f'X{x = }Y', 'Xx\t=\t'+repr(x)+'Y')
|
||||
|
||||
def test_walrus(self):
|
||||
x = 20
|
||||
# This isn't an assignment expression, it's 'x', with a format
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue