1
0
forked from VimPlug/jedi

Param is now the parent of its names and not just a helper class.

This commit is contained in:
Dave Halter
2014-10-28 02:05:44 +01:00
parent 1a6ff3e8e6
commit fe7c750c2c
4 changed files with 34 additions and 17 deletions

View File

@@ -443,13 +443,11 @@ builtin = Builtin(_builtins)
magic_function_class = CompiledObject(type(load_module), parent=builtin) magic_function_class = CompiledObject(type(load_module), parent=builtin)
generator_obj = CompiledObject(_a_generator(1.0)) generator_obj = CompiledObject(_a_generator(1.0))
type_names = [] # Need this, because it's return in get_defined_names. type_names = [] # Need this, because it's return in get_defined_names.
#type_names = builtin.get_by_name('type').get_defined_names() type_names = builtin.get_by_name('type').get_defined_names()
#none_obj = builtin.get_by_name('None') none_obj = builtin.get_by_name('None')
#false_obj = builtin.get_by_name('False') false_obj = builtin.get_by_name('False')
#true_obj = builtin.get_by_name('True') true_obj = builtin.get_by_name('True')
#object_obj = builtin.get_by_name('object') object_obj = builtin.get_by_name('object')
true_obj = object()
false_obj = object()
def keyword_from_value(obj): def keyword_from_value(obj):

View File

@@ -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. # 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 = _unpack_var_args(evaluator, var_args, func)
unpacked_va = list(var_args.unpack()) 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)) var_arg_iterator = common.PushBackIterator(iter(unpacked_va))
non_matching_keys = defaultdict(lambda: []) non_matching_keys = defaultdict(lambda: [])

View File

@@ -162,6 +162,7 @@ class Instance(use_metaclass(CachedMetaClass, Executed)):
if pr.is_node(trailer, 'trailer') \ if pr.is_node(trailer, 'trailer') \
and len(trailer.children) == 2: and len(trailer.children) == 2:
name = trailer.children[1] # After dot. name = trailer.children[1] # After dot.
if name.is_definition():
names.append(get_instance_el(self._evaluator, self, name)) names.append(get_instance_el(self._evaluator, self, name))
for s in self.base.py__bases__(self._evaluator): for s in self.base.py__bases__(self._evaluator):

View File

@@ -748,20 +748,19 @@ class Function(ClassOrFunc):
:param start_pos: The start position (line, column) the Function. :param start_pos: The start position (line, column) the Function.
:type start_pos: tuple(int, int) :type start_pos: tuple(int, int)
""" """
__slots__ = ('decorators', 'listeners', '_params') __slots__ = ('decorators', 'listeners', 'params')
def __init__(self, children): def __init__(self, children):
super(Function, self).__init__(children) super(Function, self).__init__(children)
self.decorators = [] self.decorators = []
self.listeners = set() # not used here, but in evaluation. self.listeners = set() # not used here, but in evaluation.
self.params = self._params()
@property @property
def name(self): def name(self):
return self.children[1] # First token after `def` return self.children[1] # First token after `def`
@property def _params(self):
@cache.underscore_memoization
def params(self):
node = self.children[2].children[1:-1] # After `def foo` node = self.children[2].children[1:-1] # After `def foo`
if not node: if not node:
return [] return []
@@ -780,10 +779,10 @@ class Function(ClassOrFunc):
next(iterator, None) next(iterator, None)
else: else:
default = None default = None
params.append(Param(n, default, stars)) params.append(Param(n, self, default, stars))
return params return params
else: else:
return [Param(node[0])] return [Param(node[0], self)]
def annotation(self): def annotation(self):
try: try:
@@ -1118,6 +1117,11 @@ class Statement(Simple, DocstringMixin):
names += check_tuple(child) names += check_tuple(child)
elif is_node(current, 'atom'): elif is_node(current, 'atom'):
names += check_tuple(current.children[1]) 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: else:
names.append(current) names.append(current)
return names return names
@@ -1235,13 +1239,19 @@ class Param(Base):
A helper class for functions. Read only. A helper class for functions. Read only.
""" """
__slots__ = ('tfpdef', 'default', 'stars', 'position_nr', 'is_generated', 'annotation_stmt', __slots__ = ('tfpdef', 'default', 'stars', 'parent', 'is_generated', 'annotation_stmt')
'parent_function')
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.tfpdef = tfpdef # tfpdef: see grammar.txt
self.default = default self.default = default
self.stars = stars 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 @property
def start_pos(self): def start_pos(self):
@@ -1253,6 +1263,10 @@ class Param(Base):
else: else:
return self.tfpdef return self.tfpdef
@property
def position_nr(self):
return self.parent.params.index(self)
@property @property
def parent_function(self): def parent_function(self):
return self.get_parent_until(IsScope) return self.get_parent_until(IsScope)