forked from VimPlug/jedi
Merge branch 'master' of https://github.com/johannesmik/jedi
This commit is contained in:
@@ -17,6 +17,7 @@ from jedi.evaluate import helpers
|
|||||||
from jedi.evaluate import analysis
|
from jedi.evaluate import analysis
|
||||||
from jedi.evaluate import imports
|
from jedi.evaluate import imports
|
||||||
from jedi.evaluate import arguments
|
from jedi.evaluate import arguments
|
||||||
|
from jedi.evaluate.pep0484 import _evaluate_for_annotation
|
||||||
from jedi.evaluate.context import ClassContext, FunctionContext
|
from jedi.evaluate.context import ClassContext, FunctionContext
|
||||||
from jedi.evaluate.context import iterable
|
from jedi.evaluate.context import iterable
|
||||||
from jedi.evaluate.context import TreeInstance, CompiledInstance
|
from jedi.evaluate.context import TreeInstance, CompiledInstance
|
||||||
@@ -440,6 +441,22 @@ def _remove_statements(evaluator, context, stmt, name):
|
|||||||
|
|
||||||
|
|
||||||
def tree_name_to_contexts(evaluator, context, tree_name):
|
def tree_name_to_contexts(evaluator, context, tree_name):
|
||||||
|
|
||||||
|
context_set = ContextSet()
|
||||||
|
module = context.get_root_context().tree_node
|
||||||
|
names = module.get_used_names().get(tree_name.value)
|
||||||
|
for name in names:
|
||||||
|
expr_stmt = name.parent
|
||||||
|
|
||||||
|
correct_scope = parser_utils.get_parent_scope(name) == context.tree_node
|
||||||
|
|
||||||
|
if expr_stmt.type == "expr_stmt" and expr_stmt.children[1].type == "annassign" and correct_scope:
|
||||||
|
print("found node in correct scope!", expr_stmt.children[1].children[1])
|
||||||
|
context_set |= _evaluate_for_annotation(context, expr_stmt.children[1].children[1])
|
||||||
|
|
||||||
|
if context_set:
|
||||||
|
return context_set
|
||||||
|
|
||||||
types = []
|
types = []
|
||||||
node = tree_name.get_definition(import_name_always=True)
|
node = tree_name.get_definition(import_name_always=True)
|
||||||
if node is None:
|
if node is None:
|
||||||
|
|||||||
34
test/completion/pep0484_aheadoftime.py
Normal file
34
test/completion/pep0484_aheadoftime.py
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
""" Pep-0484 type hinting with ahead of time annotations """
|
||||||
|
|
||||||
|
# python >= 3.6
|
||||||
|
|
||||||
|
somelist = [1, 2, 3, "A", "A"]
|
||||||
|
element : int
|
||||||
|
for element in somelist[0:3]:
|
||||||
|
#? int()
|
||||||
|
element
|
||||||
|
|
||||||
|
|
||||||
|
otherlist = [1, "A"]
|
||||||
|
for e in otherlist:
|
||||||
|
#? int() str()
|
||||||
|
e
|
||||||
|
|
||||||
|
|
||||||
|
test_string: str = "Hello, world!"
|
||||||
|
#? str()
|
||||||
|
test_string
|
||||||
|
|
||||||
|
|
||||||
|
char: str
|
||||||
|
for char in test_string:
|
||||||
|
#? str()
|
||||||
|
char
|
||||||
|
|
||||||
|
|
||||||
|
import numpy
|
||||||
|
somearrays = [numpy.ones((10, 10)), numpy.eye(10), 2, 2.3]
|
||||||
|
array : numpy.ndarray
|
||||||
|
for array in somearrays[0:2]:
|
||||||
|
#? numpy.ndarray()
|
||||||
|
array
|
||||||
Reference in New Issue
Block a user