mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-06 14:04:26 +08:00
Try to make qualified_names access clearer
This commit is contained in:
@@ -38,7 +38,7 @@ class LambdaName(AbstractNameDefinition):
|
||||
return ContextSet([self._lambda_context])
|
||||
|
||||
|
||||
class FunctionAndClassMixin(object):
|
||||
class FunctionAndClassBase(TreeContext):
|
||||
def get_qualified_names(self):
|
||||
if self.parent_context.is_class():
|
||||
n = self.parent_context.get_qualified_names()
|
||||
@@ -51,11 +51,8 @@ class FunctionAndClassMixin(object):
|
||||
else:
|
||||
return None
|
||||
|
||||
def py__name__(self):
|
||||
return self.name.string_name
|
||||
|
||||
|
||||
class FunctionMixin(FunctionAndClassMixin):
|
||||
class FunctionMixin(object):
|
||||
api_type = u'function'
|
||||
|
||||
def get_filters(self, search_global=False, until_position=None, origin_scope=None):
|
||||
@@ -89,6 +86,9 @@ class FunctionMixin(FunctionAndClassMixin):
|
||||
return LambdaName(self)
|
||||
return ContextName(self, self.tree_node.name)
|
||||
|
||||
def py__name__(self):
|
||||
return self.name.string_name
|
||||
|
||||
def py__call__(self, arguments):
|
||||
function_execution = self.get_function_execution(arguments)
|
||||
return function_execution.infer()
|
||||
@@ -100,7 +100,7 @@ class FunctionMixin(FunctionAndClassMixin):
|
||||
return FunctionExecutionContext(self.evaluator, self.parent_context, self, arguments)
|
||||
|
||||
|
||||
class FunctionContext(use_metaclass(CachedMetaClass, FunctionMixin, TreeContext)):
|
||||
class FunctionContext(use_metaclass(CachedMetaClass, FunctionMixin, FunctionAndClassBase)):
|
||||
"""
|
||||
Needed because of decorators. Decorators are evaluated here.
|
||||
"""
|
||||
|
||||
@@ -47,8 +47,8 @@ from jedi.evaluate.filters import ParserTreeFilter
|
||||
from jedi.evaluate.names import TreeNameDefinition, ContextName
|
||||
from jedi.evaluate.arguments import unpack_arglist
|
||||
from jedi.evaluate.base_context import ContextSet, iterator_to_context_set, \
|
||||
TreeContext, NO_CONTEXTS
|
||||
from jedi.evaluate.context.function import FunctionAndClassMixin
|
||||
NO_CONTEXTS
|
||||
from jedi.evaluate.context.function import FunctionAndClassBase
|
||||
|
||||
|
||||
def apply_py__get__(context, instance, class_context):
|
||||
@@ -118,7 +118,7 @@ class ClassFilter(ParserTreeFilter):
|
||||
return [name for name in names if self._access_possible(name)]
|
||||
|
||||
|
||||
class ClassMixin(FunctionAndClassMixin):
|
||||
class ClassMixin(object):
|
||||
def is_class(self):
|
||||
return True
|
||||
|
||||
@@ -133,6 +133,9 @@ class ClassMixin(FunctionAndClassMixin):
|
||||
def name(self):
|
||||
return ContextName(self, self.tree_node.name)
|
||||
|
||||
def py__name__(self):
|
||||
return self.name.string_name
|
||||
|
||||
def get_param_names(self):
|
||||
for context_ in self.py__getattribute__(u'__init__'):
|
||||
if context_.is_function():
|
||||
@@ -199,7 +202,7 @@ class ClassMixin(FunctionAndClassMixin):
|
||||
yield next(type_.get_filters())
|
||||
|
||||
|
||||
class ClassContext(use_metaclass(CachedMetaClass, ClassMixin, TreeContext)):
|
||||
class ClassContext(use_metaclass(CachedMetaClass, ClassMixin, FunctionAndClassBase)):
|
||||
"""
|
||||
This class is not only important to extend `tree.Class`, it is also a
|
||||
important for descriptors (if the descriptor methods are evaluated or not).
|
||||
|
||||
@@ -13,11 +13,17 @@ from jedi.evaluate.gradual.conversion import stub_to_actual_context_set
|
||||
|
||||
('pow', 'pow(x, y, z=None) -> number', ['x', 'y', 'z'], lt, (3, 5)),
|
||||
('pow', 'pow(x, y, z=None, /)', ['x', 'y', 'z'], ge, (3, 5)),
|
||||
|
||||
('bytes.partition', 'partition(self, sep) -> (head, sep, tail)', ['self', 'sep'], lt, (3, 5)),
|
||||
('bytes.partition', 'partition(self, sep, /)', ['self', 'sep'], ge, (3, 5)),
|
||||
|
||||
('bytes().partition', 'partition(sep) -> (head, sep, tail)', ['sep'], lt, (3, 5)),
|
||||
('bytes().partition', 'partition(sep, /)', ['sep'], ge, (3, 5)),
|
||||
]
|
||||
)
|
||||
def test_compiled_signature(Script, environment, code, sig, names, op, version):
|
||||
if not op(environment.version_info, version):
|
||||
pytest.skip("Not running for this version")
|
||||
return # The test right next to it should take over.
|
||||
|
||||
d, = Script(code).goto_definitions()
|
||||
context, = d._name.infer()
|
||||
|
||||
Reference in New Issue
Block a user