forked from VimPlug/jedi
Get rid of some potential issues when using pandas interactively
The issue was that the python_object passed in was not hashable. Since it's not used anyway and it doesn't make sense there, just ignore it. Fixes #916, #875
This commit is contained in:
@@ -101,18 +101,17 @@ class MixedObjectFilter(compiled.CompiledObjectFilter):
|
|||||||
|
|
||||||
|
|
||||||
@evaluator_function_cache()
|
@evaluator_function_cache()
|
||||||
def _load_module(evaluator, path, python_object):
|
def _load_module(evaluator, path):
|
||||||
module = evaluator.grammar.parse(
|
module_node = evaluator.grammar.parse(
|
||||||
path=path,
|
path=path,
|
||||||
cache=True,
|
cache=True,
|
||||||
diff_cache=True,
|
diff_cache=True,
|
||||||
cache_path=settings.cache_directory
|
cache_path=settings.cache_directory
|
||||||
).get_root_node()
|
).get_root_node()
|
||||||
python_module = inspect.getmodule(python_object)
|
# python_module = inspect.getmodule(python_object)
|
||||||
|
|
||||||
# TODO we should actually make something like this possible.
|
# TODO we should actually make something like this possible.
|
||||||
#evaluator.modules[python_module.__name__] = module
|
#evaluator.modules[python_module.__name__] = module_node
|
||||||
return module
|
return module_node
|
||||||
|
|
||||||
|
|
||||||
def _get_object_to_check(python_object):
|
def _get_object_to_check(python_object):
|
||||||
@@ -141,33 +140,33 @@ def _find_syntax_node_name(evaluator, access_handle):
|
|||||||
path = inspect.getsourcefile(python_object)
|
path = inspect.getsourcefile(python_object)
|
||||||
except TypeError:
|
except TypeError:
|
||||||
# The type might not be known (e.g. class_with_dict.__weakref__)
|
# The type might not be known (e.g. class_with_dict.__weakref__)
|
||||||
return None, None
|
return None, None, None
|
||||||
if path is None or not os.path.exists(path):
|
if path is None or not os.path.exists(path):
|
||||||
# The path might not exist or be e.g. <stdin>.
|
# The path might not exist or be e.g. <stdin>.
|
||||||
return None, None
|
return None, None, None
|
||||||
|
|
||||||
module = _load_module(evaluator, path, python_object)
|
module_node = _load_module(evaluator, path)
|
||||||
|
|
||||||
if inspect.ismodule(python_object):
|
if inspect.ismodule(python_object):
|
||||||
# We don't need to check names for modules, because there's not really
|
# We don't need to check names for modules, because there's not really
|
||||||
# a way to write a module in a module in Python (and also __name__ can
|
# a way to write a module in a module in Python (and also __name__ can
|
||||||
# be something like ``email.utils``).
|
# be something like ``email.utils``).
|
||||||
return module, path
|
return module_node, module_node, path
|
||||||
|
|
||||||
try:
|
try:
|
||||||
name_str = python_object.__name__
|
name_str = python_object.__name__
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
# Stuff like python_function.__code__.
|
# Stuff like python_function.__code__.
|
||||||
return None, None
|
return None, None, None
|
||||||
|
|
||||||
if name_str == '<lambda>':
|
if name_str == '<lambda>':
|
||||||
return None, None # It's too hard to find lambdas.
|
return None, None, None # It's too hard to find lambdas.
|
||||||
|
|
||||||
# Doesn't always work (e.g. os.stat_result)
|
# Doesn't always work (e.g. os.stat_result)
|
||||||
try:
|
try:
|
||||||
names = module.get_used_names()[name_str]
|
names = module_node.get_used_names()[name_str]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
return None, None
|
return None, None, None
|
||||||
names = [n for n in names if n.is_definition()]
|
names = [n for n in names if n.is_definition()]
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@@ -184,26 +183,25 @@ def _find_syntax_node_name(evaluator, access_handle):
|
|||||||
# There's a chance that the object is not available anymore, because
|
# There's a chance that the object is not available anymore, because
|
||||||
# the code has changed in the background.
|
# the code has changed in the background.
|
||||||
if line_names:
|
if line_names:
|
||||||
return line_names[-1].parent, path
|
return module_node, line_names[-1].parent, path
|
||||||
|
|
||||||
# It's really hard to actually get the right definition, here as a last
|
# It's really hard to actually get the right definition, here as a last
|
||||||
# resort we just return the last one. This chance might lead to odd
|
# resort we just return the last one. This chance might lead to odd
|
||||||
# completions at some points but will lead to mostly correct type
|
# completions at some points but will lead to mostly correct type
|
||||||
# inference, because people tend to define a public name in a module only
|
# inference, because people tend to define a public name in a module only
|
||||||
# once.
|
# once.
|
||||||
return names[-1].parent, path
|
return module_node, names[-1].parent, path
|
||||||
|
|
||||||
|
|
||||||
@compiled_objects_cache('mixed_cache')
|
@compiled_objects_cache('mixed_cache')
|
||||||
def _create(evaluator, access_handle, parent_context=None, *args):
|
def _create(evaluator, access_handle, parent_context, *args):
|
||||||
tree_node, path = _find_syntax_node_name(evaluator, access_handle)
|
module_node, tree_node, path = _find_syntax_node_name(evaluator, access_handle)
|
||||||
|
|
||||||
compiled_object = create_cached_compiled_object(
|
compiled_object = create_cached_compiled_object(
|
||||||
evaluator, access_handle, parent_context=parent_context.compiled_object)
|
evaluator, access_handle, parent_context=parent_context.compiled_object)
|
||||||
if tree_node is None:
|
if tree_node is None:
|
||||||
return compiled_object
|
return compiled_object
|
||||||
|
|
||||||
module_node = tree_node.get_root_node()
|
|
||||||
if parent_context.tree_node.get_root_node() == module_node:
|
if parent_context.tree_node.get_root_node() == module_node:
|
||||||
module_context = parent_context.get_root_context()
|
module_context = parent_context.get_root_context()
|
||||||
else:
|
else:
|
||||||
|
|||||||
Reference in New Issue
Block a user