autopep8: fix E202 whitespace before ')'
authorDenis Laxalde <denis.laxalde@logilab.fr>
Wed, 13 Feb 2019 15:29:38 +0100
changeset 829 7fc7aed2c0b2
parent 828 9a4d926f95cb
child 830 a128e1293ce9
autopep8: fix E202 whitespace before ')'
rql/analyze.py
rql/parser.py
rql/stcheck.py
rql/stmts.py
test/unittest_analyze.py
test/unittest_rqlgen.py
tools/rql_analyze.py
tools/rql_cmp.py
tools/rql_parse.py
--- a/rql/analyze.py	Wed Feb 13 12:31:37 2019 +0100
+++ b/rql/analyze.py	Wed Feb 13 15:29:38 2019 +0100
@@ -85,13 +85,13 @@
     def get_constraints(self):
         return self.constraints
 
-    def add_expr(self, vars, expr ):
-        self.constraints.append(fd.make_expression(vars, expr ) )
+    def add_expr(self, vars, expr):
+        self.constraints.append(fd.make_expression(vars, expr))
         self.scons.append(expr)
 
     def var_has_type(self, var, etype):
         assert isinstance(etype, string_types)
-        self.add_expr((var,), '%s == %r' % (var, etype) )
+        self.add_expr((var,), '%s == %r' % (var, etype))
 
     def var_has_types(self, var, etypes):
         etypes = tuple(etypes)
@@ -116,14 +116,14 @@
                 for t in types:
                     assert isinstance(t, string_types)
                 if len(types)==1:
-                    anded.add('%s == "%s"' % ('=='.join(vars), types[0]) )
+                    anded.add('%s == "%s"' % ('=='.join(vars), types[0]))
                 else:
-                    anded.add('%s in %s' % ('=='.join(vars), types) )
+                    anded.add('%s in %s' % ('=='.join(vars), types))
                 for var in vars:
                     variables.add(var)
-            orred.add('(' + ' and '.join(list(anded) ) + ')' )
-        expr = " or ".join(list(orred) )
-        self.add_expr(tuple(variables), expr )
+            orred.add('(' + ' and '.join(list(anded)) + ')')
+        expr = " or ".join(list(orred))
+        self.add_expr(tuple(variables), expr)
 
 
 # GECODE based constraint solver
@@ -159,7 +159,7 @@
     """
     def __init__(self):
         self.constraints = []
-        self.op = [_AND ]
+        self.op = [_AND]
         self.domains = {}       # maps var name -> var value
         self.variables = {}     # maps var name -> var index
         self.ivariables = []    # maps var index-> var name
@@ -179,16 +179,16 @@
 
     def pretty_print_ops(self, ops):
         if ops[0] in (_AND, _OR):
-            res = [OPSYM[ops[0]], '(' ]
+            res = [OPSYM[ops[0]], '(']
             for op in ops[1:]:
                 res.append(self.pretty_print_ops(op))
                 res.append(',')
-            res.append(')' )
+            res.append(')')
             return "".join(res)
         elif ops[0] == _EQ:
             return "%s==%s" % (self.ivariables[ops[1]], self.ivalues[ops[2]])
         elif ops[0] == _EQV:
-            res = [self.ivariables[k] for k in ops[1:] ]
+            res = [self.ivariables[k] for k in ops[1:]]
             return '~='.join(res)
 
     def get_output(self):
@@ -201,7 +201,7 @@
         #import time
         #t0=time.time()
 
-        sols = rql_solve.solve(self.idx_domains, len(self.all_values), constraints )
+        sols = rql_solve.solve(self.idx_domains, len(self.all_values), constraints)
         rql_sols = []
         for s in sols:
             r={}
@@ -213,7 +213,7 @@
 
     def add_var(self, name, values):
         assert name not in self.variables
-        self.all_values.update(values )
+        self.all_values.update(values)
         self.variables[name] = len(self.variables)
         self.ivariables.append(name)
         self.domains[name] = values
@@ -222,20 +222,20 @@
         # maps integer->value
         self.all_values = list(self.all_values)
         # maps value->integer
-        self.values = dict([(v,i) for i,v in enumerate(self.all_values)] )
+        self.values = dict([(v,i) for i,v in enumerate(self.all_values)])
         #print(self.values)
         #print(self.domains)
         for var_name in self.ivariables:
             val_domain = self.domains[var_name]
-            idx_domain = [self.values[val] for val in val_domain ]
-            self.idx_domains.append(idx_domain )
+            idx_domain = [self.values[val] for val in val_domain]
+            self.idx_domains.append(idx_domain)
 
-    def and_eq(self, var, value ):
-        self.op.append([_EQ, self.variables[var], self.values[value] ] )
+    def and_eq(self, var, value):
+        self.op.append([_EQ, self.variables[var], self.values[value]])
 
     def equal_vars(self, varnames):
         if len(varnames)>1:
-            self.op.append([_EQV] + [self.variables[v] for v in varnames ] )
+            self.op.append([_EQV] + [self.variables[v] for v in varnames])
 
     def var_has_type(self, var, etype):
         self.and_eq(var, etype)
@@ -244,39 +244,39 @@
         for t in etypes:
             assert isinstance(t, string_types)
         if len(etypes) == 1:
-            self.and_eq(var, tuple(etypes)[0] )
+            self.and_eq(var, tuple(etypes)[0])
         else:
-            orred = [_OR ]
+            orred = [_OR]
             for t in etypes:
                 try:
-                    orred.append([_EQ, self.variables[var], self.values[t] ] )
+                    orred.append([_EQ, self.variables[var], self.values[t]])
                 except KeyError:
                     # key error may be raised by self.values[t] if self.values
                     # reflects constraints from subqueries
                     continue
-            self.op.append(orred )
+            self.op.append(orred)
 
     def vars_have_same_types(self, varnames, types):
-        self.equal_vars(varnames )
+        self.equal_vars(varnames)
         for var in varnames:
-            self.var_has_types(var, types )
+            self.var_has_types(var, types)
 
     def or_and(self, equalities):
-        orred = [_OR ]
+        orred = [_OR]
         for orred_expr in equalities:
-            anded = [_AND ]
+            anded = [_AND]
             for vars, types in orred_expr:
-                self.equal_vars(vars )
+                self.equal_vars(vars)
                 for t in types:
                     assert isinstance(t, string_types)
                 for var in vars:
                     if len(types)==1:
-                        anded.append([_EQ, self.variables[var], self.values[types[0]] ] )
+                        anded.append([_EQ, self.variables[var], self.values[types[0]]])
                     else:
-                        or2 = [_OR ]
+                        or2 = [_OR]
                         for t in types:
-                            or2.append([_EQ, self.variables[var], self.values[t] ] )
-                        anded.append(or2 )
+                            or2.append([_EQ, self.variables[var], self.values[t]])
+                        anded.append(or2)
             orred.append(anded)
         self.op.append(orred)
 
@@ -374,7 +374,7 @@
         pb = CSPProblem()
         # set domain for all the variables
         for var in node.defined_vars.values():
-            pb.add_var(var.name, self._base_domain )
+            pb.add_var(var.name, self._base_domain)
         # no variable short cut
         return pb
 
@@ -387,7 +387,7 @@
         else:
             alltypes = get_target_types()
         domain = constraints.domains[var]
-        constraints.var_has_types(var, [str(t) for t in alltypes if t in domain] )
+        constraints.var_has_types(var, [str(t) for t in alltypes if t in domain])
 
     def visit(self, node, uid_func_mapping=None, kwargs=None, debug=False):
         # FIXME: not thread safe
@@ -419,7 +419,7 @@
                 continue
             assert etype in self.schema, etype
             var = variable.name
-            constraints.var_has_type(var, etype )
+            constraints.var_has_type(var, etype)
         for relation in node.main_relations:
             self._visit(relation, constraints)
         # get constraints from the restriction subtree
@@ -452,7 +452,7 @@
         for ca in node.aliases.values():
             etypes = set(stmt.selection[ca.colnum].get_type(sol, self.kwargs)
                          for stmt in ca.query.children for sol in stmt.solutions)
-            constraints.add_var(ca.name, etypes )
+            constraints.add_var(ca.name, etypes)
         constraints.end_domain_definition()
         if self.uid_func:
             # check rewritten uid const
@@ -471,7 +471,7 @@
                 # add constraint on real relation types if no restriction
                 types = [eschema.type for eschema in self.schema.entities()
                          if not eschema.final]
-                constraints.vars_have_same_types(varnames, types )
+                constraints.vars_have_same_types(varnames, types)
         self.solve(node, constraints)
 
     def visit_relation(self, relation, constraints):
@@ -490,7 +490,7 @@
             else:
                 etypes = self._uid_node_types(rhs)
             if etypes:
-                constraints.var_has_types(lhs.name, etypes )
+                constraints.var_has_types(lhs.name, etypes)
                 return None
         if isinstance(rhs, nodes.Comparison):
             rhs = rhs.children[0]
@@ -523,7 +523,7 @@
                     totypes = set(str(t) for t in toetypes)
                     ptypes = totypes & rhsdomain
                     res.append([([lhsvar], [str(fromtype)]),
-                                  ([rhsvar], list(ptypes)) ] )
+                                  ([rhsvar], list(ptypes))])
                     if same_var and (fromtype in totypes): #ptypes ?
                         var_types.append(fromtype)
             constraints.or_and(res)
@@ -534,7 +534,7 @@
             lhsdomain = constraints.domains[lhs.name]
             ptypes = [str(subj) for subj in rschema.subjects()
                       if subj in lhsdomain]
-            constraints.var_has_types(lhs.name, ptypes )
+            constraints.var_has_types(lhs.name, ptypes)
         return None
 
     def visit_type_restriction(self, relation, constraints):
@@ -548,7 +548,7 @@
         if relation.neged(strict=True):
             etypes = frozenset(t for t in self._nonfinal_domain if not t in etypes)
 
-        constraints.var_has_types(lhs.name, [str(t) for t in etypes ] )
+        constraints.var_has_types(lhs.name, [str(t) for t in etypes])
 
     def visit_and(self, et, constraints):
         pass
--- a/rql/parser.py	Wed Feb 13 12:31:37 2019 +0100
+++ b/rql/parser.py	Wed Feb 13 15:29:38 2019 +0100
@@ -562,16 +562,16 @@
             while self._peek('ADD_OP', 'QMARK', 'r"\\)"', "','", 'SORT_DESC', 'SORT_ASC', 'CMP_OP', 'R_TYPE', "'IN'", 'GROUPBY', 'ORDERBY', 'WHERE', 'LIMIT', 'OFFSET', 'HAVING', 'WITH', "';'", 'AND', 'OR', context=_context) == 'ADD_OP':
                 ADD_OP = self._scan('ADD_OP', context=_context)
                 expr_mul = self.expr_mul(S, _context)
-                node = MathExpression(ADD_OP, node, expr_mul )
+                node = MathExpression(ADD_OP, node, expr_mul)
             return node
         else: # == 'UNARY_OP'
             UNARY_OP = self._scan('UNARY_OP', context=_context)
             expr_mul = self.expr_mul(S, _context)
-            node = UnaryExpression(UNARY_OP, expr_mul )
+            node = UnaryExpression(UNARY_OP, expr_mul)
             while self._peek('ADD_OP', 'QMARK', 'r"\\)"', "','", 'SORT_DESC', 'SORT_ASC', 'CMP_OP', 'R_TYPE', "'IN'", 'GROUPBY', 'ORDERBY', 'WHERE', 'LIMIT', 'OFFSET', 'HAVING', 'WITH', "';'", 'AND', 'OR', context=_context) == 'ADD_OP':
                 ADD_OP = self._scan('ADD_OP', context=_context)
                 expr_mul = self.expr_mul(S, _context)
-                node = MathExpression(ADD_OP, node, expr_mul )
+                node = MathExpression(ADD_OP, node, expr_mul)
             return node
 
     def expr_mul(self, S, _parent=None):
--- a/rql/stcheck.py	Wed Feb 13 12:31:37 2019 +0100
+++ b/rql/stcheck.py	Wed Feb 13 15:29:38 2019 +0100
@@ -576,7 +576,7 @@
                             and self.schema.rschema(rel.r_type).final):
                         update_attrvars(newvar, rel, lhs)
                         lhsvar = getattr(lhs, 'variable', None)
-                        stinfo['attrvars'].remove((lhsvar, rel.r_type) )
+                        stinfo['attrvars'].remove((lhsvar, rel.r_type))
                         if stinfo['attrvar'] is lhsvar:
                             if stinfo['attrvars']:
                                 stinfo['attrvar'] = next(iter(stinfo['attrvars']))
@@ -705,7 +705,7 @@
     # where the `var` attribute variable is used
     lhsvar = getattr(lhs, 'variable', None)
     try:
-        var.stinfo['attrvars'].add((lhsvar, relation.r_type) )
+        var.stinfo['attrvars'].add((lhsvar, relation.r_type))
     except KeyError:
         var.stinfo['attrvars'] = set([(lhsvar, relation.r_type)])
     # give priority to variable which is not in an EXISTS as
--- a/rql/stmts.py	Wed Feb 13 12:31:37 2019 +0100
+++ b/rql/stmts.py	Wed Feb 13 15:29:38 2019 +0100
@@ -920,7 +920,7 @@
         #if etype == 'Any':
         #    raise BadRQLQuery('"Any" is not supported in DELETE statement')
         vref.parent = self
-        self.main_variables.append((etype, vref) )
+        self.main_variables.append((etype, vref))
 
     def add_main_relation(self, relation):
         """add a relation to the list of deleted relations"""
@@ -928,7 +928,7 @@
         assert isinstance(relation.children[1], nodes.Comparison)
         assert isinstance(relation.children[1].children[0], nodes.VariableRef)
         relation.parent = self
-        self.main_relations.append(relation )
+        self.main_relations.append(relation)
 
     # repr / as_string / copy #################################################
 
@@ -1009,7 +1009,7 @@
         """add a variable to the list of inserted variables"""
         if etype == 'Any':
             raise BadRQLQuery('"Any" is not supported in INSERT statement')
-        self.main_variables.append((etype, vref) )
+        self.main_variables.append((etype, vref))
         vref.parent = self
         self.inserted_variables[vref.variable] = 1
 
@@ -1023,7 +1023,7 @@
 insertion variable'
                 raise BadRQLQuery(msg % (var, var))
         relation.parent = self
-        self.main_relations.append(relation )
+        self.main_relations.append(relation)
 
     # repr / as_string / copy #################################################
 
@@ -1096,7 +1096,7 @@
     def add_main_relation(self, relation):
         """add a relation to the list of modified relations"""
         relation.parent = self
-        self.main_relations.append(relation )
+        self.main_relations.append(relation)
 
     # repr / as_string / copy #################################################
 
--- a/test/unittest_analyze.py	Wed Feb 13 12:31:37 2019 +0100
+++ b/test/unittest_analyze.py	Wed Feb 13 15:29:38 2019 +0100
@@ -90,74 +90,74 @@
             self._types[etype] = EntitySchema(etype)
         self._types['Person']._specialized_by = [self._types['Student']]
         self._relations  = {
-            'eid' : RelationSchema((('Person', ('Int',) ),
-                                      ('Student', ('Int',) ),
-                                      ('Company', ('Int',) ),
-                                      ('Address', ('Int',) ),
-                                      ('Eetype', ('Int',) ),
+            'eid' : RelationSchema((('Person', ('Int',)),
+                                      ('Student', ('Int',)),
+                                      ('Company', ('Int',)),
+                                      ('Address', ('Int',)),
+                                      ('Eetype', ('Int',)),
                                       )
                                     ),
-            'creation_date' : RelationSchema((('Person', ('Datetime',) ),
-                                                ('Student', ('Datetime',) ),
-                                                ('Company', ('Datetime',) ),
-                                                ('Address', ('Datetime',) ),
-                                                ('Eetype', ('Datetime',) ),
+            'creation_date' : RelationSchema((('Person', ('Datetime',)),
+                                                ('Student', ('Datetime',)),
+                                                ('Company', ('Datetime',)),
+                                                ('Address', ('Datetime',)),
+                                                ('Eetype', ('Datetime',)),
                                                 )
                                     ),
-            'name' : RelationSchema((('Person', ('String',) ),
-                                       ('Student', ('String',) ),
-                                       ('Company', ('String',) ),
+            'name' : RelationSchema((('Person', ('String',)),
+                                       ('Student', ('String',)),
+                                       ('Company', ('String',)),
                                       )
                                     ),
-            'firstname' : RelationSchema((('Person', ('String',) ),
-                                            ('Student', ('String',) ),
+            'firstname' : RelationSchema((('Person', ('String',)),
+                                            ('Student', ('String',)),
                                            )
                                     ),
-            'work_for' : RelationSchema((('Person', ('Company',) ),
-                                           ('Student', ('Company',) ),
+            'work_for' : RelationSchema((('Person', ('Company',)),
+                                           ('Student', ('Company',)),
                                            ),
                                          card='?*'),
-            'is' : RelationSchema((('Person', ('Eetype',) ),
-                                     ('Student', ('Eetype',) ),
-                                     ('Company', ('Eetype',) ),
-                                     ('Address', ('Eetype',) ),
-                                     ('Eetype', ('Eetype',) ),
+            'is' : RelationSchema((('Person', ('Eetype',)),
+                                     ('Student', ('Eetype',)),
+                                     ('Company', ('Eetype',)),
+                                     ('Address', ('Eetype',)),
+                                     ('Eetype', ('Eetype',)),
                                      )
                                    ),
-            'is_instance_of' : RelationSchema((('Person', ('Eetype',) ),
-                                              ('Student', ('Eetype',) ),
-                                              ('Company', ('Eetype',) ),
-                                              ('Address', ('Eetype',) ),
-                                              ('Eetype', ('Eetype',) ),
+            'is_instance_of' : RelationSchema((('Person', ('Eetype',)),
+                                              ('Student', ('Eetype',)),
+                                              ('Company', ('Eetype',)),
+                                              ('Address', ('Eetype',)),
+                                              ('Eetype', ('Eetype',)),
                                               )
                                             ),
-            'connait' : RelationSchema((('Person', ('Person',) ),
-                                         ('Student', ('Person',) ),
-                                         ('Student', ('Student',) ),
-                                         ('Person', ('Student',) ),
+            'connait' : RelationSchema((('Person', ('Person',)),
+                                         ('Student', ('Person',)),
+                                         ('Student', ('Student',)),
+                                         ('Person', ('Student',)),
                                          ),
                                         symmetric=True),
-            'located' : RelationSchema((('Person', ('Address',) ),
-                                          ('Student', ('Address',) ),
-                                          ('Company', ('Address',) ),
+            'located' : RelationSchema((('Person', ('Address',)),
+                                          ('Student', ('Address',)),
+                                          ('Company', ('Address',)),
                                          )
                                        ),
-            'owned_by' : RelationSchema((('Person', ('Person',) ),
-                                           ('Student', ('Person',) ),
-                                           ('Company', ('Person',) ),
-                                           ('Eetype', ('Person',) ),
+            'owned_by' : RelationSchema((('Person', ('Person',)),
+                                           ('Student', ('Person',)),
+                                           ('Company', ('Person',)),
+                                           ('Eetype', ('Person',)),
                                            )
                                          ),
-            'identity' : RelationSchema((('Person', ('Person',) ),
-                                           ('Student', ('Student',) ),
-                                           ('Company', ('Company',) ),
-                                           ('Address', ('Address',) ),
-                                           ('Eetype', ('Eetype',) ),
+            'identity' : RelationSchema((('Person', ('Person',)),
+                                           ('Student', ('Student',)),
+                                           ('Company', ('Company',)),
+                                           ('Address', ('Address',)),
+                                           ('Eetype', ('Eetype',)),
                                       )
                                     ),
-            'number' : RelationSchema((('Person', ('Int',) ),
-                                         ('Student', ('Int',) ),
-                                         ('Company', ('Float',) ),
+            'number' : RelationSchema((('Person', ('Int',)),
+                                         ('Student', ('Int',)),
+                                         ('Company', ('Float',)),
                                       )
                                     ),
             }
--- a/test/unittest_rqlgen.py	Wed Feb 13 12:31:37 2019 +0100
+++ b/test/unittest_rqlgen.py	Wed Feb 13 15:29:38 2019 +0100
@@ -61,7 +61,7 @@
                                         (('X','work_for','S'),
                                           ('S','name','"Logilab"'),
                                           ('X','firstname','F'),
-                                          ('X','surname','S') ),
+                                          ('X','surname','S')),
                                         ('X',),
                                         ('F ASC', 'S DESC'))
         self.assertEqual(rql, 'Person X\nWHERE X work_for S , S name "Logilab"'
@@ -74,7 +74,7 @@
         rql = self.rql_generator.where((('X','work_for','S'),
                                          ('S','name','"Logilab"'),
                                          ('X','firstname','F'),
-                                         ('X','surname','S') ) )
+                                         ('X','surname','S')))
         self.assertEqual(rql, 'WHERE X work_for S , S name "Logilab" '
                          ', X firstname F , X surname S')
 
--- a/tools/rql_analyze.py	Wed Feb 13 12:31:37 2019 +0100
+++ b/tools/rql_analyze.py	Wed Feb 13 15:29:38 2019 +0100
@@ -27,11 +27,11 @@
 SCHEMA_DIRECTORY = "/home/ludal/SB/prive/soft/ginco/applications/crm/schema"
 APP_NAME = "toto"
 
-schema = load_schema(SCHEMA_DIRECTORY, APP_NAME )
+schema = load_schema(SCHEMA_DIRECTORY, APP_NAME)
 
 #print(schema)
 
-def cmp_sol(sol1, sol2 ):
+def cmp_sol(sol1, sol2):
     ret = True
     for l in sol1:
         if l not in sol2:
@@ -43,14 +43,14 @@
             print("Sol2", l)
     return ret
 
-def analyze_rq(rq ):
+def analyze_rq(rq):
     print("RQL:", rq)
-    helper1 = RQLHelper(schema, Resolver=ETypeResolver  )
-    helper2 = RQLHelper(schema, Resolver=ETypeResolver2 )
-    node1 = helper1.parse(rq )
-    node2 = helper2.parse(rq )
-    sol1 = helper1.get_solutions(node1 )
-    sol2 = helper2.get_solutions(node2 )
+    helper1 = RQLHelper(schema, Resolver=ETypeResolver)
+    helper2 = RQLHelper(schema, Resolver=ETypeResolver2)
+    node1 = helper1.parse(rq)
+    node2 = helper2.parse(rq)
+    sol1 = helper1.get_solutions(node1)
+    sol2 = helper2.get_solutions(node2)
     return helper1, helper2, node1, node2, sol1, sol2
 
 
@@ -63,6 +63,6 @@
     helper1, helper2, node1, node2, sol1, sol2 = analyze_rq(l)
     an1 = helper1._rql_analyser
     an2 = helper2._rql_analyser
-    if not cmp_sol(sol1, sol2 ):
+    if not cmp_sol(sol1, sol2):
         break
     
--- a/tools/rql_cmp.py	Wed Feb 13 12:31:37 2019 +0100
+++ b/tools/rql_cmp.py	Wed Feb 13 15:29:38 2019 +0100
@@ -49,8 +49,8 @@
     x1 = cparse(l, builder)
     x2 = parse(l)
     l = l.strip()
-    d1 = make_canon_dict(x1 )
-    d2 = make_canon_dict(x2 )
+    d1 = make_canon_dict(x1)
+    d2 = make_canon_dict(x2)
     t = d1==d2
     print('%s : "%s"' % (t,l))
     if not t:
--- a/tools/rql_parse.py	Wed Feb 13 12:31:37 2019 +0100
+++ b/tools/rql_parse.py	Wed Feb 13 15:29:38 2019 +0100
@@ -39,4 +39,4 @@
 }
 
 
-v = rqlparse.parse("Any X where X eid 4;", builder )
+v = rqlparse.parse("Any X where X eid 4;", builder)