1
0
forked from VimPlug/jedi

Revert "Use __str__ instead of to_string"

This reverts commit 1151700114.
This commit is contained in:
Dave Halter
2019-07-31 18:39:17 +02:00
parent 7d2374ed81
commit a5a544cb09
5 changed files with 15 additions and 17 deletions

View File

@@ -531,7 +531,7 @@ class Definition(BaseDefinition):
typ = self.type typ = self.type
tree_name = self._name.tree_name tree_name = self._name.tree_name
if typ == 'param': if typ == 'param':
return typ + ' ' + str(self._name) return typ + ' ' + self._name.to_string()
if typ in ('function', 'class', 'module', 'instance') or tree_name is None: if typ in ('function', 'class', 'module', 'instance') or tree_name is None:
if typ == 'function': if typ == 'function':
# For the description we want a short and a pythonic way. # For the description we want a short and a pythonic way.
@@ -633,13 +633,14 @@ class CallSignature(Definition):
return '<%s: index=%r %s>' % ( return '<%s: index=%r %s>' % (
type(self).__name__, type(self).__name__,
self.index, self.index,
self._signature, self._signature.to_string(),
) )
def _format_signatures(context): def _format_signatures(context):
return '\n'.join( return '\n'.join(
str(signature) for signature in context.get_signatures() signature.to_string()
for signature in context.get_signatures()
) )

View File

@@ -309,7 +309,7 @@ class SignatureParamName(ParamNameInterface, AbstractNameDefinition):
def string_name(self): def string_name(self):
return self._signature_param.name return self._signature_param.name
def __str__(self): def to_string(self):
s = self._kind_string() + self.string_name s = self._kind_string() + self.string_name
if self._signature_param.has_annotation: if self._signature_param.has_annotation:
s += ': ' + self._signature_param.annotation_string s += ': ' + self._signature_param.annotation_string
@@ -341,7 +341,7 @@ class UnresolvableParamName(ParamNameInterface, AbstractNameDefinition):
def get_kind(self): def get_kind(self):
return Parameter.POSITIONAL_ONLY return Parameter.POSITIONAL_ONLY
def __str__(self): def to_string(self):
string = self.string_name string = self.string_name
if self._default: if self._default:
string += '=' + self._default string += '=' + self._default

View File

@@ -178,7 +178,7 @@ class ParamNameInterface(_ParamMixin):
def get_kind(self): def get_kind(self):
raise NotImplementedError raise NotImplementedError
def __str__(self): def to_string(self):
raise NotImplementedError raise NotImplementedError
def get_param(self): def get_param(self):
@@ -201,7 +201,7 @@ class BaseTreeParamName(ParamNameInterface, AbstractTreeName):
annotation_node = None annotation_node = None
default_node = None default_node = None
def __str__(self): def to_string(self):
output = self._kind_string() + self.string_name output = self._kind_string() + self.string_name
annotation = self.annotation_node annotation = self.annotation_node
default = self.default_node default = self.default_node
@@ -277,9 +277,6 @@ class ParamNameWrapper(_ParamMixin):
def __getattr__(self, name): def __getattr__(self, name):
return getattr(self._wrapped_param_name, name) return getattr(self._wrapped_param_name, name)
def __str__(self):
return str(self._wrapped_param_name)
def __repr__(self): def __repr__(self):
return '<%s: %s>' % (self.__class__.__name__, self._wrapped_param_name) return '<%s: %s>' % (self.__class__.__name__, self._wrapped_param_name)

View File

@@ -2,7 +2,7 @@ from jedi._compatibility import Parameter
class _SignatureMixin(object): class _SignatureMixin(object):
def __str__(self): def to_string(self):
def param_strings(): def param_strings():
is_positional = False is_positional = False
is_kw_only = False is_kw_only = False
@@ -19,7 +19,7 @@ class _SignatureMixin(object):
yield '*' yield '*'
is_kw_only = True is_kw_only = True
yield str(n) yield n.to_string()
if is_positional: if is_positional:
yield '/' yield '/'

View File

@@ -33,7 +33,7 @@ def test_compiled_signature(Script, environment, code, sig, names, op, version):
context, = d._name.infer() context, = d._name.infer()
compiled, = _stub_to_python_context_set(context) compiled, = _stub_to_python_context_set(context)
signature, = compiled.get_signatures() signature, = compiled.get_signatures()
assert str(signature) == sig assert signature.to_string() == sig
assert [n.string_name for n in signature.get_param_names()] == names assert [n.string_name for n in signature.get_param_names()] == names
@@ -90,7 +90,7 @@ def test_tree_signature(Script, environment, code, expected):
assert not Script(code).call_signatures() assert not Script(code).call_signatures()
else: else:
sig, = Script(code).call_signatures() sig, = Script(code).call_signatures()
assert expected == str(sig._signature) assert expected == sig._signature.to_string()
@pytest.mark.parametrize( @pytest.mark.parametrize(
@@ -180,7 +180,7 @@ def test_nested_signatures(Script, environment, combination, expected, skip_pre_
''') ''')
code += 'z = ' + combination + '\nz(' code += 'z = ' + combination + '\nz('
sig, = Script(code).call_signatures() sig, = Script(code).call_signatures()
computed = str(sig._signature) computed = sig._signature.to_string()
if not re.match('\w+\(', expected): if not re.match('\w+\(', expected):
expected = '<lambda>(' + expected + ')' expected = '<lambda>(' + expected + ')'
assert expected == computed assert expected == computed
@@ -189,7 +189,7 @@ def test_nested_signatures(Script, environment, combination, expected, skip_pre_
def test_pow_signature(Script): def test_pow_signature(Script):
# See github #1357 # See github #1357
sigs = Script('pow(').call_signatures() sigs = Script('pow(').call_signatures()
strings = {str(sig._signature) for sig in sigs} strings = {sig._signature.to_string() for sig in sigs}
assert strings == {'pow(x: float, y: float, z: float, /) -> float', assert strings == {'pow(x: float, y: float, z: float, /) -> float',
'pow(x: float, y: float, /) -> float', 'pow(x: float, y: float, /) -> float',
'pow(x: int, y: int, z: int, /) -> Any', 'pow(x: int, y: int, z: int, /) -> Any',
@@ -228,7 +228,7 @@ def test_pow_signature(Script):
) )
def test_wraps_signature(Script, code, signature, skip_pre_python35): def test_wraps_signature(Script, code, signature, skip_pre_python35):
sigs = Script(code).call_signatures() sigs = Script(code).call_signatures()
assert {str(sig._signature) for sig in sigs} == {signature} assert {sig._signature.to_string() for sig in sigs} == {signature}
@pytest.mark.parametrize( @pytest.mark.parametrize(