mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-08 06:44:46 +08:00
Make API param names appear without leading double underscores, fixes #1357 again
This commit is contained in:
@@ -176,6 +176,15 @@ class ParamName(ParamNameInterface, AbstractTreeName):
|
|||||||
def _get_param_node(self):
|
def _get_param_node(self):
|
||||||
return search_ancestor(self.tree_name, 'param')
|
return search_ancestor(self.tree_name, 'param')
|
||||||
|
|
||||||
|
@property
|
||||||
|
def string_name(self):
|
||||||
|
name = self.tree_name.value
|
||||||
|
if name.startswith('__'):
|
||||||
|
# Params starting with __ are an equivalent to positional only
|
||||||
|
# variables in typeshed.
|
||||||
|
name = name[2:]
|
||||||
|
return name
|
||||||
|
|
||||||
def get_kind(self):
|
def get_kind(self):
|
||||||
tree_param = self._get_param_node()
|
tree_param = self._get_param_node()
|
||||||
if tree_param.star_count == 1: # *args
|
if tree_param.star_count == 1: # *args
|
||||||
@@ -205,12 +214,7 @@ class ParamName(ParamNameInterface, AbstractTreeName):
|
|||||||
return Parameter.POSITIONAL_OR_KEYWORD
|
return Parameter.POSITIONAL_OR_KEYWORD
|
||||||
|
|
||||||
def to_string(self):
|
def to_string(self):
|
||||||
name = self.string_name
|
output = self._kind_string() + self.string_name
|
||||||
if name.startswith('__'):
|
|
||||||
# Params starting with __ are an equivalent to positional only
|
|
||||||
# variables in typeshed.
|
|
||||||
name = name[2:]
|
|
||||||
output = self._kind_string() + name
|
|
||||||
param_node = self._get_param_node()
|
param_node = self._get_param_node()
|
||||||
if param_node.annotation is not None:
|
if param_node.annotation is not None:
|
||||||
output += ': ' + param_node.annotation.get_code(include_prefix=False)
|
output += ': ' + param_node.annotation.get_code(include_prefix=False)
|
||||||
|
|||||||
@@ -273,6 +273,13 @@ def test_int_params(Script):
|
|||||||
assert sig2.params[0].name == 'x'
|
assert sig2.params[0].name == 'x'
|
||||||
|
|
||||||
|
|
||||||
|
def test_pow_params(Script):
|
||||||
|
# See Github #1357.
|
||||||
|
for sig in Script('pow(').call_signatures():
|
||||||
|
param_names = [p.name for p in sig.params]
|
||||||
|
assert param_names in (['x', 'y'], ['x', 'y', 'z'])
|
||||||
|
|
||||||
|
|
||||||
def test_param_name(Script):
|
def test_param_name(Script):
|
||||||
sigs = Script('open(something,').call_signatures()
|
sigs = Script('open(something,').call_signatures()
|
||||||
for sig in sigs:
|
for sig in sigs:
|
||||||
|
|||||||
Reference in New Issue
Block a user