mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-10 07:41:51 +08:00
Fix issues with the os module.
Using a try/finally assures that the recursion checkers work the right way.
This commit is contained in:
@@ -179,6 +179,7 @@ class ImportWrapper(pr.Base):
|
|||||||
# check recursion
|
# check recursion
|
||||||
return []
|
return []
|
||||||
|
|
||||||
|
try:
|
||||||
if self.import_path:
|
if self.import_path:
|
||||||
try:
|
try:
|
||||||
module, rest = self._importer.follow_file_system()
|
module, rest = self._importer.follow_file_system()
|
||||||
@@ -224,6 +225,7 @@ class ImportWrapper(pr.Base):
|
|||||||
if not scopes:
|
if not scopes:
|
||||||
analysis.add(self._evaluator, 'import-error',
|
analysis.add(self._evaluator, 'import-error',
|
||||||
self._importer.import_path[-1])
|
self._importer.import_path[-1])
|
||||||
|
finally:
|
||||||
self._evaluator.recursion_detector.pop_stmt()
|
self._evaluator.recursion_detector.pop_stmt()
|
||||||
return scopes
|
return scopes
|
||||||
|
|
||||||
|
|||||||
@@ -686,6 +686,14 @@ class ModuleWrapper(use_metaclass(CachedMetaClass, pr.Module, Wrapper)):
|
|||||||
imp = helpers.FakeImport(name, self, level=1)
|
imp = helpers.FakeImport(name, self, level=1)
|
||||||
name.parent = imp
|
name.parent = imp
|
||||||
names.append(name)
|
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
|
return names
|
||||||
|
|
||||||
def __getattr__(self, name):
|
def __getattr__(self, name):
|
||||||
|
|||||||
@@ -267,3 +267,14 @@ class TestGotoAssignments(TestCase):
|
|||||||
n = nms[1].goto_assignments()[0]
|
n = nms[1].goto_assignments()[0]
|
||||||
assert n.name == 'load'
|
assert n.name == 'load'
|
||||||
assert n.type == 'function'
|
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'
|
||||||
|
|||||||
Reference in New Issue
Block a user