forked from VimPlug/jedi
Merge remote-tracking branch 'origin/master' into typeshed
This commit is contained in:
@@ -397,7 +397,7 @@ class Completion(BaseDefinition):
|
|||||||
def _complete(self, like_name):
|
def _complete(self, like_name):
|
||||||
append = ''
|
append = ''
|
||||||
if settings.add_bracket_after_function \
|
if settings.add_bracket_after_function \
|
||||||
and self.type == 'Function':
|
and self.type == 'function':
|
||||||
append = '('
|
append = '('
|
||||||
|
|
||||||
if self._name.api_type == 'param' and self._stack is not None:
|
if self._name.api_type == 'param' and self._stack is not None:
|
||||||
|
|||||||
@@ -334,7 +334,10 @@ def get_system_environment(version):
|
|||||||
|
|
||||||
if os.name == 'nt':
|
if os.name == 'nt':
|
||||||
for exe in _get_executables_from_windows_registry(version):
|
for exe in _get_executables_from_windows_registry(version):
|
||||||
return Environment(exe)
|
try:
|
||||||
|
return Environment(exe)
|
||||||
|
except InvalidPythonEnvironment:
|
||||||
|
pass
|
||||||
raise InvalidPythonEnvironment("Cannot find executable python%s." % version)
|
raise InvalidPythonEnvironment("Cannot find executable python%s." % version)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -190,6 +190,9 @@ def get_module_names(module, all_scopes):
|
|||||||
# but that would be a big change that could break type inference, whereas for now
|
# but that would be a big change that could break type inference, whereas for now
|
||||||
# this discrepancy looks like only a problem for "get_module_names".
|
# this discrepancy looks like only a problem for "get_module_names".
|
||||||
parent_scope = parent_scope.parent
|
parent_scope = parent_scope.parent
|
||||||
|
# async functions have an extra wrapper. Strip it.
|
||||||
|
if parent_scope and parent_scope.type == 'async_stmt':
|
||||||
|
parent_scope = parent_scope.parent
|
||||||
return parent_scope in (module, None)
|
return parent_scope in (module, None)
|
||||||
|
|
||||||
names = [n for n in names if is_module_scope_name(n)]
|
names = [n for n in names if is_module_scope_name(n)]
|
||||||
|
|||||||
@@ -95,6 +95,43 @@ class TestDefinedNames(TestCase):
|
|||||||
self.assert_definition_names(C_subdefs, ['h'])
|
self.assert_definition_names(C_subdefs, ['h'])
|
||||||
self.assert_definition_names(foo_subdefs, ['x', 'bar'])
|
self.assert_definition_names(foo_subdefs, ['x', 'bar'])
|
||||||
|
|
||||||
|
def test_async_stmt_with_all_scopes_false(self):
|
||||||
|
definitions = self.check_defined_names("""
|
||||||
|
from module import f
|
||||||
|
import asyncio
|
||||||
|
|
||||||
|
g = f(f)
|
||||||
|
class C:
|
||||||
|
h = g
|
||||||
|
def __init__(self):
|
||||||
|
pass
|
||||||
|
|
||||||
|
async def __aenter__(self):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def foo(x=a):
|
||||||
|
bar = x
|
||||||
|
return bar
|
||||||
|
|
||||||
|
async def async_foo(duration):
|
||||||
|
async def wait():
|
||||||
|
await asyncio.sleep(100)
|
||||||
|
for i in range(duration//100):
|
||||||
|
await wait()
|
||||||
|
return duration//100*100
|
||||||
|
|
||||||
|
async with C() as cinst:
|
||||||
|
d = cinst
|
||||||
|
""", ['f', 'asyncio', 'g', 'C', 'foo', 'async_foo', 'cinst', 'd'])
|
||||||
|
C_subdefs = definitions[3].defined_names()
|
||||||
|
foo_subdefs = definitions[4].defined_names()
|
||||||
|
async_foo_subdefs = definitions[5].defined_names()
|
||||||
|
cinst_subdefs = definitions[6].defined_names()
|
||||||
|
self.assert_definition_names(C_subdefs, ['h', '__init__', '__aenter__'])
|
||||||
|
self.assert_definition_names(foo_subdefs, ['x', 'bar'])
|
||||||
|
self.assert_definition_names(async_foo_subdefs, ['duration', 'wait', 'i'])
|
||||||
|
# We treat d as a name outside `async with` block
|
||||||
|
self.assert_definition_names(cinst_subdefs, [])
|
||||||
|
|
||||||
def test_follow_imports(environment):
|
def test_follow_imports(environment):
|
||||||
# github issue #344
|
# github issue #344
|
||||||
|
|||||||
@@ -21,3 +21,14 @@ def test_add_dynamic_mods(Script):
|
|||||||
result = script.goto_definitions()
|
result = script.goto_definitions()
|
||||||
assert len(result) == 1
|
assert len(result) == 1
|
||||||
assert result[0].description == 'class int'
|
assert result[0].description == 'class int'
|
||||||
|
|
||||||
|
|
||||||
|
def test_add_bracket_after_function(monkeypatch, Script):
|
||||||
|
settings = api.settings
|
||||||
|
monkeypatch.setattr(settings, 'add_bracket_after_function', True)
|
||||||
|
script = Script('''\
|
||||||
|
def foo():
|
||||||
|
pass
|
||||||
|
foo''')
|
||||||
|
completions = script.completions()
|
||||||
|
assert completions[0].complete == '('
|
||||||
|
|||||||
Reference in New Issue
Block a user