bug in 3.x importlists

consts.py: add rule for importlists. imports weren't separated by ', '.
parser.py: Make importlist a list type of node.

test/* add test for importlist
This commit is contained in:
rocky
2017-11-09 04:41:16 -05:00
parent 5d42fe39bb
commit 9ec43de039
4 changed files with 18 additions and 7 deletions

Binary file not shown.

View File

@@ -0,0 +1,7 @@
# Had bug in 3.x in not having semantic importlist rule
def main(osp, Mfile, mainpyfile, dbg=None):
try:
from xdis import load_module, PYTHON_VERSION, IS_PYPY
return PYTHON_VERSION, IS_PYPY, load_module
except:
pass

View File

@@ -30,13 +30,16 @@ class PythonParser(GenericASTBuilder):
def __init__(self, AST, start, debug):
super(PythonParser, self).__init__(AST, start, debug)
self.collect = frozenset(
['stmts', 'except_stmts', '_stmts', 'load_attrs',
# FIXME: customize per python parser version
nt_list = [
'stmts', 'except_stmts', '_stmts', 'load_attrs',
'exprlist', 'kvlist', 'kwargs', 'come_froms', '_come_from',
'importlist',
# Python < 3
'print_items',
# PyPy:
'kvlist_n'])
'kvlist_n']
self.collect = frozenset(nt_list)
def ast_first_offset(self, ast):
if hasattr(ast, 'offset'):

View File

@@ -269,6 +269,7 @@ TABLE_DIRECT = {
'kv2': ( '%c: %c', 1, 2 ),
'mapexpr': ( '{%[1]C}', (0, maxint, ', ') ),
'importstmt': ( '%|import %c\n', 2),
'importlist': ( '%C', (0, maxint, ', ') ),
'importfrom': ( '%|from %[2]{pattr} import %c\n',
(3, 'importlist') ),
'importstar': ( '%|from %[2]{pattr} import *\n', ),