diff --git a/jedi/evaluate/__init__.py b/jedi/evaluate/__init__.py index ce46c4da..a5b5b5ff 100644 --- a/jedi/evaluate/__init__.py +++ b/jedi/evaluate/__init__.py @@ -77,6 +77,7 @@ from jedi.evaluate import compiled from jedi.evaluate import precedence from jedi.evaluate import param from jedi.evaluate import helpers +from jedi.evaluate import pep0484 from jedi.evaluate.filters import TreeNameDefinition, ParamName from jedi.evaluate.instance import AnonymousInstance, BoundMethod @@ -152,7 +153,7 @@ class Evaluator(object): types = finder.check_tuple_assignments(self, types, seek_name) first_operation = stmt.first_operation() - if first_operation not in ('=', None): + if first_operation not in ('=', None) and first_operation.type == 'operator': # `=` is always the last character in aug assignments -> -1 operator = copy.copy(first_operation) operator.value = operator.value[:-1] @@ -315,6 +316,10 @@ class Evaluator(object): types = types elif element.type == 'eval_input': types = self._eval_element_not_cached(context, element.children[0]) + elif element.type == 'annassign': + print(element.children[1]) + types = pep0484._evaluate_for_annotation(context, element.children[1]) + print('xxx') else: types = precedence.calculate_children(self, context, element.children) debug.dbg('eval_element result %s', types) diff --git a/jedi/parser/tree.py b/jedi/parser/tree.py index 8dc84cd4..da00dc16 100644 --- a/jedi/parser/tree.py +++ b/jedi/parser/tree.py @@ -1531,9 +1531,14 @@ class ExprStmt(BaseNode, DocstringMixin): __slots__ = () def get_defined_names(self): - return list(chain.from_iterable(_defined_names(self.children[i]) - for i in range(0, len(self.children) - 2, 2) - if '=' in self.children[i + 1].value)) + names = [] + if self.children[1].type == 'annassign': + names = _defined_names(self.children[0]) + return list(chain.from_iterable( + _defined_names(self.children[i]) + for i in range(0, len(self.children) - 2, 2) + if '=' in self.children[i + 1].value) + ) + names def get_rhs(self): """Returns the right-hand-side of the equals.""" diff --git a/test/completion/pep0526_variables.py b/test/completion/pep0526_variables.py new file mode 100644 index 00000000..24b681da --- /dev/null +++ b/test/completion/pep0526_variables.py @@ -0,0 +1,22 @@ +""" +PEP 526 introduced a new way of using type annotations on variables. It was +introduced in Python 3.6. +""" +# python >= 3.6 + +import typing + +asdf = '' +asdf: int +# This is not necessarily correct, but for now this is ok (at least no error). +#? int() +asdf + + +direct: int = NOT_DEFINED +#? int() +direct + +with_typing_module: typing.List[float] = NOT_DEFINED +#? float() +with_typing_module[0]