[py3] Fix comparison of cardinality when maxc is graph_nodes.INFINITY
authorDenis Laxalde <denis.laxalde@logilab.fr>
Wed, 02 Oct 2019 14:42:30 +0200
changeset 3042 1dd2faa2de16
parent 3041 e7bc12390c5d
child 3043 01ca8b6ba1d5
[py3] Fix comparison of cardinality when maxc is graph_nodes.INFINITY `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.
cubicweb_seda/entities/profile_generation.py
--- a/cubicweb_seda/entities/profile_generation.py	Wed Oct 02 14:25:12 2019 +0200
+++ b/cubicweb_seda/entities/profile_generation.py	Wed Oct 02 14:42:30 2019 +0200
@@ -133,9 +133,10 @@
             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)