1
0
forked from VimPlug/jedi

Disable usage of filter_private_variable for now.

This commit is contained in:
Dave Halter
2014-10-28 17:00:12 +01:00
parent 4f2223ae7b
commit 1c09a90ac1
5 changed files with 30 additions and 25 deletions

View File

@@ -28,12 +28,12 @@ from jedi.api import classes
from jedi.api import interpreter from jedi.api import interpreter
from jedi.api import usages from jedi.api import usages
from jedi.api import helpers from jedi.api import helpers
from jedi.evaluate import Evaluator, filter_private_variable from jedi.evaluate import Evaluator
from jedi.evaluate import representation as er from jedi.evaluate import representation as er
from jedi.evaluate import compiled from jedi.evaluate import compiled
from jedi.evaluate import imports from jedi.evaluate import imports
from jedi.evaluate.helpers import FakeName, get_module_name_parts from jedi.evaluate.helpers import FakeName, get_module_name_parts
from jedi.evaluate.finder import get_names_of_scope from jedi.evaluate.finder import get_names_of_scope, filter_private_variable
from jedi.evaluate.helpers import search_call_signatures from jedi.evaluate.helpers import search_call_signatures
from jedi.evaluate import analysis from jedi.evaluate import analysis

View File

@@ -485,19 +485,3 @@ class Evaluator(object):
follow_res += self.find_types(s, search_name_part, pos, follow_res += self.find_types(s, search_name_part, pos,
search_global=search_global, is_goto=True) search_global=search_global, is_goto=True)
return follow_res return follow_res
def filter_private_variable(scope, call_scope, var_name):
"""private variables begin with a double underline `__`"""
var_name = str(var_name) # var_name could be a Name
if isinstance(var_name, (str, unicode)) and isinstance(scope, er.Instance)\
and var_name.startswith('__') and not var_name.endswith('__'):
s = call_scope.get_parent_until((pr.Class, er.Instance, compiled.CompiledObject))
if s != scope:
if isinstance(scope.base, compiled.CompiledObject):
if s != scope.base:
return True
else:
if s != scope.base.base:
return True
return False

View File

@@ -38,7 +38,7 @@ class NameFinder(object):
@debug.increase_indent @debug.increase_indent
def find(self, scopes, resolve_decorator=True, search_global=False): def find(self, scopes, resolve_decorator=True, search_global=False):
names = self.filter_name(scopes) names = self.filter_name(scopes, search_global)
types = self._names_to_types(names, resolve_decorator) types = self._names_to_types(names, resolve_decorator)
if not names and not types \ if not names and not types \
@@ -65,7 +65,7 @@ class NameFinder(object):
return iter([(self.scope, self.scope.get_magic_function_names())]) return iter([(self.scope, self.scope.get_magic_function_names())])
return self.scope.scope_names_generator(self.position) return self.scope.scope_names_generator(self.position)
def filter_name(self, scope_names_generator): def filter_name(self, scope_names_generator, search_global=False):
""" """
Filters all variables of a scope (which are defined in the Filters all variables of a scope (which are defined in the
`scope_names_generator`), until the name fits. `scope_names_generator`), until the name fits.
@@ -91,6 +91,11 @@ class NameFinder(object):
scope = stmt.parent scope = stmt.parent
if scope in break_scopes: if scope in break_scopes:
continue continue
# TODO create a working version for filtering private
# variables.
#if not search_global and filter_private_variable(self.scope, scope, name.value):
# filter_private_variable(name_list_scope, scope, name.value):
# continue
# Exclude `arr[1] =` from the result set. # Exclude `arr[1] =` from the result set.
if not self._name_is_array_assignment(name, stmt): if not self._name_is_array_assignment(name, stmt):
@@ -595,3 +600,17 @@ def find_assignments(lhs, results, seek_name):
return results return results
else: else:
return [] return []
def filter_private_variable(scope, call_scope, var_name):
"""private variables begin with a double underline `__`"""
if isinstance(scope, er.Instance) and var_name.startswith('__') and not var_name.endswith('__'):
s = call_scope.get_parent_until((pr.Class, er.Instance, compiled.CompiledObject))
if s != scope:
if isinstance(scope.base, compiled.CompiledObject):
if s != scope.base:
return True
else:
if s != scope.base.base:
return True
return False

View File

@@ -120,6 +120,8 @@ class Arguments(pr.Base):
return (self._trailer or self.argument_node).get_parent_until(pr.IsScope) return (self._trailer or self.argument_node).get_parent_until(pr.IsScope)
def eval_args(self): def eval_args(self):
# TODO this method doesn't work with named args and a lot of other
# things. Use unpack.
return [self._evaluator.eval_element(el) for stars, el in self._split()] return [self._evaluator.eval_element(el) for stars, el in self._split()]
def __repr__(self): def __repr__(self):

View File

@@ -17,6 +17,7 @@ from jedi.evaluate.helpers import FakeArray, FakeStatement
from jedi.parser import Parser from jedi.parser import Parser
from jedi.parser import representation as pr from jedi.parser import representation as pr
from jedi import debug from jedi import debug
from jedi.evaluate import precedence
class NotInStdLib(LookupError): class NotInStdLib(LookupError):
@@ -97,7 +98,7 @@ def argument_clinic(string, want_obj=False, want_scope=False):
@argument_clinic('object, name[, default], /') @argument_clinic('object, name[, default], /')
def builtins_getattr(evaluator, objects, names, defaults=None): def builtins_getattr(evaluator, objects, names, defaults=None):
# TODO rename to types # TODO rename to types
stmts = [] types = []
# follow the first param # follow the first param
for obj in objects: for obj in objects:
if not isinstance(obj, (er.Instance, er.Class, pr.Module, compiled.CompiledObject)): if not isinstance(obj, (er.Instance, er.Class, pr.Module, compiled.CompiledObject)):
@@ -105,13 +106,12 @@ def builtins_getattr(evaluator, objects, names, defaults=None):
continue continue
for name in names: for name in names:
s = unicode, str if precedence.is_string(name):
if isinstance(name, compiled.CompiledObject) and isinstance(name.obj, s): return evaluator.find_types(obj, name.obj)
stmts += evaluator.follow_path(iter([name.obj]), [obj], obj)
else: else:
debug.warning('getattr called without str') debug.warning('getattr called without str')
continue continue
return stmts return types
def builtins_type(evaluator, obj, params): def builtins_type(evaluator, obj, params):