diff --git a/test/bytecode_3.6_run/08_comp_gen_for.pyc b/test/bytecode_3.6_run/08_comp_gen_for.pyc new file mode 100644 index 00000000..3f0e838b Binary files /dev/null and b/test/bytecode_3.6_run/08_comp_gen_for.pyc differ diff --git a/test/simple_source/bug36/08_comp_gen_for.py b/test/simple_source/bug36/08_comp_gen_for.py new file mode 100644 index 00000000..496cc6ef --- /dev/null +++ b/test/simple_source/bug36/08_comp_gen_for.py @@ -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] diff --git a/uncompyle6/semantics/consts.py b/uncompyle6/semantics/consts.py index d4aed209..3fcf6111 100644 --- a/uncompyle6/semantics/consts.py +++ b/uncompyle6/semantics/consts.py @@ -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) ), diff --git a/uncompyle6/semantics/customize3.py b/uncompyle6/semantics/customize3.py index 5b7e300b..791a4585 100644 --- a/uncompyle6/semantics/customize3.py +++ b/uncompyle6/semantics/customize3.py @@ -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', ),