[PATCH 10 of 17 seda] [py3] Fix comparison of cardinality when maxc is graph_nodes.INFINITY

Denis Laxalde denis.laxalde at logilab.fr
Wed Oct 2 16:06:38 CEST 2019


`max(maxc, maxvalue)` would evaluate to `max("Infinity", <some
integer>)` when maxc is graph_nodes.INFINITY. While this works on
python2 (by chance, since strings and integers can be compared), this
does not on python3.

We thus move the "if" that checks for graph_nodes.INFINITY inside the
"for" loop.

diff --git a/cubicweb_seda/entities/profile_generation.py b/cubicweb_seda/entities/profile_generation.py
index e173814..68211e4 100644
--- a/cubicweb_seda/entities/profile_generation.py
+++ b/cubicweb_seda/entities/profile_generation.py
@@ -133,9 +133,10 @@ def integrity_cardinality(data_object):
             continue
         minc, maxc = minmax_cardinality(parent_cardinality)
         minvalue = min(minc, minvalue)
-        maxvalue = max(maxc, maxvalue)
-    if maxvalue == graph_nodes.INFINITY:
-        maxvalue = 'n'
+        if maxc == graph_nodes.INFINITY:
+            maxvalue = 'n'
+        else:
+            maxvalue = max(maxc, maxvalue)
     if minvalue == maxvalue == 1:
         return '1'
     return '{}..{}'.format(minvalue, maxvalue)



More information about the saem-devel mailing list