changeset dbabd4cdfb5a in proteus:default
details: https://hg.tryton.org/proteus?cmd=changeset&node=dbabd4cdfb5a
description:
        Remove same types restriction on PYSON If

        issue11644
        review419661003
diffstat:

 proteus/pyson.py |  19 +++++++------------
 1 files changed, 7 insertions(+), 12 deletions(-)

diffs (37 lines):

diff -r 7cedd42a20a6 -r dbabd4cdfb5a proteus/pyson.py
--- a/proteus/pyson.py  Sat Jul 16 23:59:09 2022 +0200
+++ b/proteus/pyson.py  Thu Sep 08 13:17:54 2022 +0200
@@ -400,16 +400,6 @@
                 condition = Bool(condition)
         elif not isinstance(condition, bool):
             condition = bool(condition)
-        if isinstance(then_statement, PYSON):
-            then_types = then_statement.types()
-        else:
-            then_types = {type(then_statement)}
-        if isinstance(else_statement, PYSON):
-            else_types = else_statement.types()
-        else:
-            else_types = {type(else_statement)}
-        assert then_types == else_types, \
-            'then and else statements must be the same type'
         self._condition = condition
         self._then_statement = then_statement
         self._else_statement = else_statement
@@ -428,9 +418,14 @@
 
     def types(self):
         if isinstance(self._then_statement, PYSON):
-            return self._then_statement.types()
+            types = self._then_statement.types()
         else:
-            return {type(self._then_statement)}
+            types = {type(self._then_statement)}
+        if isinstance(self._else_statement, PYSON):
+            types |= self._else_statement.types()
+        else:
+            types |= {type(self._else_statement)}
+        return types
 
     @staticmethod
     def eval(dct, context):

Reply via email to