diff --git a/coconut/compiler/compiler.py b/coconut/compiler/compiler.py index c0eb1ee7d..c2e0a96b4 100644 --- a/coconut/compiler/compiler.py +++ b/coconut/compiler/compiler.py @@ -172,7 +172,7 @@ def set_to_tuple(tokens): """Converts set literal tokens to tuples.""" internal_assert(len(tokens) == 1, "invalid set maker tokens", tokens) - if "comp" in tokens or "list" in tokens: + if "list" in tokens or "comp" in tokens or "testlist_star_expr" in tokens: return "(" + tokens[0] + ")" elif "test" in tokens: return "(" + tokens[0] + ",)" diff --git a/coconut/compiler/grammar.py b/coconut/compiler/grammar.py index f34838bea..0f898596d 100644 --- a/coconut/compiler/grammar.py +++ b/coconut/compiler/grammar.py @@ -1172,9 +1172,10 @@ class Grammar(object): set_m = fixto(CaselessLiteral("m"), "m") set_letter = set_s | set_f | set_m setmaker = Group( - addspace(new_namedexpr_test + comp_for)("comp") - | new_namedexpr_testlist_has_comma("list") - | new_namedexpr_test("test"), + (new_namedexpr_test + FollowedBy(rbrace))("test") + | (new_namedexpr_testlist_has_comma + FollowedBy(rbrace))("list") + | addspace(new_namedexpr_test + comp_for + FollowedBy(rbrace))("comp") + | (testlist_star_namedexpr + FollowedBy(rbrace))("testlist_star_expr"), ) set_literal_ref = lbrace.suppress() + setmaker + rbrace.suppress() set_letter_literal_ref = combine(set_letter + lbrace.suppress()) + Optional(setmaker) + rbrace.suppress() diff --git a/coconut/root.py b/coconut/root.py index f65c1c08b..dc369d25c 100644 --- a/coconut/root.py +++ b/coconut/root.py @@ -26,7 +26,7 @@ VERSION = "2.1.1" VERSION_NAME = "The Spanish Inquisition" # False for release, int >= 1 for develop -DEVELOP = 24 +DEVELOP = 25 ALPHA = False # for pre releases rather than post releases # ----------------------------------------------------------------------------------------------------------------------- @@ -138,6 +138,8 @@ def __reversed__(self): return _coconut.reversed(self._xrange) def __len__(self): return _coconut.len(self._xrange) + def __bool__(self): + return _coconut.bool(self._xrange) def __contains__(self, elem): return elem in self._xrange def __getitem__(self, index): diff --git a/coconut/tests/src/cocotest/agnostic/main.coco b/coconut/tests/src/cocotest/agnostic/main.coco index 62c4fb1bc..0f8b739ba 100644 --- a/coconut/tests/src/cocotest/agnostic/main.coco +++ b/coconut/tests/src/cocotest/agnostic/main.coco @@ -1331,6 +1331,8 @@ def main_test() -> bool: assert m{1, 1, 2} >= m{1, 1, 2} > m{1, 2} > m{} >= m{} assert m{1} != {1:1, 2:0} assert not (m{1} == {1:1, 2:0}) + assert s{1, 2, *(2, 3, 4), *(4, 5)} == s{1, 2, 3, 4, 5} + assert m{1, 2, *(2, 3, 4), *(4, 5)} == m{1, 2, 2, 3, 4, 4, 5} return True def test_asyncio() -> bool: