[querier] add_types_restriction_cleanups: remove useless try/except (we already filtered out variables not in newroot.defined_vars) and dict accss. Also systematically set computed solutions instead of modifying existing ones stable
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Fri, 20 Aug 2010 08:15:06 +0200
branchstable
changeset 6123 0d0a87e88281
parent 6122 4d2b04b32cdc
child 6124 c5900230809b
[querier] add_types_restriction_cleanups: remove useless try/except (we already filtered out variables not in newroot.defined_vars) and dict accss. Also systematically set computed solutions instead of modifying existing ones
rqlrewrite.py
--- a/rqlrewrite.py	Fri Aug 20 08:46:32 2010 +0200
+++ b/rqlrewrite.py	Fri Aug 20 08:15:06 2010 +0200
@@ -45,14 +45,12 @@
     allpossibletypes = {}
     for solution in solutions:
         for varname, etype in solution.iteritems():
-            if not varname in newroot.defined_vars or eschema(etype).final:
+            # XXX not considering aliases by design, right ?
+            if varname not in newroot.defined_vars or eschema(etype).final:
                 continue
             allpossibletypes.setdefault(varname, set()).add(etype)
     for varname in sorted(allpossibletypes):
-        try:
-            var = newroot.defined_vars[varname]
-        except KeyError:
-            continue
+        var = newroot.defined_vars[varname]
         stinfo = var.stinfo
         if stinfo.get('uidrel') is not None:
             continue # eid specified, no need for additional type specification
@@ -64,7 +62,7 @@
         if newroot is rqlst and typerel is not None:
             mytyperel = typerel
         else:
-            for vref in newroot.defined_vars[varname].references():
+            for vref in var.references():
                 rel = vref.relation()
                 if rel and rel.is_types_restriction():
                     mytyperel = rel
@@ -79,12 +77,6 @@
             for cst in mytyperel.get_nodes(n.Constant):
                 if not cst.value in possibletypes:
                     cst.parent.remove(cst)
-                    try:
-                        stinfo['possibletypes'].remove(cst.value)
-                    except KeyError:
-                        # restriction on a type not used by this query, may
-                        # occurs with X is IN(...)
-                        pass
         else:
             # we have to add types restriction
             if stinfo.get('scope') is not None:
@@ -94,7 +86,7 @@
                 # to the root
                 rel = newroot.add_type_restriction(var, possibletypes)
             stinfo['typerel'] = rel
-            stinfo['possibletypes'] = possibletypes
+        stinfo['possibletypes'] = possibletypes
 
 
 def remove_solutions(origsolutions, solutions, defined):