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