From 212776a37206326eaf2283e1a85a00b4af9275ca Mon Sep 17 00:00:00 2001
From: Stephan Seitz <stephan.seitz@fau.de>
Date: Tue, 17 Dec 2019 12:56:37 +0100
Subject: [PATCH] Implement __bool__ for AssignmentCollection

AssignmentCollection can be used in many cases where you could also use
a List[Assignment]. With AssignmentCollection.__bool__, an empty
AssignmentCollection is falsy and a non-empty one truthy.

So you can `assert assignments, 'must not be emtpy'`
---
 pystencils/simp/assignment_collection.py | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/pystencils/simp/assignment_collection.py b/pystencils/simp/assignment_collection.py
index bf4074ed9..e4827cdbc 100644
--- a/pystencils/simp/assignment_collection.py
+++ b/pystencils/simp/assignment_collection.py
@@ -404,6 +404,9 @@ class AssignmentCollection:
     def __eq__(self, other):
         return set(self.all_assignments) == set(other.all_assignments)
 
+    def __bool__(self):
+        return bool(self.all_assignments)
+
 
 class SymbolGen:
     """Default symbol generator producing number symbols ζ_0, ζ_1, ..."""
-- 
GitLab