mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-07 22:44:27 +08:00
This also includes a rework for error recovery in the parser. This is now just possible for file_input parsing, which means for full files. Includes also a refactoring of the tokenizer. No more do we have to add an additional newline, because it now works correctly (removes certain confusion.
55 lines
1.1 KiB
Python
55 lines
1.1 KiB
Python
from textwrap import dedent
|
|
|
|
import jedi
|
|
import pytest
|
|
|
|
|
|
@pytest.mark.skipif('sys.version_info[0] < 3')
|
|
def test_simple_annotations():
|
|
"""
|
|
Annotations only exist in Python 3.
|
|
If annotations adhere to PEP-0484, we use them (they override inference),
|
|
else they are parsed but ignored
|
|
"""
|
|
|
|
source = dedent("""\
|
|
def annot(a:3):
|
|
return a
|
|
|
|
annot('')""")
|
|
|
|
assert [d.name for d in jedi.Script(source, ).goto_definitions()] == ['str']
|
|
|
|
source = dedent("""\
|
|
|
|
def annot_ret(a:3) -> 3:
|
|
return a
|
|
|
|
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']
|
|
|
|
|
|
@pytest.mark.skipif('sys.version_info[0] < 3')
|
|
@pytest.mark.parametrize('reference', [
|
|
'assert 1',
|
|
'1',
|
|
'lambda: 3',
|
|
'def x(): pass',
|
|
'1, 2',
|
|
r'1\n'
|
|
])
|
|
def test_illegal_forward_references(reference):
|
|
source = """
|
|
def foo(bar: "%s"):
|
|
bar""" % reference
|
|
|
|
assert not jedi.Script(source).goto_definitions()
|