Add rule for 3.x comp_for

This commit is contained in:
rocky
2019-04-22 18:42:21 -04:00
parent 0e5eb954b2
commit f1b69a8a28
4 changed files with 23 additions and 3 deletions

Binary file not shown.

View File

@@ -0,0 +1,18 @@
# Bug in 3.3 weakset
# Bug was not having a rule for 3.x "comp_for"
class WeakSet:
def __init__(self, data=None):
self.data = set(data)
def __iter__(self):
for item in self.data:
if item is not None:
yield item
def union(self, other):
return self.__class__(e for s in (self, other) for e in s)
a = WeakSet([1, 2, 3])
b = WeakSet([1, 3, 5])
assert list(a.union(b)) == [1, 2, 3, 5]

View File

@@ -186,9 +186,9 @@ TABLE_DIRECT = {
'comp_if': ( ' if %c%c', 0, 2 ),
'comp_if_not': ( ' if not %p%c', (0, 22), 2 ),
'comp_body': ( '', ), # ignore when recusing
'set_comp_body': ( '%c', 0 ),
'gen_comp_body': ( '%c', 0 ),
'dict_comp_body': ( '%c:%c', 1, 0 ),
'set_comp_body': ( '%c', 0 ),
'gen_comp_body': ( '%c', 0 ),
'dict_comp_body': ( '%c:%c', 1, 0 ),
'assign': ( '%|%c = %p\n', -1, (0, 200) ),

View File

@@ -29,6 +29,8 @@ def customize_for_version3(self, version):
TABLE_DIRECT.update({
'except_cond2': ( '%|except %c as %c:\n', 1, 5 ),
'function_def_annotate': ( '\n\n%|def %c%c\n', -1, 0),
'comp_for' : ( ' for %c in %c',
(2, 'store') , (0, 'expr') ),
'importmultiple': ( '%|import %c%c\n', 2, 3 ),
'import_cont' : ( ', %c', 2 ),
'store_locals': ( '%|# inspect.currentframe().f_locals = __locals__\n', ),