mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-07 06:24:27 +08:00
Some small improvements
This commit is contained in:
@@ -75,7 +75,7 @@ class BaseDefinition(object):
|
||||
# This can take a while to complete, because in the worst case of
|
||||
# imports (consider `import a` completions), we need to load all
|
||||
# modules starting with a first.
|
||||
return self._name.get_root_value()
|
||||
return self._name.get_root_context()
|
||||
|
||||
@property
|
||||
def module_path(self):
|
||||
@@ -289,7 +289,7 @@ class BaseDefinition(object):
|
||||
if not self._name.is_value_name:
|
||||
return False
|
||||
|
||||
return self._name.get_root_value().is_stub()
|
||||
return self._name.get_root_context().is_stub()
|
||||
|
||||
def goto_assignments(self, **kwargs): # Python 2...
|
||||
with debug.increase_indent_cm('goto for %s' % self._name):
|
||||
@@ -389,7 +389,7 @@ class BaseDefinition(object):
|
||||
if not self._name.is_value_name or self.in_builtin_module():
|
||||
return ''
|
||||
|
||||
lines = self._name.get_root_value().code_lines
|
||||
lines = self._name.get_root_context().code_lines
|
||||
|
||||
index = self._name.start_pos[0] - 1
|
||||
start_index = max(index - before, 0)
|
||||
|
||||
@@ -28,18 +28,17 @@ class AbstractContext(object):
|
||||
return self._value.py__getattribute__
|
||||
|
||||
@property
|
||||
def tree_name(self):
|
||||
def tree_node(self):
|
||||
return self._value.tree_node
|
||||
|
||||
def infer_node(self, node):
|
||||
raise NotImplementedError
|
||||
return self.inference_state.infer_element(self, node)
|
||||
|
||||
def __repr__(self):
|
||||
return '%s(%s)' % (self.__class__.__name__, self._value)
|
||||
|
||||
|
||||
class FunctionContext(AbstractContext):
|
||||
@abstractmethod
|
||||
def get_filters(self, until_position=None, origin_scope=None):
|
||||
yield ParserTreeFilter(
|
||||
self.inference_state,
|
||||
@@ -56,3 +55,15 @@ class ModuleContext(AbstractContext):
|
||||
@property
|
||||
def py__package__(self):
|
||||
return self._value.py__package__
|
||||
|
||||
|
||||
class ClassContext(AbstractContext):
|
||||
def get_filters(self, until_position=None, origin_scope=None):
|
||||
yield self._value.get_global_filter(until_position, origin_scope)
|
||||
|
||||
def get_global_filter(self, until_position=None, origin_scope=None):
|
||||
return ParserTreeFilter(
|
||||
value=self,
|
||||
until_position=until_position,
|
||||
origin_scope=origin_scope
|
||||
)
|
||||
|
||||
@@ -157,7 +157,7 @@ def infer_trailer(context, atom_values, trailer):
|
||||
if trailer_op == '[':
|
||||
trailer_op, node, _ = trailer.children
|
||||
return atom_values.get_item(
|
||||
infer_subscript_list(context.inference_state, context, node),
|
||||
_infer_subscript_list(context, node),
|
||||
ValueualizedNode(context, trailer)
|
||||
)
|
||||
else:
|
||||
@@ -705,7 +705,7 @@ def check_tuple_assignments(valueualized_name, value_set):
|
||||
return value_set
|
||||
|
||||
|
||||
def infer_subscript_list(context, index):
|
||||
def _infer_subscript_list(context, index):
|
||||
"""
|
||||
Handles slices in subscript nodes.
|
||||
"""
|
||||
|
||||
@@ -11,6 +11,7 @@ from jedi.inference.names import SubModuleName
|
||||
from jedi.inference.helpers import values_from_qualified_names
|
||||
from jedi.inference.compiled import create_simple_object
|
||||
from jedi.inference.base_value import ValueSet
|
||||
from jedi.inference.context import ModuleContext
|
||||
|
||||
|
||||
class _ModuleAttributeName(AbstractNameDefinition):
|
||||
@@ -275,6 +276,9 @@ class ModuleValue(ModuleMixin, TreeValue):
|
||||
else:
|
||||
raise AttributeError('Only packages have __path__ attributes.')
|
||||
|
||||
def as_context(self):
|
||||
return ModuleContext(self)
|
||||
|
||||
def __repr__(self):
|
||||
return "<%s: %s@%s-%s is_stub=%s>" % (
|
||||
self.__class__.__name__, self._string_name,
|
||||
|
||||
@@ -227,7 +227,7 @@ class IntegrationTestCase(object):
|
||||
element = parser.get_root_node()
|
||||
module_context = script._get_module_context()
|
||||
user_context = get_user_context(module_context, (self.line_nr, 0))
|
||||
if user_context.api_type == 'function':
|
||||
if user_context._value.api_type == 'function':
|
||||
user_context = user_context.get_function_execution()
|
||||
element.parent = user_context.tree_node
|
||||
results = convert_values(
|
||||
|
||||
Reference in New Issue
Block a user