forked from VimPlug/jedi
Param is now the parent of its names and not just a helper class.
This commit is contained in:
@@ -443,13 +443,11 @@ builtin = Builtin(_builtins)
|
||||
magic_function_class = CompiledObject(type(load_module), parent=builtin)
|
||||
generator_obj = CompiledObject(_a_generator(1.0))
|
||||
type_names = [] # Need this, because it's return in get_defined_names.
|
||||
#type_names = builtin.get_by_name('type').get_defined_names()
|
||||
#none_obj = builtin.get_by_name('None')
|
||||
#false_obj = builtin.get_by_name('False')
|
||||
#true_obj = builtin.get_by_name('True')
|
||||
#object_obj = builtin.get_by_name('object')
|
||||
true_obj = object()
|
||||
false_obj = object()
|
||||
type_names = builtin.get_by_name('type').get_defined_names()
|
||||
none_obj = builtin.get_by_name('None')
|
||||
false_obj = builtin.get_by_name('False')
|
||||
true_obj = builtin.get_by_name('True')
|
||||
object_obj = builtin.get_by_name('object')
|
||||
|
||||
|
||||
def keyword_from_value(obj):
|
||||
|
||||
@@ -167,6 +167,10 @@ def get_params(evaluator, func, var_args):
|
||||
# There may be calls, which don't fit all the params, this just ignores it.
|
||||
#unpacked_va = _unpack_var_args(evaluator, var_args, func)
|
||||
unpacked_va = list(var_args.unpack())
|
||||
from jedi.evaluate.representation import InstanceElement
|
||||
if isinstance(func, InstanceElement):
|
||||
# Include self at this place.
|
||||
unpacked_va.insert(0, (None, [func.instance]))
|
||||
var_arg_iterator = common.PushBackIterator(iter(unpacked_va))
|
||||
|
||||
non_matching_keys = defaultdict(lambda: [])
|
||||
|
||||
@@ -162,7 +162,8 @@ class Instance(use_metaclass(CachedMetaClass, Executed)):
|
||||
if pr.is_node(trailer, 'trailer') \
|
||||
and len(trailer.children) == 2:
|
||||
name = trailer.children[1] # After dot.
|
||||
names.append(get_instance_el(self._evaluator, self, name))
|
||||
if name.is_definition():
|
||||
names.append(get_instance_el(self._evaluator, self, name))
|
||||
|
||||
for s in self.base.py__bases__(self._evaluator):
|
||||
if not isinstance(s, compiled.CompiledObject):
|
||||
|
||||
@@ -748,20 +748,19 @@ class Function(ClassOrFunc):
|
||||
:param start_pos: The start position (line, column) the Function.
|
||||
:type start_pos: tuple(int, int)
|
||||
"""
|
||||
__slots__ = ('decorators', 'listeners', '_params')
|
||||
__slots__ = ('decorators', 'listeners', 'params')
|
||||
|
||||
def __init__(self, children):
|
||||
super(Function, self).__init__(children)
|
||||
self.decorators = []
|
||||
self.listeners = set() # not used here, but in evaluation.
|
||||
self.params = self._params()
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
return self.children[1] # First token after `def`
|
||||
|
||||
@property
|
||||
@cache.underscore_memoization
|
||||
def params(self):
|
||||
def _params(self):
|
||||
node = self.children[2].children[1:-1] # After `def foo`
|
||||
if not node:
|
||||
return []
|
||||
@@ -780,10 +779,10 @@ class Function(ClassOrFunc):
|
||||
next(iterator, None)
|
||||
else:
|
||||
default = None
|
||||
params.append(Param(n, default, stars))
|
||||
params.append(Param(n, self, default, stars))
|
||||
return params
|
||||
else:
|
||||
return [Param(node[0])]
|
||||
return [Param(node[0], self)]
|
||||
|
||||
def annotation(self):
|
||||
try:
|
||||
@@ -1118,6 +1117,11 @@ class Statement(Simple, DocstringMixin):
|
||||
names += check_tuple(child)
|
||||
elif is_node(current, 'atom'):
|
||||
names += check_tuple(current.children[1])
|
||||
elif is_node(current, 'power'):
|
||||
if current.children[-2] != '**': # Just if there's no operation
|
||||
trailer = current.children[-1]
|
||||
if trailer.children[0] == '.':
|
||||
names.append(trailer.children[1])
|
||||
else:
|
||||
names.append(current)
|
||||
return names
|
||||
@@ -1235,13 +1239,19 @@ class Param(Base):
|
||||
|
||||
A helper class for functions. Read only.
|
||||
"""
|
||||
__slots__ = ('tfpdef', 'default', 'stars', 'position_nr', 'is_generated', 'annotation_stmt',
|
||||
'parent_function')
|
||||
__slots__ = ('tfpdef', 'default', 'stars', 'parent', 'is_generated', 'annotation_stmt')
|
||||
|
||||
def __init__(self, tfpdef, default=None, stars=0):
|
||||
def __init__(self, tfpdef, parent, default=None, stars=0):
|
||||
self.tfpdef = tfpdef # tfpdef: see grammar.txt
|
||||
self.default = default
|
||||
self.stars = stars
|
||||
self.parent = parent
|
||||
# Here we reset the parent of our name. IMHO this is ok.
|
||||
self.get_name().parent = self
|
||||
|
||||
@property
|
||||
def children(self):
|
||||
return []
|
||||
|
||||
@property
|
||||
def start_pos(self):
|
||||
@@ -1253,6 +1263,10 @@ class Param(Base):
|
||||
else:
|
||||
return self.tfpdef
|
||||
|
||||
@property
|
||||
def position_nr(self):
|
||||
return self.parent.params.index(self)
|
||||
|
||||
@property
|
||||
def parent_function(self):
|
||||
return self.get_parent_until(IsScope)
|
||||
|
||||
Reference in New Issue
Block a user