mirror of
https://github.com/python/cpython.git
synced 2025-07-23 19:25:40 +00:00
Fix "import as" (has always skipping the as name)
Fix com_NEWLINE() so that is accepts arguments, which occurs for lines like: stmt; # note trailing semicolon Add XXX about checking for assignment to list comps
This commit is contained in:
parent
a384f737cc
commit
42a0830713
2 changed files with 30 additions and 18 deletions
|
@ -367,7 +367,7 @@ class Transformer:
|
||||||
names.append((nodelist[i][1], None))
|
names.append((nodelist[i][1], None))
|
||||||
else:
|
else:
|
||||||
for i in range(3, len(nodelist), 2):
|
for i in range(3, len(nodelist), 2):
|
||||||
names.append(self.com_import_as_name(nodelist[i][1]))
|
names.append(self.com_import_as_name(nodelist[i]))
|
||||||
n = From(self.com_dotted_name(nodelist[1]), names)
|
n = From(self.com_dotted_name(nodelist[1]), names)
|
||||||
n.lineno = nodelist[0][2]
|
n.lineno = nodelist[0][2]
|
||||||
return n
|
return n
|
||||||
|
@ -692,7 +692,7 @@ class Transformer:
|
||||||
# We'll just dispatch them.
|
# We'll just dispatch them.
|
||||||
return self._dispatch[node[0]](node[1:])
|
return self._dispatch[node[0]](node[1:])
|
||||||
|
|
||||||
def com_NEWLINE(self):
|
def com_NEWLINE(self, *args):
|
||||||
# A ';' at the end of a line can make a NEWLINE token appear
|
# A ';' at the end of a line can make a NEWLINE token appear
|
||||||
# here, Render it harmless. (genc discards ('discard',
|
# here, Render it harmless. (genc discards ('discard',
|
||||||
# ('const', xxxx)) Nodes)
|
# ('const', xxxx)) Nodes)
|
||||||
|
@ -784,14 +784,17 @@ class Transformer:
|
||||||
return dot, node[3][1]
|
return dot, node[3][1]
|
||||||
|
|
||||||
def com_import_as_name(self, node):
|
def com_import_as_name(self, node):
|
||||||
if node == '*':
|
if node[0] == token.STAR:
|
||||||
return '*', None
|
return '*', None
|
||||||
if node[0] == token.NAME:
|
assert node[0] == symbol.import_as_name
|
||||||
return node[1], None
|
node = node[1:]
|
||||||
assert len(node) == 4
|
if len(node) == 1:
|
||||||
assert node[2][1] == 'as'
|
assert node[0][0] == token.NAME
|
||||||
assert node[3][0] == token.NAME
|
return node[0][1], None
|
||||||
return node[1][1], node[3][1]
|
|
||||||
|
assert node[1][1] == 'as', node
|
||||||
|
assert node[2][0] == token.NAME
|
||||||
|
return node[0][1], node[2][1]
|
||||||
|
|
||||||
def com_bases(self, node):
|
def com_bases(self, node):
|
||||||
bases = []
|
bases = []
|
||||||
|
@ -963,6 +966,9 @@ class Transformer:
|
||||||
# list_iter: list_for | list_if
|
# list_iter: list_for | list_if
|
||||||
# list_for: 'for' exprlist 'in' testlist [list_iter]
|
# list_for: 'for' exprlist 'in' testlist [list_iter]
|
||||||
# list_if: 'if' test [list_iter]
|
# list_if: 'if' test [list_iter]
|
||||||
|
|
||||||
|
# XXX should raise SyntaxError for assignment
|
||||||
|
|
||||||
lineno = node[1][2]
|
lineno = node[1][2]
|
||||||
fors = []
|
fors = []
|
||||||
while node:
|
while node:
|
||||||
|
|
|
@ -367,7 +367,7 @@ class Transformer:
|
||||||
names.append((nodelist[i][1], None))
|
names.append((nodelist[i][1], None))
|
||||||
else:
|
else:
|
||||||
for i in range(3, len(nodelist), 2):
|
for i in range(3, len(nodelist), 2):
|
||||||
names.append(self.com_import_as_name(nodelist[i][1]))
|
names.append(self.com_import_as_name(nodelist[i]))
|
||||||
n = From(self.com_dotted_name(nodelist[1]), names)
|
n = From(self.com_dotted_name(nodelist[1]), names)
|
||||||
n.lineno = nodelist[0][2]
|
n.lineno = nodelist[0][2]
|
||||||
return n
|
return n
|
||||||
|
@ -692,7 +692,7 @@ class Transformer:
|
||||||
# We'll just dispatch them.
|
# We'll just dispatch them.
|
||||||
return self._dispatch[node[0]](node[1:])
|
return self._dispatch[node[0]](node[1:])
|
||||||
|
|
||||||
def com_NEWLINE(self):
|
def com_NEWLINE(self, *args):
|
||||||
# A ';' at the end of a line can make a NEWLINE token appear
|
# A ';' at the end of a line can make a NEWLINE token appear
|
||||||
# here, Render it harmless. (genc discards ('discard',
|
# here, Render it harmless. (genc discards ('discard',
|
||||||
# ('const', xxxx)) Nodes)
|
# ('const', xxxx)) Nodes)
|
||||||
|
@ -784,14 +784,17 @@ class Transformer:
|
||||||
return dot, node[3][1]
|
return dot, node[3][1]
|
||||||
|
|
||||||
def com_import_as_name(self, node):
|
def com_import_as_name(self, node):
|
||||||
if node == '*':
|
if node[0] == token.STAR:
|
||||||
return '*', None
|
return '*', None
|
||||||
if node[0] == token.NAME:
|
assert node[0] == symbol.import_as_name
|
||||||
return node[1], None
|
node = node[1:]
|
||||||
assert len(node) == 4
|
if len(node) == 1:
|
||||||
assert node[2][1] == 'as'
|
assert node[0][0] == token.NAME
|
||||||
assert node[3][0] == token.NAME
|
return node[0][1], None
|
||||||
return node[1][1], node[3][1]
|
|
||||||
|
assert node[1][1] == 'as', node
|
||||||
|
assert node[2][0] == token.NAME
|
||||||
|
return node[0][1], node[2][1]
|
||||||
|
|
||||||
def com_bases(self, node):
|
def com_bases(self, node):
|
||||||
bases = []
|
bases = []
|
||||||
|
@ -963,6 +966,9 @@ class Transformer:
|
||||||
# list_iter: list_for | list_if
|
# list_iter: list_for | list_if
|
||||||
# list_for: 'for' exprlist 'in' testlist [list_iter]
|
# list_for: 'for' exprlist 'in' testlist [list_iter]
|
||||||
# list_if: 'if' test [list_iter]
|
# list_if: 'if' test [list_iter]
|
||||||
|
|
||||||
|
# XXX should raise SyntaxError for assignment
|
||||||
|
|
||||||
lineno = node[1][2]
|
lineno = node[1][2]
|
||||||
fors = []
|
fors = []
|
||||||
while node:
|
while node:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue