A couple more bugs found running 2.7 stdlib tests

This commit is contained in:
rocky 2017-11-24 10:22:58 -05:00
parent f908e8dd8e
commit 37b8e21c76
10 changed files with 32 additions and 5 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -6,6 +6,11 @@ def some_other_function():
some_variable, = some_function()
print(some_variable)
# From 2.7 test_compile.py
# Bug is adding erroneous parens in d[(1:2, 1:2)] += 1
def bug(d):
d[1:2, 1:2] += 1
empty_tup = ()
one_item_tup = ("item1", )
one_item_tup_without_parentheses = "item",

View File

@ -10,3 +10,9 @@
def formatweekday(self):
with self as encoding:
return encoding
# Bug in 2.7.14 test_contextlib.py. Bug was not enclosing (x,y) in parenthesis
def withas_bug(self, nested, a, b):
with self.assertRaises(ZeroDivisionError):
with nested(a(), b()) as (x, y):
1 // 0

View File

@ -140,9 +140,9 @@ TABLE_DIRECT = {
'binary_subscr': ( '%c[%p]',
(0, 'expr'),
(1, 100) ),
'binary_subscr2': ( '%c[%p]',
'binary_subscr2': ( '%c[%c]',
(0, 'expr'),
(1, 100) ),
(1, 'expr') ),
'store_subscr': ( '%c[%c]', 0, 1),
'STORE_FAST': ( '%{pattr}', ),
'STORE_NAME': ( '%{pattr}', ),

View File

@ -315,8 +315,10 @@ class SourceWalker(GenericASTTraversal, object):
'importmultiple': ( '%|import %c%c\n', 2, 3 ),
'import_cont' : ( ', %c', 2 ),
# With/as is allowed as "from future" thing in 2.5
# Note: It is safe to put the variables after "as" in parenthesis,
# and sometimes it is needed.
'withstmt': ( '%|with %c:\n%+%c%-', 0, 3),
'withasstmt': ( '%|with %c as %c:\n%+%c%-', 0, 2, 3),
'withasstmt': ( '%|with %c as (%c):\n%+%c%-', 0, 2, 3),
})
########################################
@ -1726,7 +1728,21 @@ class SourceWalker(GenericASTTraversal, object):
if lastnodetype.startswith('BUILD_LIST'):
self.write('['); endchar = ']'
elif lastnodetype.startswith('BUILD_TUPLE'):
# Tuples can appear places that can NOT
# have parenthesis around them, like array
# subscripts. We check for that by seeing
# if a tuple item is some sort of slice.
no_parens = False
for n in node:
if n == 'expr' and n[0].kind.startswith('buildslice'):
no_parens = True
break
pass
if no_parens:
endchar = ''
else:
self.write('('); endchar = ')'
pass
elif lastnodetype.startswith('BUILD_SET'):
self.write('{'); endchar = '}'
elif lastnodetype.startswith('BUILD_MAP_UNPACK'):