Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ad563ee

Browse files
Costa HuangDonJayamanne
Costa Huang
authored andcommitted
Add PEP 526 AutoCompletion (DonJayamanne#1102)
By following instructions similar to this link: davidhalter/jedi@3f09f3a It is now possible to give autocompletion for variable declared in the following fashion: test: str = "PEP 562 Support" Related issues can be found here: https://github.com/DonJayamanne/pythonVSCode/issues/1101
1 parent e1a9c55 commit ad563ee

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

pythonFiles/preview/jedi/evaluate/__init__.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ def eval_statement(self, stmt, seek_name=None):
162162
types = finder.check_tuple_assignments(self, types, seek_name)
163163

164164
first_operation = stmt.first_operation()
165-
if first_operation not in ('=', None) and not isinstance(stmt, er.InstanceElement): # TODO don't check for this.
165+
if first_operation not in ('=', None) and not isinstance(stmt, er.InstanceElement) and first_operation.type == 'operator': # TODO don't check for this.
166166
# `=` is always the last character in aug assignments -> -1
167167
operator = copy.copy(first_operation)
168168
operator.value = operator.value[:-1]
@@ -327,6 +327,8 @@ def _eval_element_not_cached(self, element):
327327
types = types
328328
elif element.type == 'eval_input':
329329
types = self._eval_element_not_cached(element.children[0])
330+
elif element.type == 'annassign':
331+
types = self.eval_element(element.children[1])
330332
else:
331333
types = precedence.calculate_children(self, element.children)
332334
debug.dbg('eval_element result %s', types)

pythonFiles/preview/jedi/parser/tree.py

+8-3
Original file line numberDiff line numberDiff line change
@@ -1522,9 +1522,14 @@ class ExprStmt(BaseNode, DocstringMixin):
15221522
__slots__ = ()
15231523

15241524
def get_defined_names(self):
1525-
return list(chain.from_iterable(_defined_names(self.children[i])
1526-
for i in range(0, len(self.children) - 2, 2)
1527-
if '=' in self.children[i + 1].value))
1525+
names = []
1526+
if self.children[1].type == 'annassign':
1527+
names = _defined_names(self.children[0])
1528+
return list(chain.from_iterable(
1529+
_defined_names(self.children[i])
1530+
for i in range(0, len(self.children) - 2, 2)
1531+
if '=' in self.children[i + 1].value)
1532+
) + names
15281533

15291534
def get_rhs(self):
15301535
"""Returns the right-hand-side of the equals."""

0 commit comments

Comments
 (0)