Anonymous avatar Anonymous committed 9be67c9

Handling integer builtin types
Handling BoolOp, BinOp, UnaryOp, and Compare AST nodes

Comments (0)

Files changed (6)

docs/dev/issues.txt

 * Informing others about the changes rope performs
 * Tools should inform rope about the changes they want to perform
 
+How can we make it work:
+
+* Letting rope do the changes and the IDE should observe
+* The IDE should perform the changes and rope should observe
+* Letting rope perform the refactoring changes and observe IDE changes
+
+
+Outgoing Changes
+----------------
+
 One way is to collect all file-system operations inside
 `FileSystemCommands`.
 
 of FS in the `FileSystemCommands`.  Since rope knows that it is
 working on a real file-system.
 
+So we can ask tools to register their own `FileSystemCommands` and
+commit all changes.
+
+
+Incoming Changes
+----------------
+
+
 
 Releasing Library Package
 =========================

docs/dev/library.txt

 existence of this module is supporting version control systems.  Have
 a look at `FileSystemCommands` and `SubversionCommands` in the same
 module.  If you need other version control systems you can write a new
-class providing this interface.  `rope.base.project.Project` accepts a
-``fscommands`` argument.  You can use this argument to force rope to
-use your new class.
+class that provides this interface.  `rope.base.project.Project`
+accepts a ``fscommands`` argument.  You can use this argument to force
+rope to use your new class.
 
 
 ``.ropeproject`` Folder
 See code documentation and test suites for more information.
 
 .. _overview.txt: ../user/overview.html
+
+
+Using Rope In Other IDEs
+========================
+
+In normal situation its as easy as described above.  But the problem
+happens when both Rope and the IDE need to know or possibly perform
+the changes that the other needs to perform.
+
+
+Outgoing Changes
+----------------
+
+Outgoing changes are the changes required by refactorings.  The
+`get_changes()` method of refactoring classes return a
+`rope.base.change.Change` object.  You perform these changes by
+calling `Project.do()`.  But as explained above some IDEs need to
+perform the changes themselves.
+
+Every change to file-system in rope is commited using an object that
+provides `rope.base.fscommands.FileSystemCommands` interface.  As
+explained above in `rope.base.fscommands`_ section, rope uses this
+interface to handle different VCSs.
+
+You can implement your own fscommands object::
+
+  class MyFileSystemCommands(object):
+
+    def create_file(self, path):
+        """Create a new file"""
+        # ...
+
+    def create_folder(self, path):
+        """Create a new folder"""
+        # ...
+
+    def move(self, path, new_location):
+        """Move resource at `path` to `new_location`"""
+        # ...
+
+    def remove(self, path):
+        """Remove resource"""
+        # ...
+
+    def write(self, path, data):
+        """Write `data` to file at `path`"""
+        # ...
+
+And you can create a project like this::
+
+  my_fscommands = MyFileSystemCommands()
+  project = rope.base.project.Project('~/myproject',
+                                      fscommands=my_fscommands)
+
+
+Incoming Changes
+----------------
+
+These are the changes that are performed by the IDE.  Rope needs to
+know the changes in order to update its cached data.  Also some useful
+features of rope are activated when changing the project.  For example
+when a file is saved static object inference is performed on the
+changed scopes.  Also project history records file changes and that is
+useful if you want to be able to undo and redo the changes.
+
+But if you don't care about these features you can use
+`Project.validate()`_ as described above.  But I don't recommend it.

docs/dev/workingon.txt

 Being A Better Library
 ======================
 
-- Moving write to `FileSystemCommands`
+- Handling the type of `int`, `float`, `bool`, and `complex` literals
+- Handling `BinOp`, `UnaryOp`, `BoolOp`, and `Compare` AST nodes
+
+* Specifying `__builtins__` module in restructuring dialog
 
 * Handling strings in following lines in `patchedast`
 * Extracting subexpressions; look at `extracttest` for more info

rope/base/evaluate.py

             pyobject=rope.base.builtins.get_str())
 
     def _Num(self, node):
-        pass
+        type_name = type(node.n).__name__
+        self.result = self._get_builtin_name(type_name)
+
+    def _get_builtin_name(self, type_name):
+        pytype = rope.base.builtins.builtins[type_name].get_object()
+        return rope.base.pynames.UnboundName(
+            rope.base.pyobjects.PyObject(pytype))
 
     def _BinOp(self, node):
-        pass
+        self.result = rope.base.pynames.UnboundName(
+            self._get_object_for_node(node.left))
 
     def _BoolOp(self, node):
-        pass
+        self.result = rope.base.pynames.UnboundName(
+            self._get_object_for_node(node.values[0]))
 
     def _Repr(self, node):
-        pass
+        self.result = self._get_builtin_name('str')
 
     def _UnaryOp(self, node):
-        pass
+        self.result = rope.base.pynames.UnboundName(
+            self._get_object_for_node(node.operand))
 
     def _Compare(self, node):
-        pass
+        self.result = self._get_builtin_name('bool')
 
     def _Dict(self, node):
         keys = None

rope/base/fscommands.py

                                   new_location, after=False)
 
     def remove(self, path):
-        self.client.remove(self.ui, self.repo, path)
+        mercurial.commands.remove(self.ui, self.repo, path)
 
     def write(self, path, data):
         self.normal_actions.write(path, data)

ropetest/builtintest.py

         a_var = pymod.get_attribute('a_var').get_object()
         self.assertEquals(c_class, a_var.get_type())
 
+    def test_simple_int_type(self):
+        self.mod.write('l = 1\n')
+        pymod = self.pycore.resource_to_pyobject(self.mod)
+        self.assertEquals(builtins.builtins['int'].get_object(),
+                          pymod.get_attribute('l').get_object().get_type())
+
+    def test_simple_float_type(self):
+        self.mod.write('l = 1.0\n')
+        pymod = self.pycore.resource_to_pyobject(self.mod)
+        self.assertEquals(builtins.builtins['float'].get_object(),
+                          pymod.get_attribute('l').get_object().get_type())
+
+    def test_simple_float_type2(self):
+        self.mod.write('l = 1e1\n')
+        pymod = self.pycore.resource_to_pyobject(self.mod)
+        self.assertEquals(builtins.builtins['float'].get_object(),
+                          pymod.get_attribute('l').get_object().get_type())
+
+    def test_simple_complex_type(self):
+        self.mod.write('l = 1.0j\n')
+        pymod = self.pycore.resource_to_pyobject(self.mod)
+        self.assertEquals(builtins.builtins['complex'].get_object(),
+                          pymod.get_attribute('l').get_object().get_type())
+
+    def test_handling_unaryop_on_ints(self):
+        self.mod.write('l = -(1)\n')
+        pymod = self.pycore.resource_to_pyobject(self.mod)
+        self.assertEquals(builtins.builtins['int'].get_object(),
+                          pymod.get_attribute('l').get_object().get_type())
+
+    def test_handling_binop_on_ints(self):
+        self.mod.write('l = 1 + 1\n')
+        pymod = self.pycore.resource_to_pyobject(self.mod)
+        self.assertEquals(builtins.builtins['int'].get_object(),
+                          pymod.get_attribute('l').get_object().get_type())
+
+    def test_handling_compares(self):
+        self.mod.write('l = 1 == 1\n')
+        pymod = self.pycore.resource_to_pyobject(self.mod)
+        self.assertEquals(builtins.builtins['bool'].get_object(),
+                          pymod.get_attribute('l').get_object().get_type())
+
+    def test_handling_boolops(self):
+        self.mod.write('l = 1 and 2\n')
+        pymod = self.pycore.resource_to_pyobject(self.mod)
+        self.assertEquals(builtins.builtins['int'].get_object(),
+                          pymod.get_attribute('l').get_object().get_type())
+
 
 if __name__ == '__main__':
     unittest.main()
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.