mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-06 22:14:27 +08:00
This commit is contained in:
@@ -27,7 +27,7 @@ from jedi.inference.compiled.mixed import MixedName
|
|||||||
from jedi.inference.names import ImportName, SubModuleName
|
from jedi.inference.names import ImportName, SubModuleName
|
||||||
from jedi.inference.gradual.stub_value import StubModuleValue
|
from jedi.inference.gradual.stub_value import StubModuleValue
|
||||||
from jedi.inference.gradual.conversion import convert_names, convert_values
|
from jedi.inference.gradual.conversion import convert_names, convert_values
|
||||||
from jedi.inference.base_value import ValueSet
|
from jedi.inference.base_value import ValueSet, HasNoContext
|
||||||
from jedi.api.keywords import KeywordName
|
from jedi.api.keywords import KeywordName
|
||||||
from jedi.api import completion_cache
|
from jedi.api import completion_cache
|
||||||
from jedi.api.helpers import filter_follow_imports
|
from jedi.api.helpers import filter_follow_imports
|
||||||
@@ -37,13 +37,17 @@ def _sort_names_by_start_pos(names):
|
|||||||
return sorted(names, key=lambda s: s.start_pos or (0, 0))
|
return sorted(names, key=lambda s: s.start_pos or (0, 0))
|
||||||
|
|
||||||
|
|
||||||
def defined_names(inference_state, context):
|
def defined_names(inference_state, value):
|
||||||
"""
|
"""
|
||||||
List sub-definitions (e.g., methods in class).
|
List sub-definitions (e.g., methods in class).
|
||||||
|
|
||||||
:type scope: Scope
|
:type scope: Scope
|
||||||
:rtype: list of Name
|
:rtype: list of Name
|
||||||
"""
|
"""
|
||||||
|
try:
|
||||||
|
context = value.as_context()
|
||||||
|
except HasNoContext:
|
||||||
|
return []
|
||||||
filter = next(context.get_filters())
|
filter = next(context.get_filters())
|
||||||
names = [name for name in filter.values()]
|
names = [name for name in filter.values()]
|
||||||
return [Name(inference_state, n) for n in _sort_names_by_start_pos(names)]
|
return [Name(inference_state, n) for n in _sort_names_by_start_pos(names)]
|
||||||
@@ -759,7 +763,7 @@ class Name(BaseName):
|
|||||||
"""
|
"""
|
||||||
defs = self._name.infer()
|
defs = self._name.infer()
|
||||||
return sorted(
|
return sorted(
|
||||||
unite(defined_names(self._inference_state, d.as_context()) for d in defs),
|
unite(defined_names(self._inference_state, d) for d in defs),
|
||||||
key=lambda s: s._name.start_pos or (0, 0)
|
key=lambda s: s._name.start_pos or (0, 0)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -22,6 +22,10 @@ from jedi.cache import memoize_method
|
|||||||
sentinel = object()
|
sentinel = object()
|
||||||
|
|
||||||
|
|
||||||
|
class HasNoContext(Exception):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
class HelperValueMixin:
|
class HelperValueMixin:
|
||||||
def get_root_context(self):
|
def get_root_context(self):
|
||||||
value = self
|
value = self
|
||||||
@@ -261,7 +265,7 @@ class Value(HelperValueMixin):
|
|||||||
return self.parent_context.is_stub()
|
return self.parent_context.is_stub()
|
||||||
|
|
||||||
def _as_context(self):
|
def _as_context(self):
|
||||||
raise NotImplementedError('Not all values need to be converted to contexts: %s', self)
|
raise HasNoContext
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def name(self):
|
def name(self):
|
||||||
|
|||||||
@@ -189,3 +189,9 @@ def test_no_error(get_names):
|
|||||||
def test_is_side_effect(get_names, code, index, is_side_effect):
|
def test_is_side_effect(get_names, code, index, is_side_effect):
|
||||||
names = get_names(code, references=True, all_scopes=True)
|
names = get_names(code, references=True, all_scopes=True)
|
||||||
assert names[index].is_side_effect() == is_side_effect
|
assert names[index].is_side_effect() == is_side_effect
|
||||||
|
|
||||||
|
|
||||||
|
def test_no_defined_names(get_names):
|
||||||
|
definition, = get_names("x = (1, 2)")
|
||||||
|
|
||||||
|
assert not definition.defined_names()
|
||||||
|
|||||||
Reference in New Issue
Block a user