Fix issues with the os module.

Using a try/finally assures that the recursion checkers work the right way.
This commit is contained in:
Dave Halter
2014-09-19 10:59:24 +02:00
parent b2342c76be
commit fc5f73861c
3 changed files with 65 additions and 44 deletions

View File

@@ -179,6 +179,7 @@ class ImportWrapper(pr.Base):
# check recursion
return []
try:
if self.import_path:
try:
module, rest = self._importer.follow_file_system()
@@ -224,6 +225,7 @@ class ImportWrapper(pr.Base):
if not scopes:
analysis.add(self._evaluator, 'import-error',
self._importer.import_path[-1])
finally:
self._evaluator.recursion_detector.pop_stmt()
return scopes

View File

@@ -686,6 +686,14 @@ class ModuleWrapper(use_metaclass(CachedMetaClass, pr.Module, Wrapper)):
imp = helpers.FakeImport(name, self, level=1)
name.parent = imp
names.append(name)
# TODO add something like this in the future, its cleaner than the
# import hacks.
# ``os.path`` is a hardcoded exception, because it's a
# ``sys.modules`` modification.
#if str(self.name) == 'os':
# names.append(helpers.FakeName('path', parent=self))
return names
def __getattr__(self, name):

View File

@@ -267,3 +267,14 @@ class TestGotoAssignments(TestCase):
n = nms[1].goto_assignments()[0]
assert n.name == 'load'
assert n.type == 'function'
nms = names('import os; os.path', references=True)
assert nms[0].name == 'os'
assert nms[0].type == 'import'
n = nms[0].goto_assignments()[0]
assert n.name == 'os'
assert n.type == 'module'
n = nms[2].goto_assignments()[0]
assert n.name == 'path'
assert n.type == 'import'