Fix precidence between list_if and if_expr in 3.x

This commit is contained in:
rocky
2019-05-05 08:16:29 -04:00
parent bb94c7f5bc
commit 6df65a87bc
3 changed files with 10 additions and 1 deletions

View File

@@ -35,6 +35,11 @@ else:
# Things at the top of this list below with low-value precidence will # Things at the top of this list below with low-value precidence will
# tend to have parenthesis around them. Things at the bottom # tend to have parenthesis around them. Things at the bottom
# of the list will tend not to have parenthesis around them. # of the list will tend not to have parenthesis around them.
# Note: The values in this table tend to be even value. Inside
# various templates we use odd values. Avoiding equal-precident comparisons
# avoids ambiguity what to do when the precedence is equal.
PRECEDENCE = { PRECEDENCE = {
'list': 0, 'list': 0,
'dict': 0, 'dict': 0,

View File

@@ -23,6 +23,9 @@ def customize_for_version37(self, version):
####################### #######################
PRECEDENCE['attribute37'] = 2 PRECEDENCE['attribute37'] = 2
PRECEDENCE['ifexp_37a'] = 28
PRECEDENCE['ifexp_37b'] = 28
TABLE_DIRECT.update({ TABLE_DIRECT.update({
'and_not': ( '%c and not %c', 'and_not': ( '%c and not %c',
(0, 'expr'), (2, 'expr') ), (0, 'expr'), (2, 'expr') ),

View File

@@ -1168,6 +1168,7 @@ class SourceWalker(GenericASTTraversal, object):
self.write(' if ') self.write(' if ')
if have_not: if have_not:
self.write('not ') self.write('not ')
self.prec = 27
self.preorder(if_node) self.preorder(if_node)
pass pass
self.prec = p self.prec = p