Skip to content

Commit

Permalink
delint and add contib to README
Browse files Browse the repository at this point in the history
  • Loading branch information
Lkruitwagen authored and danthedeckie committed Oct 4, 2024
1 parent 4835603 commit c9dcca1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion simpleeval.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
- edgarrmondragon (Edgar Ramírez-Mondragón) Address Python 3.12+ deprecation warnings
- cedk (Cédric Krier) <ced@b2ck.com> Allow running tests with Werror
- decorator-factory <decorator-factory@protonmail.com> More security fixes
- lkruitwagen (Lucas Kruitwagen) Adding support for dict comprehensions
-------------------------------------
Basic Usage:
Expand Down Expand Up @@ -700,7 +701,6 @@ def _eval_set(self, node):
return set(self._eval(x) for x in node.elts)

def _eval_comprehension(self, node):

if isinstance(node, ast.DictComp):
to_return = {}
else:
Expand Down
12 changes: 6 additions & 6 deletions test_simpleeval.py
Original file line number Diff line number Diff line change
Expand Up @@ -730,22 +730,22 @@ def test_nested_unpack(self):
self.t("[a+b+c for a, (b, c) in ((1,(1,1)),(3,(2,2)))]", [3, 7])

def test_dictcomp_basic(self):
self.t("{a:a + 1 for a in [1,2,3]}", {1:2, 2:3, 3:4})
self.t("{a:a + 1 for a in [1,2,3]}", {1: 2, 2: 3, 3: 4})

def test_dictcomp_with_self_reference(self):
self.t("{a:a + a for a in [1,2,3]}", {1:2, 2:4, 3:6})
self.t("{a:a + a for a in [1,2,3]}", {1: 2, 2: 4, 3: 6})

def test_dictcomp_with_if(self):
self.t("{a:a for a in [1,2,3,4,5] if a <= 3}", {1:1, 2:2, 3:3})
self.t("{a:a for a in [1,2,3,4,5] if a <= 3}", {1: 1, 2: 2, 3: 3})

def test_dictcomp_with_multiple_if(self):
self.t("{a:a for a in [1,2,3,4,5] if a <= 3 and a > 1 }", {2:2, 3:3})
self.t("{a:a for a in [1,2,3,4,5] if a <= 3 and a > 1 }", {2: 2, 3: 3})

def test_dictcomp_unpack(self):
self.t("{a:a+b for a,b in ((1,2),(3,4))}", {1:3, 3:7})
self.t("{a:a+b for a,b in ((1,2),(3,4))}", {1: 3, 3: 7})

def test_dictcomp_nested_unpack(self):
self.t("{a:a+b+c for a, (b, c) in ((1,(1,1)),(3,(2,2)))}", {1:3, 3:7})
self.t("{a:a+b+c for a, (b, c) in ((1,(1,1)),(3,(2,2)))}", {1: 3, 3: 7})

def test_other_places(self):
self.s.functions = {"sum": sum}
Expand Down

0 comments on commit c9dcca1

Please sign in to comment.