forked from VimPlug/jedi
Fix an issue with keyword params, fixes #1356
This commit is contained in:
@@ -412,7 +412,7 @@ class DirectObjectAccess(object):
|
||||
name=p.name,
|
||||
has_default=p.default is not p.empty,
|
||||
default=self._create_access_path(p.default),
|
||||
default_string=str(p.default),
|
||||
default_string=repr(p.default),
|
||||
has_annotation=p.annotation is not p.empty,
|
||||
annotation=self._create_access_path(p.annotation),
|
||||
annotation_string=str(p.default),
|
||||
|
||||
@@ -294,9 +294,7 @@ class CompiledName(AbstractNameDefinition):
|
||||
)])
|
||||
|
||||
|
||||
class SignatureParamName(AbstractNameDefinition, ParamNameInterface):
|
||||
api_type = u'param'
|
||||
|
||||
class SignatureParamName(ParamNameInterface, AbstractNameDefinition):
|
||||
def __init__(self, compiled_obj, signature_param):
|
||||
self.parent_context = compiled_obj.parent_context
|
||||
self._signature_param = signature_param
|
||||
@@ -306,7 +304,7 @@ class SignatureParamName(AbstractNameDefinition, ParamNameInterface):
|
||||
return self._signature_param.name
|
||||
|
||||
def to_string(self):
|
||||
s = self.string_name
|
||||
s = self._kind_string() + self.string_name
|
||||
if self._signature_param.has_annotation:
|
||||
s += ': ' + self._signature_param.annotation_string
|
||||
if self._signature_param.has_default:
|
||||
@@ -331,9 +329,7 @@ class SignatureParamName(AbstractNameDefinition, ParamNameInterface):
|
||||
return contexts
|
||||
|
||||
|
||||
class UnresolvableParamName(AbstractNameDefinition, ParamNameInterface):
|
||||
api_type = u'param'
|
||||
|
||||
class UnresolvableParamName(ParamNameInterface, AbstractNameDefinition):
|
||||
def __init__(self, compiled_obj, name, default):
|
||||
self.parent_context = compiled_obj.parent_context
|
||||
self.string_name = name
|
||||
|
||||
@@ -151,6 +151,16 @@ class TreeNameDefinition(AbstractTreeName):
|
||||
|
||||
|
||||
class ParamNameInterface(object):
|
||||
api_type = u'param'
|
||||
|
||||
def _kind_string(self):
|
||||
kind = self.get_kind()
|
||||
if kind == Parameter.VAR_POSITIONAL: # *args
|
||||
return '*'
|
||||
if kind == Parameter.VAR_KEYWORD: # **kwargs
|
||||
return '**'
|
||||
return ''
|
||||
|
||||
def get_kind(self):
|
||||
raise NotImplementedError
|
||||
|
||||
@@ -158,9 +168,7 @@ class ParamNameInterface(object):
|
||||
raise NotImplementedError
|
||||
|
||||
|
||||
class ParamName(AbstractTreeName, ParamNameInterface):
|
||||
api_type = u'param'
|
||||
|
||||
class ParamName(ParamNameInterface, AbstractTreeName):
|
||||
def __init__(self, parent_context, tree_name):
|
||||
self.parent_context = parent_context
|
||||
self.tree_name = tree_name
|
||||
@@ -185,7 +193,7 @@ class ParamName(AbstractTreeName, ParamNameInterface):
|
||||
return Parameter.POSITIONAL_OR_KEYWORD
|
||||
|
||||
def to_string(self):
|
||||
output = self.string_name
|
||||
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)
|
||||
|
||||
@@ -26,7 +26,7 @@ class AbstractSignature(object):
|
||||
is_positional = False
|
||||
|
||||
if kind == Parameter.KEYWORD_ONLY and not is_kw_only:
|
||||
yield '*'
|
||||
yield '*,'
|
||||
is_kw_only = True
|
||||
|
||||
yield n.to_string()
|
||||
|
||||
Reference in New Issue
Block a user