forked from VimPlug/jedi
A first working iteration of dataclass signatures, fixes #1213
This commit is contained in:
@@ -168,14 +168,34 @@ class ParamNameInterface(object):
|
||||
raise NotImplementedError
|
||||
|
||||
|
||||
class ParamName(ParamNameInterface, AbstractTreeName):
|
||||
def __init__(self, parent_context, tree_name):
|
||||
self.parent_context = parent_context
|
||||
self.tree_name = tree_name
|
||||
class BaseTreeParamName(ParamNameInterface, AbstractTreeName):
|
||||
def get_default_node(self):
|
||||
return None
|
||||
|
||||
def get_annotation_node(self):
|
||||
return None
|
||||
|
||||
def to_string(self):
|
||||
output = self._kind_string() + self.string_name
|
||||
annotation = self.get_annotation_node()
|
||||
default = self.get_default_node()
|
||||
if annotation is not None:
|
||||
output += ': ' + annotation.get_code(include_prefix=False)
|
||||
if default is not None:
|
||||
output += '=' + default.get_code(include_prefix=False)
|
||||
return output
|
||||
|
||||
|
||||
class ParamName(BaseTreeParamName):
|
||||
def _get_param_node(self):
|
||||
return search_ancestor(self.tree_name, 'param')
|
||||
|
||||
def get_annotation_node(self):
|
||||
return self._get_param_node().annotation
|
||||
|
||||
def get_default_node(self):
|
||||
return self._get_param_node().default
|
||||
|
||||
@property
|
||||
def string_name(self):
|
||||
name = self.tree_name.value
|
||||
@@ -213,15 +233,6 @@ class ParamName(ParamNameInterface, AbstractTreeName):
|
||||
param_appeared = True
|
||||
return Parameter.POSITIONAL_OR_KEYWORD
|
||||
|
||||
def to_string(self):
|
||||
output = self._kind_string() + 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