Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

set precedence on f-string expressions #155

Merged
merged 1 commit into from
Dec 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions astor/code_gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -604,6 +604,7 @@ def recurse(node):
if getattr(value, 'expr_text', None):
self.write(value.expr_text)
else:
set_precedence(value, value.value)
self.visit(value.value)
if value.conversion != -1:
self.write('!%s' % chr(value.conversion))
Expand Down
1 change: 1 addition & 0 deletions astor/op_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
ExtSlice 1
comprehension_target 1
Tuple 0
FormattedValue 0

Comma 1
NamedExpr 1
Expand Down
13 changes: 13 additions & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,19 @@
Release Notes
=============

0.8.1 - in development
----------------------

Bug fixes
~~~~~~~~~

* Fixed precedence issue for f-string expressions that caused
redundant parenthesis around expression.
(Reported by Ilya Kamenshchikov in `Issue 153`_ and fixed by Batuhan Taskaya in `PR 155`_.)

.. _`Issue 153`: https://github.com/berkerpeksag/astor/issues/153
.. _`PR 155`: https://github.com/berkerpeksag/astor/pull/155

0.8.0 - 2019-05-19
------------------

Expand Down
1 change: 1 addition & 0 deletions tests/test_code_gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,7 @@ def test_fstrings(self):
x = f'{int(x)}'
x = f'a{b:c}d'
x = f'a{b!s:c{d}e}f'
x = f'{x + y}'
x = f'""'
x = f'"\\''
"""
Expand Down