1
0
forked from VimPlug/jedi

Ignore stdlib paths for dynamic param inference.

This commit is contained in:
Dave Halter
2017-09-07 00:09:14 +02:00
parent 8d06e9f9c9
commit d2b4e0511f
5 changed files with 29 additions and 2 deletions

View File

@@ -206,7 +206,7 @@ class CompiledObject(Context):
# Get rid of side effects, we won't call custom `__getitem__`s. # Get rid of side effects, we won't call custom `__getitem__`s.
return return
for part in self.obj: for i, part in enumerate(self.obj):
yield LazyKnownContext(create(self.evaluator, part)) yield LazyKnownContext(create(self.evaluator, part))
def py__name__(self): def py__name__(self):

View File

@@ -23,6 +23,7 @@ from jedi import debug
from jedi.evaluate.cache import evaluator_function_cache from jedi.evaluate.cache import evaluator_function_cache
from jedi.evaluate import imports from jedi.evaluate import imports
from jedi.evaluate.param import TreeArguments, create_default_param from jedi.evaluate.param import TreeArguments, create_default_param
from jedi.evaluate.helpers import is_stdlib_path
from jedi.common import to_list, unite from jedi.common import to_list, unite
from jedi.parser_utils import get_parent_scope from jedi.parser_utils import get_parent_scope
@@ -67,11 +68,20 @@ def search_params(evaluator, execution_context, funcdef):
is. is.
""" """
if not settings.dynamic_params: if not settings.dynamic_params:
return set() return []
evaluator.dynamic_params_depth += 1 evaluator.dynamic_params_depth += 1
try: try:
path = execution_context.get_root_context().py__file__()
if path is not None and is_stdlib_path(path):
# We don't want to search for usages in the stdlib. Usually people
# don't work with it (except if you are a core maintainer, sorry).
# This makes everything slower. Just disable it and run the tests,
# you will see the slowdown, especially in 3.6.
return []
debug.dbg('Dynamic param search in %s.', funcdef.name.value, color='MAGENTA') debug.dbg('Dynamic param search in %s.', funcdef.name.value, color='MAGENTA')
module_context = execution_context.get_root_context() module_context = execution_context.get_root_context()
function_executions = _search_function_executions( function_executions = _search_function_executions(
evaluator, evaluator,

View File

@@ -1,4 +1,7 @@
import copy import copy
import sys
import re
import os
from itertools import chain from itertools import chain
from contextlib import contextmanager from contextlib import contextmanager
@@ -6,6 +9,14 @@ from parso.python import tree
from jedi.parser_utils import get_parent_scope from jedi.parser_utils import get_parent_scope
def is_stdlib_path(path):
# Python standard library paths look like this:
# /usr/lib/python3.5/...
# TODO The implementation below is probably incorrect and not complete.
base_path = os.path.join(sys.prefix, 'lib', 'python')
return bool(re.match(re.escape(base_path) + '\d.\d', path))
def deep_ast_copy(obj): def deep_ast_copy(obj):
""" """
Much, much faster than copy.deepcopy, but just for parser tree nodes. Much, much faster than copy.deepcopy, but just for parser tree nodes.

View File

@@ -407,6 +407,9 @@ class ParamArguments(object):
continue continue
yield None, self.LazyParamContext(p) yield None, self.LazyParamContext(p)
def get_calling_nodes(self):
return []
class InstanceVarArgs(object): class InstanceVarArgs(object):
def __init__(self, execution_context, funcdef, var_args): def __init__(self, execution_context, funcdef, var_args):

View File

@@ -70,6 +70,9 @@ class AbstractArguments():
types = lazy_context.infer() types = lazy_context.infer()
try_iter_content(types) try_iter_content(types)
def get_calling_nodes(self):
raise NotImplementedError
class TreeArguments(AbstractArguments): class TreeArguments(AbstractArguments):
def __init__(self, evaluator, context, argument_node, trailer=None): def __init__(self, evaluator, context, argument_node, trailer=None):