autopep8: E261 at least two spaces before inline comment
authorSimon Chabot <simon.chabot@logilab.fr>
Wed, 13 Feb 2019 18:25:45 +0100
changeset 854 fe2a97f8a99e
parent 853 739621276982
child 855 c313ddea4a3e
autopep8: E261 at least two spaces before inline comment
__pkginfo__.py
rql/__init__.py
rql/analyze.py
rql/nodes.py
rql/parser.py
rql/rqlgen.py
rql/stcheck.py
rql/stmts.py
rql/undo.py
test/unittest_nodes.py
test/unittest_parser.py
--- a/__pkginfo__.py	Wed Feb 13 18:24:25 2019 +0100
+++ b/__pkginfo__.py	Wed Feb 13 18:25:45 2019 +0100
@@ -94,8 +94,8 @@
 install_requires = [
     'logilab-common >= 0.47.0',
     'logilab-database >= 1.6.0',
-    'yapps2 >= 2.2.0', # XXX to ensure we don't use the broken pypi version
-    'logilab-constraint >= 0.5.0', # fallback if the gecode compiled module is missing
+    'yapps2 >= 2.2.0',  # XXX to ensure we don't use the broken pypi version
+    'logilab-constraint >= 0.5.0',  # fallback if the gecode compiled module is missing
     'six >= 1.4.0',
     'setuptools',
     ]
--- a/rql/__init__.py	Wed Feb 13 18:24:25 2019 +0100
+++ b/rql/__init__.py	Wed Feb 13 18:25:45 2019 +0100
@@ -240,7 +240,7 @@
             exc = RQLSyntaxError(stream.getvalue())
             exc.__traceback__ = sys.exc_info()[-1]
             raise exc
-        except ImportError: # duh?
+        except ImportError:  # duh?
             sys.stderr = out
             exc = RQLSyntaxError('Syntax Error', ex.msg, 'on line',
                                  1 + pinput.count('\n', 0, ex.pos))
--- a/rql/analyze.py	Wed Feb 13 18:24:25 2019 +0100
+++ b/rql/analyze.py	Wed Feb 13 18:25:45 2019 +0100
@@ -128,7 +128,7 @@
 
 
 # GECODE based constraint solver
-_AND = 0 # symbolic values
+_AND = 0  # symbolic values
 _OR = 1
 _EQ = 2
 _EQV = 3
@@ -167,7 +167,7 @@
         self.variables = {}     # maps var name -> var index
         self.ivariables = []    # maps var index-> var name
         self.values = {}        # maps val name -> val index
-        self.all_values = set() # this gets turned into a list later
+        self.all_values = set()  # this gets turned into a list later
         self.idx_domains = []   # maps var index -> list of val index
         self.ivalues = {}       # only used for debugging
 
@@ -449,7 +449,7 @@
         if not (node.defined_vars or node.aliases):
             node.set_possible_types([{}])
             return
-        for subquery in node.with_: # resolve subqueries first
+        for subquery in node.with_:  # resolve subqueries first
             self.visit_union(subquery.query)
         constraints = self._init_stmt(node)
         for ca in node.aliases.values():
@@ -498,7 +498,7 @@
         if isinstance(rhs, nodes.Comparison):
             rhs = rhs.children[0]
         rschema = self.schema.rschema(rtype)
-        if isinstance(lhs, nodes.Constant): # lhs is a constant node (simplified tree)
+        if isinstance(lhs, nodes.Constant):  # lhs is a constant node (simplified tree)
             if not isinstance(rhs, nodes.VariableRef):
                 return None
             self._extract_constraint(constraints, rhs.name, lhs, rschema.objects)
--- a/rql/nodes.py	Wed Feb 13 18:24:25 2019 +0100
+++ b/rql/nodes.py	Wed Feb 13 18:25:45 2019 +0100
@@ -230,7 +230,7 @@
                 istarget = typerel.children[1].children[0]
                 if isinstance(istarget, Constant):
                     etypes = (istarget.value,)
-                else: # Function (IN)
+                else:  # Function (IN)
                     etypes = [et.value for et in istarget.children]
                 if isinstance(etype, string_types):
                     restr_etypes = {etype}
@@ -420,14 +420,14 @@
 
     def ored(self, traverse_scope=False, _fromnode=None):
         if not traverse_scope:
-            if _fromnode is not None: # stop here
+            if _fromnode is not None:  # stop here
                 return False
             return self.parent.ored(traverse_scope, self)
         return self.parent.ored(traverse_scope, _fromnode)
 
     def neged(self, traverse_scope=False, _fromnode=None, strict=False):
         if not traverse_scope:
-            if _fromnode is not None: # stop here
+            if _fromnode is not None:  # stop here
                 return False
             return self.parent.neged(self)
         elif strict:
@@ -438,7 +438,7 @@
 class Relation(Node):
     """a RQL relation"""
     __slots__ = ('r_type', 'optional',
-                 '_q_sqltable', '_q_needcast') # XXX cubicweb specific
+                 '_q_sqltable', '_q_needcast')  # XXX cubicweb specific
 
     def __init__(self, r_type, optional=None):
         Node.__init__(self)
@@ -467,7 +467,7 @@
             if self.optional in ('right', 'both'):
                 rhs += '?'
         except IndexError:
-            return repr(self) # not fully built relation
+            return repr(self)  # not fully built relation
         return '%s %s %s' % (lhs, self.r_type, rhs)
 
     def __repr__(self):
@@ -738,7 +738,7 @@
 
     def __init__(self, value, c_type, _uid=False, _uidtype=None):
         assert c_type in CONSTANT_TYPES, "Error got c_type="+repr(c_type)
-        LeafNode.__init__(self) # don't care about Node attributes
+        LeafNode.__init__(self)  # don't care about Node attributes
         self.value = value
         self.type = c_type
         # updated by the annotator/analyzer if necessary
@@ -787,7 +787,7 @@
     def eval(self, kwargs):
         if self.type == 'Substitute':
             return kwargs[self.value]
-        if self.type in ('Date', 'Datetime'): # TODAY, NOW
+        if self.type in ('Date', 'Datetime'):  # TODAY, NOW
             return KEYWORD_MAP[self.value]()
         return self.value
 
@@ -806,7 +806,7 @@
     __slots__ = ('variable', 'name')
 
     def __init__(self, variable, noautoref=None):
-        LeafNode.__init__(self) # don't care about Node attributes
+        LeafNode.__init__(self)  # don't care about Node attributes
         self.variable = variable
         self.name = variable.name
         if noautoref is None:
@@ -1092,7 +1092,7 @@
 
 class ColumnAlias(Referenceable):
     __slots__ = ('colnum', 'query',
-                 '_q_sql', '_q_sqltable') # XXX cubicweb specific
+                 '_q_sql', '_q_sqltable')  # XXX cubicweb specific
 
     def __init__(self, alias, colnum, query=None):
         super(ColumnAlias, self).__init__(alias)
@@ -1134,7 +1134,7 @@
 
     collects information about a variable use in a syntax tree
     """
-    __slots__ = ('_q_invariant', '_q_sql', '_q_sqltable') # XXX ginco specific
+    __slots__ = ('_q_invariant', '_q_sql', '_q_sqltable')  # XXX ginco specific
 
     def __repr__(self):
         return '%s' % self.name
--- a/rql/parser.py	Wed Feb 13 18:24:25 2019 +0100
+++ b/rql/parser.py	Wed Feb 13 18:25:45 2019 +0100
@@ -128,7 +128,7 @@
             update = self.update(Set(), _context)
             self._scan("';'", context=_context)
             return update
-        else: # in ['r"\\("', 'DISTINCT', 'E_TYPE']
+        else:  # in ['r"\\("', 'DISTINCT', 'E_TYPE']
             union = self.union(Union(), _context)
             self._scan("';'", context=_context)
             return union
@@ -141,7 +141,7 @@
             where = self.where(R, _context)
             having = self.having(R, _context)
             return R
-        else: # == 'E_TYPE'
+        else:  # == 'E_TYPE'
             decl_vars = self.decl_vars(R, _context)
             where = self.where(R, _context)
             having = self.having(R, _context)
@@ -162,7 +162,7 @@
             where = self.where(R, _context)
             having = self.having(R, _context)
             return R
-        else: # == "';'"
+        else:  # == "';'"
             pass
 
     def update(self, R, _parent=None):
@@ -179,7 +179,7 @@
             select = self.select(Select(), _context)
             R.append(select)
             return R
-        else: # == 'r"\\("'
+        else:  # == 'r"\\("'
             self._scan('r"\\("', context=_context)
             select = self.select(Select(), _context)
             self._scan('r"\\)"', context=_context)
@@ -200,7 +200,7 @@
             select_ = self.select_(S, _context)
             S.distinct = True
             return S
-        else: # == 'E_TYPE'
+        else:  # == 'E_TYPE'
             select_ = self.select_(S, _context)
             return S
 
@@ -250,7 +250,7 @@
             HAVING = self._scan('HAVING', context=_context)
             logical_expr = self.logical_expr(S, _context)
             S.set_having([logical_expr])
-        else: # in ['WITH', "';'", 'r"\\)"']
+        else:  # in ['WITH', "';'", 'r"\\)"']
             pass
 
     def orderby(self, S, _parent=None):
@@ -283,7 +283,7 @@
                 subquery = self.subquery(S, _context)
                 nodes.append(subquery)
             S.set_with(nodes)
-        else: # in ['r"\\)"', "';'"]
+        else:  # in ['r"\\)"', "';'"]
             pass
 
     def subquery(self, S, _parent=None):
@@ -314,7 +314,7 @@
             SORT_ASC = self._scan('SORT_ASC', context=_context)
             return 1
         else:
-            return 1 # default to SORT_ASC
+            return 1  # default to SORT_ASC
 
     def limit_offset(self, R, _parent=None):
         _context = self.Context(_parent, self._scanner, 'limit_offset', [R])
@@ -330,7 +330,7 @@
             INT = self._scan('INT', context=_context)
             R.set_limit(int(INT))
             return True
-        else: # in ['OFFSET', 'WHERE', 'HAVING', 'WITH', "';'", 'r"\\)"']
+        else:  # in ['OFFSET', 'WHERE', 'HAVING', 'WITH', "';'", 'r"\\)"']
             pass
 
     def offset(self, R, _parent=None):
@@ -341,7 +341,7 @@
             INT = self._scan('INT', context=_context)
             R.set_offset(int(INT))
             return True
-        else: # in ['WHERE', 'HAVING', 'WITH', "';'", 'r"\\)"']
+        else:  # in ['WHERE', 'HAVING', 'WITH', "';'", 'r"\\)"']
             pass
 
     def where(self, S, _parent=None):
@@ -351,7 +351,7 @@
             WHERE = self._scan('WHERE', context=_context)
             restriction = self.restriction(S, _context)
             S.set_where(restriction)
-        else: # in ['HAVING', 'WITH', "';'", 'r"\\)"']
+        else:  # in ['HAVING', 'WITH', "';'", 'r"\\)"']
             pass
 
     def restriction(self, S, _parent=None):
@@ -391,7 +391,7 @@
             NOT = self._scan('NOT', context=_context)
             rel = self.rel(S, _context)
             return Not(rel)
-        else: # in ['r"\\("', 'EXISTS', 'VARIABLE']
+        else:  # in ['r"\\("', 'EXISTS', 'VARIABLE']
             rel = self.rel(S, _context)
             return rel
 
@@ -401,7 +401,7 @@
         if _token != 'r"\\("':
             rel_base = self.rel_base(S, _context)
             return rel_base
-        else: # == 'r"\\("'
+        else:  # == 'r"\\("'
             self._scan('r"\\("', context=_context)
             restriction = self.restriction(S, _context)
             self._scan('r"\\)"', context=_context)
@@ -421,7 +421,7 @@
             rtype.append(expr)
             rtype.set_optional(opt_right)
             return rtype
-        else: # == 'EXISTS'
+        else:  # == 'EXISTS'
             EXISTS = self._scan('EXISTS', context=_context)
             self._scan('r"\\("', context=_context)
             restriction = self.restriction(S, _context)
@@ -439,7 +439,7 @@
         if _token == 'QMARK':
             QMARK = self._scan('QMARK', context=_context)
             return 'left'
-        else: # in ['R_TYPE', 'CMP_OP', "'IN'"]
+        else:  # in ['R_TYPE', 'CMP_OP', "'IN'"]
             pass
 
     def opt_right(self, S, _parent=None):
@@ -448,7 +448,7 @@
         if _token == 'QMARK':
             QMARK = self._scan('QMARK', context=_context)
             return 'right'
-        else: # in ['AND', 'OR', "','", 'r"\\)"', 'WITH', "';'", 'HAVING']
+        else:  # in ['AND', 'OR', "','", 'r"\\)"', 'WITH', "';'", 'HAVING']
             pass
 
     def logical_expr(self, S, _parent=None):
@@ -518,7 +518,7 @@
             CMP_OP = self._scan('CMP_OP', context=_context)
             expr_add = self.expr_add(S, _context)
             return Comparison(CMP_OP.upper(), expr_add)
-        else: # == "'IN'"
+        else:  # == "'IN'"
             in_expr = self.in_expr(S, _context)
             return Comparison('=', in_expr)
 
@@ -585,7 +585,7 @@
                 expr_mul = self.expr_mul(S, _context)
                 node = MathExpression(ADD_OP, node, expr_mul)
             return node
-        else: # == 'UNARY_OP'
+        else:  # == 'UNARY_OP'
             UNARY_OP = self._scan('UNARY_OP', context=_context)
             expr_mul = self.expr_mul(S, _context)
             node = UnaryExpression(UNARY_OP, expr_mul)
@@ -630,7 +630,7 @@
         elif _token == 'FUNCTION':
             func = self.func(S, _context)
             return func
-        else: # == 'r"\\("'
+        else:  # == 'r"\\("'
             self._scan('r"\\("', context=_context)
             expr_add = self.expr_add(S, _context)
             self._scan('r"\\)"', context=_context)
@@ -703,7 +703,7 @@
         elif _token == 'STRING':
             STRING = self._scan('STRING', context=_context)
             return Constant(unquote(STRING), 'String')
-        else: # == 'SUBSTITUTE'
+        else:  # == 'SUBSTITUTE'
             SUBSTITUTE = self._scan('SUBSTITUTE', context=_context)
             return Constant(SUBSTITUTE[2:-2], 'Substitute')
 
--- a/rql/rqlgen.py	Wed Feb 13 18:24:25 2019 +0100
+++ b/rql/rqlgen.py	Wed Feb 13 18:25:45 2019 +0100
@@ -151,7 +151,7 @@
         'INSERT Person X: X firstname "Clark", X lastname "Kent"'
         """
         restrictions = ['X %s "%s"' % (attr_name, attr_value)
-                        for attr_name, attr_value in attributes] # .items()]
+                        for attr_name, attr_value in attributes]  # .items()]
         return 'INSERT %s X: %s' % (etype, ', '.join(restrictions))
 
     def delete(self, etype, attributes):
@@ -168,7 +168,7 @@
         'DELETE Person X where X firstname "Clark", X lastname "Kent"'
         """
         restrictions = ['X %s "%s"' % (attr_name, attr_value)
-                        for attr_name, attr_value in attributes] # .items()]
+                        for attr_name, attr_value in attributes]  # .items()]
         return 'DELETE %s X where %s' % (etype, ', '.join(restrictions))
 
     def update(self, etype, old_descr, new_descr):
--- a/rql/stcheck.py	Wed Feb 13 18:24:25 2019 +0100
+++ b/rql/stcheck.py	Wed Feb 13 18:25:45 2019 +0100
@@ -141,7 +141,7 @@
         pass
 
     def visit_select(self, node, state):
-        node.vargraph = {} # graph representing links between variable
+        node.vargraph = {}  # graph representing links between variable
         node.aggregated = set()
         self._visit_selectedterm(node, state)
 
@@ -180,7 +180,7 @@
                             if self.has_unique_value_path(node, vname, vref.name):
                                 break
                         except KeyError:
-                            continue # unlinked variable (usually from a subquery)
+                            continue  # unlinked variable (usually from a subquery)
                     else:
                         msg = ('can\'t sort on variable %s which is linked to a'
                                ' variable in the selection but may have different'
@@ -301,7 +301,7 @@
             r1type = r1.r_type
             r2type = r2.r_type
         except AttributeError:
-            return # can't be
+            return  # can't be
         if r1type == r2type and self.schema.rschema(r1type).symmetric:
             lhs1, rhs1 = r1.get_variable_parts()
             lhs2, rhs2 = r2.get_variable_parts()
@@ -618,7 +618,7 @@
                     stinfo['typerel'] = None
         # shared references
         newvar.stinfo['constnode'] = var.stinfo['constnode']
-        if newvar.stmt.solutions: # solutions already computed
+        if newvar.stmt.solutions:  # solutions already computed
             newvar.stinfo['possibletypes'] = var.stinfo['possibletypes']
             for sol in newvar.stmt.solutions:
                 sol[newvar.name] = sol[var.name]
--- a/rql/stmts.py	Wed Feb 13 18:24:25 2019 +0100
+++ b/rql/stmts.py	Wed Feb 13 18:25:45 2019 +0100
@@ -68,7 +68,7 @@
 
 class ScopeNode(BaseNode):
     solutions = ()   # list of possibles solutions for used variables
-    _varmaker = None # variable names generator, built when necessary
+    _varmaker = None  # variable names generator, built when necessary
     where = None     # where clause node
     having = ()      # XXX now a single node
     should_register_op = None
@@ -179,7 +179,7 @@
     # default values for optional instance attributes, set on the instance when
     # used
     schema = None     # ISchema
-    annotated = False # set by the annotator
+    annotated = False  # set by the annotator
 
     # navigation helper methods #############################################
 
@@ -637,7 +637,7 @@
         """
         if name in self.aliases:
             return self.aliases[name]
-        if colnum is not None: # take care, may be 0
+        if colnum is not None:  # take care, may be 0
             self.aliases[name] = calias = nodes.ColumnAlias(name, colnum)
             calias.stmt = self
             # alias may already have been used as a regular variable, replace it
@@ -767,7 +767,7 @@
                 self.remove_sort_term(vref.parent)
             elif vref in self.groupby:
                 self.remove_group_term(vref)
-            else: # selected variable
+            else:  # selected variable
                 self.remove_selected(vref)
         # effective undefine operation
         if self.should_register_op:
@@ -868,7 +868,7 @@
             try:
                 vref.register_reference()
             except AssertionError:
-                pass # already referenced
+                pass  # already referenced
         if self.should_register_op:
             from rql.undo import AddSortOperation
             self.undo_manager.add_operation(AddSortOperation(term))
--- a/rql/undo.py	Wed Feb 13 18:24:25 2019 +0100
+++ b/rql/undo.py	Wed Feb 13 18:25:45 2019 +0100
@@ -27,7 +27,7 @@
     """Manage the operation stacks."""
 
     def __init__(self, selection):
-        self._selection = selection # The selection tree
+        self._selection = selection  # The selection tree
         self.op_list = []           # The operations we'll have to undo
         self.state_stack = []       # The save_state()'s index stack
 
@@ -167,7 +167,7 @@
         if self.index is None:
             if isinstance(parent, Select):
                 parent.where = self.node
-            else: # Exists
+            else:  # Exists
                 parent.query = self.node
             sibling = self.node
         if self.binary_remove:
--- a/test/unittest_nodes.py	Wed Feb 13 18:24:25 2019 +0100
+++ b/test/unittest_nodes.py	Wed Feb 13 18:25:45 2019 +0100
@@ -327,7 +327,7 @@
 
     def test_recover_add_type_restriction_is_in(self):
         tree = self._parse('Any X WHERE X is IN(Person, Company), X name ILIKE "A%"')
-        annotator.annotate(tree) # needed to get typerel index
+        annotator.annotate(tree)  # needed to get typerel index
         tree.save_state()
         select = tree.children[0]
         x = next(select.get_selected_variables())
@@ -339,7 +339,7 @@
 
     def test_recover_add_type_restriction_is_instance_of(self):
         tree = self._parse('Any X WHERE X is_instance_of IN(Person, Company), X name ILIKE "A%"')
-        annotator.annotate(tree) # needed to get typerel index
+        annotator.annotate(tree)  # needed to get typerel index
         tree.save_state()
         select = tree.children[0]
         x = next(select.get_selected_variables())
--- a/test/unittest_parser.py	Wed Feb 13 18:24:25 2019 +0100
+++ b/test/unittest_parser.py	Wed Feb 13 18:25:45 2019 +0100
@@ -43,9 +43,9 @@
     'Any X GROUPBY X ORDERBY X WHERE X nom "toto" UNION Any X GROUPBY X ORDERBY X WHERE X firstname "toto";',
     '(Any X GROUPBY X WHERE X nom "toto") UNION (Any X GROUPBY X WHERE X firstname "toto") ORDERBY X;',
 
-    'Any X, X/Y FROM (Any SUM(X) WHERE X is Person) WHERE X is Person;', # missing AS for subquery
+    'Any X, X/Y FROM (Any SUM(X) WHERE X is Person) WHERE X is Person;',  # missing AS for subquery
 
-    'Any X, X/Y FROM (Any X WHERE X is) WHERE X is Person;', # missing AS for subquery
+    'Any X, X/Y FROM (Any X WHERE X is) WHERE X is Person;',  # missing AS for subquery
 
     )
 
@@ -107,7 +107,7 @@
 
     "Any X, COUNT(B) GROUPBY X ORDERBY 1 WHERE B concerns X HAVING COUNT(B) > 2;",
 
-    'Any X, MAX(COUNT(B)) GROUPBY X WHERE B concerns X;', # syntaxically correct
+    'Any X, MAX(COUNT(B)) GROUPBY X WHERE B concerns X;',  # syntaxically correct
 
     'Any X WHERE X eid > 12;',
     'DELETE Any X WHERE X eid > 12;',