forked from VimPlug/jedi
Better signature generation
This commit is contained in:
+16
-2
@@ -122,10 +122,12 @@ class TreeNameDefinition(AbstractTreeName):
|
||||
|
||||
|
||||
class ParamNameInterface(object):
|
||||
# annotation default?!
|
||||
def get_kind(self):
|
||||
raise NotImplementedError
|
||||
|
||||
def to_string(self):
|
||||
raise NotImplementedError
|
||||
|
||||
|
||||
class ParamName(AbstractTreeName, ParamNameInterface):
|
||||
api_type = u'param'
|
||||
@@ -134,8 +136,11 @@ class ParamName(AbstractTreeName, ParamNameInterface):
|
||||
self.parent_context = parent_context
|
||||
self.tree_name = tree_name
|
||||
|
||||
def _get_param_node(self):
|
||||
return search_ancestor(self.tree_name, 'param')
|
||||
|
||||
def get_kind(self):
|
||||
tree_param = search_ancestor(self.tree_name, 'param')
|
||||
tree_param = self._get_param_node()
|
||||
if tree_param.star_count == 1: # *args
|
||||
return Parameter.VAR_POSITIONAL
|
||||
if tree_param.star_count == 2: # **kwargs
|
||||
@@ -150,6 +155,15 @@ class ParamName(AbstractTreeName, ParamNameInterface):
|
||||
break
|
||||
return Parameter.POSITIONAL_OR_KEYWORD
|
||||
|
||||
def to_string(self):
|
||||
output = self.string_name
|
||||
param_node = self._get_param_node()
|
||||
if param_node.annotation is not None:
|
||||
output += ': ' + param_node.annotation.get_code(include_prefix=False)
|
||||
if param_node.default is not None:
|
||||
output += '=' + param_node.default.get_code(include_prefix=False)
|
||||
return output
|
||||
|
||||
def infer(self):
|
||||
return self.get_param().infer()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user