pylint suggested refactorings stable
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Fri, 26 Feb 2010 13:30:24 +0100
branchstable
changeset 4722 9c13d5db03d9
parent 4721 8f63691ccb7f
child 4723 77bec4c4775a
pylint suggested refactorings
devtools/devctl.py
hooks/syncschema.py
server/msplanner.py
server/querier.py
server/schemaserial.py
web/captcha.py
web/views/old_calendar.py
--- a/devtools/devctl.py	Fri Feb 26 13:24:47 2010 +0100
+++ b/devtools/devctl.py	Fri Feb 26 13:30:24 2010 +0100
@@ -101,7 +101,7 @@
     # set_schema triggers objects registrations
     vreg.set_schema(schema)
     w(DEFAULT_POT_HEAD)
-    _generate_schema_pot(w, vreg, schema, libconfig=libconfig, cube=cube)
+    _generate_schema_pot(w, vreg, schema, libconfig=libconfig)
 
 
 def _generate_schema_pot(w, vreg, schema, libconfig=None):
@@ -213,7 +213,7 @@
         add_msg(w, objid)
 
 
-def _iter_vreg_objids(vreg, done, prefix=None):
+def _iter_vreg_objids(vreg, done):
     for reg, objdict in vreg.items():
         for objects in objdict.values():
             for obj in objects:
--- a/hooks/syncschema.py	Fri Feb 26 13:24:47 2010 +0100
+++ b/hooks/syncschema.py	Fri Feb 26 13:30:24 2010 +0100
@@ -419,7 +419,7 @@
         rdef = self.init_rdef(composite=entity.composite)
         schema = session.vreg.schema
         rtype = rdef.name
-        rschema = session.vreg.schema.rschema(rtype)
+        rschema = schema.rschema(rtype)
         # this have to be done before permissions setting
         if rschema.inlined:
             # need to add a column if the relation is inlined and if this is the
@@ -441,15 +441,15 @@
             if not (rschema.subjects() or
                     rtype in session.transaction_data.get('createdtables', ())):
                 try:
-                    rschema = session.vreg.schema.rschema(rtype)
+                    rschema = schema.rschema(rtype)
                     tablesql = rschema2sql(rschema)
                 except KeyError:
                     # fake we add it to the schema now to get a correctly
                     # initialized schema but remove it before doing anything
                     # more dangerous...
-                    rschema = session.vreg.schema.add_relation_type(rdef)
+                    rschema = schema.add_relation_type(rdef)
                     tablesql = rschema2sql(rschema)
-                    session.vreg.schema.del_relation_type(rtype)
+                    schema.del_relation_type(rtype)
                 # create the necessary table
                 for sql in tablesql.split(';'):
                     if sql.strip():
--- a/server/msplanner.py	Fri Feb 26 13:24:47 2010 +0100
+++ b/server/msplanner.py	Fri Feb 26 13:30:24 2010 +0100
@@ -1027,7 +1027,7 @@
         plan.preprocess(rqlst)
         ppis = [PartPlanInformation(plan, select, self.rqlhelper)
                 for select in rqlst.children]
-        steps = self._union_plan(plan, rqlst, ppis)
+        steps = self._union_plan(plan, ppis)
         if server.DEBUG & server.DBG_MS:
             from pprint import pprint
             for step in plan.steps:
@@ -1045,7 +1045,7 @@
             for sppi in sppis:
                 if sppi.needsplit or sppi.part_sources != ppi.part_sources:
                     temptable = 'T%s' % make_uid(id(subquery))
-                    sstep = self._union_plan(plan, subquery.query, sppis, temptable)[0]
+                    sstep = self._union_plan(plan, sppis, temptable)[0]
                     break
             else:
                 sstep = None
@@ -1056,7 +1056,7 @@
                 ppi.plan.add_step(sstep)
         return inputmap
 
-    def _union_plan(self, plan, union, ppis, temptable=None):
+    def _union_plan(self, plan, ppis, temptable=None):
         tosplit, cango, allsources = [], {}, set()
         for planinfo in ppis:
             if planinfo.needsplit:
--- a/server/querier.py	Fri Feb 26 13:24:47 2010 +0100
+++ b/server/querier.py	Fri Feb 26 13:30:24 2010 +0100
@@ -26,7 +26,7 @@
 
 READ_ONLY_RTYPES = set(('eid', 'has_text', 'is', 'is_instance_of', 'identity'))
 
-def empty_rset(session, rql, args, rqlst=None):
+def empty_rset(rql, args, rqlst=None):
     """build an empty result set object"""
     return ResultSet([], rql, args, rqlst=rqlst)
 
@@ -612,7 +612,7 @@
                 except UnknownEid:
                     # we want queries such as "Any X WHERE X eid 9999"
                     # return an empty result instead of raising UnknownEid
-                    return empty_rset(session, rql, args)
+                    return empty_rset(rql, args)
                 cachekey.append(etype)
                 # ensure eid is correctly typed in args
                 args[key] = typed_eid(args[key])
@@ -630,7 +630,7 @@
             except UnknownEid:
                 # we want queries such as "Any X WHERE X eid 9999"
                 # return an empty result instead of raising UnknownEid
-                return empty_rset(session, rql, args, rqlst)
+                return empty_rset(rql, args, rqlst)
             self._rql_cache[cachekey] = rqlst
         orig_rqlst = rqlst
         if not rqlst.TYPE == 'select':
--- a/server/schemaserial.py	Fri Feb 26 13:24:47 2010 +0100
+++ b/server/schemaserial.py	Fri Feb 26 13:30:24 2010 +0100
@@ -294,7 +294,7 @@
     relations = ['X %s %%(%s)s' % (attr, attr) for attr in sorted(values)]
     return relations, values
 
-def _rdef_values(rschema, objtype, props):
+def _rdef_values(objtype, props):
     amap = {'order': 'ordernum'}
     values = {}
     for prop, default in schemamod.RelationDefinitionSchema.rproperty_defs(objtype).iteritems():
@@ -310,13 +310,13 @@
         values[amap.get(prop, prop)] = value
     return values
 
-def nfrdef_relations_values(rschema, objtype, props):
-    values = _rdef_values(rschema, objtype, props)
+def nfrdef_relations_values(objtype, props):
+    values = _rdef_values(objtype, props)
     relations = ['X %s %%(%s)s' % (attr, attr) for attr in sorted(values)]
     return relations, values
 
-def frdef_relations_values(rschema, objtype, props):
-    values = _rdef_values(rschema, objtype, props)
+def frdef_relations_values(objtype, props):
+    values = _rdef_values(objtype, props)
     default = values['default']
     del values['default']
     if default is not None:
@@ -429,7 +429,7 @@
 _LOCATE_RDEF_RQL1 = 'SE name %(se)s,ER name %(rt)s,OE name %(oe)s'
 
 def frdef2rql(rschema, subjtype, objtype, props):
-    relations, values = frdef_relations_values(rschema, objtype, props)
+    relations, values = frdef_relations_values(objtype, props)
     relations.append(_LOCATE_RDEF_RQL0)
     values.update({'se': str(subjtype), 'rt': str(rschema), 'oe': str(objtype)})
     yield 'INSERT CWAttribute X: %s WHERE %s' % (','.join(relations), _LOCATE_RDEF_RQL1), values
@@ -437,7 +437,7 @@
         yield rql + ', EDEF is CWAttribute', values
 
 def nfrdef2rql(rschema, subjtype, objtype, props):
-    relations, values = nfrdef_relations_values(rschema, objtype, props)
+    relations, values = nfrdef_relations_values(objtype, props)
     relations.append(_LOCATE_RDEF_RQL0)
     values.update({'se': str(subjtype), 'rt': str(rschema), 'oe': str(objtype)})
     yield 'INSERT CWRelation X: %s WHERE %s' % (','.join(relations), _LOCATE_RDEF_RQL1), values
@@ -504,14 +504,14 @@
     return __rdef2rql(genmap, rschema, subjtype, objtype, props)
 
 def updatefrdef2rql(rschema, subjtype, objtype, props):
-    relations, values = frdef_relations_values(rschema, objtype, props)
+    relations, values = frdef_relations_values(objtype, props)
     values.update({'se': subjtype, 'rt': str(rschema), 'oe': objtype})
     yield 'SET %s WHERE %s, %s, X is CWAttribute' % (','.join(relations),
                                                      _LOCATE_RDEF_RQL0,
                                                      _LOCATE_RDEF_RQL1), values
 
 def updatenfrdef2rql(rschema, subjtype, objtype, props):
-    relations, values = nfrdef_relations_values(rschema, objtype, props)
+    relations, values = nfrdef_relations_values(objtype, props)
     values.update({'se': subjtype, 'rt': str(rschema), 'oe': objtype})
     yield 'SET %s WHERE %s, %s, X is CWRelation' % (','.join(relations),
                                                     _LOCATE_RDEF_RQL0,
--- a/web/captcha.py	Fri Feb 26 13:24:47 2010 +0100
+++ b/web/captcha.py	Fri Feb 26 13:30:24 2010 +0100
@@ -38,7 +38,7 @@
     draw = ImageDraw.Draw(img)
     # draw 100 random colored boxes on the background
     x, y = img.size
-    for num in range(100):
+    for num in xrange(100):
         draw.rectangle((randint(0, x), randint(0, y),
                         randint(0, x), randint(0, y)),
                        fill=randint(0, 0xffffff))
--- a/web/views/old_calendar.py	Fri Feb 26 13:24:47 2010 +0100
+++ b/web/views/old_calendar.py	Fri Feb 26 13:30:24 2010 +0100
@@ -136,11 +136,11 @@
         end = last_day(next_month(day, shift))
         return begin, end
 
-    def _build_ampm_cells(self, daynum, events):
+    def _build_ampm_cells(self, events):
         """create a view without any hourly details.
 
-        :param daynum: day of the built cell
-        :param events: dictionnary with all events classified by hours"""
+        :param events: dictionnary with all events classified by hours
+        """
         # split events according am/pm
         am_events = [event for e_time, e_list in events.iteritems()
                      if 0 <= e_time.hour < 12
@@ -317,7 +317,7 @@
             day = first_day + timedelta(daynum)
             events = schedule.get(day)
             if events:
-                current_row.append((AMPM_DAY % (daynum+1),) + self._build_ampm_cells(daynum, events))
+                current_row.append((AMPM_DAY % (daynum+1),) + self._build_ampm_cells(events))
             else:
                 current_row.append((AMPM_DAY % (daynum+1),
                                     AMPM_EMPTY % ("amCell", "am"),
@@ -386,7 +386,7 @@
 
     def format_day_events(self, day, events):
         if events:
-            self.w(u'\n'.join(self._build_ampm_cells(day, events)))
+            self.w(u'\n'.join(self._build_ampm_cells(events)))
         else:
             self.w(u'%s %s'% (AMPM_EMPTY % ("amCell", "am"),
                               AMPM_EMPTY % ("pmCell", "pm")))
@@ -408,7 +408,7 @@
             day = first_day + timedelta(daynum)
             events = schedule.get(day)
             if events:
-                current_row.append((AMPM_DAY % (daynum+1),) + self._build_ampm_cells(daynum, events))
+                current_row.append((AMPM_DAY % (daynum+1),) + self._build_ampm_cells(events))
             else:
                 current_row.append((AMPM_DAY % (daynum+1),
                                     AMPM_EMPTY % ("amCell", "am"),