changeset 90f8f3bfaad8 in tryton:default
details: https://hg.tryton.org/tryton?cmd=changeset&node=90f8f3bfaad8
description:
Remove same types restriction on PYSON If
issue11644
review419661003
diffstat:
tryton/pyson.py | 19 +++++++------------
1 files changed, 7 insertions(+), 12 deletions(-)
diffs (37 lines):
diff -r 30f71de3e567 -r 90f8f3bfaad8 tryton/pyson.py
--- a/tryton/pyson.py Thu Sep 01 22:07:13 2022 +0200
+++ b/tryton/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):