From 47d3aa73dcd99aeed2b0861ce6e579391de35fac Mon Sep 17 00:00:00 2001 From: Dave Halter Date: Sat, 4 Jan 2020 02:39:36 +0100 Subject: [PATCH] Disable some features for big annoying libraries like pandas, tensorflow, see #520 --- jedi/inference/dynamic_params.py | 5 ++++- jedi/inference/flow_analysis.py | 4 ++++ jedi/inference/helpers.py | 6 ++++++ jedi/inference/value/instance.py | 4 +++- 4 files changed, 17 insertions(+), 2 deletions(-) diff --git a/jedi/inference/dynamic_params.py b/jedi/inference/dynamic_params.py index e37c442e..9e82a281 100644 --- a/jedi/inference/dynamic_params.py +++ b/jedi/inference/dynamic_params.py @@ -24,7 +24,7 @@ from jedi.inference.cache import inference_state_method_cache from jedi.inference import imports from jedi.inference.arguments import TreeArguments from jedi.inference.param import get_executed_param_names -from jedi.inference.helpers import is_stdlib_path +from jedi.inference.helpers import is_stdlib_path, is_big_annoying_library from jedi.inference.utils import to_list from jedi.inference.value import instance from jedi.inference.base_value import ValueSet, NO_VALUES @@ -67,6 +67,9 @@ def dynamic_param_lookup(function_value, param_index): have to look for all calls to ``func`` to find out what ``foo`` possibly is. """ + if is_big_annoying_library(function_value.parent_context): + return NO_VALUES + funcdef = function_value.tree_node if not settings.dynamic_params: diff --git a/jedi/inference/flow_analysis.py b/jedi/inference/flow_analysis.py index 020e13c5..0e0fadf0 100644 --- a/jedi/inference/flow_analysis.py +++ b/jedi/inference/flow_analysis.py @@ -1,5 +1,6 @@ from jedi.parser_utils import get_flow_branch_keyword, is_scope, get_parent_scope from jedi.inference.recursion import execution_allowed +from jedi.inference.helpers import is_big_annoying_library class Status(object): @@ -42,6 +43,9 @@ def _get_flow_scopes(node): def reachability_check(context, value_scope, node, origin_scope=None): + if is_big_annoying_library(context): + return UNSURE + first_flow_scope = get_parent_scope(node, include_flows=True) if origin_scope is not None: origin_flow_scopes = list(_get_flow_scopes(origin_scope)) diff --git a/jedi/inference/helpers.py b/jedi/inference/helpers.py index aeefc31d..607bb0c6 100644 --- a/jedi/inference/helpers.py +++ b/jedi/inference/helpers.py @@ -261,3 +261,9 @@ def parse_dotted_names(nodes, is_import_from, until_node=None): def values_from_qualified_names(inference_state, *names): return inference_state.import_module(names[:-1]).py__getattribute__(names[-1]) + + +def is_big_annoying_library(context): + string_names = context.get_root_context().string_names + # Pandas is huge, so just ignore it, because stuff makes everything slow. + return string_names[0] in ('pandas', 'numpy', 'tensorflow', 'matplotlib') diff --git a/jedi/inference/value/instance.py b/jedi/inference/value/instance.py index 8c1d76fa..8071c20a 100644 --- a/jedi/inference/value/instance.py +++ b/jedi/inference/value/instance.py @@ -6,7 +6,7 @@ from jedi import debug from jedi import settings from jedi.inference import compiled from jedi.inference.compiled.value import CompiledObjectFilter -from jedi.inference.helpers import values_from_qualified_names +from jedi.inference.helpers import values_from_qualified_names, is_big_annoying_library from jedi.inference.filters import AbstractFilter, AnonymousFunctionExecutionFilter from jedi.inference.names import ValueName, TreeNameDefinition, ParamName, \ NameWrapper @@ -237,6 +237,8 @@ class _BaseTreeInstance(AbstractInstanceValue): # We are inversing this, because a hand-crafted `__getattribute__` # could still call another hand-crafted `__getattr__`, but not the # other way around. + if is_big_annoying_library(self.parent_context): + return NO_VALUES names = (self.get_function_slot_names(u'__getattr__') or self.get_function_slot_names(u'__getattribute__')) return self.execute_function_slots(names, name)