Commits

Anonymous committed 96906e6

Using items instead of iteritems
Using // instead of /

  • Participants
  • Parent commits 7808056

Comments (0)

Files changed (14)

docs/dev/issues.txt

 Hot Topics
 ==========
 
-* `Restructuring UI`_
-
+* `Enhanding Extract`
 
 To Be Discussed
 ===============
 * Should `rope.base` be thread safe? which parts?
 
 
+Enhancing Extract
+=================
+
+Now that we have implemented restructurings, we can add extract
+similar statements option to extract variable/method refactoring.  But
+there are issues to be handled first.
+
+
+Where To Search
+---------------
+
+The inserted definition should appear before the occurrences.  This is
+not an issue for methods but for functions and variables.  We can
+*not* solve this by limited the region to search from the extracted
+expression till the end of its containing scope.::
+
+  if False:
+      print 1 + 1
+      print 1 + 1
+  print 1 + 1
+
+now if we extract the first appearance of ``1 + 1`` we'll have::
+
+  if False:
+      new_var = 1 + 1
+      print new_var
+      print new_var
+  print new_var
+
+But in the last line `new_var` cannot be resolved.
+
+
+Implementation
+--------------
+
+
+
 Finding Similar Pieces
 ======================
 
   goal = '${?x} = [${?a}] * 2'
 
 
-Restructuring UI
-================
-
-If restructuring is going to be used by a normal python user it has to
-have a good UI.  The search pattern and the goal is straightforward
-but adding checks is really a problem.
-
-We can have a list of changes.  Each item in this list is a tuple
-containing whose first item is a name that appear in search pattern
-plus an identifier like '', '.object', '.type'.  Its second item should
-be a string that indicates a `PyName` or a `PyObject`.
-
-Now the we have to find good ways for:
-
-* Specifying a `PyName` or `PyObject`
-* Differentiating between `PyName`\s and `PyObject`\s
-
-
 Memory Management
 =================
 

rope/base/builtins.py

         item = get_tuple(self.keys, self.values)
         collector = _AttributeCollector(dict)
         collector('__new__', function=self._new_dict)
-        for method in ['clear', 'has_key', 'setdefault']:
+        for method in ['clear', 'setdefault']:
             collector(method)
         collector('__setitem__', function=self._dict_add)
         collector('popitem', function=self._item_get)
         collector('items', function=self._item_list)
         collector('copy', function=self._self_get)
         collector('__getitem__', function=self._value_get)
-        collector('iterkeys', function=self._key_iter)
-        collector('itervalues', function=self._value_iter)
-        collector('iteritems', function=self._item_iter)
         collector('__iter__', function=self._key_iter)
         collector('update', function=self._self_set)
         super(Dict, self).__init__(dict, collector.attributes)

rope/base/codeanalyze.py

     def get_line_number(self, offset):
         down = 0
         up = len(self.line_starts)
-        current = (down + up) / 2
+        current = (down + up) // 2
         while down <= current < up:
             if self.line_starts[current] <= offset < self.line_starts[current + 1]:
                 return current + 1
                 up = current - 1
             else:
                 down = current + 1
-            current = (down + up) / 2
+            current = (down + up) // 2
         return current + 1
 
     def get_line_start(self, line_number):

rope/base/project.py

         for resource in changes.changes:
             self.observer.resource_changed(resource)
             self.resources[resource] = self.timekeeper.getmtime(resource)
-        for resource, new_resource in changes.moves.iteritems():
+        for resource, new_resource in changes.moves.items():
             self.resources[resource] = None
             if new_resource is not None:
                 self.observer.resource_moved(resource, new_resource)

rope/base/pynames.py

             #    return {}
             result = {}
             imported = self.imported_module.get_object()
-            for name, pyname in imported.get_attributes().iteritems():
+            for name, pyname in imported.get_attributes().items():
                 if not name.startswith('_'):
                     result[name] = ImportedName(self.imported_module, name)
             self.names.set(result)

rope/base/taskhandle.py

 
     def get_percent_done(self):
         if self.count is not None and self.count > 0:
-            percent = self.done * 100 / self.count
+            percent = self.done * 100 // self.count
             return min(percent, 100)
 
     def get_name(self):

rope/ide/codeassist.py

                                                          self.expression)
         if found_pyname is not None:
             element = found_pyname.get_object()
-            for name, pyname in element.get_attributes().iteritems():
+            for name, pyname in element.get_attributes().items():
                 if name.startswith(self.starting) or self.starting == '':
                     result[name] = CompletionProposal(
                         name, 'attribute', self._get_pyname_type(pyname))
             names = scope.get_propagated_names()
         else:
             names = scope.get_names()
-        for name, pyname in names.iteritems():
+        for name, pyname in names.items():
             if name.startswith(self.starting):
                 kind = 'local'
                 if scope.get_kind() == 'Module':

rope/refactor/importutils/module_imports.py

         super(_GlobalUnboundNameFinder, self).__init__(pymodule)
         self.unbound = set()
         self.names = set()
-        for name, pyname in pymodule._get_structural_attributes().iteritems():
+        for name, pyname in pymodule._get_structural_attributes().items():
             if not isinstance(pyname, (rope.base.pynames.ImportedName,
                                        rope.base.pynames.ImportedModule)):
                 self.names.add(name)

rope/refactor/inline.py

         paramdict = self.definition_params
         mapping = rope.refactor.functionutils.ArgumentMapping(self.definition_info,
                                                               call_info)
-        for param_name, value in mapping.param_dict.iteritems():
+        for param_name, value in mapping.param_dict.items():
             paramdict[param_name] = value
         header = ''
         to_be_inlined = []
-        for name, value in paramdict.iteritems():
+        for name, value in paramdict.items():
             if name != value:
                 header += name + ' = ' + value + '\n'
                 to_be_inlined.append(name)

rope/ui/editor.py

         start = self._get_line_from_index(self.text.index('@0,0'))
         end = self._get_line_from_index(
             self.text.index('@0,%d' % self.text.winfo_height()))
-        return (start + end) / 2
+        return (start + end) // 2
 
     def get_region_offset(self):
         start, end = self._get_region_index()
 
     def set_highlighting(self, highlighting):
         self.highlighting = highlighting
-        for name, style in self.highlighting.get_styles().iteritems():
+        for name, style in self.highlighting.get_styles().items():
             fontKWs = {}
             if style.italic is not None:
                 if style.italic:
         end = len(text)
         indexer = _OffsetToIndexCacher(self.text)
         while start < end:
-            mid = (start + end) / 2
+            mid = (start + end) // 2
             if self.text.compare(indexer.get_index(mid), '>', index):
                 end = mid - 1
             elif self.text.compare(indexer.get_index(mid), '==', index):

rope/ui/sourceactions.py

     entries = {}
     def ok(event=None):
         mapping = {}
-        for var, entry in entries.iteritems():
+        for var, entry in entries.items():
             mapping[var] = entry.get()
         apply_template(mapping)
         toplevel.destroy()

rope/ui/testview.py

     def stop_test(self, test_name):
         self.run_count += 1
         self.progress.set_text('ran %d of %d' % (self.run_count, self.count))
-        self.progress.set_done_percent(self.run_count * 100 / self.count)
+        self.progress.set_done_percent(self.run_count * 100 // self.count)
         return True
 
     def _is_finished(self):

rope/ui/uihelpers.py

         self.text['text'] = text
 
     def _draw_shape(self):
-        width = int(self.canvas['width']) * self.percent / 100
+        width = int(self.canvas['width']) * self.percent // 100
         self.canvas.create_rectangle(0, 0, width, self.canvas['height'],
                                      fill=self.color)
         total_width = self.canvas['width']

ropetest/builtintest.py

 
     def test_getting_iterkeys_from_dicts(self):
         self.mod.write('class C1(object):\n    pass\nclass C2(object):\n    pass\n'
-                       'd = {C1(): C2()}\nfor c in d.iterkeys():\n    a_var = c\n')
+                       'd = {C1(): C2()}\nfor c in d.keys():\n    a_var = c\n')
         pymod = self.pycore.resource_to_pyobject(self.mod)
         c_class = pymod.get_attribute('C1').get_object()
         a_var = pymod.get_attribute('a_var').get_object()
 
     def test_getting_itervalues_from_dicts(self):
         self.mod.write('class C1(object):\n    pass\nclass C2(object):\n    pass\n'
-                       'd = {C1(): C2()}\nfor c in d.itervalues():\n    a_var = c\n')
+                       'd = {C1(): C2()}\nfor c in d.values():\n    a_var = c\n')
         pymod = self.pycore.resource_to_pyobject(self.mod)
         c_class = pymod.get_attribute('C2').get_object()
         a_var = pymod.get_attribute('a_var').get_object()
 
     def test_tuple_assignments_for_iteritems_in_fors(self):
         self.mod.write('class C1(object):\n    pass\nclass C2(object):\n    pass\n'
-                       'd = {C1(): C2()}\nfor x, y in d.iteritems():\n    a = x;\n    b = y\n')
+                       'd = {C1(): C2()}\nfor x, y in d.items():\n    a = x;\n    b = y\n')
         pymod = self.pycore.resource_to_pyobject(self.mod)
         c1_class = pymod.get_attribute('C1').get_object()
         c2_class = pymod.get_attribute('C2').get_object()