summaryrefslogtreecommitdiffstats
path: root/Lib/compiler/transformer.py
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>2006-08-28 15:27:34 (GMT)
committerGuido van Rossum <guido@python.org>2006-08-28 15:27:34 (GMT)
commit86e58e239e39845e706c4afa392423f0fedcdf39 (patch)
tree1d0f4d942e644ee5c903636d87176b98a7203371 /Lib/compiler/transformer.py
parentecfd0b2f3bfd622c3ba148e53d3feebb8c1ae721 (diff)
downloadcpython-86e58e239e39845e706c4afa392423f0fedcdf39.zip
cpython-86e58e239e39845e706c4afa392423f0fedcdf39.tar.gz
cpython-86e58e239e39845e706c4afa392423f0fedcdf39.tar.bz2
SF patch 1547796 by Georg Brandl -- set literals.
Diffstat (limited to 'Lib/compiler/transformer.py')
-rw-r--r--Lib/compiler/transformer.py21
1 files changed, 14 insertions, 7 deletions
diff --git a/Lib/compiler/transformer.py b/Lib/compiler/transformer.py
index b564300..42640e8 100644
--- a/Lib/compiler/transformer.py
+++ b/Lib/compiler/transformer.py
@@ -738,7 +738,7 @@ class Transformer:
def atom_lbrace(self, nodelist):
if nodelist[1][0] == token.RBRACE:
return Dict((), lineno=nodelist[0][2])
- return self.com_dictmaker(nodelist[1])
+ return self.com_dictsetmaker(nodelist[1])
def atom_backquote(self, nodelist):
return Backquote(self.com_node(nodelist[1]))
@@ -1182,13 +1182,20 @@ class Transformer:
assert node[0] == symbol.gen_iter
return node[1]
- def com_dictmaker(self, nodelist):
- # dictmaker: test ':' test (',' test ':' value)* [',']
+ def com_dictsetmaker(self, nodelist):
+ # dictsetmaker: (test ':' test (',' test ':' value)* [',']) | (test (',' test)* [','])
items = []
- for i in range(1, len(nodelist), 4):
- items.append((self.com_node(nodelist[i]),
- self.com_node(nodelist[i+2])))
- return Dict(items, lineno=items[0][0].lineno)
+ if nodelist[2] != ':':
+ # it's a set
+ for i in range(1, len(nodelist), 2):
+ items.append(self.com_node(nodelist[i]))
+ return Set(items, lineno=items[0].lineno)
+ else:
+ # it's a dict
+ for i in range(1, len(nodelist), 4):
+ items.append((self.com_node(nodelist[i]),
+ self.com_node(nodelist[i+2])))
+ return Dict(items, lineno=items[0][0].lineno)
def com_apply_trailer(self, primaryNode, nodelist):
t = nodelist[1][0]