mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-18 11:35:57 +08:00
Make sure a self variable is only defined in a function not outside
This commit is contained in:
@@ -331,7 +331,6 @@ class SimpleParamName(X):
|
|||||||
values = super(SimpleParamName, self).infer()
|
values = super(SimpleParamName, self).infer()
|
||||||
if values:
|
if values:
|
||||||
return values
|
return values
|
||||||
# TODO private access
|
|
||||||
from jedi.inference.dynamic_params import dynamic_param_lookup
|
from jedi.inference.dynamic_params import dynamic_param_lookup
|
||||||
param = self._get_param_node()
|
param = self._get_param_node()
|
||||||
values = dynamic_param_lookup(self.function_value, param.position_index)
|
values = dynamic_param_lookup(self.function_value, param.position_index)
|
||||||
|
|||||||
@@ -66,6 +66,7 @@ def get_executed_param_names_and_issues(function_value, arguments):
|
|||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
issues.append(None)
|
issues.append(None)
|
||||||
|
debug.warning('non-public warning: %s', m)
|
||||||
|
|
||||||
issues = [] # List[Optional[analysis issue]]
|
issues = [] # List[Optional[analysis issue]]
|
||||||
result_params = []
|
result_params = []
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
from abc import abstractproperty
|
from abc import abstractproperty
|
||||||
|
|
||||||
|
from parso.python.tree import search_ancestor
|
||||||
|
|
||||||
from jedi import debug
|
from jedi import debug
|
||||||
from jedi import settings
|
from jedi import settings
|
||||||
from jedi.inference import compiled
|
from jedi.inference import compiled
|
||||||
@@ -484,10 +486,7 @@ class SelfName(TreeNameDefinition):
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def parent_context(self):
|
def parent_context(self):
|
||||||
return self._instance.create_instance_context(
|
return self._instance.create_instance_context(self.class_context, self.tree_name)
|
||||||
self.class_context,
|
|
||||||
self.tree_name
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
class LazyInstanceClassName(object):
|
class LazyInstanceClassName(object):
|
||||||
@@ -548,9 +547,9 @@ class SelfAttributeFilter(ClassFilter):
|
|||||||
self._instance = instance
|
self._instance = instance
|
||||||
|
|
||||||
def _filter(self, names):
|
def _filter(self, names):
|
||||||
names = self._filter_self_names(names)
|
|
||||||
start, end = self._parser_scope.start_pos, self._parser_scope.end_pos
|
start, end = self._parser_scope.start_pos, self._parser_scope.end_pos
|
||||||
return [n for n in names if start < n.start_pos < end]
|
names = [n for n in names if start < n.start_pos < end]
|
||||||
|
return self._filter_self_names(names)
|
||||||
|
|
||||||
def _filter_self_names(self, names):
|
def _filter_self_names(self, names):
|
||||||
for name in names:
|
for name in names:
|
||||||
@@ -559,9 +558,20 @@ class SelfAttributeFilter(ClassFilter):
|
|||||||
and len(trailer.parent.children) == 2 \
|
and len(trailer.parent.children) == 2 \
|
||||||
and trailer.children[0] == '.':
|
and trailer.children[0] == '.':
|
||||||
if name.is_definition() and self._access_possible(name, from_instance=True):
|
if name.is_definition() and self._access_possible(name, from_instance=True):
|
||||||
# TODO filter non-self assignments.
|
# TODO filter non-self assignments instead of this bad
|
||||||
|
# filter.
|
||||||
|
if self._is_in_right_scope(name):
|
||||||
yield name
|
yield name
|
||||||
|
|
||||||
|
def _is_in_right_scope(self, name):
|
||||||
|
base = name
|
||||||
|
hit_funcdef = False
|
||||||
|
while True:
|
||||||
|
base = search_ancestor(base, 'funcdef', 'classdef', 'lambdef')
|
||||||
|
if base is self._parser_scope:
|
||||||
|
return hit_funcdef
|
||||||
|
hit_funcdef = True
|
||||||
|
|
||||||
def _convert_names(self, names):
|
def _convert_names(self, names):
|
||||||
return [SelfName(self._instance, self._node_context, name) for name in names]
|
return [SelfName(self._instance, self._node_context, name) for name in names]
|
||||||
|
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ second = 1
|
|||||||
second = ""
|
second = ""
|
||||||
class TestClass(object):
|
class TestClass(object):
|
||||||
var_class = TestClass(1)
|
var_class = TestClass(1)
|
||||||
|
self.pseudo_var = 3
|
||||||
|
|
||||||
def __init__(self2, first_param, second_param, third=1.0):
|
def __init__(self2, first_param, second_param, third=1.0):
|
||||||
self2.var_inst = first_param
|
self2.var_inst = first_param
|
||||||
@@ -85,6 +86,10 @@ TestClass.var
|
|||||||
inst.var_local
|
inst.var_local
|
||||||
#? []
|
#? []
|
||||||
TestClass.var_local.
|
TestClass.var_local.
|
||||||
|
#?
|
||||||
|
TestClass.pseudo_var
|
||||||
|
#?
|
||||||
|
TestClass().pseudo_var
|
||||||
|
|
||||||
#? int()
|
#? int()
|
||||||
TestClass().ret(1)
|
TestClass().ret(1)
|
||||||
|
|||||||
Reference in New Issue
Block a user