forked from VimPlug/jedi
seperate parser and testing code
This commit is contained in:
@@ -13,6 +13,7 @@ x Local variable type hints
|
||||
x Assigned types: `Url = str\ndef get(url:Url) -> str:`
|
||||
x Type hints in `with` statements
|
||||
x Stub files support
|
||||
x support `@no_type_check` and `@no_type_check_decorator`
|
||||
"""
|
||||
|
||||
from itertools import chain
|
||||
@@ -22,12 +23,9 @@ from jedi.evaluate.cache import memoize_default
|
||||
|
||||
@memoize_default(None, evaluator_is_first_arg=True)
|
||||
def follow_param(evaluator, param):
|
||||
# annotation is in param.children[0] if present
|
||||
# either this firstchild is a Name (if no annotation is present) or a Node
|
||||
if hasattr(param.children[0], "children"):
|
||||
assert len(param.children[0].children) == 3 and \
|
||||
param.children[0].children[1] == ":"
|
||||
definitions = evaluator.eval_element(param.children[0].children[2])
|
||||
annotation = param.annotation()
|
||||
if annotation:
|
||||
definitions = evaluator.eval_element(annotation)
|
||||
return list(chain.from_iterable(
|
||||
evaluator.execute(d) for d in definitions))
|
||||
else:
|
||||
|
||||
@@ -1403,8 +1403,13 @@ class Param(BaseNode):
|
||||
return None
|
||||
|
||||
def annotation(self):
|
||||
# Generate from tfpdef.
|
||||
raise NotImplementedError
|
||||
tfpdef = self._tfpdef()
|
||||
if is_node(tfpdef, 'tfpdef'):
|
||||
assert tfpdef.children[1] == ":"
|
||||
assert len(tfpdef.children) == 3
|
||||
return tfpdef.children[2]
|
||||
else:
|
||||
return None
|
||||
|
||||
def _tfpdef(self):
|
||||
"""
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
""" Pep-0484 type hinting """
|
||||
|
||||
# -----------------
|
||||
# sphinx style
|
||||
# simple classes
|
||||
# -----------------
|
||||
def typehints(a, b: str, c: int, d:int = 4):
|
||||
#?
|
||||
|
||||
|
||||
def typehints(a, b: str, c: int, d: int=4):
|
||||
#?
|
||||
a
|
||||
#? str()
|
||||
b
|
||||
|
||||
@@ -8,8 +8,8 @@ import pytest
|
||||
def test_simple_annotations():
|
||||
"""
|
||||
Annotations only exist in Python 3.
|
||||
At the moment we ignore them. So they should be parsed and not interfere
|
||||
with anything.
|
||||
If annotations adhere to PEP-0484, we use them (they override inference),
|
||||
else they are parsed but ignored
|
||||
"""
|
||||
|
||||
source = dedent("""\
|
||||
@@ -27,3 +27,11 @@ def test_simple_annotations():
|
||||
|
||||
annot_ret('')""")
|
||||
assert [d.name for d in jedi.Script(source, ).goto_definitions()] == ['str']
|
||||
|
||||
source = dedent("""\
|
||||
def annot(a:int):
|
||||
return a
|
||||
|
||||
annot('')""")
|
||||
|
||||
assert [d.name for d in jedi.Script(source, ).goto_definitions()] == ['int']
|
||||
|
||||
Reference in New Issue
Block a user