diff --git a/jedi/api_classes.py b/jedi/api_classes.py index dfff964a..66d4db8c 100644 --- a/jedi/api_classes.py +++ b/jedi/api_classes.py @@ -205,7 +205,8 @@ class Completion(BaseDefinition): @property def word(self): """ - Similar to :meth:`Completion.complete`, but return the whole word, e.g. :: + Similar to :meth:`Completion.complete`, but return the whole word, for + example:: >>> isinstan @@ -235,11 +236,11 @@ class Completion(BaseDefinition): def follow_definition(self): """ Return the original definitions. I strongly recommend not using it for - your completions, because it might slow down |jedi|. If you want to read - only a few objects (<=20), it might be useful, especially to - get the original docstrings. The basic problem of this function is - that it follows all results. This means with 1000 completions (e.g. - numpy), it's just PITA-slow. + your completions, because it might slow down |jedi|. If you want to + read only a few objects (<=20), it might be useful, especially to get + the original docstrings. The basic problem of this function is that it + follows all results. This means with 1000 completions (e.g. numpy), + it's just PITA-slow. """ if self._followed_definitions is None: if self.definition.isinstance(pr.Statement): diff --git a/jedi/docstrings.py b/jedi/docstrings.py index 00da11aa..4495fc3b 100644 --- a/jedi/docstrings.py +++ b/jedi/docstrings.py @@ -18,17 +18,18 @@ import evaluate_representation as er import parsing DOCSTRING_PARAM_PATTERNS = [ - r'\s*:type\s+%s:\s*([^\n]+)', # Sphinx - r'\s*@type\s+%s:\s*([^\n]+)', # Epidoc + r'\s*:type\s+%s:\s*([^\n]+)', # Sphinx + r'\s*@type\s+%s:\s*([^\n]+)', # Epidoc ] DOCSTRING_RETURN_PATTERNS = [ - re.compile(r'\s*:rtype:\s*([^\n]+)', re.M), # Sphinx - re.compile(r'\s*@rtype:\s*([^\n]+)', re.M), # Epidoc + re.compile(r'\s*:rtype:\s*([^\n]+)', re.M), # Sphinx + re.compile(r'\s*@rtype:\s*([^\n]+)', re.M), # Epidoc ] REST_ROLE_PATTERN = re.compile(r':[^`]+:`([^`]+)`') + #@cache.memoize_default() # TODO add def follow_param(param): func = param.parent_function @@ -68,7 +69,8 @@ def search_param_in_docstr(docstr, param_str): """ # look at #40 to see definitions of those params - patterns = [ re.compile(p % re.escape(param_str)) for p in DOCSTRING_PARAM_PATTERNS ] + patterns = [re.compile(p % re.escape(param_str)) + for p in DOCSTRING_PARAM_PATTERNS] for pattern in patterns: match = pattern.search(docstr) if match: @@ -114,6 +116,7 @@ def find_return_types(func): p.user_stmt.parent = func return list(evaluate.follow_statement(p.user_stmt)) + def search_return_in_docstr(code): for p in DOCSTRING_RETURN_PATTERNS: match = p.search(code) diff --git a/jedi/fast_parser.py b/jedi/fast_parser.py index e2117e56..0c0078d3 100644 --- a/jedi/fast_parser.py +++ b/jedi/fast_parser.py @@ -16,7 +16,7 @@ import cache class Module(pr.Simple, pr.Module): def __init__(self, parsers): self._end_pos = None, None - super(Module, self).__init__(self, (1,0)) + super(Module, self).__init__(self, (1, 0)) self.parsers = parsers self.reset_caches() self.line_offset = 0 diff --git a/jedi/modules.py b/jedi/modules.py index d8cac0cb..5f33118e 100644 --- a/jedi/modules.py +++ b/jedi/modules.py @@ -373,13 +373,15 @@ def source_to_unicode(source, encoding=None): http://docs.python.org/2/reference/lexical_analysis.html#encoding-\ declarations """ - byte_mark = '\xef\xbb\xbf' if is_py25 else literal_eval(r"b'\xef\xbb\xbf'") + byte_mark = '\xef\xbb\xbf' if is_py25 else \ + literal_eval(r"b'\xef\xbb\xbf'") if source.startswith(byte_mark): # UTF-8 byte-order mark return 'utf-8' first_two_lines = re.match(r'(?:[^\n]*\n){0,2}', str(source)).group(0) - possible_encoding = re.search(r"coding[=:]\s*([-\w.]+)", first_two_lines) + possible_encoding = re.search(r"coding[=:]\s*([-\w.]+)", + first_two_lines) if possible_encoding: return possible_encoding.group(1) else: diff --git a/jedi/refactoring.py b/jedi/refactoring.py index 79c59685..d88e3f78 100644 --- a/jedi/refactoring.py +++ b/jedi/refactoring.py @@ -65,6 +65,7 @@ def _rename(names, replace_str): """ For both rename and inline. """ order = sorted(names, key=lambda x: (x.module_path, x.start_pos), reverse=True) + def process(path, old_lines, new_lines): if new_lines is not None: # goto next file, save last dct[path] = path, old_lines, new_lines @@ -130,7 +131,6 @@ def extract(script, new_name): end_line = new_lines[end_pos[0] - 1] text += '\n' + end_line[:end_pos[1]] - # remove code from new lines t = text.lstrip() del_start = start_pos[1] + len(text) - len(t) @@ -144,7 +144,7 @@ def extract(script, new_name): e = e - del_end start_line = start_line[:del_start] + new_name + start_line[e:] new_lines[start_pos[0] - 1] = start_line - new_lines[start_pos[0]:end_pos[0]-1] = [] + new_lines[start_pos[0]:end_pos[0] - 1] = [] # add parentheses in multiline case open_brackets = ['(', '[', '{'] @@ -194,7 +194,6 @@ def inline(script): if len(stmt.set_vars) == 1: line = line[:stmt.start_pos[1]] + line[stmt.end_pos[1]:] - dct = _rename(inlines, replace_str) # remove the empty line new_lines = dct[script.source_path][2] diff --git a/jedi/settings.py b/jedi/settings.py index 9e0f28c4..63c6413b 100644 --- a/jedi/settings.py +++ b/jedi/settings.py @@ -124,11 +124,13 @@ Use filesystem cache to save once parsed files with pickle. """ if platform.system().lower() == 'windows': - _cache_directory = os.path.join(os.getenv('APPDATA') or '~', 'Jedi', 'Jedi') + _cache_directory = os.path.join(os.getenv('APPDATA') or '~', 'Jedi', + 'Jedi') elif platform.system().lower() == 'darwin': _cache_directory = os.path.join('~', 'Library', 'Caches', 'Jedi') else: - _cache_directory = os.path.join(os.getenv('XDG_CACHE_HOME') or '~/.cache', 'jedi') + _cache_directory = os.path.join(os.getenv('XDG_CACHE_HOME') or '~/.cache', + 'jedi') cache_directory = os.path.expanduser(_cache_directory) """ The path where all the caches can be found.