mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-08 23:04:48 +08:00
+=, |=, etc. operators have better support now
This commit is contained in:
12
evaluate.py
12
evaluate.py
@@ -954,6 +954,7 @@ def get_scopes_for_name(scope, name_str, position=None, search_global=False):
|
|||||||
|
|
||||||
def handle_non_arrays(name):
|
def handle_non_arrays(name):
|
||||||
result = []
|
result = []
|
||||||
|
no_break_scope = False
|
||||||
if isinstance(scope, InstanceElement) \
|
if isinstance(scope, InstanceElement) \
|
||||||
and scope.var == name.parent().parent():
|
and scope.var == name.parent().parent():
|
||||||
name = InstanceElement(scope.instance, name)
|
name = InstanceElement(scope.instance, name)
|
||||||
@@ -993,13 +994,17 @@ def get_scopes_for_name(scope, name_str, position=None, search_global=False):
|
|||||||
for op, assignee in par.assignment_details:
|
for op, assignee in par.assignment_details:
|
||||||
is_exe |= is_execution(assignee)
|
is_exe |= is_execution(assignee)
|
||||||
if is_exe:
|
if is_exe:
|
||||||
|
# filter array[3] = ...
|
||||||
# TODO: check executions for dict contents
|
# TODO: check executions for dict contents
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
|
details = par.assignment_details
|
||||||
|
if details and details[0][0] != '=':
|
||||||
|
no_break_scope = True
|
||||||
result.append(par)
|
result.append(par)
|
||||||
else:
|
else:
|
||||||
result.append(par)
|
result.append(par)
|
||||||
return result
|
return result, no_break_scope
|
||||||
|
|
||||||
result = []
|
result = []
|
||||||
# compare func uses the tuple of line/indent = line/column
|
# compare func uses the tuple of line/indent = line/column
|
||||||
@@ -1013,12 +1018,13 @@ def get_scopes_for_name(scope, name_str, position=None, search_global=False):
|
|||||||
and isinstance(p.var, parsing.Class):
|
and isinstance(p.var, parsing.Class):
|
||||||
p = p.var
|
p = p.var
|
||||||
if name_str == name.get_code() and p not in break_scopes:
|
if name_str == name.get_code() and p not in break_scopes:
|
||||||
result += handle_non_arrays(name)
|
r, no_break_scope = handle_non_arrays(name)
|
||||||
|
result += r
|
||||||
# for comparison we need the raw class
|
# for comparison we need the raw class
|
||||||
s = scope.base if isinstance(scope, Class) else scope
|
s = scope.base if isinstance(scope, Class) else scope
|
||||||
# this means that a definition was found and is not e.g.
|
# this means that a definition was found and is not e.g.
|
||||||
# in if/else.
|
# in if/else.
|
||||||
if result:
|
if result and not no_break_scope:
|
||||||
if not name.parent() or p == s:
|
if not name.parent() or p == s:
|
||||||
break
|
break
|
||||||
break_scopes.append(p)
|
break_scopes.append(p)
|
||||||
|
|||||||
@@ -223,6 +223,25 @@ tuple(lst)[0]
|
|||||||
#?
|
#?
|
||||||
iter(lst)[0]
|
iter(lst)[0]
|
||||||
|
|
||||||
|
# -----------------
|
||||||
|
# complex including +=
|
||||||
|
# -----------------
|
||||||
|
class C(): pass
|
||||||
|
class D(): pass
|
||||||
|
class E(): pass
|
||||||
|
lst = [1]
|
||||||
|
lst.append(1.0)
|
||||||
|
lst += [C]
|
||||||
|
s = set(lst)
|
||||||
|
s.add("")
|
||||||
|
s += [D]
|
||||||
|
lst = list(s)
|
||||||
|
lst.append({})
|
||||||
|
lst += [E]
|
||||||
|
|
||||||
|
##? dict() int() float() str() C D E
|
||||||
|
lst[0]
|
||||||
|
|
||||||
# -----------------
|
# -----------------
|
||||||
# functions
|
# functions
|
||||||
# -----------------
|
# -----------------
|
||||||
|
|||||||
Reference in New Issue
Block a user