agr / rope_py3k (http://rope.sf.net/)

A python refactoring library; py3k branch.

Clone this repository (size: 3.4 MB): HTTPS / SSH
$ hg clone http://bitbucket.org/agr/rope_py3k/
commit 1432: 7bd0e1aef1fb
parent 1431: 0500223628c9
branch: trunk
autoimport: handling builtin modules
Ali Gholami Rudi
21 months ago

Changed (Δ462 bytes):

raw changeset »

rope/contrib/autoimport.py (9 lines added, 2 lines removed)

ropetest/contrib/autoimporttest.py (4 lines added, 0 lines removed)

Up to file-list rope/contrib/autoimport.py:

1
1
import re
2
2
3
from rope.base import exceptions, pynames, resourceobserver, taskhandle
3
from rope.base import (exceptions, pynames, resourceobserver,
4
                       taskhandle, pyobjects, builtins)
4
5
from rope.refactor import importutils
5
6
6
7
@@ -163,11 +164,17 @@ class AutoImport(object):
163
164
        if underlined is None:
164
165
            underlined = self.underlined
165
166
        globals = []
166
        for name, pyname in pymodule._get_structural_attributes().items():
167
        if isinstance(pymodule, pyobjects.PyDefinedObject):
168
            attributes = pymodule._get_structural_attributes()
169
        else:
170
            attributes = pymodule.get_attributes()
171
        for name, pyname in attributes.items():
167
172
            if not underlined and name.startswith('_'):
168
173
                continue
169
174
            if isinstance(pyname, (pynames.AssignedName, pynames.DefinedName)):
170
175
                globals.append(name)
176
            if isinstance(pymodule, builtins.BuiltinModule):
177
                globals.append(name)
171
178
        self.names[modname] = globals
172
179
173
180
    def _write(self):

Up to file-list ropetest/contrib/autoimporttest.py:

@@ -117,6 +117,10 @@ class AutoImportTest(unittest.TestCase):
117
117
        self.assertEquals(set([(self.mod1, 1), (self.mod2, 2)]),
118
118
                          set(self.importer.get_name_locations('myvar')))
119
119
120
    def test_handling_builtin_modules(self):
121
        self.importer.update_module('sys')
122
        self.assertTrue('sys' in self.importer.get_modules('exit'))
123
120
124
121
125
class AutoImportObservingTest(unittest.TestCase):
122
126