Merge branch 'master' into python-2.4

This commit is contained in:
rocky
2018-03-25 17:37:04 -04:00
7 changed files with 39 additions and 17 deletions

1
test/.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
/nohup.out

View File

@@ -1,5 +1,5 @@
# From 2.7 test_argparse.py # From 2.7 test_argparse.py
# Bug was turnning assert into an "or raise" statement # Bug was turning assert into an "or raise" statement
def __call__(arg, dest): def __call__(arg, dest):
try: try:
assert arg == 'spam', 'dest: %s' % dest assert arg == 'spam', 'dest: %s' % dest
@@ -15,3 +15,17 @@ def refactor_doctest(clipped, new):
if not new: if not new:
new += u"\n" new += u"\n"
return return
# From 2.7.14 test_hashlib.py
# The bug was turning assert into an "if"
# statement which isn't wrong, but we got the
# range of the if incorrect. When we have
# better control flow analysis we can revisit.
def test_threaded_hashing():
for threadnum in xrange(1):
result = 1
assert result > 0
result = 2
return result
assert test_threaded_hashing() == 2

View File

@@ -2,7 +2,7 @@
USER=${USER:-rocky} USER=${USER:-rocky}
EMAIL=${EMAIL:-rb@dustyfeet.com} EMAIL=${EMAIL:-rb@dustyfeet.com}
SUBJECT_PREFIX="stdlib unit testing for" SUBJECT_PREFIX="stdlib unit testing for"
for VERSION in 2.7.14 2.6.9 ; do for VERSION in 2.7.14 2.6.9 3.6.4 ; do
typeset -i rc=0 typeset -i rc=0
LOGFILE=/tmp/runtests-$VERSION-$$.log LOGFILE=/tmp/runtests-$VERSION-$$.log
if ! pyenv local $VERSION ; then if ! pyenv local $VERSION ; then

View File

@@ -328,11 +328,9 @@ class Python2Parser(PythonParser):
'dict_comp_func', 0, customize) 'dict_comp_func', 0, customize)
else: else:
kvlist_n = "kvlist_%s" % token.attr kvlist_n = ' kv3' * token.attr
self.add_unique_rules([ rule = "dict ::= %s%s" % (opname, kvlist_n)
(kvlist_n + " ::=" + ' kv3' * token.attr), self.addRule(rule, nop_func)
"dict ::= %s %s" % (opname, kvlist_n)
], customize)
continue continue
elif opname_base == 'BUILD_SLICE': elif opname_base == 'BUILD_SLICE':
slice_num = token.attr slice_num = token.attr
@@ -518,7 +516,7 @@ class Python2Parser(PythonParser):
self.addRule(rule, nop_func) self.addRule(rule, nop_func)
pass pass
self.check_reduce['aug_assign1'] = 'AST' self.check_reduce['raise_stmt1'] = 'tokens'
self.check_reduce['aug_assign2'] = 'AST' self.check_reduce['aug_assign2'] = 'AST'
self.check_reduce['or'] = 'AST' self.check_reduce['or'] = 'AST'
# self.check_reduce['_stmts'] = 'AST' # self.check_reduce['_stmts'] = 'AST'
@@ -538,7 +536,11 @@ class Python2Parser(PythonParser):
if lhs in ('aug_assign1', 'aug_assign2') and ast[0] and ast[0][0] in ('and', 'or'): if lhs in ('aug_assign1', 'aug_assign2') and ast[0] and ast[0][0] in ('and', 'or'):
return True return True
if rule == ('or', ('expr', 'jmp_true', 'expr', '\\e_come_from_opt')): elif lhs in ('raise_stmt1',):
# We will assme 'LOAD_ASSERT' will be handled by an assert grammar rule
return (tokens[first] == 'LOAD_ASSERT' and
(last >= len(tokens) or tokens[last] != 'JUMP_FORWARD'))
elif rule == ('or', ('expr', 'jmp_true', 'expr', '\\e_come_from_opt')):
expr2 = ast[2] expr2 = ast[2]
return expr2 == 'expr' and expr2[0] == 'LOAD_ASSERT' return expr2 == 'expr' and expr2[0] == 'LOAD_ASSERT'
return False return False

View File

@@ -647,6 +647,8 @@ class Python3Parser(PythonParser):
elif self.version >= 3.5: elif self.version >= 3.5:
if opname != 'BUILD_MAP_WITH_CALL': if opname != 'BUILD_MAP_WITH_CALL':
if opname == 'BUILD_MAP_UNPACK': if opname == 'BUILD_MAP_UNPACK':
# FIXME: start here
# rule = "%s ::= %s %s" % (kvlist_n, 'expr ' * (token.attr*2), opname)
rule = kvlist_n + ' ::= ' + 'expr ' * (token.attr*2) rule = kvlist_n + ' ::= ' + 'expr ' * (token.attr*2)
self.add_unique_rule(rule, opname, token.attr, customize) self.add_unique_rule(rule, opname, token.attr, customize)
rule = 'dict_entry ::= ' + 'expr ' * (token.attr*2) rule = 'dict_entry ::= ' + 'expr ' * (token.attr*2)

View File

@@ -152,7 +152,7 @@ class Scanner2(Scanner):
# raise AssertionError # raise AssertionError
# and # and
# assert ... # assert ...
# Below we use the heuristic that it is preceded by a POP_JUMP. # Below we use the heuristic that an "sssert" is preceded by a POP_JUMP.
# however we could also use followed by RAISE_VARARGS # however we could also use followed by RAISE_VARARGS
# or for PyPy there may be a JUMP_IF_NOT_DEBUG before. # or for PyPy there may be a JUMP_IF_NOT_DEBUG before.
# FIXME: remove uses of PJIF, and PJIT # FIXME: remove uses of PJIF, and PJIT

View File

@@ -1705,10 +1705,6 @@ class SourceWalker(GenericASTTraversal, object):
kv_node = node[0] kv_node = node[0]
l = list(kv_node) l = list(kv_node)
length = len(l) length = len(l)
# FIXME: Parser-speed improved grammars will have BUILD_MAP
# at the end. So in the future when everything is
# complete, we can do an "assert" instead of "if".
if kv_node[-1].kind.startswith("BUILD_MAP"): if kv_node[-1].kind.startswith("BUILD_MAP"):
length -= 1 length -= 1
i = 0 i = 0
@@ -1784,13 +1780,20 @@ class SourceWalker(GenericASTTraversal, object):
pass pass
pass pass
else: else:
# Python 2 style kvlist # Python 2 style kvlist. Find beginning of kvlist.
assert node[-1].kind.startswith('kvlist') if node[0].kind.startswith("BUILD_MAP"):
kv_node = node[-1] # goto kvlist if len(node) > 1 and node[1].kind in ('kvlist', 'kvlist_n'):
kv_node = node[1]
else:
kv_node = node[1:]
else:
assert node[-1].kind.startswith('kvlist')
kv_node = node[-1]
first_time = True first_time = True
for kv in kv_node: for kv in kv_node:
assert kv in ('kv', 'kv2', 'kv3') assert kv in ('kv', 'kv2', 'kv3')
# kv ::= DUP_TOP expr ROT_TWO expr STORE_SUBSCR # kv ::= DUP_TOP expr ROT_TWO expr STORE_SUBSCR
# kv2 ::= DUP_TOP expr expr ROT_THREE STORE_SUBSCR # kv2 ::= DUP_TOP expr expr ROT_THREE STORE_SUBSCR
# kv3 ::= expr expr STORE_MAP # kv3 ::= expr expr STORE_MAP