Commits

Anonymous committed 455d704

using name in pyobject instead of name in pyobject.get_attributes()

Comments (0)

Files changed (11)

rope/base/builtins.py

         return None
     seq = pyname.get_object()
     args = rope.base.evaluate.ObjectArguments([pyname])
-    if '__iter__' in seq.get_attributes():
+    if '__iter__' in seq:
         iter = seq['__iter__'].get_object().\
                get_returned_object(args)
-        if iter is not None and 'next' in iter.get_attributes():
+        if iter is not None and 'next' in iter:
             holding = iter['next'].get_object().\
                       get_returned_object(args)
             return holding

rope/base/evaluate.py

             if isinstance(pyobject, pyobjects.AbstractFunction):
                 return pyobject
             elif isinstance(pyobject, pyobjects.AbstractClass) and \
-                 '__init__' in pyobject.get_attributes():
+                 '__init__' in pyobject:
                 return pyobject['__init__'].get_object()
-            elif '__call__' in pyobject.get_attributes():
+            elif '__call__' in pyobject:
                 return pyobject['__call__'].get_object()
         return None
 
             return pyobject.get_returned_object(args)
         if isinstance(pyobject, rope.base.pyobjects.AbstractClass):
             result = None
-            if '__new__' in pyobject.get_attributes():
+            if '__new__' in pyobject:
                 new_function = pyobject['__new__'].get_object()
                 result = _get_returned(new_function)
             if result is None or \
         pyfunction = None
         if isinstance(pyobject, rope.base.pyobjects.AbstractFunction):
             pyfunction = pyobject
-        elif '__call__' in pyobject.get_attributes():
+        elif '__call__' in pyobject:
             pyfunction = pyobject['__call__'].get_object()
         if pyfunction is not None:
             self.result = rope.base.pynames.UnboundName(
             pyobject = pyname.get_object()
         else:
             return
-        if function_name in pyobject.get_attributes():
+        if function_name in pyobject:
             call_function = pyobject[function_name].get_object()
             args = [node]
             if other_args:

rope/base/oi/objectinfer.py

     return _infer_assignment_object(evaluated.assignment, pyobject)
 
 def _get_attribute(pyobject, name):
-    if pyobject is not None and name in pyobject.get_attributes():
+    if pyobject is not None and name in pyobject:
         return pyobject[name]
 
 

rope/base/oi/staticoi.py

                                              node, self.scope)
         elif isinstance(pyfunction, pyobjects.PyClass):
             pyclass = pyfunction
-            if '__init__' in pyfunction.get_attributes():
+            if '__init__' in pyfunction:
                 pyfunction = pyfunction['__init__'].get_object()
             pyname = rope.base.pynames.UnboundName(pyobjects.PyObject(pyclass))
             args = self._args_with_self(primary, pyname, pyfunction, node)
-        elif '__call__' in pyfunction.get_attributes():
+        elif '__call__' in pyfunction:
             pyfunction = pyfunction['__call__'].get_object()
             args = self._args_with_self(primary, pyname, pyfunction, node)
         else:
             args_pynames.append(rope.base.pynames.UnboundName(value))
             if instance is not None and value is not None:
                 pyobject = instance.get_object()
-                if '__setitem__' in pyobject.get_attributes():
+                if '__setitem__' in pyobject:
                     pyfunction = pyobject['__setitem__'].get_object()
                     args = evaluate.ObjectArguments([instance] + args_pynames)
                     self._call(pyfunction, args)

rope/base/pyobjects.py

         """The same as ``get_attribute(key)``"""
         return self.get_attribute(key)
 
+    def __contains__(self, key):
+        """The same as ``key in self.get_attributes()``"""
+        return key in self.get_attributes()
+
     def __eq__(self, obj):
         """Check the equality of two `PyObject`\s
 

rope/contrib/codeassist.py

                 if isinstance(pyobject, pyobjects.AbstractFunction):
                     pass
                 elif isinstance(pyobject, pyobjects.AbstractClass) and \
-                     '__init__' in pyobject.get_attributes():
+                     '__init__' in pyobject:
                     pyobject = pyobject['__init__'].get_object()
-                elif '__call__' in pyobject.get_attributes():
+                elif '__call__' in pyobject:
                     pyobject = pyobject['__call__'].get_object()
                 if isinstance(pyobject, pyobjects.AbstractFunction):
                     param_names = []
         supers = [super.get_name() for super in pyclass.get_superclasses()]
         doc = 'class %s(%s):\n\n' % (pyclass.get_name(), ', '.join(supers)) + contents
 
-        if '__init__' in pyclass.get_attributes():
+        if '__init__' in pyclass:
             init = pyclass['__init__'].get_object()
             if isinstance(init, pyobjects.AbstractFunction):
                 doc += '\n\n' + self._get_single_function_docstring(init)
     def _get_super_methods(self, pyclass, name):
         result = []
         for super_class in pyclass.get_superclasses():
-            if name in super_class.get_attributes():
+            if name in super_class:
                 function = super_class[name].get_object()
                 if isinstance(function, pyobjects.AbstractFunction):
                     result.append(function)

rope/refactor/change_signature.py

             return
         pyobject = self.pyname.get_object()
         if isinstance(pyobject, pyobjects.PyClass) and \
-           '__init__' in pyobject.get_attributes():
+           '__init__' in pyobject:
             self.pyname = pyobject['__init__']
             self.name = '__init__'
         pyobject = self.pyname.get_object()

rope/refactor/localtofield.py

 
     def _check_redefinition(self, name, function_scope):
         class_scope = function_scope.parent
-        if name in class_scope.pyobject.get_attributes():
+        if name in class_scope.pyobject:
             raise exceptions.RefactoringError(
                 'The field %s already exists' % name)
 

rope/refactor/rename.py

     def _get_superclasses_defining_method(self, pyclass, attr_name):
         result = set()
         for superclass in pyclass.get_superclasses():
-            if attr_name in superclass.get_attributes():
+            if attr_name in superclass:
                 result.update(self._get_superclasses_defining_method(
                               superclass, attr_name))
         if not result:

ropetest/builtinstest.py

     def test_simple_case(self):
         self.mod.write('l = []\n')
         pymod = self.pycore.resource_to_pyobject(self.mod)
-        self.assertTrue('append' in pymod['l'].get_object().get_attributes())
+        self.assertTrue('append' in pymod['l'].get_object())
 
     def test_holding_type_information(self):
         self.mod.write('class C(object):\n    pass\nl = [C()]\na_var = l.pop()\n')
     def test_simple_case_for_dicts(self):
         self.mod.write('d = {}\n')
         pymod = self.pycore.resource_to_pyobject(self.mod)
-        self.assertTrue('get' in pymod['d'].get_object().get_attributes())
+        self.assertTrue('get' in pymod['d'].get_object())
 
     def test_get_item_for_dicts(self):
         self.mod.write('class C(object):\n    pass\nd = {1: C()}\na_var = d[1]\n')
     def test_simple_builtin_scope_test(self):
         self.mod.write('l = list()\n')
         pymod = self.pycore.resource_to_pyobject(self.mod)
-        self.assertTrue('append' in pymod['l'].get_object().get_attributes())
+        self.assertTrue('append' in pymod['l'].get_object())
 
     def test_simple_sets(self):
         self.mod.write('s = set()\n')
         pymod = self.pycore.resource_to_pyobject(self.mod)
-        self.assertTrue('add' in pymod['s'].get_object().get_attributes())
+        self.assertTrue('add' in pymod['s'].get_object())
 
     def test_making_lists_using_the_passed_argument_to_init(self):
         self.mod.write('class C(object):\n    pass\nl1 = [C()]\n'
         self.mod.write('l = range(1)\n')
         pymod = self.pycore.resource_to_pyobject(self.mod)
         l = pymod['l'].get_object()
-        self.assertTrue('append' in l.get_attributes())
+        self.assertTrue('append' in l)
 
     def test_reversed_builtin_function(self):
         self.mod.write('class C(object):\n    pass\nl = [C()]\n'
         self.mod.write('p = property()\n')
         pymod = self.pycore.resource_to_pyobject(self.mod)
         p_var = pymod['p'].get_object()
-        self.assertTrue('fget' in p_var.get_attributes())
+        self.assertTrue('fget' in p_var)
 
     def test_lambda_functions(self):
         self.mod.write('l = lambda: 1\n')

ropetest/pycoretest.py

         mod = self.pycore.get_string_module('class Base(object):\n    def method(self):\n        pass\n' +
                                              'class Derived(Base):\n    pass\n')
         derived = mod['Derived'].get_object()
-        self.assertTrue('method' in derived.get_attributes())
+        self.assertTrue('method' in derived)
         self.assertEquals(get_base_type('Function'),
                           derived['method'].get_object().get_type())
 
                'class Derived(Base1, Base2):\n    pass\n'
         mod = self.pycore.get_string_module(code)
         derived = mod['Derived'].get_object()
-        self.assertTrue('method1' in derived.get_attributes())
-        self.assertTrue('method2' in derived.get_attributes())
+        self.assertTrue('method1' in derived)
+        self.assertTrue('method2' in derived)
 
     def test_inheriting_multiple_base_class_attributes_with_the_same_name(self):
         code = 'class Base1(object):\n    def method(self):\n        pass\n' \
         mod = self.pycore.get_string_module('class Derived(NotFound):\n' \
                                             '    def f(self):\n        pass\n')
         derived = mod['Derived'].get_object()
-        self.assertTrue('f' in derived.get_attributes())
+        self.assertTrue('f' in derived)
 
     def test_module_creation(self):
         new_module = testutils.create_module(self.project, 'module')
     def test_out_of_project_modules(self):
         scope = self.pycore.get_string_scope('import rope.base.project as project\n')
         imported_module = scope.get_name('project').get_object()
-        self.assertTrue('Project' in imported_module.get_attributes())
+        self.assertTrue('Project' in imported_module)
 
     def test_file_encoding_reading(self):
         contents = u'# -*- coding: utf-8 -*-\n#\N{LATIN SMALL LETTER I WITH DIAERESIS}\n'
                   '        for my_var1, my_var2 in []:\n            pass\n')
         pymod = self.pycore.resource_to_pyobject(mod)
         c_class = pymod['C'].get_object()
-        self.assertFalse('my_var1' in c_class.get_attributes())
-        self.assertFalse('my_var2' in c_class.get_attributes())
+        self.assertFalse('my_var1' in c_class)
+        self.assertFalse('my_var2' in c_class)
 
     def test_not_leaking_for_vars_inside_parent_scope2(self):
         mod = testutils.create_module(self.project, 'mod')
                   '        for my_var in []:\n            pass\n')
         pymod = self.pycore.resource_to_pyobject(mod)
         c_class = pymod['C'].get_object()
-        self.assertFalse('my_var' in c_class.get_attributes())
+        self.assertFalse('my_var' in c_class)
 
     def test_not_leaking_tuple_assigned_names_inside_parent_scope(self):
         mod = testutils.create_module(self.project, 'mod')
                   '        var1, var2 = range(2)\n')
         pymod = self.pycore.resource_to_pyobject(mod)
         c_class = pymod['C'].get_object()
-        self.assertFalse('var1' in c_class.get_attributes())
+        self.assertFalse('var1' in c_class)
 
     @testutils.run_only_for_25
     def test_with_statement_variables(self):
         if sys.version_info < (2, 6, 0):
             code = 'from __future__ import with_statement\n' + code
         pymod = self.pycore.get_string_module(code)
-        self.assertTrue('var' in pymod.get_attributes())
+        self.assertTrue('var' in pymod)
 
     @testutils.run_only_for_25
     def test_with_statement_variables_and_tuple_assignment(self):
         if sys.version_info < (2, 6, 0):
             code = 'from __future__ import with_statement\n' + code
         pymod = self.pycore.get_string_module(code)
-        self.assertTrue('a' in pymod.get_attributes())
-        self.assertTrue('b' in pymod.get_attributes())
+        self.assertTrue('a' in pymod)
+        self.assertTrue('b' in pymod)
 
     @testutils.run_only_for_25
     def test_with_statement_variable_type(self):
 
     def test_unknown_when_module_cannot_be_found(self):
         mod = self.pycore.get_string_module('from doesnotexist import nestedmod\n')
-        self.assertTrue('nestedmod' in mod.get_attributes())
+        self.assertTrue('nestedmod' in mod)
 
     def test_from_import_function(self):
         scope = self.pycore.get_string_scope('def f():\n    from samplemod import SampleClass\n')
         pkg_mod = testutils.create_module(self.project, 'mod', pkg)
         pkg_mod.write('def sample_func():\n    pass\n')
         mod = self.pycore.get_string_module('import pkg.mod\n')
-        self.assertTrue('pkg' in mod.get_attributes())
-        self.assertTrue('sample_func' in
-                        mod['pkg'].get_object()['mod'].
-                        get_object().get_attributes())
+        self.assertTrue('pkg' in mod)
+        self.assertTrue('sample_func' in mod['pkg'].get_object()['mod'].
+                                get_object())
 
     def test_multi_dot_imports2(self):
         pkg = testutils.create_package(self.project, 'pkg')
         mod = self.pycore.get_string_module('import pkg.mod1\nimport pkg.mod2\n')
         package = mod['pkg'].get_object()
         self.assertEquals(2, len(package.get_attributes()))
-        self.assertTrue('mod1' in package.get_attributes() and
-                        'mod2' in package.get_attributes())
+        self.assertTrue('mod1' in package and
+                        'mod2' in package)
 
     def test_multi_dot_imports3(self):
         pkg1 = testutils.create_package(self.project, 'pkg1')
         package1 = mod['pkg1'].get_object()
         package2 = package1['pkg2'].get_object()
         self.assertEquals(2, len(package2.get_attributes()))
-        self.assertTrue('mod1' in package2.get_attributes() and
-                        'mod2' in package2.get_attributes())
+        self.assertTrue('mod1' in package2 and
+                        'mod2' in package2)
 
     def test_multi_dot_imports_as(self):
         pkg = testutils.create_package(self.project, 'pkg')
         mod1.write('def f():\n    pass\n')
         mod = self.pycore.get_string_module('import pkg.mod1 as mod1\n')
         module = mod['mod1'].get_object()
-        self.assertTrue('f' in module.get_attributes())
+        self.assertTrue('f' in module)
 
     # TODO: not showing unimported names as attributes of packages
     def xxx_test_from_package_import_package(self):
         self.assertTrue('var' not in mod1.get_attributes())
         module.write('var = 10\n')
         mod2 = self.pycore.get_module('mod')
-        self.assertTrue('var' in mod2.get_attributes())
+        self.assertTrue('var' in mod2)
 
     def test_invalidating_cache_after_resource_change_for_init_dot_pys(self):
         pkg = testutils.create_package(self.project, 'pkg')
         init_dot_py.write('a_var = 10\n')
         mod.write('import pkg\n')
         pymod = self.pycore.get_module('mod')
-        self.assertTrue('a_var' in pymod['pkg'].get_object().get_attributes())
+        self.assertTrue('a_var' in pymod['pkg'].get_object())
         init_dot_py.write('new_var = 10\n')
         self.assertTrue('a_var' not in pymod['pkg'].get_object().get_attributes())
 
         init_dot_py.write('a_var = 10\n')
         mod.write('import pkg1\n')
         pymod = self.pycore.get_module('mod')
-        self.assertTrue('a_var' in pymod['pkg1'].get_object()['pkg2'].get_object().get_attributes())
+        self.assertTrue('a_var' in pymod['pkg1'].get_object()['pkg2'].get_object())
         init_dot_py.write('new_var = 10\n')
         self.assertTrue('a_var' not in pymod['pkg1'].get_object()['pkg2'].get_object().get_attributes())
 
     def test_from_import_nonexistent_module(self):
         mod = self.pycore.get_string_module('from doesnotexistmod import DoesNotExistClass\n')
-        self.assertTrue('DoesNotExistClass' in mod.get_attributes())
+        self.assertTrue('DoesNotExistClass' in mod)
         self.assertEquals(get_base_type('Unknown'),
                           mod['DoesNotExistClass'].
                           get_object().get_type())
 
     def test_from_import_nonexistent_name(self):
         mod = self.pycore.get_string_module('from samplemod import DoesNotExistClass\n')
-        self.assertTrue('DoesNotExistClass' in mod.get_attributes())
+        self.assertTrue('DoesNotExistClass' in mod)
         self.assertEquals(get_base_type('Unknown'),
                           mod['DoesNotExistClass'].
                           get_object().get_type())
         mod = self.pycore.get_string_module('import samplemod\n' +
                                             'class Derived(samplemod.SampleClass):\n    pass\n')
         derived = mod['Derived'].get_object()
-        self.assertTrue('sample_method' in derived.get_attributes())
+        self.assertTrue('sample_method' in derived)
 
     def test_self_in_methods(self):
         scope = self.pycore.get_string_scope('class Sample(object):\n' \
         self.assertEquals(sample_class,
                           func_scope.get_name('self').get_object().get_type())
         self.assertTrue('func' in func_scope.get_name('self').
-                        get_object().get_attributes())
+                                get_object())
 
     def test_none_assignments_in_classes(self):
         scope = self.pycore.get_string_scope(
             'class C(object):\n    var = ""\n'
             '    def f(self):\n        self.var += "".join([])\n')
         c_class = scope.get_name('C').get_object()
-        self.assertTrue('var' in c_class.get_attributes())
+        self.assertTrue('var' in c_class)
 
     def test_self_in_methods_with_decorators(self):
         scope = self.pycore.get_string_scope('class Sample(object):\n    @staticmethod\n' +
         init_dot_py = pkg.get_child('__init__.py')
         init_dot_py.write('a_var = 1\n')
         pkg_object = self.pycore.get_module('pkg')
-        self.assertTrue('a_var' in pkg_object.get_attributes())
+        self.assertTrue('a_var' in pkg_object)
 
     def test_relative_imports(self):
         pkg = testutils.create_package(self.project, 'pkg')
         mod2.write('import mod1\nclass B(mod1.A):\n    pass\n')
 
         b_class = self.pycore.get_module('mod2')['B'].get_object()
-        self.assertTrue('func1' in b_class.get_attributes())
+        self.assertTrue('func1' in b_class)
 
         mod1.write('class A(object):\n    def func2(self):\n        pass\n')
-        self.assertTrue('func2' in b_class.get_attributes())
+        self.assertTrue('func2' in b_class)
 
     def test_simple_module(self):
         mod = testutils.create_module(self.project, 'mod')
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.