3.7+ use attribute_w_parens like we do in pre 3.7

This commit is contained in:
rocky
2020-01-16 11:43:29 -05:00
parent bad40eb63f
commit a532aa5b0e
6 changed files with 19 additions and 1 deletions

Binary file not shown.

View File

@@ -79,3 +79,7 @@ class ResultMixin(object):
class SplitResult(namedtuple('SplitResult', 'scheme netloc path query fragment'), ResultMixin):
pass
# From 3.3.7 test_long.py
# Bug was that we need parens around first "0"
assert (0).bit_length() == 0

View File

@@ -81,7 +81,7 @@ def customize_for_version37(self, version):
(17, "for_block"),
(25, "else_suite"),
),
"attribute37": ("%c.%[1]{pattr}", 0),
"attribute37": ("%c.%[1]{pattr}", (0, "expr")),
"attributes37": ("%[0]{pattr} import %c",
(0, "IMPORT_NAME_ATTR"),
(1, "IMPORT_FROM")),
@@ -175,6 +175,20 @@ def customize_for_version37(self, version):
pass
return
def n_attribute37(node):
expr = node[0]
assert expr == "expr"
if expr[0] == "LOAD_CONST":
# FIXME: I didn't record which constants parenthesis is
# necessary. However, I suspect that we could further
# refine this by looking at operator precedence and
# eval'ing the constant value (pattr) and comparing with
# the type of the constant.
node.kind = "attribute_w_parens"
self.default(node)
self.n_attribute37 = n_attribute37
def n_call(node):
p = self.prec
self.prec = 100