mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-07 06:24:27 +08:00
Fix get_parent_scope
This commit is contained in:
@@ -243,14 +243,16 @@ def get_parent_scope(node, include_flows=False):
|
|||||||
Returns the underlying scope.
|
Returns the underlying scope.
|
||||||
"""
|
"""
|
||||||
scope = node.parent
|
scope = node.parent
|
||||||
|
if scope is None:
|
||||||
|
return None # It's a module already.
|
||||||
if scope.type in ('funcdef', 'classdef') and scope.name == node:
|
if scope.type in ('funcdef', 'classdef') and scope.name == node:
|
||||||
scope = scope.parent
|
scope = scope.parent
|
||||||
|
if scope.parent is None: # The module scope.
|
||||||
|
return scope
|
||||||
|
|
||||||
while scope is not None:
|
while True:
|
||||||
if include_flows and isinstance(scope, tree.Flow):
|
if include_flows and isinstance(scope, tree.Flow) or is_scope(scope):
|
||||||
return scope
|
return scope
|
||||||
if is_scope(scope):
|
|
||||||
break
|
|
||||||
scope = scope.parent
|
scope = scope.parent
|
||||||
return scope
|
return scope
|
||||||
|
|
||||||
|
|||||||
@@ -99,7 +99,7 @@ def test_function_call_signature_in_doc(Script):
|
|||||||
|
|
||||||
|
|
||||||
def test_param_docstring():
|
def test_param_docstring():
|
||||||
param = jedi.names("def test(parameter): pass")[1]
|
param = jedi.names("def test(parameter): pass", all_scopes=True)[1]
|
||||||
assert param.name == 'parameter'
|
assert param.name == 'parameter'
|
||||||
assert param.docstring() == ''
|
assert param.docstring() == ''
|
||||||
|
|
||||||
|
|||||||
@@ -41,6 +41,7 @@ def test_namedtuple_list(Script):
|
|||||||
assert completions == {'legs', 'length', 'large'}
|
assert completions == {'legs', 'length', 'large'}
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.skip(reason='TODO Please remove this once typeshed is merged')
|
||||||
def test_namedtuple_content(Script):
|
def test_namedtuple_content(Script):
|
||||||
source = dedent("""\
|
source = dedent("""\
|
||||||
import collections
|
import collections
|
||||||
|
|||||||
Reference in New Issue
Block a user