forked from VimPlug/jedi
Move common to evaluate.utils.
This commit is contained in:
@@ -11,7 +11,7 @@ from parso.python.tree import search_ancestor
|
|||||||
|
|
||||||
from jedi._compatibility import u
|
from jedi._compatibility import u
|
||||||
from jedi import settings
|
from jedi import settings
|
||||||
from jedi import common
|
from jedi.evaluate.utils import ignored, unite
|
||||||
from jedi.cache import memoize_method
|
from jedi.cache import memoize_method
|
||||||
from jedi.evaluate import representation as er
|
from jedi.evaluate import representation as er
|
||||||
from jedi.evaluate import instance
|
from jedi.evaluate import instance
|
||||||
@@ -311,7 +311,7 @@ class BaseDefinition(object):
|
|||||||
if not path:
|
if not path:
|
||||||
return None # for keywords the path is empty
|
return None # for keywords the path is empty
|
||||||
|
|
||||||
with common.ignored(KeyError):
|
with ignored(KeyError):
|
||||||
path[0] = self._mapping[path[0]]
|
path[0] = self._mapping[path[0]]
|
||||||
for key, repl in self._tuple_mapping.items():
|
for key, repl in self._tuple_mapping.items():
|
||||||
if tuple(path[:len(key)]) == key:
|
if tuple(path[:len(key)]) == key:
|
||||||
@@ -588,7 +588,7 @@ class Definition(BaseDefinition):
|
|||||||
"""
|
"""
|
||||||
defs = self._name.infer()
|
defs = self._name.infer()
|
||||||
return sorted(
|
return sorted(
|
||||||
common.unite(defined_names(self._evaluator, d) for d in defs),
|
unite(defined_names(self._evaluator, d) for d in defs),
|
||||||
key=lambda s: s._name.start_pos or (0, 0)
|
key=lambda s: s._name.start_pos or (0, 0)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import pydoc
|
|||||||
import keyword
|
import keyword
|
||||||
|
|
||||||
from jedi._compatibility import is_py3, is_py35
|
from jedi._compatibility import is_py3, is_py35
|
||||||
from jedi import common
|
from jedi.evaluate.utils import ignored
|
||||||
from jedi.evaluate.filters import AbstractNameDefinition
|
from jedi.evaluate.filters import AbstractNameDefinition
|
||||||
from parso.python.tree import Leaf
|
from parso.python.tree import Leaf
|
||||||
|
|
||||||
@@ -123,7 +123,7 @@ def imitate_pydoc(string):
|
|||||||
# with unicode strings)
|
# with unicode strings)
|
||||||
string = str(string)
|
string = str(string)
|
||||||
h = pydoc.help
|
h = pydoc.help
|
||||||
with common.ignored(KeyError):
|
with ignored(KeyError):
|
||||||
# try to access symbols
|
# try to access symbols
|
||||||
string = h.symbols[string]
|
string = h.symbols[string]
|
||||||
string, _, related = string.partition(' ')
|
string, _, related = string.partition(' ')
|
||||||
|
|||||||
@@ -67,7 +67,7 @@ from parso.python import tree
|
|||||||
import parso
|
import parso
|
||||||
|
|
||||||
from jedi import debug
|
from jedi import debug
|
||||||
from jedi.common import unite
|
from jedi.evaluate.utils import unite
|
||||||
from jedi.evaluate import representation as er
|
from jedi.evaluate import representation as er
|
||||||
from jedi.evaluate import imports
|
from jedi.evaluate import imports
|
||||||
from jedi.evaluate import recursion
|
from jedi.evaluate import recursion
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
from jedi._compatibility import Python3Method
|
from jedi._compatibility import Python3Method
|
||||||
from jedi.common import unite
|
from jedi.evaluate.utils import unite
|
||||||
from parso.python.tree import ExprStmt, CompFor
|
from parso.python.tree import ExprStmt, CompFor
|
||||||
from jedi.parser_utils import clean_scope_docstring, get_doc_with_call_signature
|
from jedi.parser_utils import clean_scope_docstring, get_doc_with_call_signature
|
||||||
|
|
||||||
|
|||||||
@@ -21,10 +21,9 @@ from textwrap import dedent
|
|||||||
from parso import parse
|
from parso import parse
|
||||||
|
|
||||||
from jedi._compatibility import u
|
from jedi._compatibility import u
|
||||||
from jedi.common import unite
|
from jedi.evaluate.utils import unite, indent_block
|
||||||
from jedi.evaluate import context
|
from jedi.evaluate import context
|
||||||
from jedi.evaluate.cache import evaluator_method_cache
|
from jedi.evaluate.cache import evaluator_method_cache
|
||||||
from jedi.common import indent_block
|
|
||||||
from jedi.evaluate.iterable import SequenceLiteralContext, FakeSequence
|
from jedi.evaluate.iterable import SequenceLiteralContext, FakeSequence
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ 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_params
|
from jedi.evaluate.param import TreeArguments, create_default_params
|
||||||
from jedi.evaluate.helpers import is_stdlib_path
|
from jedi.evaluate.helpers import is_stdlib_path
|
||||||
from jedi.common import to_list, unite
|
from jedi.evaluate.utils import to_list, unite
|
||||||
from jedi.parser_utils import get_parent_scope
|
from jedi.parser_utils import get_parent_scope
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ from abc import abstractmethod
|
|||||||
|
|
||||||
from parso.tree import search_ancestor
|
from parso.tree import search_ancestor
|
||||||
from jedi.evaluate import flow_analysis
|
from jedi.evaluate import flow_analysis
|
||||||
from jedi.common import to_list, unite
|
from jedi.evaluate.utils import to_list, unite
|
||||||
from jedi.parser_utils import get_parent_scope
|
from jedi.parser_utils import get_parent_scope
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ check for -> a is a string). There's big potential in these checks.
|
|||||||
from parso.python import tree
|
from parso.python import tree
|
||||||
from parso.tree import search_ancestor
|
from parso.tree import search_ancestor
|
||||||
from jedi import debug
|
from jedi import debug
|
||||||
from jedi.common import unite
|
from jedi.evaluate.utils import unite
|
||||||
from jedi import settings
|
from jedi import settings
|
||||||
from jedi.evaluate import representation as er
|
from jedi.evaluate import representation as er
|
||||||
from jedi.evaluate.instance import AbstractInstanceContext
|
from jedi.evaluate.instance import AbstractInstanceContext
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ from parso import python_bytes_to_unicode
|
|||||||
from jedi._compatibility import find_module, unicode, ImplicitNSInfo
|
from jedi._compatibility import find_module, unicode, ImplicitNSInfo
|
||||||
from jedi import debug
|
from jedi import debug
|
||||||
from jedi import settings
|
from jedi import settings
|
||||||
from jedi.common import unite
|
from jedi.evaluate.utils import unite
|
||||||
from jedi.evaluate import sys_path
|
from jedi.evaluate import sys_path
|
||||||
from jedi.evaluate import helpers
|
from jedi.evaluate import helpers
|
||||||
from jedi.evaluate import compiled
|
from jedi.evaluate import compiled
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
from abc import abstractproperty
|
from abc import abstractproperty
|
||||||
|
|
||||||
from jedi._compatibility import is_py3
|
from jedi._compatibility import is_py3
|
||||||
from jedi.common import unite
|
from jedi.evaluate.utils import unite
|
||||||
from jedi import debug
|
from jedi import debug
|
||||||
from jedi.evaluate import compiled
|
from jedi.evaluate import compiled
|
||||||
from jedi.evaluate import filters
|
from jedi.evaluate import filters
|
||||||
|
|||||||
@@ -22,9 +22,9 @@ It is important to note that:
|
|||||||
"""
|
"""
|
||||||
from jedi import debug
|
from jedi import debug
|
||||||
from jedi import settings
|
from jedi import settings
|
||||||
from jedi import common
|
from jedi.evaluate.utils import unite, safe_property
|
||||||
from jedi.common import unite, safe_property
|
|
||||||
from jedi._compatibility import unicode, zip_longest, is_py3
|
from jedi._compatibility import unicode, zip_longest, is_py3
|
||||||
|
from jedi.evaluate.utils import to_list
|
||||||
from jedi.evaluate import compiled
|
from jedi.evaluate import compiled
|
||||||
from jedi.evaluate import helpers
|
from jedi.evaluate import helpers
|
||||||
from jedi.evaluate import analysis
|
from jedi.evaluate import analysis
|
||||||
@@ -262,7 +262,7 @@ class Comprehension(AbstractSequence):
|
|||||||
yield iterated
|
yield iterated
|
||||||
|
|
||||||
@evaluator_method_cache(default=[])
|
@evaluator_method_cache(default=[])
|
||||||
@common.to_list
|
@to_list
|
||||||
def _iterate(self):
|
def _iterate(self):
|
||||||
comp_fors = tuple(get_comp_fors(self._get_comp_for()))
|
comp_fors = tuple(get_comp_fors(self._get_comp_for()))
|
||||||
for result in self._nested(comp_fors):
|
for result in self._nested(comp_fors):
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ from collections import defaultdict
|
|||||||
|
|
||||||
from jedi._compatibility import zip_longest
|
from jedi._compatibility import zip_longest
|
||||||
from jedi import debug
|
from jedi import debug
|
||||||
from jedi import common
|
from jedi.evaluate.utils import PushBackIterator
|
||||||
from parso.python import tree
|
from parso.python import tree
|
||||||
from jedi.evaluate import iterable
|
from jedi.evaluate import iterable
|
||||||
from jedi.evaluate import analysis
|
from jedi.evaluate import analysis
|
||||||
@@ -258,7 +258,7 @@ def get_params(execution_context, var_args):
|
|||||||
for param in funcdef.get_params():
|
for param in funcdef.get_params():
|
||||||
param_dict[param.name.value] = param
|
param_dict[param.name.value] = param
|
||||||
unpacked_va = list(var_args.unpack(funcdef))
|
unpacked_va = list(var_args.unpack(funcdef))
|
||||||
var_arg_iterator = common.PushBackIterator(iter(unpacked_va))
|
var_arg_iterator = PushBackIterator(iter(unpacked_va))
|
||||||
|
|
||||||
non_matching_keys = defaultdict(lambda: [])
|
non_matching_keys = defaultdict(lambda: [])
|
||||||
keys_used = {}
|
keys_used = {}
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ import re
|
|||||||
from parso import ParserSyntaxError
|
from parso import ParserSyntaxError
|
||||||
from parso.python import tree
|
from parso.python import tree
|
||||||
|
|
||||||
from jedi.common import unite
|
from jedi.evaluate.utils import unite
|
||||||
from jedi.evaluate.cache import evaluator_method_cache
|
from jedi.evaluate.cache import evaluator_method_cache
|
||||||
from jedi.evaluate import compiled
|
from jedi.evaluate import compiled
|
||||||
from jedi.evaluate.context import LazyTreeContext
|
from jedi.evaluate.context import LazyTreeContext
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ compiled module that returns the types for C-builtins.
|
|||||||
import collections
|
import collections
|
||||||
import re
|
import re
|
||||||
|
|
||||||
from jedi.common import unite
|
from jedi.evaluate.utils import unite
|
||||||
from jedi.evaluate import compiled
|
from jedi.evaluate import compiled
|
||||||
from jedi.evaluate import representation as er
|
from jedi.evaluate import representation as er
|
||||||
from jedi.evaluate.instance import InstanceFunctionExecution, \
|
from jedi.evaluate.instance import InstanceFunctionExecution, \
|
||||||
|
|||||||
@@ -10,13 +10,13 @@ from jedi.evaluate.compiled import CompiledObject
|
|||||||
from jedi.evaluate.context import ContextualizedNode
|
from jedi.evaluate.context import ContextualizedNode
|
||||||
from jedi import settings
|
from jedi import settings
|
||||||
from jedi import debug
|
from jedi import debug
|
||||||
from jedi import common
|
from jedi.evaluate.utils import ignored
|
||||||
|
|
||||||
|
|
||||||
def get_venv_path(venv):
|
def get_venv_path(venv):
|
||||||
"""Get sys.path for specified virtual environment."""
|
"""Get sys.path for specified virtual environment."""
|
||||||
sys_path = _get_venv_path_dirs(venv)
|
sys_path = _get_venv_path_dirs(venv)
|
||||||
with common.ignored(ValueError):
|
with ignored(ValueError):
|
||||||
sys_path.remove('')
|
sys_path.remove('')
|
||||||
sys_path = _get_sys_path_with_egglinks(sys_path)
|
sys_path = _get_sys_path_with_egglinks(sys_path)
|
||||||
# As of now, get_venv_path_dirs does not scan built-in pythonpath and
|
# As of now, get_venv_path_dirs does not scan built-in pythonpath and
|
||||||
@@ -194,7 +194,7 @@ def sys_path_with_modifications(evaluator, module_context):
|
|||||||
|
|
||||||
curdir = os.path.abspath(os.curdir)
|
curdir = os.path.abspath(os.curdir)
|
||||||
#TODO why do we need a chdir?
|
#TODO why do we need a chdir?
|
||||||
with common.ignored(OSError):
|
with ignored(OSError):
|
||||||
os.chdir(os.path.dirname(path))
|
os.chdir(os.path.dirname(path))
|
||||||
|
|
||||||
buildout_script_paths = set()
|
buildout_script_paths = set()
|
||||||
@@ -246,7 +246,7 @@ def _detect_django_path(module_path):
|
|||||||
result = []
|
result = []
|
||||||
|
|
||||||
for parent in traverse_parents(module_path):
|
for parent in traverse_parents(module_path):
|
||||||
with common.ignored(IOError):
|
with ignored(IOError):
|
||||||
with open(parent + os.path.sep + 'manage.py'):
|
with open(parent + os.path.sep + 'manage.py'):
|
||||||
debug.dbg('Found django path: %s', module_path)
|
debug.dbg('Found django path: %s', module_path)
|
||||||
result.append(parent)
|
result.append(parent)
|
||||||
|
|||||||
@@ -4,7 +4,17 @@ import contextlib
|
|||||||
import functools
|
import functools
|
||||||
|
|
||||||
from jedi._compatibility import reraise
|
from jedi._compatibility import reraise
|
||||||
from jedi import settings
|
|
||||||
|
|
||||||
|
def to_list(func):
|
||||||
|
def wrapper(*args, **kwargs):
|
||||||
|
return list(func(*args, **kwargs))
|
||||||
|
return wrapper
|
||||||
|
|
||||||
|
|
||||||
|
def unite(iterable):
|
||||||
|
"""Turns a two dimensional array into a one dimensional."""
|
||||||
|
return set(typ for types in iterable for typ in types)
|
||||||
|
|
||||||
|
|
||||||
class UncaughtAttributeError(Exception):
|
class UncaughtAttributeError(Exception):
|
||||||
@@ -78,16 +88,6 @@ class PushBackIterator(object):
|
|||||||
return self.current
|
return self.current
|
||||||
|
|
||||||
|
|
||||||
def indent_block(text, indention=' '):
|
|
||||||
"""This function indents a text block with a default of four spaces."""
|
|
||||||
temp = ''
|
|
||||||
while text and text[-1] == '\n':
|
|
||||||
temp += text[-1]
|
|
||||||
text = text[:-1]
|
|
||||||
lines = text.split('\n')
|
|
||||||
return '\n'.join(map(lambda s: indention + s, lines)) + temp
|
|
||||||
|
|
||||||
|
|
||||||
@contextlib.contextmanager
|
@contextlib.contextmanager
|
||||||
def ignored(*exceptions):
|
def ignored(*exceptions):
|
||||||
"""
|
"""
|
||||||
@@ -100,12 +100,11 @@ def ignored(*exceptions):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
def unite(iterable):
|
def indent_block(text, indention=' '):
|
||||||
"""Turns a two dimensional array into a one dimensional."""
|
"""This function indents a text block with a default of four spaces."""
|
||||||
return set(typ for types in iterable for typ in types)
|
temp = ''
|
||||||
|
while text and text[-1] == '\n':
|
||||||
|
temp += text[-1]
|
||||||
def to_list(func):
|
text = text[:-1]
|
||||||
def wrapper(*args, **kwargs):
|
lines = text.split('\n')
|
||||||
return list(func(*args, **kwargs))
|
return '\n'.join(map(lambda s: indention + s, lines)) + temp
|
||||||
return wrapper
|
|
||||||
@@ -14,7 +14,6 @@ following functions (sometimes bug-prone):
|
|||||||
"""
|
"""
|
||||||
import difflib
|
import difflib
|
||||||
|
|
||||||
from jedi import common
|
|
||||||
from parso import python_bytes_to_unicode, split_lines
|
from parso import python_bytes_to_unicode, split_lines
|
||||||
from jedi.evaluate import helpers
|
from jedi.evaluate import helpers
|
||||||
|
|
||||||
@@ -165,7 +164,6 @@ def inline(script):
|
|||||||
dct = {}
|
dct = {}
|
||||||
|
|
||||||
definitions = script.goto_assignments()
|
definitions = script.goto_assignments()
|
||||||
with common.ignored(AssertionError):
|
|
||||||
assert len(definitions) == 1
|
assert len(definitions) == 1
|
||||||
stmt = definitions[0]._definition
|
stmt = definitions[0]._definition
|
||||||
usages = script.usages()
|
usages = script.usages()
|
||||||
|
|||||||
Reference in New Issue
Block a user