mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-06 14:04:26 +08:00
Remove the word 'class' from annotation_string
Currently, 'foo(x: int)' results with annotation_string="<class 'int'>". Change this to 'int'.
This commit is contained in:
committed by
Dave Halter
parent
c4cf0d78e1
commit
1874e9be81
@@ -55,5 +55,6 @@ Max Woerner Chase (@mwchase) <max.chase@gmail.com>
|
|||||||
Johannes Maria Frank (@jmfrank63) <jmfrank63@gmail.com>
|
Johannes Maria Frank (@jmfrank63) <jmfrank63@gmail.com>
|
||||||
Shane Steinert-Threlkeld (@shanest) <ssshanest@gmail.com>
|
Shane Steinert-Threlkeld (@shanest) <ssshanest@gmail.com>
|
||||||
Tim Gates (@timgates42) <tim.gates@iress.com>
|
Tim Gates (@timgates42) <tim.gates@iress.com>
|
||||||
|
Lior Goldberg (@goldberglior)
|
||||||
|
|
||||||
Note: (@user) means a github user name.
|
Note: (@user) means a github user name.
|
||||||
|
|||||||
@@ -484,6 +484,11 @@ class DirectObjectAccess(object):
|
|||||||
def needs_type_completions(self):
|
def needs_type_completions(self):
|
||||||
return inspect.isclass(self._obj) and self._obj != type
|
return inspect.isclass(self._obj) and self._obj != type
|
||||||
|
|
||||||
|
def _annotation_to_str(self, annotation):
|
||||||
|
if isinstance(annotation, type):
|
||||||
|
return str(annotation.__name__)
|
||||||
|
return str(annotation)
|
||||||
|
|
||||||
def get_signature_params(self):
|
def get_signature_params(self):
|
||||||
return [
|
return [
|
||||||
SignatureParam(
|
SignatureParam(
|
||||||
@@ -493,7 +498,7 @@ class DirectObjectAccess(object):
|
|||||||
default_string=repr(p.default),
|
default_string=repr(p.default),
|
||||||
has_annotation=p.annotation is not p.empty,
|
has_annotation=p.annotation is not p.empty,
|
||||||
annotation=self._create_access_path(p.annotation),
|
annotation=self._create_access_path(p.annotation),
|
||||||
annotation_string=str(p.annotation),
|
annotation_string=self._annotation_to_str(p.annotation),
|
||||||
kind_name=str(p.kind)
|
kind_name=str(p.kind)
|
||||||
) for p in self._get_signature().parameters.values()
|
) for p in self._get_signature().parameters.values()
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -342,7 +342,7 @@ def test_completion_params():
|
|||||||
|
|
||||||
@pytest.mark.skipif('py_version < 33', reason='inspect.signature was created in 3.3.')
|
@pytest.mark.skipif('py_version < 33', reason='inspect.signature was created in 3.3.')
|
||||||
def test_completion_param_annotations():
|
def test_completion_param_annotations():
|
||||||
# Need to define this function not directly in Python. Otherwise Jedi is to
|
# Need to define this function not directly in Python. Otherwise Jedi is too
|
||||||
# clever and uses the Python code instead of the signature object.
|
# clever and uses the Python code instead of the signature object.
|
||||||
code = 'def foo(a: 1, b: str, c: int = 1.0) -> bytes: pass'
|
code = 'def foo(a: 1, b: str, c: int = 1.0) -> bytes: pass'
|
||||||
exec_(code, locals())
|
exec_(code, locals())
|
||||||
@@ -354,6 +354,10 @@ def test_completion_param_annotations():
|
|||||||
assert [d.name for d in b.infer()] == ['str']
|
assert [d.name for d in b.infer()] == ['str']
|
||||||
assert {d.name for d in c.infer()} == {'int', 'float'}
|
assert {d.name for d in c.infer()} == {'int', 'float'}
|
||||||
|
|
||||||
|
assert a.description == 'param a: 1'
|
||||||
|
assert b.description == 'param b: str'
|
||||||
|
assert c.description == 'param c: int=1.0'
|
||||||
|
|
||||||
d, = jedi.Interpreter('foo()', [locals()]).infer()
|
d, = jedi.Interpreter('foo()', [locals()]).infer()
|
||||||
assert d.name == 'bytes'
|
assert d.name == 'bytes'
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user