Make API param names appear without leading double underscores, fixes #1357 again

This commit is contained in:
Dave Halter
2019-07-10 12:10:12 -07:00
parent e85fba844c
commit 670cf4d394
2 changed files with 17 additions and 6 deletions

View File

@@ -176,6 +176,15 @@ class ParamName(ParamNameInterface, AbstractTreeName):
def _get_param_node(self):
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):
tree_param = self._get_param_node()
if tree_param.star_count == 1: # *args
@@ -205,12 +214,7 @@ class ParamName(ParamNameInterface, AbstractTreeName):
return Parameter.POSITIONAL_OR_KEYWORD
def to_string(self):
name = 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
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)

View File

@@ -273,6 +273,13 @@ def test_int_params(Script):
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):
sigs = Script('open(something,').call_signatures()
for sig in sigs: